#!/usr/bin/env python3 """Compare a native Chromium event log with a Wine Access publisher event log. Usage: compare_events.py NATIVE.events.txt PUBLISHER.events.txt Exits 0 when the logs match after the documented normalizations, 1 otherwise. """ import difflib import re import sys # Each rule: (reason, predicate or rewrite) applied to both logs. DROPPED = [ ("atk-bridge reports objects defunct when it drops its temporary references; native Chromium shows " "the same on objects that stay in place, so these say nothing about presentation", re.compile(r"^object:state-changed:defunct ")), ("native Chromium has browser UI (address bar, navigation buttons) that an Electron window does not", re.compile(r" src=(entry:Address and search bar|button:(Back|Forward|Reload|Home))\b")), ] REWRITES = [ ("the removed child is described after removal, so its role depends on timing; the event itself matters", re.compile(r"^(object:children-changed:remove .*) data=.*$"), r"\1 data="), ] def normalize(path): lines = [] with open(path, encoding="utf-8") as logFile: for line in logFile.read().splitlines(): if any(pattern.search(line) for _reason, pattern in DROPPED): continue for _reason, pattern, replacement in REWRITES: line = pattern.sub(replacement, line) lines.append(line) return lines def main(): if len(sys.argv) != 3: print(__doc__) return 2 nativeLines = normalize(sys.argv[1]) publisherLines = normalize(sys.argv[2]) if sum(1 for line in nativeLines if line.startswith("STEP")) == 0: print("The native log has no steps") return 1 difference = list(difflib.unified_diff(nativeLines, publisherLines, "native", "publisher", lineterm="")) if difference: print("\n".join(difference)) print("MISMATCH") return 1 events = sum(1 for line in nativeLines if not line.startswith("STEP")) print(f"MATCH ({events} events after allowed differences)") return 0 if __name__ == "__main__": sys.exit(main())