KB-620C

fold packet — verify_fold.py

3 min read Revision 1
tool-kiem-thucanonical-foldpacket

#!/usr/bin/env python3

Self-contained gate: verifies the fold safety facts from packet artifacts. exit 0 = PASS.

import json,sys,os d=os.path.dirname(os.path.abspath(file)) def L(n): return json.load(open(os.path.join(d,n))) fail=[] rsm=L("range-source-map.json"); coc=L("collision-orphan-check.json") post=L("post-fold-snapshot.json"); rb=L("rollback-evidence.json")

1 contiguity/coverage

ids=[] for r in rsm["ranges"]: a,b=[int(x) for x in r["range"].split("..")]; ids+=list(range(a,b+1)) ids=sorted(ids) if ids!=list(range(225,442)): fail.append("G1 coverage 225..441") if len(set(ids))!=217: fail.append("G1b distinct 217")

2 safety verdict

if coc["verdict"]!="SAFE": fail.append("G2 verdict") for key in ("gaps","extra_outside_range","internal_duplicates","inter_range_overlaps","collision_with_canonical_body","orphan_ids_no_source","inter_range_adjacency_gaps"): if coc.get(key): fail.append(f"G2:{key} nonempty")

3 every source readable

if not all(r["readable"] for r in rsm["ranges"]): fail.append("G3 readable")

4 baseline max 224

if coc["canonical_body_max_before"]!=224: fail.append("G4 baseline max")

5 post-fold byte-exact + valid + 217

if not all(post["byte_exact_vs_locally_built_fold"].values()): fail.append("G5 byte-exact") if not post["json_valid"]: fail.append("G5 json valid") if post["folded_object_count"]!=217: fail.append("G5 count")

6 old content preserved

op=post["old_content_preserved"] if not (op["top_level_keys_only_added_one"] and op["all_ids_le_224_present"] and op["objects_array_count"]==92): fail.append("G6 preserved")

7 rollback proven

if not rb["all_reversible"]: fail.append("G7 rollback")

8 no-exec boundaries asserted

print("GATE LEDGER:") print(" G1 coverage 225..441 (217 ids):", "PASS" if "G1 coverage 225..441" not in fail and "G1b distinct 217" not in fail else "FAIL") print(" G2 collision/orphan/gap SAFE:", "PASS" if coc["verdict"]=="SAFE" and not any(f.startswith('G2') for f in fail) else "FAIL") print(" G3 every source readable:", "PASS" if "G3 readable" not in fail else "FAIL") print(" G4 baseline body-max 224:", "PASS" if "G4 baseline max" not in fail else "FAIL") print(" G5 post-fold byte-exact + valid JSON + 217:", "PASS" if not any(f.startswith('G5') for f in fail) else "FAIL") print(" G6 old content preserved:", "PASS" if "G6 preserved" not in fail else "FAIL") print(" G7 rollback proven reversible:", "PASS" if "G7 rollback" not in fail else "FAIL") if fail: print("OVERALL: FAIL ->",fail); sys.exit(1) print("OVERALL: PASS"); sys.exit(0)

Back to Knowledge Hub knowledge/dev/reports/architecture/tkt-canonical-governance-fold-225-441-packet-2026-06-11/verify_fold.py