"""Narrow documentation/transport correction checks; no original suite reruns.""" import ast import difflib import json from recover import HERE, ROOT, sha, write OLD_DOCS = ROOT / "docs/hel-892/batch179-target-snapshots" def read(name): return json.loads((HERE / name).read_text()) def json_differences(old, new, pointer=""): if isinstance(old, dict) and isinstance(new, dict): rows = [] for key in sorted(old.keys() | new.keys()): path = pointer + "/" + key.replace("~", "~0").replace("/", "~1") if key not in old or key not in new: rows.append( dict( pointer=path, old_present=key in old, new_present=key in new, old=old.get(key), new=new.get(key), ) ) else: rows.extend(json_differences(old[key], new[key], path)) return rows return [] if old == new else [dict(pointer=pointer, old=old, new=new)] def main(): baseline = read("baseline.json") allowed = set(baseline["allowed_changes"]) changed = [] for row in baseline["files"]: path = ROOT / row["path"] assert path.is_file() current_sha = sha(path.read_bytes()) if current_sha != row["sha256"]: assert row["path"] in allowed, row["path"] original = next(r for r in read("original-files.json") if r["path"] == row["path"]) raw = (ROOT / original["archive_path"]).read_bytes() assert sha(raw) == original["sha256"] == row["sha256"] changed.append( dict( path=row["path"], original_archive=original["archive_path"], old_sha256=row["sha256"], new_sha256=current_sha, old_bytes=len(raw), new_bytes=path.stat().st_size, ) ) assert {r["path"] for r in changed} == allowed diffs = [] for row in changed: old = (ROOT / row["original_archive"]).read_text() new = (ROOT / row["path"]).read_text() diffs.append( dict( path=row["path"], unified_diff="".join( difflib.unified_diff( old.splitlines(keepends=True), new.splitlines(keepends=True), fromfile="original/" + row["path"], tofile="current/" + row["path"], ) ), ) ) write("file-differences.json", diffs) old_plan = read("original-files/next-step-plan.json") plan = json.loads((OLD_DOCS / "next-step-plan.json").read_text()) selection = read("selection-fact.json") assert plan["selected_installation"] == selection["selected_installation"] == "/media/ComfyUI" assert plan["selection_source_comment_id"] == selection["source_comment"]["id"] assert plan["selection_confirmed"] is True and plan["loaded_or_started_verified"] is False assert plan["executed"] is False and plan["new_upstream_reads_now"] is False assert plan["new_target_reads_now"] is False and plan["phase180"] is False assert "historical comparison only" in plan["second_installation_scope"] assert plan["historical_roots"] == old_plan["roots"] for name in ("README.md", "离线安装比对说明.md"): text = (OLD_DOCS / name).read_text() assert selection["source_comment"]["id"] in text assert "8010b48" in text and "先确认平时启动哪套" not in text for name in ("离线安装比对说明.md", "next-step-plan.json"): assert (OLD_DOCS / name).read_bytes() == ( ROOT / ".local-evidence/batch179-correction/report-preview" / name ).read_bytes() write("plan-field-differences.json", json_differences(old_plan, plan)) supplement = read("log-supplement-index.json") for entry in supplement["additions"]: log = entry["original_record_log"] raw = (HERE / entry["preserved_file"]).read_bytes() assert len(raw) == log["bytes"] and sha(raw) == log["sha256"] assert raw == (ROOT / entry["original_path"]).read_bytes() assert supplement["original_streams_now_accounted"] == 40 for row in read("old-local-artifacts.json")["files"]: path = ROOT / row["path"] assert path.stat().st_size == row["bytes"] and sha(path.read_bytes()) == row["sha256"] assert path.stat().st_mtime_ns == row["observed_mtime_ns"] for path in [*HERE.glob("*.py"), OLD_DOCS / "report.py"]: ast.parse(path.read_text()) write( "verification.json", dict( baseline_files=len(baseline["files"]), frozen_nonrelated_files=len(baseline["files"]) - len(changed), allowed_modified_files=changed, unexpected_modified_files=[], original_log_streams_supplied=2, original_streams_accounted=40, original_command_count=20, original_commands_rerun=0, original_11_contracts_rerun=False, current_documents_consistent=True, generator_output_equal=True, source_data_and_qualification_unchanged=True, target_requests=0, new_upstream_reads=0, tools_ast=True, ), ) print( "four allowed files changed; all other old bytes frozen; " "original missing streams verified; no old tests rerun" ) if __name__ == "__main__": main()