refactor: assert warn sink, rename disk-pair sifter, trim WHAT docstrings
Capture loguru warning via project sink pattern and assert the dangling-orphan warning is emitted; rename _sift_disk_pairs to _keep_complete_disk_pairs; drop pure-WHAT docstrings on __init__/pending_orphans while keeping WHY notes.
This commit is contained in:
@@ -15,6 +15,7 @@ from __future__ import annotations
|
||||
import json
|
||||
|
||||
import pytest
|
||||
from loguru import logger
|
||||
|
||||
from app.harness.pools import _q_to_dict
|
||||
from app.question_gen.pair_atomic_writer import (
|
||||
@@ -179,7 +180,7 @@ def test_write_read_roundtrip_keeps_pair_and_single(tmp_path) -> None:
|
||||
assert {q.flip_axis for q in loaded_pair.questions} == {"before_after"}
|
||||
|
||||
|
||||
def test_read_drops_disk_dangling_orphan(tmp_path, caplog) -> None:
|
||||
def test_read_drops_disk_dangling_orphan(tmp_path) -> None:
|
||||
"""磁盘上某 pair 只有 original(缺 mirror)→ read_accepted warn+drop,不 raise。"""
|
||||
single = _make_single()
|
||||
original, _ = _make_pair()
|
||||
@@ -188,11 +189,19 @@ def test_read_drops_disk_dangling_orphan(tmp_path, caplog) -> None:
|
||||
out = tmp_path / "bank.json"
|
||||
out.write_text(json.dumps(records, ensure_ascii=False, indent=2), encoding="utf-8")
|
||||
|
||||
loaded = read_accepted(out)
|
||||
# loguru 不走标准 logging,用项目既定 sink 捕获模式(见 test_inference_pair_aggregate)
|
||||
captured: list[str] = []
|
||||
sink_id = logger.add(captured.append, level="WARNING", format="{message}")
|
||||
try:
|
||||
loaded = read_accepted(out)
|
||||
finally:
|
||||
logger.remove(sink_id)
|
||||
|
||||
assert len(loaded) == 1
|
||||
assert loaded[0].kind == "single"
|
||||
assert loaded[0].questions[0].question_id == single.question_id
|
||||
# warn+drop 契约的 "warn" 半:悬挂孤儿必须告警,不静默丢弃
|
||||
assert any("悬挂孤儿" in msg for msg in captured), "悬挂孤儿未告警(静默丢弃)"
|
||||
|
||||
|
||||
def test_read_raises_on_disk_corrupt_duplicate_role(tmp_path) -> None:
|
||||
|
||||
Reference in New Issue
Block a user