128 lines
5.5 KiB
Python
128 lines
5.5 KiB
Python
#!/usr/bin/env python3
|
|
"""gen_self_model_truth.py — freeze the self_model parity oracle (dichotomy
|
|
wave #2479 tranche).
|
|
|
|
Generator law: RUNE_SMM_CORE=python pinned, inputs deep-copied, every
|
|
public function and branch exercised (estimate_tokens incl. unicode and
|
|
sub/over boundaries; compile_self_model incl. empty corpus, exact-fit
|
|
boundary, evidence overflow, key defaults, stable weight ties, zero and
|
|
negative budgets, small-weight ordering, default budget; why_question incl.
|
|
statement match, evidence match, case-insensitivity, empty topic, empty
|
|
model). Output: src/rust/self_model/frozen_sm_truth.json — replayed
|
|
VERBATIM by the crate's cfg(test) battery.
|
|
"""
|
|
import copy
|
|
import json
|
|
import os
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
sys.path.insert(0, str(ROOT / "src"))
|
|
sys.path.insert(0, str(ROOT / "src" / "rune"))
|
|
|
|
os.environ["RUNE_SMM_CORE"] = "python"
|
|
|
|
import self_model as sm # noqa: E402
|
|
|
|
cases: list = []
|
|
|
|
|
|
def freeze(fn, args):
|
|
args = copy.deepcopy(args)
|
|
f = getattr(sm, fn)
|
|
expected = f(**copy.deepcopy(args))
|
|
cases.append({"fn": fn, "args": args, "expected": expected})
|
|
|
|
|
|
# --- estimate_tokens: every boundary ---
|
|
for text in [
|
|
"", # max(1, 0) -> 1
|
|
"ab", # 0 // 4 -> 1
|
|
"abcd", # exactly 1
|
|
"abcde", # 1
|
|
"a" * 8, # 2
|
|
"a" * 9, # 2
|
|
"a" * 12, # 3
|
|
"hello — em-dash unicode", # char count, not bytes
|
|
"line one\nline two\nline three",
|
|
]:
|
|
freeze("estimate_tokens", {"text": text})
|
|
|
|
# --- compile_self_model: every branch ---
|
|
freeze("compile_self_model", {"corpus": []}) # empty, default budget
|
|
freeze("compile_self_model", { # single fits
|
|
"corpus": [{"text": "I speak plainly and show my work.",
|
|
"source": "persona.md", "weight": 0.9}],
|
|
})
|
|
freeze("compile_self_model", { # exact-fill boundary + overflow
|
|
"corpus": [
|
|
{"text": "a" * 16, "source": "s1", "weight": 2.0}, # tok 4
|
|
{"text": "b" * 16, "source": "s2", "weight": 1.5}, # tok 4 -> used 8 == budget
|
|
{"text": "c", "source": "s3", "weight": 1.0}, # tok 1 -> evidence
|
|
],
|
|
"budget_tokens": 8,
|
|
})
|
|
freeze("compile_self_model", { # missing keys -> defaults
|
|
"corpus": [{"text": "no weight no source"}, {"source": "only-source"},
|
|
{"weight": 0.1}],
|
|
})
|
|
freeze("compile_self_model", { # stable ties keep order
|
|
"corpus": [
|
|
{"text": "first", "source": "a", "weight": 1.0},
|
|
{"text": "second", "source": "b", "weight": 1.0},
|
|
{"text": "third", "source": "c", "weight": 1.0},
|
|
],
|
|
"budget_tokens": 3,
|
|
})
|
|
freeze("compile_self_model", {"corpus": [{"text": "x" * 40, "source": "big",
|
|
"weight": 9.9}],
|
|
"budget_tokens": 0}) # zero budget -> all evidence
|
|
freeze("compile_self_model", {"corpus": [{"text": "x" * 40, "source": "big",
|
|
"weight": 9.9}],
|
|
"budget_tokens": -3}) # negative budget
|
|
freeze("compile_self_model", { # small weights order round
|
|
"corpus": [{"text": "quarter weight", "source": "q", "weight": 0.25},
|
|
{"text": "three-quarter weight", "source": "t", "weight": 0.75}],
|
|
"budget_tokens": 50,
|
|
})
|
|
freeze("compile_self_model", { # 219/220 boundary at default budget
|
|
"corpus": [
|
|
{"text": "w" * 700, "source": "big1", "weight": 3.0}, # tok 175
|
|
{"text": "y" * 176, "source": "big2", "weight": 2.0}, # tok 44 -> 219
|
|
{"text": "z" * 4, "source": "over", "weight": 1.0}, # tok 1 -> evidence
|
|
],
|
|
})
|
|
freeze("compile_self_model", { # first item alone exceeds budget
|
|
"corpus": [{"text": "v" * 100, "source": "huge", "weight": 5.0},
|
|
{"text": "tiny", "source": "t", "weight": 0.4}],
|
|
"budget_tokens": 10,
|
|
})
|
|
|
|
compiled = sm.compile_self_model(copy.deepcopy([
|
|
{"text": "I prefer evidence over vibes.", "source": "s1", "weight": 2.0},
|
|
{"text": "CONTRADICTIONS get surfaced loudly.", "source": "s2", "weight": 1.5},
|
|
{"text": "Growth is measured, not asserted.", "source": "s3", "weight": 1.0},
|
|
{"text": "quiet evidence overflow note", "source": "s4", "weight": 0.1},
|
|
]), budget_tokens=10)
|
|
|
|
# --- why_question: every branch ---
|
|
freeze("why_question", {"model": compiled, "topic": "evidence"}) # statements + evidence hits
|
|
freeze("why_question", {"model": compiled, "topic": "EVIDENCE"}) # case-insensitive both ways
|
|
freeze("why_question", {"model": compiled, "topic": "growth"}) # single statement hit
|
|
freeze("why_question", {"model": compiled, "topic": "absent-topic"}) # no hits
|
|
freeze("why_question", {"model": compiled, "topic": ""}) # empty topic matches all
|
|
freeze("why_question", {"model": {}, "topic": "anything"}) # empty model
|
|
freeze("why_question", { # bare evidence-only model
|
|
"model": {"evidence_ref": [{"text": "overflowed raw note",
|
|
"source": "raw"}]},
|
|
"topic": "raw",
|
|
})
|
|
|
|
doc = {"module": "self_model", "core_env": "RUNE_SMM_CORE=python",
|
|
"cases": cases}
|
|
out = ROOT / "src" / "rust" / "self_model" / "frozen_sm_truth.json"
|
|
out.parent.mkdir(parents=True, exist_ok=True)
|
|
out.write_text(json.dumps(doc, indent=1) + "\n")
|
|
print(f"frozen {len(cases)} cases -> {out}")
|