fix(harness): change _runs INSERT OR IGNORE to ON CONFLICT DO UPDATE for incremental infer
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -8,6 +8,7 @@ from __future__ import annotations
|
||||
|
||||
import sqlite3
|
||||
import threading
|
||||
import time
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
import pytest
|
||||
@@ -118,8 +119,8 @@ class TestHarnessLog:
|
||||
|
||||
assert row["status"] == "failed"
|
||||
|
||||
def test_insert_or_ignore_idempotent(self, db_path: str, run_id: str) -> None:
|
||||
"""同一 run_id 多次创建 HarnessLog 不报错(INSERT OR IGNORE 幂等)。"""
|
||||
def test_upsert_idempotent(self, db_path: str, run_id: str) -> None:
|
||||
"""同一 run_id 多次创建 HarnessLog 不报错(ON CONFLICT DO UPDATE 幂等)。"""
|
||||
with HarnessLog(db_path, run_id):
|
||||
pass
|
||||
|
||||
@@ -134,7 +135,7 @@ class TestHarnessLog:
|
||||
).fetchone()[0]
|
||||
conn.close()
|
||||
|
||||
assert count == 1, "INSERT OR IGNORE 应保证 _runs 只有一行"
|
||||
assert count == 1, "ON CONFLICT DO UPDATE 应保证 _runs 只有一行"
|
||||
|
||||
def test_wal_mode(self, db_path: str, run_id: str) -> None:
|
||||
"""连接初始化后 journal_mode 应为 WAL。"""
|
||||
@@ -195,6 +196,34 @@ class TestHarnessLog:
|
||||
assert rows[0]["val"] == "2"
|
||||
|
||||
|
||||
# ===========================================================================
|
||||
# HarnessLog upsert 行为测试
|
||||
# ===========================================================================
|
||||
|
||||
|
||||
class TestHarnessLogUpsert:
|
||||
"""_runs 表 upsert 行为。"""
|
||||
|
||||
def test_same_run_id_updates_started_at(self, tmp_path: Path) -> None:
|
||||
"""同 run_id 第二次创建 HarnessLog 应更新 started_at。"""
|
||||
db = str(tmp_path / "test.db")
|
||||
with HarnessLog(db, "run_1", git_sha="abc") as log1:
|
||||
rows = log1.query("SELECT started_at FROM _runs WHERE run_id='run_1'")
|
||||
first_time = rows[0]["started_at"]
|
||||
|
||||
time.sleep(0.05)
|
||||
|
||||
with HarnessLog(db, "run_1", git_sha="abc") as log2:
|
||||
rows = log2.query("SELECT started_at FROM _runs WHERE run_id='run_1'")
|
||||
second_time = rows[0]["started_at"]
|
||||
|
||||
assert second_time > first_time
|
||||
|
||||
with HarnessLog(db, "run_1") as log3:
|
||||
rows = log3.query("SELECT COUNT(*) as cnt FROM _runs WHERE run_id='run_1'")
|
||||
assert rows[0]["cnt"] == 1
|
||||
|
||||
|
||||
# ===========================================================================
|
||||
# RunLogImpl 测试
|
||||
# ===========================================================================
|
||||
|
||||
Reference in New Issue
Block a user