128 lines
5.1 KiB
Python
128 lines
5.1 KiB
Python
#!/usr/bin/env python3
|
|
"""gen_intent_continuity_truth.py — freeze the intent_continuity parity
|
|
oracle (dichotomy wave #2479 tranche).
|
|
|
|
Generator law: RUNE_IC_CORE=python pinned, the clock STUBBED (deterministic
|
|
per-op `now`), inputs deep-copied, every public transition/branch exercised
|
|
(create, create_detour incl. PARKED-parent no-op, resolve incl. missing and
|
|
already-resolved, resolve_detour incl. re-entry and un-parking, supersede
|
|
incl. obligations guard + KeyError). Output:
|
|
src/rust/intent_continuity/frozen_ic_truth.json — replayed VERBATIM by the
|
|
crate's cfg(test) battery.
|
|
"""
|
|
import copy
|
|
import json
|
|
import os
|
|
import sys
|
|
import tempfile
|
|
import types
|
|
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_IC_CORE"] = "python"
|
|
|
|
import rune.intent_continuity as ic # noqa: E402
|
|
|
|
# deterministic clock: op k gets 2026-10-12T00:00:kZ
|
|
_tick = [0]
|
|
|
|
|
|
def _fake_strftime(_fmt, _t):
|
|
_tick[0] += 1
|
|
return f"2026-10-12T00:00:{_tick[0]:02d}Z"
|
|
|
|
|
|
ic.time = types.SimpleNamespace(strftime=_fake_strftime, gmtime=lambda: 0)
|
|
|
|
cases: list = []
|
|
|
|
|
|
def ledger_state(led: ic.IntentLedger) -> dict:
|
|
return {"intents": [r.to_dict() for r in led.records.values()]}
|
|
|
|
|
|
def record_op(led, fn, op_args, now, expected_record, before, after, err=None):
|
|
"""Freeze one op: kernel args from the pre-op state, expected from the
|
|
observed oracle outcome."""
|
|
args = {"ledger": copy.deepcopy(before), "now": now, **copy.deepcopy(op_args)}
|
|
if err is not None:
|
|
expected = {"err": err}
|
|
else:
|
|
expected = {"ledger": copy.deepcopy(after),
|
|
"record": copy.deepcopy(expected_record)}
|
|
cases.append({"fn": fn, "args": args, "expected": expected})
|
|
|
|
|
|
def op(led, fn, run, **kwargs):
|
|
"""run(**kwargs) performs the oracle op (e.g. led.create); kwargs are
|
|
recorded verbatim as kernel args."""
|
|
before = ledger_state(led)
|
|
now = f"2026-10-12T00:00:{_tick[0] + 1:02d}Z" # the now this op will get
|
|
try:
|
|
rec = run(**kwargs)
|
|
after = ledger_state(led)
|
|
record_op(led, fn, kwargs, now, rec.to_dict() if rec else None, before, after)
|
|
except (ValueError, KeyError) as e:
|
|
# kernel err strings match the oracle's exception text: the facade
|
|
# re-raises KeyError(e.args[0]) whose str is the quoted form, so the
|
|
# kernel carries the BARE id after the prefix
|
|
err = (f"KeyError: {e.args[0]}" if isinstance(e, KeyError) else str(e))
|
|
record_op(led, fn, kwargs, now, None, before, before, err=err)
|
|
return now
|
|
|
|
|
|
def main() -> None:
|
|
with tempfile.TemporaryDirectory() as td:
|
|
led = ic.IntentLedger(os.path.join(td, "intents.json"))
|
|
|
|
op(led, "ic_create", led.create,
|
|
id="t1", objective="ship the parser fix", classification="FIX")
|
|
op(led, "ic_create", led.create,
|
|
id="t2", objective="rewrite recall", classification="EXTENSION",
|
|
success_condition="A/B parity shown",
|
|
unresolved_obligations=["o1", "o2"])
|
|
op(led, "ic_create_detour", led.create_detour,
|
|
id="d1", objective="hotfix CI", classification="BLOCKER",
|
|
parent_intent="t1", return_when="CI green", return_to="t1")
|
|
op(led, "ic_create_detour", led.create_detour,
|
|
id="d2", objective="second detour", classification="LATER",
|
|
parent_intent="t1", # t1 already PARKED
|
|
return_when="later", return_to="t1")
|
|
op(led, "ic_resolve", led.resolve, intent_id="t2")
|
|
op(led, "ic_resolve", led.resolve, intent_id="t2") # already RESOLVED → None
|
|
op(led, "ic_resolve", led.resolve, intent_id="d1") # DETOUR → RESOLVED
|
|
op(led, "ic_resolve_detour", led.resolve_detour, detour_id="d1") # un-parks t1
|
|
op(led, "ic_resolve_detour", led.resolve_detour, detour_id="d1") # re-entry → parent
|
|
op(led, "ic_resolve", led.resolve, intent_id="missing")
|
|
op(led, "ic_resolve_detour", led.resolve_detour, detour_id="missing")
|
|
op(led, "ic_supersede", led.supersede,
|
|
old_id="t2", new_id="t2b", objective="rewrite recall v2",
|
|
classification="SUPERSEDING", carry_obligations=True)
|
|
op(led, "ic_supersede", led.supersede,
|
|
old_id="t2", new_id="t2c", objective="drop obligations",
|
|
classification="SUPERSEDING", carry_obligations=False)
|
|
op(led, "ic_supersede", led.supersede,
|
|
old_id="missing", new_id="x", objective="o", classification="FIX")
|
|
op(led, "ic_create", led.create,
|
|
id="bad", objective="o", classification="BOGUS")
|
|
op(led, "ic_create_detour", led.create_detour,
|
|
id="d3", objective="o", classification="FIX",
|
|
parent_intent="nope", return_when="w", return_to="r")
|
|
|
|
doc = {
|
|
"module": "intent_continuity",
|
|
"pin": "RUNE_IC_CORE=python",
|
|
"frozen_at": datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ"),
|
|
"cases": cases,
|
|
}
|
|
out = ROOT / "src" / "rust" / "intent_continuity" / "frozen_ic_truth.json"
|
|
out.write_text(json.dumps(doc, indent=1) + "\n")
|
|
print(f"frozen {len(cases)} cases -> {out}")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|