#!/usr/bin/env python3 """Job #1679 offline ledger: asserts the facts the return quotes. No network. Paths are derived from __file__ so nothing machine-specific is embedded. Run: python3 job1679-checks.py (writes PASS/FAIL lines and a summary) """ import json import pathlib import re import sys ROOT = pathlib.Path(__file__).resolve().parents[5] # .../ AH = ROOT / ".solveathome" RUN = AH / "runs" / "run_20260917_163659_BVIL3Q" SIB = AH / "runs" / "run_20260917_162815_u1mcGg" / "work" / "replies" HASH = "79eda0d5370d7b9a1984d1381a08cbd053d9ac4481de5115612524b94b11206a" RESULTS = [] def ck(name, cond, detail=""): RESULTS.append((name, bool(cond), str(detail)[:160])) def load(p): try: return json.loads(pathlib.Path(p).read_text(encoding="utf-8")) except Exception as exc: # noqa: BLE001 return {"__error__": repr(exc)} def walk(o, pre=""): if isinstance(o, dict): for k, v in o.items(): yield from walk(v, pre + "/" + k) elif isinstance(o, list): for i, v in enumerate(o): yield from walk(v, pre + "[%d]" % i) else: yield pre, o # ---- A: this run's bindings ------------------------------------------------ run_json = load(RUN / "run.json") asg = load(RUN / "assignment.json") ck("A1 run.json model is the measured session model", run_json.get("model") == "deepseek/deepseek-v4-flash", run_json.get("model")) ck("A1b run.json effort is unmeasured", run_json.get("effort") == "unmeasured", run_json.get("effort")) ck("A1c run.json mode is general", run_json.get("mode") == "general", run_json.get("mode")) ck("A2 assignment job_id is 1679", str(asg.get("job_id")) == "1679", asg.get("job_id")) ck("A2b assignment type explore and purpose discovery", asg.get("type") == "explore" and asg.get("purpose") == "discovery", (asg.get("type"), asg.get("purpose"))) ck("A2c assignment is routeless and 1 of 1", asg.get("research_route_id") is None and asg.get("session_max_jobs") == 1, (asg.get("research_route_id"), asg.get("session_max_jobs"))) ck("A2d assignment attempt matches the printed binding record", asg.get("attempt_id") == "f417720ba7b6649ebc38dc764a3abcc8", asg.get("attempt_id")) rd = load(AH / "state" / "readiness.json") ck("A3 readiness 27/27 on this turn", rd.get("passed") == 27 and rd.get("total") == 27, (rd.get("passed"), rd.get("total"))) ck("A3b pinned tool sha is the acting sha", str(rd.get("tool_sha256", "")).startswith("34f2326b"), rd.get("tool_sha256")) ident = load(AH / "state" / "identity" / "run_20260917_163659_BVIL3Q.json") ck("A4 identity bound to THIS turn's chat dir", ident.get("chat", "").endswith("chats/2026-09-17T14-35-38.284Z"), "chat basename " + str(ident.get("chat", "")).rsplit("/", 1)[-1]) ck("A4b identity model/effort agree with the run record", ident.get("model") == "deepseek/deepseek-v4-flash" and ident.get("effort") == "unmeasured", (ident.get("model"), ident.get("effort"))) # ---- B: the duplicate pair (sibling run's fetched records, read-only) ------ r78 = load(SIB / "ret78.json") r80 = load(SIB / "ret80.json") f78 = dict(walk(r78)) f80 = dict(walk(r80)) ck("B1 both records present and non-empty", len(f78) > 10 and len(f80) > 10, (len(f78), len(f80))) ck("B2 patch_hash equal across #78 and #80", f78.get("/patch_hash") == f80.get("/patch_hash") == HASH, f78.get("/patch_hash")) ck("B3 patch text is byte-identical", f78.get("/patch") == f80.get("/patch") and bool(f78.get("/patch")), len(str(f78.get("/patch")))) ck("B4 statuses diverge: recorded vs accepted", f78.get("/status") == "recorded" and f80.get("/status") == "accepted", (f78.get("/status"), f80.get("/status"))) ck("B5 #78 pending-integration label vs #80 integrated", str(f78.get("/patch_status", "")).startswith("pending integration") and f80.get("/patch_status") == "integrated", (str(f78.get("/patch_status"))[:30], f80.get("/patch_status"))) ck("B6 later return is the integrated one (71.025 s apart)", (f80.get("/created_at") == "2026-09-11T15:19:00.715Z" and f78.get("/created_at") == "2026-09-11T15:17:49.690Z"), (f78.get("/created_at"), f80.get("/created_at"))) ck("B7 no link key on either side", f78.get("/duplicate_of") is None and f78.get("/superseded_by") is None and f80.get("/duplicate_of") is None and f80.get("/superseded_by") is None, "all null") revs78 = r78.get("reviews") or [] # top-level list, not a walk leaf revs80 = r80.get("reviews") or [] ck("B8 #78 has zero reviews, #80 carries the review", len(revs78) == 0 and len(revs80) >= 1, (len(revs78), len(revs80))) rev80 = revs80[0] if revs80 else {} ck("B8b #80's review is #21, verdict accept", rev80.get("id") == 21 and rev80.get("verdict") == "accept", (rev80.get("id"), rev80.get("verdict"))) ck("B9 same handle on both", f78.get("/handle") == f80.get("/handle") == "MichaelRobartes", f78.get("/handle")) ck("B10 neither record resubmitted its transcript", f78.get("/transcript_resubmitted_at") is None and f80.get("/transcript_resubmitted_at") is None, "both null") # ---- C: the proposal object's shape and caps ------------------------------- res = load(RUN / "work" / "job1679-research.json") ck("C1 outcome is proposed", res.get("outcome") == "proposed", res.get("outcome")) ck("C2 no route_id key (a routeless object must omit it)", "route_id" not in res, list(res)) ck("C3 no top-level prior_art_md (proposal branch)", "prior_art_md" not in res, list(res)) ck("C4 next_step is at the top level of the research object", isinstance(res.get("next_step"), dict) and "next_step" not in res.get("proposal", {}), "top-level") title = res.get("proposal", {}).get("title", "") ck("C5 proposal.title <= 160 chars", 0 < len(title) <= 160, len(title)) for field in ("evidence_md",): ck("C6 %s <= 4000 chars" % field, 0 < len(res.get(field, "")) <= 4000, len(res.get(field, ""))) for field in ("contribution_md", "prior_art_md", "uncertainty_md"): ck("C6b proposal.%s <= 4000 chars" % field, 0 < len(res.get("proposal", {}).get(field, "")) <= 4000, len(res.get("proposal", {}).get(field, ""))) ns = res.get("next_step", {}) tok = re.compile(r"[a-z0-9_.-]+") ck("C7 required_tools are lowercase identifier tokens", all(tok.fullmatch(x) and x.islower() for x in ns.get("required_tools", [])), ns.get("required_tools")) ck("C8 required_sources are lowercase identifier tokens", all(tok.fullmatch(x) and x.islower() for x in ns.get("required_sources", [])), ns.get("required_sources")) ck("C9 next_step budget in 0.1..4 and compute present", 0.1 <= float(ns.get("budget_hours", 0)) <= 4 and isinstance(ns.get("compute"), dict), ns.get("budget_hours")) ck("C10 next_step carries question, method, success, failure", all(isinstance(ns.get(k), str) and ns.get(k) for k in ("question", "method", "success", "failure")), sorted(ns)) # ---- D: the route's content ------------------------------------------------ c_md = res.get("proposal", {}).get("contribution_md", "") ck("D1 refutation criterion (all-singleton failure branch) stated", "singleton" in c_md and "duplicate_of" in c_md, "present") ck("D2 cost stated as 0 CPU-h", "0 CPU-h" in c_md, "present") ck("D3 route counts patch_hash groups, not registry rows", "patch_hash" in c_md and "group" in c_md, "present") # ---- report ----------------------------------------------------------------- fails = 0 for name, ok, detail in RESULTS: if not ok: fails += 1 print("%-4s %-58s %s" % ("PASS" if ok else "FAIL", name, detail)) print("-" * 78) print("checks=%d failed=%d all_pass=%s" % (len(RESULTS), fails, fails == 0)) sys.exit(0 if fails == 0 else 1)