Repository navigation
docs: the published scoring formula stopped being the one the code uses #28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -600,3 +600,79 @@ def test_version_returns_quickly(self, home: Path, workdir: Path) -> None: | |
| assert "mem" in result.stdout | ||
|
|
||
| assert min(durations) < 0.5, f"mem --version took {min(durations):.3f}s" | ||
|
|
||
|
|
||
| class TestDocumentationDoesNotDrift: | ||
| """Docs that state a formula the code no longer uses are worse than none. | ||
|
|
||
| Both `README.md` and `ARCHITECTURE.md` published | ||
| `score = frequency*0.4 + recency*0.4 + context*0.2` for two releases after | ||
| that formula stopped existing — through the fix that normalised it and the | ||
| feature that added two more terms. Nothing detects prose going stale, so | ||
| the checks that can be mechanical are made mechanical. | ||
| """ | ||
|
|
||
| DOCS = ["README.md", "ARCHITECTURE.md", "PHILOSOPHY.md", "CHANGELOG.md"] | ||
|
|
||
| def test_every_adr_is_listed(self) -> None: | ||
| """A decision nobody can find from the index may as well not exist.""" | ||
| index = (REPO_ROOT / "ARCHITECTURE.md").read_text(encoding="utf-8") | ||
| missing = [ | ||
| path.name | ||
| for path in sorted((REPO_ROOT / "docs" / "decisions").glob("*.md")) | ||
| if path.name not in index | ||
| ] | ||
|
|
||
| assert not missing, f"ADRs not linked from ARCHITECTURE.md: {missing}" | ||
|
|
||
| def test_no_link_to_a_decision_record_is_broken(self) -> None: | ||
| import re | ||
|
|
||
| broken: list[tuple[str, str]] = [] | ||
| for name in self.DOCS: | ||
| text = (REPO_ROOT / name).read_text(encoding="utf-8") | ||
| for match in re.finditer(r"\]\((docs/decisions/[^)]+)\)", text): | ||
| if not (REPO_ROOT / match.group(1)).exists(): | ||
| broken.append((name, match.group(1))) | ||
|
|
||
| assert not broken, f"broken ADR links: {broken}" | ||
|
|
||
| def test_the_published_scoring_formula_names_every_feature(self) -> None: | ||
| """The docs must not describe a ranking that stopped existing. | ||
|
|
||
| Checked against `mem.ranking`'s own weight constants rather than a | ||
| hard-coded list, so adding a sixth feature fails here until it is | ||
| written down. | ||
| """ | ||
| from mem import ranking | ||
|
|
||
| features = [ | ||
| name[2:].lower() | ||
| for name in dir(ranking) | ||
| if name.startswith("W_") and isinstance(getattr(ranking, name), float) | ||
| ] | ||
| assert features, "no weight constants found — did they get renamed?" | ||
|
|
||
| for name in ("README.md", "ARCHITECTURE.md"): | ||
| formula = self._formula_in(REPO_ROOT / name) | ||
| unmentioned = [f for f in features if f not in formula] | ||
|
Comment on lines
+657
to
+658
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When a later ranking change alters a weight without renaming its Useful? React with 👍 / 👎. |
||
| assert not unmentioned, ( | ||
| f"{name} publishes a formula missing {unmentioned}; " | ||
| f"it is describing a ranking the code does not use:\n{formula}" | ||
| ) | ||
|
|
||
| @staticmethod | ||
| def _formula_in(path: Path) -> str: | ||
| """The formula itself, not the prose around it. | ||
|
|
||
| Bounded at the first blank line after `score =`. An earlier version | ||
| took a fixed 400-character window, which reached far enough to include | ||
| the bullet list underneath — so the check passed against a formula | ||
| with a term deleted, because the term was still named in the prose. | ||
| Verified by deleting one. | ||
| """ | ||
| text = path.read_text(encoding="utf-8").lower() | ||
| start = text.find("score =") | ||
| assert start != -1, f"{path.name} no longer shows the scoring formula" | ||
| end = text.find("\n\n", start) | ||
| return text[start : end if end != -1 else len(text)] | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Checking whether the filename occurs anywhere in
ARCHITECTURE.mddoes not prove that it is linked from the decision index. This already produces a false negative for ADR-010: its filename also appears in the variable-store section, so removing its new index entry would still leave this test green. Parse the decision-index links, or at least require the filename in that section's Markdown link targets.Useful? React with 👍 / 👎.