fix: read-only baseline queries skip _runs upsert (register_run flag)

This commit is contained in:
2026-07-16 05:36:47 -04:00
parent 96884dd149
commit 1468a53b7a
4 changed files with 63 additions and 21 deletions
+24
View File
@@ -215,6 +215,30 @@ class TestHarnessLogUpsert:
rows = log3.query("SELECT COUNT(*) as cnt FROM _runs WHERE run_id='run_1'")
assert rows[0]["cnt"] == 1
def test_register_run_false_skips_upsert(self, tmp_path: Path) -> None:
"""register_run=False 时只读打开不改写已有 _runs 行(started_at/status 不变)。"""
db = str(tmp_path / "h.db")
def _read_run_row(run_id: str) -> dict:
# 用 register_run=False 只读,避免读取本身污染 _runs
with HarnessLog(db, run_id, register_run=False) as log:
rows = log.query(
"SELECT started_at, status FROM _runs WHERE run_id=?", (run_id,)
)
return rows[0]
with HarnessLog(db, "r1"):
pass # 初次注册 + 正常退出置 completed
row0 = _read_run_row("r1")
time.sleep(0.02)
with HarnessLog(db, "r1", register_run=False) as log:
log.query("SELECT 1") # 只读
row1 = _read_run_row("r1")
assert row1["started_at"] == row0["started_at"]
assert row1["status"] == row0["status"]
# ===========================================================================
# RunLogImpl 测试