Skip to content

Commit e164843

Browse files
authored
test: report a bare docs/adr/NNNN citation as unresolved (#129)
1 parent f96e832 commit e164843

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

‎tests/test_adr_citations.py‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
_REPO_ROOT: typing.Final = pathlib.Path(__file__).resolve().parent.parent
99
_ADR_DIR: typing.Final = "docs/adr/"
10-
_CITATION: typing.Final = re.compile(r"docs/adr/\d{4}-[a-z0-9-]+\.md")
10+
_CITATION: typing.Final = re.compile(r"docs/adr/\d{4}(?:-[a-z0-9-]+\.md)?")
1111
_UNWALKED_DIR: typing.Final = "node_modules"
1212

1313

@@ -45,6 +45,8 @@ def test_every_adr_path_cited_from_python_resolves() -> None:
4545
offline link gate reads Markdown only, so a path in a docstring, a comment or a guard message
4646
is otherwise checked by nothing, and an `INVARIANT:` docstring that names its ADR silently
4747
loses the rationale the test depends on. A user who trips a guard is handed a link to follow.
48+
A bare `docs/adr/NNNN` is reported as well: it names no file, so it would survive the same
49+
rename or drop unnoticed and point at whatever record holds that number next.
4850
"""
4951
unresolved = unresolved_citations(_REPO_ROOT)
5052

@@ -64,6 +66,18 @@ def test_a_citation_of_a_missing_adr_is_reported_with_its_citing_file(tmp_path:
6466
assert unresolved_citations(tmp_path) == [("pkg/mod.py", f"{_ADR_DIR}9999-missing.md")]
6567

6668

69+
def test_a_short_form_citation_is_reported_even_when_the_adr_exists(tmp_path: pathlib.Path) -> None:
70+
"""`docs/adr/NNNN` with no slug names nothing on disk, so a rename or a drop never breaks it."""
71+
(tmp_path / _ADR_DIR).mkdir(parents=True)
72+
(tmp_path / _ADR_DIR / "0002-kept.md").write_text("# kept\n", encoding="utf-8")
73+
(tmp_path / "pkg").mkdir()
74+
(tmp_path / "pkg" / "mod.py").write_text(
75+
f'"""Argued in {_ADR_DIR}0002 and {_ADR_DIR}0002-kept.md."""\n', encoding="utf-8"
76+
)
77+
78+
assert unresolved_citations(tmp_path) == [("pkg/mod.py", f"{_ADR_DIR}0002")]
79+
80+
6781
def test_a_citation_split_across_adjacent_string_literals_is_found(tmp_path: pathlib.Path) -> None:
6882
"""Python joins adjacent literals at parse time, which is what the `nack` guard message relies on."""
6983
(tmp_path / "guard.py").write_text(

0 commit comments

Comments
 (0)