One run dir in -> ONE self-contained inspect.html out. The events are inlined as JSON; the page opens offline from file:// with ZERO network references. Four views (owner 26/10: IDE-like debugging a posteriori): - timeline: every component as a bar in time order — LLM calls (with real durations) vs code nodes colored differently; click a bar -> its in/out in the header detail line. The 'which expert are we inside' view. - kg: the snapshot graph on canvas (spring layout, vanilla JS): nodes sized by degree, edges with temporal windows, THIS RUN's touched edges highlighted in accent blue, click a node/edge -> detail (subject, rel, object, window, last-touch event). - facts: the two-pass debug table — claims per chunk, each claim -> typed fact (or declined), each merge verdict with reason. - probes: per question what the hybrid probe returned (seeds, rows, semantic adds, tau) and the prover's DSL + verdict + bindings. Fixed on real render (browser-verified): the KG canvas measured 0x0 while its tab was hidden (display:none) — layout now runs lazily on first visible draw and every tab activation dispatches a resize, so the canvas paints correctly (verified: painted pixels present, all four tabs render content). TDD: inspect_html 3/3 (self-contained offline, honest error without events, empty run renders). Suite: 32 test files green. Usage: python -m floop.inspect_html runs/<ts>/
108 lines
4.5 KiB
Python
108 lines
4.5 KiB
Python
"""floop-inspect tests (PR B: the post-mortem HTML debugger).
|
|
|
|
Law: one run dir in, ONE self-contained inspect.html out — the events
|
|
JSON inlined, zero network references (opens offline from file://),
|
|
every tab present (timeline, KG, facts, probes), and the run's final
|
|
answer visible. A run dir without events.jsonl errors honestly."""
|
|
import json
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
|
|
|
|
from floop.inspect_html import generate
|
|
|
|
EVENTS = [
|
|
{"seq": 1, "ts": "10:00:00.000", "run_ts": "10:00:00.000",
|
|
"event": "comp.start", "comp": "INIT", "desc": "decompose: q0"},
|
|
{"seq": 2, "ts": "10:00:01.000", "run_ts": "10:00:00.000",
|
|
"event": "llm.done", "stage": "INIT", "call_seq": 1, "dur_s": 0.9,
|
|
"file": "prompts/01-INIT.txt", "exception": None},
|
|
{"seq": 3, "ts": "10:00:01.100", "run_ts": "10:00:00.000",
|
|
"event": "comp.out", "comp": "INIT", "out": "Q1 sub"},
|
|
{"seq": 4, "ts": "10:00:02.000", "run_ts": "10:00:00.000",
|
|
"event": "claims.done", "page": "Pedro Sanchez",
|
|
"heading": "Career", "out": {"n_claims": 1,
|
|
"claims": ["PM of Spain since 2018"]}},
|
|
{"seq": 5, "ts": "10:00:03.000", "run_ts": "10:00:00.000",
|
|
"event": "type.done", "page": "Pedro Sanchez",
|
|
"claim": "PM of Spain since 2018",
|
|
"out": {"fact": {"subject": "Pedro Sanchez",
|
|
"relation": "prime minister of", "object": "Spain"}}},
|
|
{"seq": 6, "ts": "10:00:03.500", "run_ts": "10:00:00.000",
|
|
"event": "fact.merged", "eid": 7,
|
|
"fact": {"subject": "Pedro Sanchez", "relation": "prime minister of",
|
|
"object": "Spain"}, "page": "Pedro Sanchez"},
|
|
{"seq": 7, "ts": "10:00:04.000", "run_ts": "10:00:00.000",
|
|
"event": "probe.done", "q": "Q1 sub", "seeds": ["pedro"], "rows": 3,
|
|
"semantic": 1, "tau": 0.45},
|
|
{"seq": 8, "ts": "10:00:05.000", "run_ts": "10:00:00.000",
|
|
"event": "prover.done", "q": "Q1 sub", "verdict": "ambiguous",
|
|
"dsl": {"lookup": {"subject": "pedro sanchez",
|
|
"rel_any": ["prime minister of"], "bind": "x"}},
|
|
"n_bindings": 2, "bindings": ["Spain", "PSOE"]},
|
|
{"seq": 9, "ts": "10:00:06.000", "run_ts": "10:00:00.000",
|
|
"event": "kg.snapshot",
|
|
"kg": {"n_edges": 1, "n_live": 1, "n_conflicts": 0,
|
|
"edges": [{"eid": 7, "subject": "pedro sanchez",
|
|
"rel": "prime minister of", "object": "Spain",
|
|
"t_start": "2018", "t_end": None, "retracted": False,
|
|
"last_touch": {"seq": 6, "ts": "10:00:03.500",
|
|
"page": "Pedro Sanchez"}}]}},
|
|
{"seq": 10, "ts": "10:00:07.000", "run_ts": "10:00:00.000",
|
|
"event": "run.final", "out": "Spain and PSOE"},
|
|
]
|
|
|
|
|
|
def _make_run(tmp: Path, events) -> Path:
|
|
run_dir = tmp / "run"
|
|
run_dir.mkdir(parents=True)
|
|
(run_dir / "events.jsonl").write_text(
|
|
"\n".join(json.dumps(e) for e in events), encoding="utf-8")
|
|
return run_dir
|
|
|
|
|
|
def test_generate_writes_selfcontained_html():
|
|
import tempfile
|
|
tmp = Path(tempfile.mkdtemp())
|
|
run_dir = _make_run(tmp, EVENTS)
|
|
out = generate(run_dir)
|
|
assert out == run_dir / "inspect.html", out
|
|
html = out.read_text(encoding="utf-8")
|
|
# self-contained: zero network refs, JSON inlined
|
|
assert "http://" not in html and "https://" not in html, "network ref!"
|
|
assert '"PM of Spain since 2018"' in html # events inlined
|
|
for tab in ("timeline", "kg", "facts", "probes"):
|
|
assert f'id="{tab}"' in html, tab # all tabs present
|
|
assert "Spain and PSOE" in html # final answer in
|
|
assert "prime minister of" in html # KG data in
|
|
print("ok: one self-contained inspect.html (offline, all tabs, inlined)")
|
|
|
|
|
|
def test_missing_events_errors_honestly():
|
|
import tempfile
|
|
tmp = Path(tempfile.mkdtemp())
|
|
run_dir = tmp / "run"
|
|
run_dir.mkdir()
|
|
try:
|
|
generate(run_dir)
|
|
raise AssertionError("must fail")
|
|
except SystemExit as e:
|
|
assert e.code not in (0, None), e
|
|
print("ok: no events.jsonl -> honest error (exit != 0)")
|
|
|
|
|
|
def test_empty_events_still_renders():
|
|
import tempfile
|
|
tmp = Path(tempfile.mkdtemp())
|
|
run_dir = _make_run(tmp, [])
|
|
out = generate(run_dir)
|
|
assert out.exists()
|
|
print("ok: empty run renders an honest empty view")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
test_generate_writes_selfcontained_html()
|
|
test_missing_events_errors_honestly()
|
|
test_empty_events_still_renders()
|
|
print("\ninspect_run: 3/3 ok") |