Python · 2082 bytes Raw Blame History
1 """Meta-test: every documented spec/CLI option must have a real consumer.
2
3 Audit 01 caught two dead options (P14 ``defaults.differential`` and
4 P15 ``compute(weights=...)``) that were defined, documented, and never
5 read by any code path. Sprint 03 wired both of them. This test pins
6 that wiring so a future refactor that drops the consumer surfaces here
7 rather than in a user's report.
8
9 The check is a literal substring grep: each documented option name
10 must appear in *consumer* code outside the spec / scoring module that
11 declares it. We walk ``src/dlm_sway`` for the substring and compare to
12 a known set of declaration sites; anything else counts as a consumer.
13 """
14
15 from __future__ import annotations
16
17 from pathlib import Path
18
19 import pytest
20
21 SRC_ROOT = Path(__file__).parents[2] / "src" / "dlm_sway"
22
23
24 def _grep_files(needle: str) -> list[Path]:
25 """Return every .py file under ``SRC_ROOT`` whose text contains ``needle``."""
26 return sorted(p for p in SRC_ROOT.rglob("*.py") if needle in p.read_text(encoding="utf-8"))
27
28
29 @pytest.mark.parametrize(
30 ("option", "declaration_files"),
31 [
32 # P14: defaults.differential
33 (
34 "differential",
35 # Declared in the spec; everything else is a consumer.
36 {"src/dlm_sway/suite/spec.py"},
37 ),
38 # P15: compute(weights=...)
39 (
40 "score_weights",
41 # Declared in the spec; everything else is a consumer.
42 {"src/dlm_sway/suite/spec.py"},
43 ),
44 ],
45 )
46 def test_documented_options_have_consumers(option: str, declaration_files: set[str]) -> None:
47 hits = _grep_files(option)
48 assert hits, f"audit-listed option {option!r} not found anywhere — was it deleted?"
49
50 rel_hits = {str(h.relative_to(SRC_ROOT.parents[1])) for h in hits}
51 consumers = rel_hits - declaration_files
52 assert consumers, (
53 f"option {option!r} appears only in declarations {declaration_files}; "
54 f"no consumer found. Audit 01 P14/P15 caught this exact dead-option "
55 f"pattern; restore a consumer or drop the option."
56 )