Files
rune/scripts/gen_builder_bridge_cli_truth.py
Nick d005f64f53 feat(builder_bridge_cli): port to FULL Go — dichotomy wave
The CLI shell (argv join/strip, --json consumed only at argv[1], the
always-trailing-newline print quirk, Python json.dumps byte-parity:
insertion order + ", "/": " separators + ensure_ascii) over the full
deterministic preflight chain — route authority mirrored from
src/go/adaptive-router (rrf cgo membrane, DeriveSufficiency,
ClassifyRoute), capsule render from src/go/builder-bridge. Reactive
seams excluded per event-wait precedent (memory retrieval, construction
projection — the oracle's own degrade paths; PL1 lessons empty by
design). Frozen truth 13 cases from the live oracle subprocess under
pinned seams (frozen clock via sitecustomize rig, empty memory/
construction stores, HOME isolation — the selector's shard sources read
a hardcoded ~/.config/opencode that ignores RUNE_* isolation); replay
byte-identical; live parity Go binary == Python oracle 13/13; go build/
vet/gofmt clean; rune's truncate is rune-safe (Python str[:n] law).
2026-10-14 05:02:13 +01:00

95 lines
4.4 KiB
Python

#!/usr/bin/env python3
"""gen_builder_bridge_cli_truth.py — freeze the builder_bridge_cli parity
oracle (dichotomy wave #2479, GO verdict).
The module is a CLI (argv → stdout), so truth is frozen by RUNNING the
live Python oracle as a subprocess per case under pinned seams — the
oracle's own degrade paths make the surface deterministic:
* RUNE_MEMORY_DIR → fresh empty dir (selector unavailable → no memory
lines; the same degrade the oracle takes in any selector failure)
* RUNE_CONSTRUCTION_STORE → fresh empty dir (no active contract → no
construction lines)
* BBC_FROZEN_NOW via scripts/bbc_freeze_seams/sitecustomize.py — the
wall clock pinned before import (generated_at in --json output)
* BUILDER_BRIDGE_REPO → this checkout (sys.path bootstrap target)
* deep-copied argv per case; every CLI branch exercised (no-args,
join/strip semantics, --json as argv[1] exactly, --json as task
text, all three routes, floor + not-grounded constraints, test-
surface verifiability, inspection verbs)
Output: src/go/builder-bridge-cli/truth.json — [{"id", "args",
"frozen_now", "stdout", "exit"}...] — replayed VERBATIM by the module's
truth_test.go and byte-compared in live parity.
Byte-determinism: fixed frozen_now, fixed argv literals, fresh-but-empty
degrade dirs — re-running regenerates a byte-identical file.
"""
import json
import os
import subprocess
import sys
import tempfile
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
FROZEN_NOW = "2026-10-14T09:00:00+00:00"
CASES = [
{"id": "no_args", "args": []},
{"id": "local_fix_typo", "args": ["fix", "the", "typo", "in", "scripts/foo.py"]},
{"id": "floor_trigger", "args": ["adopt", "a", "replacement", "architecture",
"for", "the", "memory", "subsystem"]},
{"id": "json_local_fix", "args": ["--json", "fix", "the", "typo", "in", "scripts/foo.py"]},
{"id": "json_floor", "args": ["--json", "adopt", "a", "replacement", "architecture"]},
{"id": "json_empty_task", "args": ["--json"]},
{"id": "mechanism_constraint", "args": ["measure", "the", "latency", "of",
"the", "parser", "under", "load"]},
{"id": "external_constraint", "args": ["integrate", "the", "payments", "api",
"service", "endpoint"]},
{"id": "json_as_task_text", "args": ["summarize", "--json", "fix"]},
{"id": "join_strip_inner_spaces", "args": [" ", "fix bug ", " "]},
{"id": "whitespace_only_task", "args": [" "]},
{"id": "test_surface_verifiable", "args": ["fix", "the", "crash", "in",
"parser.py", "covered", "by",
"tests/test_parser.py"]},
{"id": "inspection_verb_readonly", "args": ["review", "the", "cache", "module"]},
]
def run_oracle(args: list[str]) -> dict:
mem = tempfile.mkdtemp(prefix="bbc-truth-mem-")
constr = tempfile.mkdtemp(prefix="bbc-truth-constr-")
home = tempfile.mkdtemp(prefix="bbc-truth-home-")
env = dict(os.environ)
env.update({
"BUILDER_BRIDGE_REPO": str(ROOT),
"RUNE_MEMORY_DIR": mem,
"RUNE_CONSTRUCTION_STORE": constr,
# HOME isolation (pin_home law): the selector's shard sources read
# a HARDCODED ~/.config/opencode dir that ignores RUNE_* isolation
# (memory_selector P1-03 deviation note) — a fresh HOME makes every
# source degrade to [] hermetically.
"HOME": home,
"PYTHONPATH": str(ROOT / "scripts" / "bbc_freeze_seams"),
"REPO_ROOT": str(ROOT),
"BBC_FROZEN_NOW": FROZEN_NOW,
})
p = subprocess.run(
[sys.executable, str(ROOT / "src" / "rune" / "builder_bridge_cli.py"), *args],
capture_output=True, text=True, env=env, timeout=120,
)
return {"stdout": p.stdout, "exit": p.returncode}
if __name__ == "__main__":
truth = []
for case in CASES:
r = run_oracle(list(case["args"]))
truth.append({"id": case["id"], "args": case["args"],
"frozen_now": FROZEN_NOW,
"stdout": r["stdout"], "exit": r["exit"]})
print(f"{case['id']}: exit={r['exit']} stdout={r['stdout'][:60]!r}")
out = ROOT / "src" / "go" / "builder-bridge-cli" / "truth.json"
out.write_text(json.dumps(truth, indent=1, ensure_ascii=False) + "\n")
print(f"frozen {len(truth)} cases -> {out}")