fix: atomic writes for manifest/record_run/update_best (tmp+replace)
This commit is contained in:
@@ -259,6 +259,33 @@ def test_update_manifest_valid(store_dir: Path, workspace_dir: Path) -> None:
|
||||
assert manifest["current"]["skills"] == "skills/v2"
|
||||
|
||||
|
||||
def test_update_manifest_is_atomic(
|
||||
store_dir: Path, workspace_dir: Path, monkeypatch: pytest.MonkeyPatch
|
||||
) -> None:
|
||||
"""写 manifest 途中崩溃不产生半截 JSON(原子写:os.replace 失败也不损原文件)。"""
|
||||
from app.harness import workspace as ws
|
||||
|
||||
init_workspace(
|
||||
workspace_dir,
|
||||
store_dir,
|
||||
questions="benchmarks/Video-MME",
|
||||
skills_version="v1",
|
||||
prompts_version="v1",
|
||||
)
|
||||
original = (workspace_dir / "manifest.json").read_text()
|
||||
|
||||
def _boom(_src: object, _dst: object) -> None:
|
||||
raise OSError("crash during replace")
|
||||
|
||||
monkeypatch.setattr(ws.os, "replace", _boom)
|
||||
with pytest.raises(OSError, match="crash during replace"):
|
||||
update_manifest(workspace_dir, skills="skills/v2")
|
||||
|
||||
# 原 manifest 未被破坏(内容不变且仍是合法 JSON)
|
||||
assert (workspace_dir / "manifest.json").read_text() == original
|
||||
assert json.loads((workspace_dir / "manifest.json").read_text())
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# record_run
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user