Files
rune/scripts/gen_builder_bridge_truth.py
Nick 85f20cfe9d feat(builder_bridge): close PARTIAL gaps — dichotomy wave
Port the 8 audit-missing functions name-preserving into the GO impl at
src/go/builder-bridge (audit 3/11 PARTIAL -> 11/11 FULL): ToDict,
ConstructionStore, ActiveConstructionLines (segment-architecture store
projection incl. pattern/layout obligations), DefaultSelector,
GetSelector, RetrieveMemory, CachedMemory, ValidatedLessonsFor, plus the
Preflight wiring over a vendored adaptive-router (pure-Go detectFlags
transcribed from the oracle's route_risk_flags insertion order; the
sibling module's cgo/Rust link is deliberately not vendored — this
module's oracle computes flags in pure Python).

Frozen truth: 22 shared-harness rows (to_dict/to_markdown recv forms
incl. line caps + inject-nothing + floor-only, cache key, lessons,
memory abstention + cache-hit, store env branch, active-construction
fixture projection) — byte-identical across generation, --verify and
regeneration under the bb_freeze_seams rig. Live parity: 11 case
families byte-equal on dict+markdown+lines+store vs the live oracle,
including the default-store branch (real store, both sides live) and
the doubled floor-prefix quirk. go build/vet/gofmt/test -race green;
Python suite green under both pins (one pre-existing env-dependent test
failure verified identical on pristine main). Documented divergences:
populated-store hybrid recall stays Python-side (frozen surface is the
degrade-safe abstention both sides reproduce).

Evidence: verification/bb-*.{txt,exit,md}.
2026-10-14 06:07:32 +01:00

158 lines
7.4 KiB
Python

#!/usr/bin/env python3
"""gen_builder_bridge_truth.py — shared-harness truth battery for the
builder_bridge gap closure (dichotomy wave, worktree rune-wave-cw).
Uses scripts/freeze_truth.py (the ONE truth law) to freeze
src/rune/builder_bridge.py behavior for the Go port at
src/go/builder-bridge:
* BuilderCapsule.to_dict / to_markdown — recv form, every branch:
defaults, the line caps (13 memory lines → 12, 7 lesson lines → 6),
the inject-nothing short-circuit, floor-only rendering, construction
projection rendering.
* _cache_key — whitespace collapse + case folding + unicode + empty.
* _validated_lessons_for — the PL1-empty contract (handoff §9).
* _retrieve_memory / _cached_memory — the degrade-safe abstention path
under the pinned-HOME rig (every selector source abstains on an
isolated HOME; fresh + cache-hit rows).
* _construction_store — the env-override branch, verbatim (the default
branch is __file__-derived and machine-absolute: live parity covers
it, frozen truth does not carry absolute paths).
* _active_construction_lines — the committed fixture store
(two open contracts pin observed_at ordering; scope caps at 8;
obligations count + first-3 kind rendering; need/next_action lines).
NOT frozen here (adaptive_router precedent: "cases whose oracle return
carries dataclass instances are exercised through their JSON-native
integration surface instead, and by the Go seam unit tests + live parity
sweep"): preflight returns a BuilderCapsule the harness cannot
JSON-serialize and stamps generated_at from an in-function datetime
import. scripts/check_builder_bridge_parity.py drives the LIVE oracle and
the Go binary across every branch with full to_dict + to_markdown
comparison under the frozen clock — that is its parity gate.
_default_selector / _get_selector return live selector instances (not
JSON-safe); their observable contract (non-None on this stack, lazy
singleton identity) is asserted by the same live parity sweep.
Rig (auto via PYTHONPATH=scripts/bb_freeze_seams — see
scripts/bb_freeze_seams/sitecustomize.py): pinned HOME/RUNE_HOME,
RUNE_MSE_CORE=python, RUNE_CONSTRUCTION_STORE=<repo>/src/go/
builder-bridge/fixtures/store_active (run from the repo root).
Verify (byte-identical law, from the repo root):
PYTHONPATH=scripts/bb_freeze_seams python3 scripts/freeze_truth.py \\
--verify src/go/builder-bridge/truth.json \\
--module rune.builder_bridge
"""
import os
import sys
from pathlib import Path
REPO = Path(__file__).resolve().parent.parent
sys.path.insert(0, str(REPO / "src"))
sys.path.insert(0, str(Path(__file__).resolve().parent))
FROZEN_NOW = "2026-10-13T11:00:00+00:00"
os.environ.setdefault("RUNE_FROZEN_NOW", FROZEN_NOW)
from freeze_truth import freeze, write_envelope # noqa: E402
def capsule_recv(**over):
state = {
"task_route": "",
"floor": False,
"unknowns": [],
"memory_lines": [],
"lesson_lines": [],
"constraints": [],
"construction_lines": [],
"generated_at": "",
"core_version": "rune-core/operator-path",
}
state.update(over)
return {"cls": "BuilderCapsule", **state}
def main():
memory13 = [f"memory line {i}" for i in range(13)]
lessons7 = [f"lesson {i}" for i in range(7)]
construction = [
"contract c-gap-fixture · phase building · status open · mode BUILD",
"project: issue161-harness",
"next action: commit the fix",
]
cases = [
# to_dict — defaults (the capsule's own field defaults)
{"fn": "BuilderCapsule.to_dict", "recv": capsule_recv(), "args": [], "kwargs": {}},
# to_dict — the caps: 13 memory lines → 12, 7 lesson lines → 6
{"fn": "BuilderCapsule.to_dict",
"recv": capsule_recv(task_route="STANDARD_CHANGE", floor=True,
unknowns=["verifiability"],
memory_lines=memory13, lesson_lines=lessons7,
constraints=["keep it bounded"],
construction_lines=construction,
generated_at="2026-10-13T11:00:00+00:00"),
"args": [], "kwargs": {}},
# to_dict — custom core_version passes through
{"fn": "BuilderCapsule.to_dict",
"recv": capsule_recv(task_route="LOCAL_FIX", core_version="rune-core/test"),
"args": [], "kwargs": {}},
# to_markdown — inject-nothing short-circuit (LOCAL_FIX, all empty)
{"fn": "BuilderCapsule.to_markdown",
"recv": capsule_recv(task_route="LOCAL_FIX"), "args": [], "kwargs": {}},
# to_markdown — STANDARD_CHANGE with nothing useful is ALSO silent
{"fn": "BuilderCapsule.to_markdown",
"recv": capsule_recv(task_route="STANDARD_CHANGE"), "args": [], "kwargs": {}},
# to_markdown — full rendering, every section
{"fn": "BuilderCapsule.to_markdown",
"recv": capsule_recv(task_route="RESEARCHED_CHANGE", floor=True,
unknowns=["external dependency"],
memory_lines=["mem one", "mem two"],
lesson_lines=["lesson one"],
constraints=["Deep-research floor: x"],
construction_lines=construction),
"args": [], "kwargs": {}},
# to_markdown — floor-only DEEP_RESEARCH renders the floor line
{"fn": "BuilderCapsule.to_markdown",
"recv": capsule_recv(task_route="DEEP_RESEARCH", floor=True),
"args": [], "kwargs": {}},
# to_markdown — unknowns-only still renders (not inject-nothing)
{"fn": "BuilderCapsule.to_markdown",
"recv": capsule_recv(task_route="LOCAL_FIX", unknowns=["verifiability"]),
"args": [], "kwargs": {}},
# to_markdown — construction projection renders for a LOCAL_FIX too
{"fn": "BuilderCapsule.to_markdown",
"recv": capsule_recv(task_route="LOCAL_FIX", construction_lines=construction),
"args": [], "kwargs": {}},
# _cache_key — collapse + fold + unicode + empty
("_cache_key", ("Fix the\tTELEMETRY\n summary",), {}),
("_cache_key", (" ünïcode tásk — with gaps ",), {}),
("_cache_key", ("",), {}),
("_cache_key", ("SIMPLE",), {}),
# _validated_lessons_for — empty until PL1 promotes a lesson
("_validated_lessons_for", ("fix the retry backoff",), {}),
# _retrieve_memory — degrade-safe abstention under the pinned rig
("_retrieve_memory", ("",), {}),
("_retrieve_memory", ("Fix typo in CLI help text",), {}),
("_retrieve_memory", ("Add the telemetry summary",), {}),
# _cached_memory — fresh miss then cache hit (both via the rig [])
("_cached_memory", ("Fix the telemetry summary log level",), {}),
("_cached_memory", ("fix THE TELEMETRY summary log level",), {}), # same cache key
("_cached_memory", ("a different task entirely",), {}),
# _construction_store — env override branch, verbatim
("_construction_store", (), {}),
# _active_construction_lines — the committed fixture store
("_active_construction_lines", (), {}),
]
truth = freeze("rune.builder_bridge", cases, oracle_module="rune.builder_bridge")
dest = REPO / "src/go/builder-bridge/truth.json"
write_envelope(FROZEN_NOW, truth, dest)
print(f"wrote {len(truth)} cases -> {dest}")
if __name__ == "__main__":
main()