The frozen corpus recorded the FREEZE-TIME checkout's absolute paths
(repo_root -> /mnt/workdrive/rune-wave-bd, crate_dir ->
/mnt/workdrive/rune-wave-bd/src/rust/<name>), so the battery failed in
every other checkout (6 subtests). Same law applied backward in repair:
absolute paths must never enter frozen truth.
- gen_paths_truth.py: derivation rows frozen REPO-RELATIVE
({REPO_ROOT}, {REPO_ROOT}/src/rust/<name>).
- truth_test.go: expandExpect substitutes the CURRENT root at replay
time and FAILS any derivation row that carries a raw absolute path
(the law is now self-enforcing).
- tests/test_paths_port.py: oracle replay substitutes identically +
asserts the placeholder law on the corpus itself; shape test updated
for the paths.go/phaseb.go split.
Verified: gofmt/vet/go test green in THIS worktree AND from a scratch
checkout at a different root (placeholder substitution proof); pytest
4/4, ruff clean.
126 lines
5.4 KiB
Python
126 lines
5.4 KiB
Python
#!/usr/bin/env python3
|
|
"""Freeze the dichotomy-wave truth corpus for src/rune/paths.py (Go side).
|
|
|
|
LAW (poisoned-truth): truth is generated by the PYTHON ORACLE ONLY.
|
|
Every public function is exercised across ALL branches: repo_root and
|
|
crate_dir (pure derivation, including a nested crate name), and the four
|
|
env-overridable resolvers — each with the env var UNSET (default) and
|
|
SET (override), since env-reading is a branch.
|
|
|
|
HOME is ALWAYS frozen to a concrete value per row: expanduser-bearing
|
|
defaults ($HOME/.rune) must replay byte-stably in Go, which has no
|
|
pwd-module fallback for an unset HOME.
|
|
|
|
MACHINE-BOUND LAW (no absolute paths in frozen truth): outputs derived
|
|
from the FREEZE-TIME repo root (repo_root, crate_dir) are recorded as
|
|
REPO-RELATIVE paths ("{REPO_ROOT}" for the root itself,
|
|
"{REPO_ROOT}/src/rust/<name>" for crates). Replay sides substitute the
|
|
placeholder with their CURRENT repo root before comparing. Everything
|
|
else (env overrides, compile-time defaults) is already absolute-safe.
|
|
Output: src/go/paths/truth.json
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
import copy
|
|
import json
|
|
import os
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
REPO = Path(__file__).resolve().parents[1]
|
|
sys.path.insert(0, str(REPO / "src"))
|
|
|
|
import rune.paths as paths # noqa: E402
|
|
|
|
OUT = REPO / "src" / "go" / "paths" / "truth.json"
|
|
|
|
cases: list[dict] = []
|
|
|
|
ENV_KEYS = ["RUNE_DEPLOY_ROOT", "RUNE_HOME", "HARNESS_SCRIPTS", "RUNE_WR_CODE", "HOME"]
|
|
|
|
|
|
def case(fn: str, name: str, args: dict, env: dict):
|
|
frozen_args = copy.deepcopy(args)
|
|
frozen_env = {k: env.get(k) for k in ENV_KEYS}
|
|
# HOME always concrete (see module docstring).
|
|
if frozen_env["HOME"] is None:
|
|
frozen_env["HOME"] = os.environ.get("HOME")
|
|
# Neutralize the freeze-time checkout: the oracle's repo_root is a
|
|
# machine-bound absolute path; the corpus records it REPO-RELATIVE.
|
|
freeze_root = paths.repo_root()
|
|
saved = {k: os.environ.pop(k, None) for k in ENV_KEYS}
|
|
try:
|
|
os.environ.update({k: v for k, v in frozen_env.items() if v is not None})
|
|
if fn == "repo_root":
|
|
expect = "{REPO_ROOT}"
|
|
elif fn == "crate_dir":
|
|
full = paths.crate_dir(**copy.deepcopy(args))
|
|
assert full.startswith(freeze_root + "/"), full
|
|
expect = "{REPO_ROOT}" + full[len(freeze_root):]
|
|
elif fn == "deploy_root":
|
|
expect = paths.deploy_root()
|
|
elif fn == "rune_home":
|
|
expect = paths.rune_home()
|
|
elif fn == "harness_scripts":
|
|
expect = paths.harness_scripts()
|
|
elif fn == "wait_resume_dir":
|
|
expect = paths.wait_resume_dir()
|
|
else: # pragma: no cover — generator typo guard
|
|
raise ValueError(fn)
|
|
finally:
|
|
for k, v in saved.items():
|
|
if v is None:
|
|
os.environ.pop(k, None)
|
|
else:
|
|
os.environ[k] = v
|
|
cases.append({"fn": fn, "name": name, "args": frozen_args,
|
|
"env": frozen_env, "expect": expect})
|
|
|
|
|
|
# ── repo_root / crate_dir: pure derivation, env-independent ────────────────
|
|
case("repo_root", "repo root", {}, {})
|
|
for name in ("evidence_provenance", "outcome_utility", "memory_types",
|
|
"paths", "a/b/c"):
|
|
case("crate_dir", f"crate {name!r}", {"name": name}, {})
|
|
|
|
# ── deploy_root: default + override ────────────────────────────────────────
|
|
case("deploy_root", "default", {}, {})
|
|
case("deploy_root", "override", {}, {"RUNE_DEPLOY_ROOT": "/srv/rune-deploy"})
|
|
|
|
# ── rune_home: default (~/.rune) + override ────────────────────────────────
|
|
case("rune_home", "default", {}, {})
|
|
case("rune_home", "override", {}, {"RUNE_HOME": "/var/lib/rune"})
|
|
|
|
# ── harness_scripts: default + override ────────────────────────────────────
|
|
case("harness_scripts", "default", {}, {})
|
|
case("harness_scripts", "override", {},
|
|
{"HARNESS_SCRIPTS": "/opt/harness/scripts"})
|
|
|
|
# ── wait_resume_dir: default + override ────────────────────────────────────
|
|
case("wait_resume_dir", "default", {}, {})
|
|
case("wait_resume_dir", "override", {},
|
|
{"RUNE_WR_CODE": "/var/cache/wait-resume"})
|
|
|
|
# ── cross-env isolation: one key set, others unset / all set ───────────────
|
|
case("rune_home", "override while siblings unset",
|
|
{}, {"RUNE_HOME": "/home/op/.rune"})
|
|
case("deploy_root", "override while siblings set",
|
|
{}, {"RUNE_DEPLOY_ROOT": "/d", "RUNE_HOME": "/h",
|
|
"HARNESS_SCRIPTS": "/s", "RUNE_WR_CODE": "/w"})
|
|
|
|
doc = {
|
|
"module": "paths",
|
|
"frozen_ts": "2026-10-13T06:15:00Z",
|
|
"generator": "scripts/gen_paths_truth.py",
|
|
"note": "HOME is frozen per row so expanduser-bearing defaults "
|
|
"(rune_home) replay byte-stably in both languages; "
|
|
"freeze-time repo-root outputs are recorded REPO-RELATIVE "
|
|
"({REPO_ROOT} placeholder) — replay sides substitute their "
|
|
"CURRENT root. The Go battery sets the row env verbatim and "
|
|
"compares against the substituted oracle output.",
|
|
"cases": cases,
|
|
}
|
|
OUT.parent.mkdir(parents=True, exist_ok=True)
|
|
OUT.write_text(json.dumps(doc, indent=1) + "\n")
|
|
print(f"frozen {len(cases)} cases -> {OUT}")
|