Files
felhom.eu/scripts/test_hub_copy_drift.py
T
admin 7ee00d59a8 R-325 (felhom.eu half): hub_copy_gate accepts the controller gate importing the shared stem list
Once retrieval_promise_gate.py imports customer_copy_vocab and drops its STEMS literal, the drift
check reads "ok — single source" instead of failing on the missing literal. An import only in a
comment, or beside a stale literal, is still drift. Pinned by scripts/test_hub_copy_drift.py.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0159rPz1ZhFKsS53msqPYxtS
2026-10-05 21:45:04 +02:00

44 lines
1.9 KiB
Python

#!/usr/bin/env python3
"""R-325: hub_copy_gate.check_drift accepts the controller gate IMPORTING the shared stem list.
Cases: a matching literal (ok), a diverged literal (drift), the import with no literal (ok — the
destination), an import that exists only in a comment (drift — the label without the fact), an import
beside a stale literal (drift), and an absent file (inconclusive, never a pass).
Run: python3 scripts/test_hub_copy_drift.py
"""
import os
import sys
import tempfile
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
import hub_copy_gate as g # noqa: E402
from customer_copy_vocab import RETRIEVAL_STEMS # noqa: E402
lit = "STEMS = [%s]\n" % ", ".join('"%s"' % x for x in RETRIEVAL_STEMS)
imp = "sys.path.insert(0, VOCAB_DIR)\nfrom customer_copy_vocab import RETRIEVAL_STEMS as STEMS # noqa\n"
CASES = [
("matching-literal", "import re\n" + lit, "ok"),
("diverged-literal", "import re\nSTEMS = [\"visszaallithat\"]\n", "drift"),
("imports-shared", "import re\n" + imp, "ok"),
("import-in-comment-only", "import re\n# from customer_copy_vocab import RETRIEVAL_STEMS\n", "drift"),
("import-beside-stale-literal", imp + "STEMS = [\"x\"]\n", "drift"),
]
fails = 0
tmp = tempfile.mkdtemp(prefix="r325-")
for name, body, want in CASES:
p = os.path.join(tmp, name + ".py")
with open(p, "w", encoding="utf-8") as f:
f.write(body)
got, msg = g.check_drift(p)
ok = got == want
fails += not ok
print(" %s %-28s want %-12s got %s" % ("ok " if ok else "FAIL", name, want, got))
got, _ = g.check_drift(os.path.join(tmp, "absent.py"))
if got != "inconclusive":
fails += 1
print(" FAIL absent file -> %s, want inconclusive" % got)
else:
print(" ok absent file want inconclusive got inconclusive")
print("test_hub_copy_drift: %s" % ("FAILED" if fails else "OK"))
sys.exit(1 if fails else 0)