from cbb_refresh_verify.post_verify_diagnostics import build_snapshot, invoke_with_evidence def test_invoke_evidence_distinguishes_entering_from_returning(): events = [] def invoke(): assert events == [{'stage': 'verify_invoke', 'lm_pid': 100}] invoke_with_evidence(invoke, events.append, {'lm_pid': 100}) assert events == [ {'stage': 'verify_invoke', 'lm_pid': 100}, {'stage': 'verify_invoke_returned', 'lm_pid': 100}, ] def test_invoke_failure_does_not_claim_returned(): events = [] def invoke(): raise RuntimeError('COM invocation failed') try: invoke_with_evidence(invoke, events.append, {'lm_pid': 100}) except RuntimeError: pass assert events == [{'stage': 'verify_invoke', 'lm_pid': 100}] def test_snapshot_records_preexisting_and_rejected_pcb_processes(): processes = [ (20, 'ExpeditionPCB.exe', r'D:\Mentor\wg\ExpeditionPCB.exe', r'D:\Mentor\wg\ExpeditionPCB.exe "F:\library\target.pcb" -ReusableCircuit'), (21, 'exppcb.exe', r'D:\Mentor\wg\exppcb.exe', r'D:\Mentor\wg\exppcb.exe "F:\library\target.pcb"'), (22, 'ExpeditionPCB.exe', r'D:\Mentor\wg\ExpeditionPCB.exe', r'D:\Mentor\wg\ExpeditionPCB.exe "F:\library\target.pcb" -ReusableCircuit'), ] snapshot = build_snapshot(processes, [], r'F:\library\target.pcb', {20}) assert [(p['pid'], p['preexisting'], p['matches_current_filter']) for p in snapshot['processes']] == [ (20, True, True), (21, False, False), (22, False, True), ] def test_snapshot_keeps_lm_modal_details_without_changing_windows(): modal = {'pid': 100, 'hwnd': 9, 'class_name': '#32770', 'title': 'Confirm Verify', 'texts': ['OK', 'Cancel']} snapshot = build_snapshot([], [modal], r'F:\library\target.pcb', set()) assert snapshot['windows'] == [modal]