"""Exercise the real Qt button and native verifier on a fresh local fixture copy. Run with PYTHONPATH=src. No verifier/reader stubs or synthetic errors are used. The source library is fingerprinted before and after the run. """ from pathlib import Path import hashlib import json import shutil import time from PySide6.QtCore import QTimer, Qt from PySide6.QtTest import QTest from PySide6.QtWidgets import QApplication, QMessageBox from cbb_refresh_verify.application import configure_qt_application from cbb_refresh_verify.ui.main_window import MainWindow def fingerprint(root): result = {} for path in root.rglob('*'): if path.is_symlink() or path.is_junction(): raise ValueError('Test source contains links') if path.is_file(): with path.open('rb') as stream: result[str(path.relative_to(root))] = hashlib.file_digest(stream, 'sha256').hexdigest() return result def main(): base = Path(__file__).resolve().parents[1] source = base/'diagnostics/icdb-auto-recovery-20261027/verify-library' root = base/'diagnostics/icdb-button-live-20261028' root.mkdir(parents=True, exist_ok=False) before = fingerprint(source) (root/'source-before.json').write_text(json.dumps(before), encoding='utf-8') library = root/'library' shutil.copytree(source, library) app = QApplication([]) configure_qt_application(app) window = MainWindow(data_root=root/'data') window.resize(1060, 820) window.show() window.libspec_edit.clear() window.dms_edit.clear() window.lmc_edit.setText(str(library/'mentor_lib.lmc')) state = {'phase': 'loading', 'started': time.monotonic()} def event(record): if record.get('stage') in {'icdb_check_start', 'native_repair_start', 'PASS', 'FAIL', 'BLOCKED', 'TIMEOUT'}: print(json.dumps(record, ensure_ascii=True), flush=True) window.signals.event.connect(event) def tick(): for widget in app.topLevelWidgets(): if isinstance(widget, QMessageBox) and widget.isVisible() and widget.windowTitle() == '全库 ICDB 检查与修复': widget.grab().save(str(root/'confirmation.png')) state['confirmation'] = widget.text() QTest.mouseClick(widget.button(QMessageBox.Yes), Qt.LeftButton) if state['phase'] == 'loading' and not window.busy: if not window.loaded_path: state.update(phase='load_failed', detail=window.status_label.text()) finish() return state.update(phase='running', rows=window.cbb_table.rowCount(), ready_before=len(window.ready_names), preflight_skipped=len(window.skipped_names)) window.grab().save(str(root/'loaded.png')) QTimer.singleShot(0, lambda: QTest.mouseClick(window.icdb_repair_button, Qt.LeftButton)) elif state['phase'] == 'running' and not window.busy and hasattr(window, 'summary'): state.update(phase='finished', detail=window.status_label.text(), ready_after=len(window.ready_names)) window.grab().save(str(root/'finished.png')) window.summary.grab().save(str(root/'summary.png')) finish() elif time.monotonic()-state['started'] > 900 and not window.stop.is_set(): window.request_stop() def finish(): timer.stop() after = fingerprint(source) state.update(source_unchanged=before == after, source_file_count=len(before), elapsed_seconds=time.monotonic()-state['started']) (root/'outcome.json').write_text(json.dumps(state, ensure_ascii=False, indent=2), encoding='utf-8') print(json.dumps(state, ensure_ascii=True), flush=True) if hasattr(window, 'summary'): window.summary.close() window.close() app.quit() timer = QTimer() timer.setInterval(100) timer.timeout.connect(tick) window.load_library() timer.start() app.exec() if __name__ == '__main__': main()