fix: idempotent ladder_rank migration for legacy gate_evidence tables

This commit is contained in:
2026-07-17 05:29:20 -04:00
parent 1930ad32a4
commit eb12006d38
2 changed files with 42 additions and 0 deletions
+36
View File
@@ -383,3 +383,39 @@ def test_write_epoch_report(tmp_path: Path) -> None:
assert data["system_tool_action"] == "updated"
assert data["momentum_updated_task_types"] == ["temporal", "causal"]
assert data["best_val_acc"] == pytest.approx(0.88)
def test_write_gate_evidence_migrates_legacy_block_idx_table(tmp_path) -> None:
"""旧块序贯表(含 block_idx 无 ladder_rank)复用:幂等补列后写入成功(终审 C1 回归锁)。"""
import sqlite3
db = tmp_path / "harness.db"
conn = sqlite3.connect(db)
conn.execute(
"CREATE TABLE gate_evidence (run_id TEXT, timestamp TEXT, epoch INTEGER,"
" step INTEGER, question_id TEXT, task_type TEXT, block_idx INTEGER,"
" baseline_correct INTEGER, candidate_correct INTEGER, e_value REAL,"
" stop_reason TEXT)"
)
conn.commit()
conn.close()
write_gate_evidence(
str(db),
run_id="r1",
epoch=1,
step=0,
rows=[
{
"question_id": "q1",
"task_type": "Action Reasoning",
"ladder_rank": 0,
"baseline_correct": False,
"candidate_correct": True,
"e_value": 1.5,
"stop_reason": "",
}
],
)
got = read_gate_evidence(str(db), run_id="r1")
assert len(got) == 1 and got[0]["ladder_rank"] == 0