Skip to content

Commit 5111e02

Browse files
committed
fix(tests): the #733 tests import each changed module by its dotted path
The mutation gate of check `unit` (run 42758075984) selects a module's tests by the dotted import (scripts/ci_mutation_diff.py select_tests). The #733 test reached cycle_types only through headless_authoring's re-export, so cycle_budget_charge's mutants ran against the throttle test alone and survived; no test imported cycle_orchestration; nothing called _claude_invoke's early returns; and no test read the headless_authoring stanza's unpriced_calls key. The budget test now imports cycle_types itself, and a new file pins the no-child (known 0.0) and killed-child (unknown) returns of _claude_invoke, the _summarize_cycle roll-up, and run_wiki_maintenance's unpriced_calls key. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_018kyZYtAKnComJzh2PytToW
1 parent 29e4166 commit 5111e02

2 files changed

Lines changed: 109 additions & 5 deletions

File tree

‎tests_py/handlers/consolidation/test_unknown_cost_733.py‎

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@
1818
import mcp_server.handlers.consolidation.distill_drain as dd
1919
import mcp_server.handlers.consolidation.headless_authoring as ha
2020
from mcp_server.handlers.consolidation.claude_invoke import _parse_invoke_response
21+
from mcp_server.handlers.consolidation.cycle_types import (
22+
CycleBudget,
23+
cycle_budget_charge,
24+
cycle_budget_exhausted,
25+
)
2126

2227

2328
@pytest.mark.parametrize(
@@ -47,13 +52,15 @@ def test_reported_cost_is_read() -> None:
4752

4853

4954
def test_unpriced_charge_is_counted_not_summed() -> None:
50-
budget = ha.CycleBudget(deadline=time.monotonic() + 60.0, usd_cap=1.0)
51-
ha.cycle_budget_charge(budget, None)
52-
ha.cycle_budget_charge(budget, 0.25)
53-
ha.cycle_budget_charge(budget, None)
55+
# Imported from cycle_types itself: the mutation gate selects a module's
56+
# tests by its dotted import, not through headless_authoring's re-export.
57+
budget = CycleBudget(deadline=time.monotonic() + 60.0, usd_cap=1.0)
58+
cycle_budget_charge(budget, None)
59+
cycle_budget_charge(budget, 0.25)
60+
cycle_budget_charge(budget, None)
5461
assert budget.usd_spent == pytest.approx(0.25)
5562
assert budget.unpriced_calls == 2
56-
assert not ha.cycle_budget_exhausted(budget)
63+
assert not cycle_budget_exhausted(budget)
5764

5865

5966
def test_distill_summary_reports_unpriced_calls(
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
"""Where an unpriced call is reported, and when a dead call costs nothing (#733).
2+
3+
Slice 2 of #733 counts the calls whose cost the CLI did not report
4+
(``CycleBudget.unpriced_calls``). This file pins the three places that count
5+
must reach or be decided: ``_claude_invoke``'s two early returns (no child
6+
started is a known 0.0, a killed child is unknown), the cycle roll-up
7+
``_summarize_cycle``, and the ``headless_authoring`` stanza of
8+
``run_wiki_maintenance``. Each module is imported by its own dotted path so
9+
the mutation gate (``scripts/ci_mutation_diff.py`` ``select_tests``) runs
10+
these tests against it. No real ``claude`` subprocess is started.
11+
"""
12+
13+
from __future__ import annotations
14+
15+
import asyncio
16+
import time
17+
from typing import Any
18+
19+
import mcp_server.handlers.consolidation.claude_invoke as ci
20+
import mcp_server.handlers.consolidation.cycle_orchestration as co
21+
import mcp_server.handlers.consolidation.headless_authoring as ha
22+
from mcp_server.handlers.consolidation import wiki_maintenance
23+
from mcp_server.handlers.consolidation.cycle_types import CycleBudget, CycleSummary
24+
from tests_py.handlers.consolidation.test_wiki_maintenance import (
25+
_FakeSqliteStore,
26+
_silence_everything_except_citation_seed,
27+
)
28+
29+
30+
class _ExitedProc:
31+
returncode = 0
32+
33+
34+
def _invoke_with(monkeypatch, spawned: Any, comm: Any) -> Any:
35+
async def _spawn(argv, cwd, child_env):
36+
return spawned
37+
38+
async def _communicate(proc, prompt, call_timeout):
39+
return comm
40+
41+
monkeypatch.setattr(ci, "_spawn_claude_process", _spawn)
42+
monkeypatch.setattr(ci, "_communicate_with_timeout", _communicate)
43+
return asyncio.run(ci._claude_invoke("p", timeout=1.0))
44+
45+
46+
def test_no_child_started_is_a_known_zero_cost(monkeypatch) -> None:
47+
ir = _invoke_with(monkeypatch, spawned=None, comm=None)
48+
assert ir.text is None
49+
assert ir.cost_usd == 0.0
50+
assert ir.cost_usd is not None
51+
52+
53+
def test_a_child_with_no_response_has_an_unknown_cost(monkeypatch) -> None:
54+
ir = _invoke_with(monkeypatch, spawned=_ExitedProc(), comm=None)
55+
assert ir.text is None
56+
assert ir.cost_usd is None
57+
58+
59+
def test_a_response_is_parsed_with_its_reported_cost(monkeypatch) -> None:
60+
out = b'{"result": "x", "total_cost_usd": 0.5}'
61+
ir = _invoke_with(monkeypatch, spawned=_ExitedProc(), comm=(out, b""))
62+
assert ir.text == "x"
63+
assert ir.cost_usd == 0.5
64+
65+
66+
def test_cycle_summary_carries_the_unpriced_count() -> None:
67+
budget = CycleBudget(deadline=time.monotonic() + 60.0, usd_cap=0.0)
68+
budget.usd_spent = 0.25
69+
budget.unpriced_calls = 3
70+
summary = co._summarize_cycle(time.monotonic(), [], [], [], [], budget, ha)
71+
assert summary.unpriced_calls == 3
72+
assert summary.usd_spent == 0.25
73+
74+
75+
def test_wiki_maintenance_reports_unpriced_calls(monkeypatch) -> None:
76+
_silence_everything_except_citation_seed(monkeypatch)
77+
78+
async def _cycle() -> CycleSummary:
79+
return CycleSummary(
80+
pages_scanned=0,
81+
pages_with_gaps=0,
82+
drains_attempted=2,
83+
drains_filled=2,
84+
drains_failed=0,
85+
duration_ms=0,
86+
results=[],
87+
unpriced_calls=2,
88+
)
89+
90+
monkeypatch.setattr(wiki_maintenance, "_headless_authoring_enabled", lambda: True)
91+
monkeypatch.setattr(wiki_maintenance, "run_headless_authoring_cycle", _cycle)
92+
result = asyncio.run(
93+
wiki_maintenance.run_wiki_maintenance(
94+
_FakeSqliteStore(), max_purges_per_axis=None
95+
)
96+
)
97+
assert result["headless_authoring"]["unpriced_calls"] == 2

0 commit comments

Comments
 (0)