fix(question_gen): raise ValueError on UPDATE of missing rows
record_run_end, update_gates, and update_difficulty now check cursor.rowcount after UPDATE+commit and raise ValueError if 0 rows were affected. Prevents silent telemetry loss. Adds three negative-path tests: - test_record_run_end_missing_run_raises - test_update_gates_missing_item_raises - test_update_difficulty_missing_item_raises Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -242,3 +242,27 @@ class TestQuestionGenStore:
|
||||
"""查询不存在的 run_id 应报错。"""
|
||||
with pytest.raises(ValueError, match="run_id"):
|
||||
store.get_run_stats("nonexistent-run")
|
||||
|
||||
def test_record_run_end_missing_run_raises(self, store: QuestionGenStore) -> None:
|
||||
"""对不存在的 run_id 调用 record_run_end 应报错。"""
|
||||
stats = RunStats(total_slots=10, accepted=5, rejected=3, heavy_sampled=2)
|
||||
with pytest.raises(ValueError, match="run_id"):
|
||||
store.record_run_end(
|
||||
run_id="ghost-run", status="completed", stats=stats
|
||||
)
|
||||
|
||||
def test_update_gates_missing_item_raises(self, store: QuestionGenStore) -> None:
|
||||
"""对不存在的 item_id 调用 update_gates 应报错。"""
|
||||
report = _MockGateReport(
|
||||
key_verify=_GateResult(_Verdict.PASS, "ok"),
|
||||
blind_answer=_GateResult(_Verdict.PASS, "ok"),
|
||||
multi_true=_GateResult(_Verdict.PASS, "ok"),
|
||||
leak_test=_GateResult(_Verdict.PASS, "ok"),
|
||||
)
|
||||
with pytest.raises(ValueError, match="item_id"):
|
||||
store.update_gates(item_id="ghost-item", report=report)
|
||||
|
||||
def test_update_difficulty_missing_item_raises(self, store: QuestionGenStore) -> None:
|
||||
"""对不存在的 item_id 调用 update_difficulty 应报错。"""
|
||||
with pytest.raises(ValueError, match="item_id"):
|
||||
store.update_difficulty(item_id="ghost-item", difficulty_steps=5)
|
||||
|
||||
Reference in New Issue
Block a user