Files
rune/scripts/gen_construction_depth_truth.py
T

97 lines
4.0 KiB
Python

#!/usr/bin/env python3
"""gen_construction_depth_truth.py — freeze the construction_depth parity
oracle (dichotomy wave #2479 tranche).
Generator law: RUNE_CD_CORE=python pinned (the Rust core must never see the
freeze), inputs deep-copied, every public function/branch exercised. Output:
src/rust/construction_depth/frozen_cd_truth.json — replayed VERBATIM by the
crate's cfg(test) battery.
"""
import copy
import json
import os
import sys
from datetime import datetime, timezone
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
sys.path.insert(0, str(ROOT / "src"))
os.environ["RUNE_CD_CORE"] = "python"
from rune.construction_depth import Depth, select_depth # noqa: E402
WIDE = [f"surface-{i}" for i in range(6)]
CASES = [
# branch: NOT_CONSTRUCTION → NONE, everything bypassed
dict(mode="NOT_CONSTRUCTION"),
# branch: UNKNOWN → UNRESOLVED, probe/clarify
dict(mode="UNKNOWN"),
# branch: LOCAL_CHANGE → LIGHT, minimal ceremony
dict(mode="LOCAL_CHANGE", objective="fix typo"),
# branch: LOCAL_CHANGE + user-locked layout
dict(mode="LOCAL_CHANGE", objective="tweak layout", user_locked_layout=True),
# branch: PROJECT_BUILD → FULL lifecycle
dict(mode="PROJECT_BUILD", objective="new project"),
# branch: EXISTING_PROJECT_CHANGE base (default path)
dict(mode="EXISTING_PROJECT_CHANGE", objective="add feature"),
# modifier: migration
dict(mode="EXISTING_PROJECT_CHANGE", has_migration=True),
# modifier: breaking
dict(mode="EXISTING_PROJECT_CHANGE", breaking=True),
# modifier: user-locked layout
dict(mode="EXISTING_PROJECT_CHANGE", user_locked_layout=True),
# modifier: external service
dict(mode="EXISTING_PROJECT_CHANGE", external_service=True),
# modifier: uncertainty high (inserts evidence probe at ceremony[0])
dict(mode="EXISTING_PROJECT_CHANGE", uncertainty="high"),
# modifier: uncertainty partial (no-op branch — no probe)
dict(mode="EXISTING_PROJECT_CHANGE", uncertainty="partial"),
# modifier: wide surface (>5 entries) → FULL
dict(mode="EXISTING_PROJECT_CHANGE", affected_surface=list(WIDE)),
# modifier: breaking + migration → FULL
dict(mode="EXISTING_PROJECT_CHANGE", breaking=True, has_migration=True),
# every modifier at once (wide surface wins over breaking+migration reason)
dict(mode="EXISTING_PROJECT_CHANGE", has_migration=True, breaking=True,
user_locked_layout=True, external_service=True,
uncertainty="high", affected_surface=list(WIDE)),
# non-canonical mode falls through to the EXISTING_PROJECT_CHANGE path
dict(mode="RESEARCHED_CHANGE", objective="investigate options"),
dict(mode="WEIRD_MODE"),
# empty affected_surface list (falsy — no wide-surface branch)
dict(mode="EXISTING_PROJECT_CHANGE", affected_surface=[]),
# exactly 5 entries — boundary (not > 5, stays STANDARD)
dict(mode="EXISTING_PROJECT_CHANGE",
affected_surface=[f"s{i}" for i in range(5)]),
# objective passthrough (ignored by the kernel — recorded for truth)
dict(mode="LOCAL_CHANGE", objective="rename variable", uncertainty=""),
]
def main() -> None:
cases = []
for kwargs in CASES:
args = copy.deepcopy(kwargs)
d = select_depth(**copy.deepcopy(kwargs))
expected = copy.deepcopy(d.to_dict())
cases.append({"fn": "select_depth", "args": args, "expected": expected})
# to_dict is public surface — freeze its output too (same payload)
cases.append({"fn": "to_dict",
"args": {"select": copy.deepcopy(kwargs)},
"expected": copy.deepcopy(d.to_dict())})
doc = {
"module": "construction_depth",
"pin": "RUNE_CD_CORE=python",
"frozen_at": datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ"),
"cases": cases,
}
out = ROOT / "src" / "rust" / "construction_depth" / "frozen_cd_truth.json"
out.write_text(json.dumps(doc, indent=1) + "\n")
print(f"frozen {len(cases)} cases -> {out}")
if __name__ == "__main__":
main()