fix: keep only judged evidence when reviewing

This commit is contained in:
Abdessamad Derraz committed 2026-11-22 00:58:05 +01:00
1 parent bb46a0282a
commit d83ba31d31
4 files changed
+43 -22

No files matched your search

+24
View File
@@ -84,6 +84,30 @@ def records_path(emulator: str) -> str:
return f"{RECORDS_DIR}/{emulator}.jsonl"
def read_record(root: Path, emulator: str, rid: str | None) -> dict | None:
"""A record by its id, or the record that supersedes it: a run
judged again offline is read as judged last."""
if not rid:
return None
path = root / records_path(emulator)
if not path.is_file():
return None
records = [json.loads(line) for line in path.read_text(encoding="utf-8").splitlines()]
by_id = {r["id"]: r for r in records}
successor = {r["supersedes"]: r["id"] for r in records if r.get("supersedes")}
seen = set()
while rid in successor and rid not in seen:
seen.add(rid)
rid = successor[rid]
return by_id.get(rid)
def judged(root: Path, emulator: str, rid: str) -> bool:
"""True for a record the boot oracle judged: only those prove a field."""
record = read_record(root, emulator, rid)
return record is not None and record.get("record_version", 0) >= 4
# The campaign's own files beside the records: append-only like them, one
# line per finding, per pass or per pack probe, each line hashed to its id.
# No profile takes these names (tests/test_campaign.py checks it).
+2 -21
View File
@@ -513,26 +513,7 @@ class Campaign:
self.settle(unit.emulator, content, core, index, entry, [verdict])
def read_record(self, emulator: str, rid: str | None) -> dict | None:
"""A record by its id, or the record that supersedes it: a run
judged again offline is read as judged last."""
if not rid:
return None
path = self.paths.root / mr.records_path(emulator)
if not path.is_file():
return None
records = [json.loads(line) for line in path.read_text(encoding="utf-8").splitlines()]
by_id = {r["id"]: r for r in records}
successor = {r["supersedes"]: r["id"] for r in records if r.get("supersedes")}
seen = set()
while rid in successor and rid not in seen:
seen.add(rid)
rid = successor[rid]
return by_id.get(rid)
def judged(self, emulator: str, rid: str) -> bool:
"""True for a record the boot oracle judged: only those prove a field."""
record = self.read_record(emulator, rid)
return record is not None and record.get("record_version", 0) >= 4
return mr.read_record(self.paths.root, emulator, rid)
@staticmethod
def opened(record: dict, position: int) -> set[str]:
@@ -621,7 +602,7 @@ class Campaign:
if not agrees or (verdict.field not in fresh and verdict.field != "validation"):
updates[verdict.field] = verdict.value
evidence = rules.merge_evidence(fresh.get("evidence"), verdict,
keep=lambda rid: self.judged(emulator, rid))
keep=lambda rid: mr.judged(self.paths.root, emulator, rid))
if evidence != fresh.get("evidence"):
updates["evidence"] = evidence
if updates:
+3 -1
View File
@@ -112,7 +112,9 @@ def review_finding(root: Path, key: str, status: str, reason: str,
entry = entries[matches[0]]
verdict = rules.Verdict(finding["rule"], finding["field"], finding["run_shows"],
finding["statement"], tuple(finding["evidence"]))
evidence = rules.merge_evidence(entry.get("evidence"), verdict)
evidence = rules.merge_evidence(
entry.get("evidence"), verdict,
keep=lambda rid: mr.judged(root, finding["emulator"], rid))
write_fields(path, matches[0], {**updates, "evidence": evidence})
body = {key_: value for key_, value in finding.items() if key_ != "id"}
line = mr.seal_line({**body, "found_at": now_iso(), "status": status, "reason": reason},
+14
View File
@@ -989,6 +989,20 @@ class Findings(Workspace):
for found in self.lines():
self.assertEqual(list(Draft202012Validator(schema).iter_errors(found)), [])
def test_a_review_drops_evidence_from_before_the_oracle(self) -> None:
"""Settle and review keep the same record ids: a record the boot
oracle never judged proves nothing on either path."""
self.c.settle("fake", self.content, self.core, 0, self.entry(), [self.contradicted()])
key = self.lines()[-1]["key"]
old = "2026-10-01-000000000003"
lines = self.root / mr.records_path("fake")
lines.parent.mkdir(parents=True, exist_ok=True)
lines.write_text(json.dumps({"id": old, "record_version": 3}) + "\n", encoding="utf-8")
profileedit.write_fields(self.profile, 0, {"evidence": {"validation": [old]}})
reports.review_finding(self.root, key, "applied", "the core logs the md5 (x.c:1)",
{"on_mismatch": "warn"})
self.assertEqual(self.entry()["evidence"], {"validation": [self.RID]})
def test_a_rejected_finding_stays_closed_on_the_same_run(self) -> None:
verdict = self.contradicted()
self.c.settle("fake", self.content, self.core, 0, self.entry(), [verdict])