tests / unittest (push) Failing after 13s
Stage 1 flags the living documents a pull request makes stale (no model, nothing sent). Stage 2, on repositories that opt in with drafter: claude, has Claude Code draft the edits in a sandboxed copy of the tree and opens them as a pull request into the feature branch. A monthly pass re-reads the top-level documents against the whole repository. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
167 lines
8.3 KiB
Python
167 lines
8.3 KiB
Python
import unittest
|
|
|
|
from docs_review.changes import parse_name_status
|
|
from docs_review.flags import compute_flags, group_uncovered, whole_repo_changes
|
|
|
|
NONE = frozenset()
|
|
|
|
|
|
class FlagTests(unittest.TestCase):
|
|
def test_rename_and_delete_make_dead(self):
|
|
ch = parse_name_status("D\tR/old.R\nR087\tR/a.R\tR/b.R\nA\tscripts/build_x.R\n")
|
|
flags = compute_flags(
|
|
ch, NONE, NONE, {"README.md": "Uses `R/old.R` and `R/a.R`."}, {},
|
|
("R", "scripts"), None,
|
|
)
|
|
dead = {(f.doc, f.subject, f.detail) for f in flags if f.kind == "dead"}
|
|
self.assertEqual(
|
|
dead,
|
|
{("README.md", "R/old.R", "removed"), ("README.md", "R/a.R", "renamed to R/b.R")},
|
|
)
|
|
self.assertFalse([f for f in flags if f.kind == "touched" and f.subject == "R/old.R"])
|
|
|
|
def test_changed_doc_still_gets_dead_flag(self):
|
|
ch = parse_name_status("D\tR/old.R\nM\tREADME.md\n")
|
|
flags = compute_flags(ch, NONE, NONE, {"README.md": "Uses `R/old.R`."}, {}, ("R",), None)
|
|
self.assertEqual(
|
|
[(f.kind, f.doc, f.subject) for f in flags], [("dead", "README.md", "R/old.R")]
|
|
)
|
|
|
|
def test_modified_path_is_touched(self):
|
|
ch = parse_name_status("M\tR/storage.R\n")
|
|
flags = compute_flags(ch, NONE, NONE, {"README.md": "See R/storage.R."}, {}, ("R",), None)
|
|
self.assertEqual(
|
|
[(f.kind, f.doc, f.subject, f.detail) for f in flags],
|
|
[("touched", "README.md", "R/storage.R", "changed")],
|
|
)
|
|
|
|
def test_uncovered_by_path_or_basename(self):
|
|
ch = parse_name_status("A\tscripts/build_x.R\nA\tscripts/build_y.R\nA\ttests/t.R\n")
|
|
flags = compute_flags(
|
|
ch, NONE, NONE, {"docs/README.md": "Run build_x.R first."}, {},
|
|
("R", "scripts"), None,
|
|
)
|
|
self.assertEqual(
|
|
[(f.subject, f.detail) for f in flags if f.kind == "uncovered"],
|
|
[("scripts/build_y.R", "new file")],
|
|
)
|
|
|
|
def test_ambiguous_basename_matches_by_path_only(self):
|
|
ch = parse_name_status("A\tR/util.R\nA\tscripts/util.R\n")
|
|
flags = compute_flags(
|
|
ch, NONE, NONE, {"README.md": "Uses util.R and R/util.R."}, {},
|
|
("R", "scripts"), None,
|
|
)
|
|
self.assertEqual(
|
|
[f.subject for f in flags if f.kind == "uncovered"], ["scripts/util.R"]
|
|
)
|
|
|
|
def test_basename_must_be_unique_across_the_repository(self):
|
|
ch = parse_name_status("M\tscripts/README.md\n")
|
|
docs = {"docs/guide.md": "Start with `README.md`."}
|
|
repo = ["README.md", "scripts/README.md", "docs/guide.md"]
|
|
flags = compute_flags(ch, NONE, NONE, docs, {}, ("scripts",), None, repo_files=repo)
|
|
self.assertEqual([f for f in flags if f.kind == "touched"], [])
|
|
alone = compute_flags(ch, NONE, NONE, docs, {}, ("scripts",), None,
|
|
repo_files=["scripts/README.md", "docs/guide.md"])
|
|
self.assertEqual([(f.kind, f.subject) for f in alone],
|
|
[("touched", "scripts/README.md")])
|
|
|
|
def test_touched_by_name_and_suppressed_when_doc_also_changed(self):
|
|
ch = parse_name_status("M\tR/storage.R\nM\tdocs/README.md\n")
|
|
docs = {"README.md": "`write_table()` writes.", "docs/README.md": "`write_table()`"}
|
|
flags = compute_flags(ch, NONE, frozenset({"write_table"}), docs, {}, ("R",), None)
|
|
self.assertEqual({f.doc for f in flags if f.kind == "touched"}, {"README.md"})
|
|
self.assertEqual(
|
|
[f.detail for f in flags if f.kind == "touched"], ["name changed"]
|
|
)
|
|
|
|
def test_stale_generated(self):
|
|
ch = parse_name_status("M\tscripts/report_coverage.R\n")
|
|
gen = {"data/x_coverage_report.md": "Generated by scripts/report_coverage.R"}
|
|
flags = compute_flags(ch, NONE, NONE, {}, gen, ("scripts",), None)
|
|
self.assertEqual(
|
|
[(f.kind, f.doc) for f in flags], [("stale_generated", "data/x_coverage_report.md")]
|
|
)
|
|
self.assertEqual(flags[0].detail, "input changed: scripts/report_coverage.R")
|
|
|
|
def test_generated_doc_in_changes_not_stale(self):
|
|
ch = parse_name_status("M\tscripts/report_coverage.R\nM\tdata/r.md\n")
|
|
gen = {"data/r.md": "Generated by scripts/report_coverage.R"}
|
|
self.assertEqual(compute_flags(ch, NONE, NONE, {}, gen, ("scripts",), None), ())
|
|
|
|
def test_unguided(self):
|
|
flags = compute_flags(
|
|
(), NONE, NONE, {"README.md": "", "pm/VISION.md": ""}, {}, ("R",),
|
|
("docs/README.md", "| [README](../README.md) | everyone |"),
|
|
)
|
|
self.assertEqual([f.doc for f in flags if f.kind == "unguided"], ["pm/VISION.md"])
|
|
self.assertEqual(flags[0].detail, "not described in docs/README.md")
|
|
|
|
def test_group_uncovered(self):
|
|
ch = whole_repo_changes(
|
|
[f"scripts/report_{i}.R" for i in range(9)] + ["R/x.R"], ("R", "scripts")
|
|
)
|
|
g = group_uncovered(compute_flags(ch, NONE, NONE, {}, {}, ("R", "scripts"), None))
|
|
self.assertEqual(
|
|
[(f.subject, f.detail) for f in g],
|
|
[("R/x.R", "1 file"), ("scripts/report_*", "9 files")],
|
|
)
|
|
|
|
def test_guide_directory_mention_covers_files_under_it(self):
|
|
docs = {"docs/book/01-a.qmd": "", "docs/book/sub/02-b.qmd": "",
|
|
"docs/other.md": ""}
|
|
guide = ("docs/README.md", "| [`book/`](book/README.md) | the book |")
|
|
flags = compute_flags((), NONE, NONE, docs, {}, ("R",), guide)
|
|
self.assertEqual([f.doc for f in flags if f.kind == "unguided"], ["docs/other.md"])
|
|
|
|
def test_guide_readme_mention_covers_its_directory(self):
|
|
docs = {"docs/book/01-a.qmd": "", "pm/VISION.md": ""}
|
|
guide = ("docs/README.md", "The book starts at `docs/book/README.md`.")
|
|
flags = compute_flags((), NONE, NONE, docs, {}, ("R",), guide)
|
|
self.assertEqual([f.doc for f in flags if f.kind == "unguided"], ["pm/VISION.md"])
|
|
|
|
def test_root_readme_and_the_guide_itself_cover_no_directory(self):
|
|
docs = {"docs/a.md": "", "pm/VISION.md": ""}
|
|
guide = ("docs/README.md", "See [README](../README.md) and `README.md`.")
|
|
flags = compute_flags((), NONE, NONE, docs, {}, ("R",), guide)
|
|
self.assertEqual([f.doc for f in flags if f.kind == "unguided"],
|
|
["docs/a.md", "pm/VISION.md"])
|
|
|
|
def test_unguided_scope_limits_the_documents_checked(self):
|
|
docs = {"docs/new.md": "", "docs/old.md": "", "docs/moved.md": ""}
|
|
guide = ("docs/README.md", "")
|
|
flags = compute_flags((), NONE, NONE, docs, {}, ("R",), guide,
|
|
unguided_scope=frozenset({"docs/new.md", "docs/moved.md"}))
|
|
self.assertEqual([f.doc for f in flags if f.kind == "unguided"],
|
|
["docs/moved.md", "docs/new.md"])
|
|
everything = compute_flags((), NONE, NONE, docs, {}, ("R",), guide)
|
|
self.assertEqual(len([f for f in everything if f.kind == "unguided"]), 3)
|
|
|
|
def test_path_most_documents_mention_is_not_touched(self):
|
|
docs = {f"docs/{i}.qmd": "source('load_all.R')" for i in range(4)}
|
|
docs["docs/README.md"] = "Index."
|
|
modified = compute_flags(parse_name_status("M\tload_all.R\n"), NONE, NONE,
|
|
docs, {}, ("R",), None)
|
|
self.assertEqual([f for f in modified if f.kind == "touched"], [])
|
|
deleted = compute_flags(parse_name_status("D\tload_all.R\n"), NONE, NONE,
|
|
docs, {}, ("R",), None)
|
|
self.assertEqual(len([f for f in deleted if f.kind == "dead"]), 4)
|
|
|
|
def test_path_few_documents_mention_is_still_touched(self):
|
|
docs = {"docs/a.qmd": "Uses R/storage.R.", "docs/b.qmd": "", "docs/c.qmd": ""}
|
|
flags = compute_flags(parse_name_status("M\tR/storage.R\n"), NONE, NONE, docs, {},
|
|
("R",), None)
|
|
self.assertEqual([f.doc for f in flags if f.kind == "touched"], ["docs/a.qmd"])
|
|
|
|
def test_boilerplate_path_does_not_hide_changed_names(self):
|
|
docs = {f"docs/{i}.qmd": "`load_all.R` and `write_table()`" for i in range(3)}
|
|
flags = compute_flags(parse_name_status("M\tload_all.R\n"), NONE,
|
|
frozenset({"write_table"}), docs, {}, ("R",), None)
|
|
self.assertEqual({(f.subject, f.detail) for f in flags if f.kind == "touched"},
|
|
{("write_table", "name changed")})
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|