feat: add dedupe_per_question to extract_run_db (canonical 902->900)
This commit is contained in:
@@ -338,6 +338,44 @@ class TestExtractRunDb:
|
||||
with pytest.raises(RuntimeError, match="无 run_id="):
|
||||
extract_run_db(src, dst, "nonexistent")
|
||||
|
||||
def test_dedupe_per_question_keeps_first_row(self, tmp_path):
|
||||
"""dedupe_per_question=True 时每 question_id 只保留 rowid 最小的首行。"""
|
||||
import sqlite3
|
||||
|
||||
src = tmp_path / "src.db"
|
||||
conn = sqlite3.connect(src)
|
||||
conn.execute(
|
||||
"CREATE TABLE _runs (run_id TEXT PRIMARY KEY, started_at TEXT)"
|
||||
)
|
||||
conn.execute("INSERT INTO _runs VALUES ('r1', 't0')")
|
||||
conn.execute(
|
||||
"CREATE TABLE predictions (run_id TEXT, question_id TEXT, prediction TEXT)"
|
||||
)
|
||||
# 743-1 三行(模拟 error/budget/finished),首行 prediction=NULL
|
||||
conn.executemany(
|
||||
"INSERT INTO predictions VALUES (?,?,?)",
|
||||
[
|
||||
("r1", "743-1", None),
|
||||
("r1", "743-1", None),
|
||||
("r1", "743-1", "C"),
|
||||
("r1", "q2", "A"),
|
||||
],
|
||||
)
|
||||
conn.commit()
|
||||
conn.close()
|
||||
|
||||
dst = tmp_path / "dst.db"
|
||||
from app.harness.store import extract_run_db
|
||||
|
||||
extract_run_db(src, dst, "r1", dedupe_per_question=True)
|
||||
|
||||
out = sqlite3.connect(dst)
|
||||
rows = out.execute(
|
||||
"SELECT question_id, prediction FROM predictions ORDER BY question_id"
|
||||
).fetchall()
|
||||
out.close()
|
||||
assert rows == [("743-1", None), ("q2", "A")], f"未按 rowid 首行去重: {rows}"
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# promote_to_seed
|
||||
|
||||
Reference in New Issue
Block a user