CI Pipeline / best-practices (push) Successful in 8s
CI Pipeline / documentation (push) Successful in 8s
CI Pipeline / rust-surface (push) Failing after 13s
CI Pipeline / go-surface (push) Failing after 15s
CI Pipeline / gitea-offline (push) Successful in 17s
CI Pipeline / required-checks (push) Canceled after 0s
CI Pipeline / CI Pipeline / notify-event-bridge (push) Canceled after 0s
Auto-version and Release / release (push) Canceled after 28s
deploy / deploy (push) Canceled after 15s
CI Pipeline / type-check (push) Canceled after 21s
CI Pipeline / canary (push) Canceled after 32s
CI Pipeline / unit-tests (push) Canceled after 33s
CI Pipeline / lint (push) Canceled after 34s
Typed registry: the frozen oracle docs parse once into BuiltinPattern values (pattern_id/revision extracted, doc kept oracle-shaped); the FFI re-emits from the typed value instead of re-plumbing raw Json. Miss- before-revision-check oracle ordering is now explicit in the typed lookup. Registry revision pinned in its own OnceLock. Truth extended (+2 cases from the live oracle, RUNE_CPB_CORE=python pinned): unknown id WITH a revision -> None (miss is decided before the revision check — oracle order) and the revision=0 boundary on a real pattern (ValueError, exact message). Branch battery now 19 cases, replayed verbatim, green throughout; clippy 0; live parity 16/16.
107 lines
4.4 KiB
Python
107 lines
4.4 KiB
Python
#!/usr/bin/env python3
|
|
"""gen_construction_patterns_builtin_truth.py — dichotomy wave #2479
|
|
(construction_patterns_builtin FULL-Rust batch).
|
|
|
|
Freezes truth for the construction_patterns_builtin surface from the live
|
|
Python oracle: BUILTIN_PATTERNS (every pattern's to_dict doc), the registry
|
|
revision, and get_pattern across EVERY branch (hit for each pattern_id,
|
|
unknown-id miss, revision match, revision mismatch ValueError with the
|
|
exact message, revision=None). Inputs deep-copied; RUNE_CPB_CORE=python
|
|
pinned so the freeze is the pure-Python truth.
|
|
|
|
Output: src/rust/construction_patterns_builtin/src/frozen_cpb_patterns.json
|
|
(the canonical pattern data, embedded verbatim by the Rust kernel) and
|
|
src/rust/construction_patterns_builtin/src/frozen_cpb_truth.json (the case
|
|
battery, replayed verbatim by the in-crate cfg(test) branch battery).
|
|
Never hand-transcribe: every `want` comes from the live oracle run below.
|
|
"""
|
|
|
|
import copy
|
|
import json
|
|
import os
|
|
import sys
|
|
|
|
REPO = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
|
sys.path.insert(0, os.path.join(REPO, "src"))
|
|
|
|
os.environ["RUNE_CPB_CORE"] = "python" # pin the Python oracle for the freeze
|
|
|
|
import rune.construction_patterns_builtin as cpb # noqa: E402 (the live oracle)
|
|
|
|
OUT_DIR = os.path.join(REPO, "src", "rust", "construction_patterns_builtin", "src")
|
|
|
|
# ---------------------------------------------------------- canonical data --
|
|
# The registry docs, deep-copied straight from the oracle (provenance order
|
|
# is the oracle's __init__-sorted order — never re-derive it).
|
|
pattern_docs = [copy.deepcopy(p.to_dict()) for p in cpb.BUILTIN_PATTERNS]
|
|
pattern_ids = [p.pattern_id for p in cpb.BUILTIN_PATTERNS]
|
|
|
|
with open(os.path.join(OUT_DIR, "frozen_cpb_patterns.json"), "w") as f:
|
|
json.dump({"revision": cpb.PATTERN_REGISTRY_REVISION, "patterns": pattern_docs}, f, indent=2)
|
|
f.write("\n")
|
|
print(f"frozen_cpb_patterns.json: {len(pattern_docs)} patterns, "
|
|
f"revision={cpb.PATTERN_REGISTRY_REVISION}")
|
|
|
|
# ------------------------------------------------------------------ cases ---
|
|
cases = []
|
|
|
|
|
|
def add(fn, name, input_, want):
|
|
cases.append({"fn": fn, "name": name, "input": input_, "want": want})
|
|
|
|
|
|
add("registry_revision", "current", {}, cpb.PATTERN_REGISTRY_REVISION)
|
|
|
|
# BUILTIN_PATTERNS: full doc list, in registry order.
|
|
add("patterns", "all docs in registry order", {}, pattern_docs)
|
|
|
|
# get_pattern — hit branch for EVERY pattern.
|
|
for pid in pattern_ids:
|
|
got = cpb.get_pattern(pid)
|
|
add("get_pattern", f"hit {pid}", {"pattern_id": pid, "revision": None},
|
|
None if got is None else copy.deepcopy(got.to_dict()))
|
|
|
|
# get_pattern — miss branch.
|
|
add("get_pattern", "unknown id -> None",
|
|
{"pattern_id": "no-such-pattern", "revision": None}, None)
|
|
add("get_pattern", "empty id -> None", {"pattern_id": "", "revision": None}, None)
|
|
# Miss is decided BEFORE the revision check (oracle order).
|
|
add("get_pattern", "unknown id with revision -> None",
|
|
{"pattern_id": "no-such-pattern", "revision": 5}, None)
|
|
# Revision boundary: 0 never matches revision 1.
|
|
try:
|
|
cpb.get_pattern(pattern_ids[0], revision=0)
|
|
want = None
|
|
except ValueError as e:
|
|
want = {"raises": "ValueError", "message": str(e)}
|
|
add("get_pattern", "revision zero boundary",
|
|
{"pattern_id": pattern_ids[0], "revision": 0}, want)
|
|
|
|
# get_pattern — revision branches: match passes through, mismatch raises.
|
|
for pid in pattern_ids:
|
|
p = cpb.get_pattern(pid)
|
|
got = cpb.get_pattern(pid, revision=p.revision)
|
|
add("get_pattern", f"revision match {pid}",
|
|
{"pattern_id": pid, "revision": p.revision}, copy.deepcopy(got.to_dict()))
|
|
try:
|
|
cpb.get_pattern(pid, revision=p.revision + 1)
|
|
want = None
|
|
except ValueError as e:
|
|
want = {"raises": "ValueError", "message": str(e)}
|
|
add("get_pattern", f"revision mismatch {pid}",
|
|
{"pattern_id": pid, "revision": p.revision + 1}, want)
|
|
|
|
# get_pattern — revision=None explicit (the default path).
|
|
got = cpb.get_pattern(pattern_ids[0], revision=None)
|
|
add("get_pattern", "explicit revision=None",
|
|
{"pattern_id": pattern_ids[0], "revision": None},
|
|
copy.deepcopy(got.to_dict()))
|
|
|
|
out = os.path.join(OUT_DIR, "frozen_cpb_truth.json")
|
|
with open(out, "w") as f:
|
|
json.dump({"frozen_from": "live oracle construction_patterns_builtin.py "
|
|
"(RUNE_CPB_CORE=python)",
|
|
"cases": cases}, f, indent=2)
|
|
f.write("\n")
|
|
print(f"frozen_cpb_truth.json: {len(cases)} cases")
|