from cbb_refresh_verify.dialog_models import ( ControlSnapshot, DialogPhase, WindowSnapshot, stable_fingerprint, ) def snapshot(*, hwnd=10, pid=20, text="Elapsed time 11 C:\\A\\x.pcb", control_types=("Button",)): controls = tuple( ControlSnapshot( handle=100 + index, control_id=index + 1, class_name=control_type, name=text if index == 0 else control_type, control_type=control_type, ) for index, control_type in enumerate(control_types) ) return WindowSnapshot( hwnd=hwnd, pid=pid, process_name="ExpeditionPCB.exe", process_role="pcb", window_class="#32770", title="Expedition PCB", phase=DialogPhase.PROJECT_INTEGRATION, controls=controls, ) def test_fingerprint_ignores_handle_pid_paths_and_elapsed_numbers(): first = snapshot(hwnd=10, pid=20, text="Elapsed time 11 C:\\A\\x.pcb") second = snapshot(hwnd=99, pid=77, text="Elapsed time 42 D:\\B\\y.pcb") assert stable_fingerprint(first) == stable_fingerprint(second) def test_fingerprint_changes_for_control_shape(): assert stable_fingerprint(snapshot(control_types=("Button",))) != stable_fingerprint( snapshot(control_types=("Button", "List")) ) def test_snapshot_json_round_trip_preserves_original_evidence(): original = snapshot(text="数据库恢复 C:\\Work\\A.pcb") restored = WindowSnapshot.from_record(original.to_record()) assert restored == original assert restored.controls[0].name == "数据库恢复 C:\\Work\\A.pcb"