mirror of
https://github.com/kuhyx/testsAndMisc.git
synced 2026-11-10 22:27:01 +01:00
Answers "what is billed on every turn regardless of use" by measurement instead of recall, which is the part earlier audits kept getting wrong. A surface is reported dead only when unused in BOTH windows. One earlier audit's seven-day dead list included six servers that had been used within thirty days, so a single window is not evidence. Shares are weighted with cache-read weight 0.1, so a cached surface is not billed as though it were re-read in full each turn. Verified by running it, not just by tests: the report renders over 44,311 turns, putting rules/ at 4,907 tokens (1.77%), MEMORY.md at 4,312 (1.55%), memories/ at 3,758 (1.35%), skill descriptions at 3,279 (1.18%) and CLAUDE.md at 2,057 (0.74%), with per-MCP 7d/30d call counts behind each verdict. The files were found untracked in the tree from an earlier session; every module is already under the 250-line cap, so nothing needed splitting, and the package was already at 100% branch coverage, so nothing needed new tests. This lands the instrument only -- no surface is unregistered on its say-so. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
65 lines
2.1 KiB
Python
65 lines
2.1 KiB
Python
"""Tests for the standing-cost checkup report."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import pytest
|
|
|
|
from python_pkg.token_audit import checkup, surfaces, unused
|
|
|
|
|
|
@pytest.fixture(autouse=True)
|
|
def stub_sources(monkeypatch: pytest.MonkeyPatch) -> None:
|
|
"""Replace disk scans with fixed rows so the render is deterministic."""
|
|
monkeypatch.setattr(
|
|
surfaces,
|
|
"collect",
|
|
lambda: [
|
|
surfaces.Surface("rules/", "always-on", 4000),
|
|
surfaces.Surface("global MCP", "13 active", 0, measurable=True),
|
|
],
|
|
)
|
|
monkeypatch.setattr(
|
|
unused,
|
|
"mcp_usage",
|
|
lambda: [unused.Usage("reaper", 0, 0), unused.Usage("ck3", 0, 9)],
|
|
)
|
|
monkeypatch.setattr(unused, "skill_usage", lambda: [unused.Usage("grilling", 0, 0)])
|
|
|
|
|
|
def test_report_lists_every_surface() -> None:
|
|
"""A surface present in the enumeration reaches the report."""
|
|
text = checkup.build(44311, 1230346533)
|
|
assert "rules/" in text
|
|
assert "global MCP" in text
|
|
|
|
|
|
def test_disk_sized_surface_shows_weighted_share() -> None:
|
|
"""Shares are weighted, not raw — the unit error an audit made."""
|
|
text = checkup.build(44311, 1230346533)
|
|
assert "| 1,000 | 0.36% |" in text
|
|
|
|
|
|
def test_unmeasurable_surface_is_labelled() -> None:
|
|
"""A surface that needs an A/B says so rather than reporting zero bytes."""
|
|
assert "A/B only" in checkup.build(1000, 1000000)
|
|
|
|
|
|
def test_only_both_window_zero_is_parked() -> None:
|
|
"""ck3 (unused 7d, used 30d) must not be recommended for parking."""
|
|
text = checkup.build(44311, 1230346533)
|
|
assert "| reaper | 0 | 0 | **park** |" in text
|
|
assert "| ck3 | 0 | 9 | keep |" in text
|
|
|
|
|
|
def test_skills_section_present() -> None:
|
|
"""Skills are audited alongside MCP servers."""
|
|
assert "## Skills" in checkup.build(1000, 1000000)
|
|
|
|
|
|
def test_main_defaults_and_args(capsys: pytest.CaptureFixture[str]) -> None:
|
|
"""The CLI accepts turns and total, and defaults when omitted."""
|
|
assert checkup.main([]) == 0
|
|
assert "Standing-cost checkup" in capsys.readouterr().out
|
|
assert checkup.main(["100", "1000000"]) == 0
|
|
assert "100 turns" in capsys.readouterr().out
|