Skip to content

Commit e25ecaf

Browse files
The deep dive's verified figures are re-derived by a test, or they are not on the line
The **Verified this pass** paragraph closes the deep dive with concrete numbers, and nothing checked them, so they drifted twice: it read "1,533 passed … 103 submodules" against a tree with 1,754 tests and 116 submodules, and it read "1,985 passed, 12 deselected" against a tree with 2,137 selected and 13 live. The paragraph's whole value is that its numbers are real. A reader who spots one stale figure discounts every other verified claim on the page, including the ones the suite genuinely enforces. The figures are now quoted as what one command re-derives — how many tests `pytest` selects, and how many it holds back as `live` — rather than as a pass count. That reword is the point, not cosmetics: a pass count cannot be re-derived without running the suite from inside itself, which is exactly how "1,985 passed" came to be a number no test owned. The suite being green is asserted by the suite being green. tests/test_deep_dive.py re-derives both in one collection pass, in a subprocess — this module is collected by the session doing the asking, so re-entering the collector in-process is not on. `-m ""` clears the addopts `-m 'not live'` and the marker is read off each item, so one pass yields both figures instead of two passes yielding one each; it costs about two seconds. Two guards sit behind the two comparisons, both closing ways the check could pass while saying nothing. One asserts the figures are still quoted at all, so deleting a number makes the test red rather than vacuous — the trap `tests/test_readme.py` already closes for its fenced blocks. The other asserts no *unowned* figure has appeared on the line: any bare count with a unit that this file does not re-derive fails, with wording that says to add a check or take the number off. That is the rule the issue settled on. The version the paragraph says is on PyPI is held against pyproject's, for the same reason `ci.yml` already refuses a `grapharc.__version__` that disagrees with it: a release note naming a third number is that failure with no check. Restoring the historical drift turns both the comparison and the unowned-figure guard red. Closes #42 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent 6b7ad91 commit e25ecaf

2 files changed

Lines changed: 173 additions & 1 deletion

File tree

docs/deep-dive.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ A stable system is not one that claims to have no edges — it is one whose edge
254254
- **`.env` and `grapharc.toml` follow the same discovery rule: the working directory, and nowhere else.** Neither searches parent directories — a run must not be governed by a file you did not know about, and must not be *billed* to one either. **This is a behaviour change:** the credential loader used to walk up to `/`, so a `.env` in an ancestor directory (a `$HOME` one on a shared box, a client project one above a demo checkout) was picked up silently. If you relied on that, move the file into the directory you run from, `export` the variable, or pass `env_file=` to name it explicitly. A real environment variable still beats any file.
255255
- **`grapharc run` has no budget unless you give it one.** Set any of `--max-tokens`, `--max-iterations`, `--max-seconds`, or `--max-concurrency`; without them each dimension is unlimited and the gate admits a topology of any worst-case cost.
256256

257-
**Verified this pass:** `pytest`1,985 passed, 12 deselected (the live ones); `ruff check .` clean; all eight `grapharc demo` stages green, plus the `trace` / `metrics` / `viz` / `replay` tour against a freshly recorded demo trace; the wheel builds and imports all submodules in a clean virtualenv with `[all]`, and `0.1.5` on PyPI is that wheel. The test count is a snapshot, not a property of the project — `pytest` re-derives it in one command, which is the only reason it is quoted.
257+
**Verified this pass:** `pytest`green, 2,137 selected and 13 deselected (the live ones); `ruff check .` clean; all eight `grapharc demo` stages green, plus the `trace` / `metrics` / `viz` / `replay` tour against a freshly recorded demo trace; the wheel builds and imports all submodules in a clean virtualenv with `[all]`, and `0.1.5` on PyPI is that wheel. The counts are a snapshot, not a property of the project — `pytest` re-derives them in one command, which is the only reason they are quoted, and `tests/test_deep_dive.py` fails this line rather than letting it drift.
258258

259259
[ROADMAP.md](../ROADMAP.md) tracks what is built and what is not, item by item.
260260

tests/test_deep_dive.py

Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
"""The deep dive's **Verified this pass** paragraph, held against reality.
2+
3+
The paragraph's whole value is that its numbers are real. Nothing checked them,
4+
so they drifted: it read "1,533 passed … 103 submodules" while the tree it
5+
described had grown to 1,754 tests and 116 submodules, and it read "1,985
6+
passed, 12 deselected" against a tree with 2,132 selected and 13 live. A reader
7+
who spots one stale figure discounts every other verified claim on the page —
8+
including the ones the suite genuinely enforces.
9+
10+
This is the discipline the cookbook pages and the README's runnable blocks
11+
already have (`tests/test_cookbook_*.py`, `tests/test_readme.py` byte-compare
12+
those against real output): prose that states a checkable fact gets a check.
13+
14+
The figures are therefore quoted as what one command re-derives — how many
15+
tests `pytest` selects, and how many it holds back as `live` — rather than as
16+
a pass count, which cannot be re-derived without running the suite from inside
17+
itself. A green suite is asserted by the suite being green.
18+
"""
19+
20+
from __future__ import annotations
21+
22+
import re
23+
import subprocess
24+
import sys
25+
import textwrap
26+
import tomllib
27+
from pathlib import Path
28+
29+
import pytest
30+
31+
ROOT = Path(__file__).resolve().parents[1]
32+
DEEP_DIVE = ROOT / "docs" / "deep-dive.md"
33+
MARKER = "**Verified this pass:**"
34+
35+
# The recount runs pytest in a subprocess rather than calling `pytest.main`
36+
# in-process: this module is itself collected by the session doing the asking,
37+
# and re-entering the collector from inside it is not a supported thing to do.
38+
_RECOUNT = textwrap.dedent(
39+
"""
40+
import pytest
41+
42+
43+
class Capture:
44+
def pytest_collection_finish(self, session):
45+
selected = live = 0
46+
for item in session.items:
47+
if item.get_closest_marker("live"):
48+
live += 1
49+
else:
50+
selected += 1
51+
print(f"COUNTS {selected} {live}")
52+
53+
54+
# `-m ""` clears the `-m 'not live'` that pyproject's addopts supplies, so
55+
# one collection pass yields both figures instead of two passes yielding one
56+
# each. The marker is read off each item rather than inferred from a second
57+
# selection.
58+
raise SystemExit(
59+
pytest.main(
60+
["--collect-only", "-q", "-m", "", "-p", "no:cacheprovider"],
61+
plugins=[Capture()],
62+
)
63+
)
64+
"""
65+
)
66+
67+
68+
def _paragraph() -> str:
69+
for line in DEEP_DIVE.read_text(encoding="utf-8").splitlines():
70+
if line.startswith(MARKER):
71+
return line
72+
raise AssertionError(f"{DEEP_DIVE.name} has no line starting with {MARKER!r}")
73+
74+
75+
@pytest.fixture(scope="module")
76+
def recount() -> tuple[int, int]:
77+
"""(selected, deselected-as-live), re-derived from this tree."""
78+
proc = subprocess.run(
79+
[sys.executable, "-c", _RECOUNT],
80+
cwd=ROOT,
81+
capture_output=True,
82+
text=True,
83+
)
84+
match = re.search(r"^COUNTS (\d+) (\d+)$", proc.stdout, re.M)
85+
assert match, (
86+
f"collection did not report counts (exit {proc.returncode}):\n"
87+
f"{proc.stdout[-2000:]}\n{proc.stderr[-2000:]}"
88+
)
89+
return int(match.group(1)), int(match.group(2))
90+
91+
92+
def _quoted(pattern: str) -> str:
93+
line = _paragraph()
94+
match = re.search(pattern, line)
95+
assert match, f"the paragraph no longer quotes {pattern!r}:\n{line}"
96+
return match.group(1)
97+
98+
99+
# -- the figures ------------------------------------------------------------
100+
101+
102+
def test_the_quoted_selection_is_what_pytest_selects(recount):
103+
selected, _ = recount
104+
quoted = int(_quoted(r"([\d,]+) selected").replace(",", ""))
105+
106+
assert quoted == selected, (
107+
f"update the **Verified this pass** paragraph in {DEEP_DIVE.name}: it "
108+
f"says {quoted:,} selected, this tree has {selected:,}"
109+
)
110+
111+
112+
def test_the_quoted_deselection_is_what_pytest_holds_back(recount):
113+
_, live = recount
114+
quoted = int(_quoted(r"([\d,]+) deselected").replace(",", ""))
115+
116+
assert quoted == live, (
117+
f"update the **Verified this pass** paragraph in {DEEP_DIVE.name}: it "
118+
f"says {quoted:,} deselected, this tree marks {live:,} `live`"
119+
)
120+
121+
122+
def test_the_quoted_published_version_is_the_packaged_one():
123+
"""The paragraph names the version it says is on PyPI. `ci.yml` already
124+
refuses a `grapharc.__version__` that disagrees with pyproject; a release
125+
note naming a third number is the same failure with no check on it."""
126+
with open(ROOT / "pyproject.toml", "rb") as fh:
127+
packaged = tomllib.load(fh)["project"]["version"]
128+
quoted = _quoted(r"`(\d+\.\d+\.\d+)` on PyPI")
129+
130+
assert quoted == packaged, (
131+
f"update the **Verified this pass** paragraph in {DEEP_DIVE.name}: it "
132+
f"says {quoted} is on PyPI, pyproject says {packaged}"
133+
)
134+
135+
136+
# -- a guard on the guard ---------------------------------------------------
137+
138+
139+
def test_the_paragraph_still_quotes_every_figure_this_file_checks():
140+
"""A rewrite that drops a figure must not pass by leaving nothing to check.
141+
142+
Without this, deleting "2,145 selected" from the sentence would make the
143+
test above vacuous rather than red — the same trap the README's
144+
`test_the_section_still_holds_the_two_blocks_this_file_checks` closes.
145+
"""
146+
line = _paragraph()
147+
148+
assert re.search(r"[\d,]+ selected", line), line
149+
assert re.search(r"[\d,]+ deselected", line), line
150+
assert re.search(r"`\d+\.\d+\.\d+` on PyPI", line), line
151+
152+
153+
def test_the_paragraph_quotes_no_figure_that_nothing_re_derives():
154+
"""The rule the issue settled on: a number on this line is either
155+
re-derived by a test in this file, or it does not belong on the line.
156+
157+
`pass`/`fail` counts are the specific thing being kept off it — they cannot
158+
be re-derived without running the suite from inside itself, which is how
159+
the old "1,985 passed" figure came to be unowned in the first place.
160+
"""
161+
line = _paragraph()
162+
checked = re.sub(r"[\d,]+ (?:selected|deselected)", "", line)
163+
checked = re.sub(r"`\d+\.\d+\.\d+` on PyPI", "", checked)
164+
# Version numbers inside command names and prose ordinals are not figures;
165+
# what this catches is a bare count with a unit, e.g. "1,985 passed".
166+
stray = re.findall(r"[\d,]{3,} \w+", checked)
167+
168+
assert not stray, (
169+
f"these figures on the **Verified this pass** line are re-derived by "
170+
f"nothing: {stray}. Either add a check for them here or take them off "
171+
f"the line — that is the rot this file exists to stop."
172+
)

0 commit comments

Comments
 (0)