import pathlib import sys import tempfile import unittest sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1])) from failure import Failure from review_rules.round_titles import Findings from review_rules.review_folder import findings_in, review_folder, standing_report class ReviewFolder(unittest.TestCase): def test_keys_a_worktree_under_home_by_its_path_relative_to_home(self): self.assertEqual(review_folder("/h", "/h/code/proj-item-3"), "/h/.local/state/larv-review/code/proj-item-3") def test_keys_a_worktree_outside_home_by_its_path_relative_to_the_root(self): self.assertEqual(review_folder("/h", "/srv/proj-item-3"), "/h/.local/state/larv-review/srv/proj-item-3") self.assertEqual(review_folder("/h", "/hx/proj"), "/h/.local/state/larv-review/hx/proj", "a sibling of home that shares its prefix is outside it") class RoundReport(unittest.TestCase): def test_counts_the_rounds_report_or_its_rerun_one_rung_up_where_there_is_one(self): with tempfile.TemporaryDirectory() as temp: folder = pathlib.Path(temp) (folder / "prose-round-1.md").write_text("BLOCK\n\n### 🟡 a\n") self.assertEqual(findings_in(standing_report(folder, "prose", 1)), Findings(0, 1, 0)) (folder / "prose-round-1-rerun.md").write_text("BLOCK\n\n### 🔴 [misread] a\n") self.assertEqual(findings_in(standing_report(folder, "prose", 1)), Findings(1, 0, 1)) (folder / "prose-round-1-rerun.md").write_text("BLOCK\n\n### 🔴 a\n\n### 🟡 b\n") self.assertEqual(findings_in(standing_report(folder, "prose", 1)), Findings(1, 1, 0)) def test_names_a_missing_report(self): with tempfile.TemporaryDirectory() as temp: missing = findings_in(standing_report(pathlib.Path(temp), "prose", 2)) self.assertIsInstance(missing, Failure) self.assertEqual(missing.reason, f"no report at {temp}/prose-round-2.md") def test_names_a_report_it_cannot_read(self): with tempfile.TemporaryDirectory() as temp: (pathlib.Path(temp) / "prose-round-1.md").mkdir() unread = findings_in(standing_report(pathlib.Path(temp), "prose", 1)) self.assertIsInstance(unread, Failure) self.assertTrue(unread.reason.startswith(f"could not read {temp}/prose-round-1.md: "), unread.reason) def test_names_a_blocking_report_that_heads_no_finding_as_its_format_asks(self): with tempfile.TemporaryDirectory() as temp: (pathlib.Path(temp) / "prose-round-1.md").write_text("\nBLOCK\n\n- 🟡 `a.md:1`: worse\n") unread = findings_in(standing_report(pathlib.Path(temp), "prose", 1)) self.assertIsInstance(unread, Failure) self.assertEqual(unread.reason, f"{temp}/prose-round-1.md says BLOCK but opens no finding with `### 🔴` or `### 🟡`; count its findings by hand") (pathlib.Path(temp) / "prose-round-1.md").write_text("APPROVE\n") self.assertEqual(findings_in(standing_report(pathlib.Path(temp), "prose", 1)), Findings(0, 0, 0)) def test_names_a_report_whose_headings_it_cannot_count(self): with tempfile.TemporaryDirectory() as temp: (pathlib.Path(temp) / "prose-round-1.md").write_text("BLOCK\n\n### 1. 🟡 `a.md:1`: worse\n") unread = findings_in(standing_report(pathlib.Path(temp), "prose", 1)) self.assertIsInstance(unread, Failure) self.assertTrue(unread.reason.startswith(f"{temp}/prose-round-1.md cannot be counted: its heading `### 1. 🟡"), unread.reason) self.assertTrue(unread.reason.endswith("; count its findings by hand"), unread.reason)