Merge pilot recovery into the semantic simplex schema delivery
This commit is contained in:
@@ -141,3 +141,82 @@ def test_judge_rejects_string_boolean():
|
||||
rp = load("run_pilot")
|
||||
with pytest.raises(ValueError, match="unusable judge"):
|
||||
rp.judge(ScriptedClient(['{"faithful": "false"}']), "passage", "code")
|
||||
|
||||
|
||||
def test_partial_resume_keeps_successful_detector_output():
|
||||
rp = load("run_pilot")
|
||||
row = rp.run_item(Stub(), ITEM)
|
||||
expected_role = row["role"]
|
||||
row.pop("judge")
|
||||
row["errors"]["judge"] = "temporary failure"
|
||||
|
||||
class JudgeOnly:
|
||||
calls = 0
|
||||
|
||||
def complete_json(self, messages):
|
||||
self.calls += 1
|
||||
assert "faithful" in messages[0]["content"]
|
||||
return {"faithful": True}
|
||||
|
||||
client = JudgeOnly()
|
||||
resumed = rp.run_item(client, ITEM, row)
|
||||
assert client.calls == 1
|
||||
assert resumed["role"] == expected_role
|
||||
assert rp.complete_row(resumed)
|
||||
assert row["errors"] == {"judge": "temporary failure"}
|
||||
|
||||
|
||||
def test_billing_failure_stops_before_next_detector():
|
||||
import pytest
|
||||
|
||||
from leanbench.llm import LLMError
|
||||
|
||||
rp = load("run_pilot")
|
||||
|
||||
class Blocked:
|
||||
calls = 0
|
||||
|
||||
def complete_json(self, messages):
|
||||
self.calls += 1
|
||||
raise LLMError("HTTP 400: Arrearage overdue-payment")
|
||||
|
||||
client = Blocked()
|
||||
with pytest.raises(rp.ProviderBlocked) as caught:
|
||||
rp.run_item(client, ITEM)
|
||||
assert client.calls == 1
|
||||
assert "role" in caught.value.row["errors"]
|
||||
assert "judge" not in caught.value.row["errors"]
|
||||
|
||||
|
||||
def test_blocked_run_preserves_and_replaces_partial_row(tmp_path, monkeypatch):
|
||||
import argparse
|
||||
import json
|
||||
|
||||
from leanbench.config import Settings
|
||||
|
||||
rp = load("run_pilot")
|
||||
args = argparse.Namespace(items=tmp_path / "items.jsonl", out=tmp_path / "results.jsonl",
|
||||
max_calls=400, dry_run=False)
|
||||
args.items.write_text(json.dumps(ITEM) + "\n")
|
||||
partial = {"id": "x1", "compiled": True, "role": {"flagged": False},
|
||||
"errors": {"judge": "Arrearage"}}
|
||||
|
||||
def blocked(client, item, previous):
|
||||
raise rp.ProviderBlocked(partial)
|
||||
|
||||
monkeypatch.setattr(rp, "run_item", blocked)
|
||||
assert rp.execute(args, [ITEM], Settings()) == 2
|
||||
meta = json.loads(args.out.with_suffix(".meta.json").read_text())
|
||||
assert meta["status"] == "provider_blocked"
|
||||
assert meta["completed_items"] == 0
|
||||
|
||||
def recover(client, item, previous):
|
||||
assert previous["role"] == partial["role"]
|
||||
return {**previous, "judge": {"faithful": True}, "errors": {}}
|
||||
|
||||
monkeypatch.setattr(rp, "run_item", recover)
|
||||
assert rp.execute(args, [ITEM], Settings()) == 0
|
||||
rows = [json.loads(line) for line in args.out.read_text().splitlines()]
|
||||
assert len(rows) == 1 and rp.complete_row(rows[0])
|
||||
meta = json.loads(args.out.with_suffix(".meta.json").read_text())
|
||||
assert meta["completed_items"] == 1 and meta["status"] == "complete"
|
||||
|
||||
Reference in New Issue
Block a user