feat: review_only input and an enumeration check in the monthly prompt
tests / unittest (push) Successful in 23s

review_only names listed documents the drafter may read but not edit. They stay
in stage 1, are listed separately in the prompt, and a change to one fails the
run like a change outside docs. Each entry must match a docs pattern.

The monthly prompt now makes checking every list and count in the top-level
documents against the repository the drafter's main job. Mode-specific text
moves to prompts/mode-pr.md and prompts/mode-monthly.md; the pr text is
unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
jaredandClaude Opus 5.5 committed 2026-11-12 15:40:09 -05:00
1 parent f39409e62c
commit 9dea56ce98
15 files changed
+223 -29

No files matched your search

+5 -2
View File
@@ -7,7 +7,8 @@ sentinel (file touched when invoked), env_file (file receiving the env var names
cwd_file (file receiving the working directory), argv_file (file receiving argv as
JSON), prompt_copy (file receiving the --append-system-prompt-file contents),
edit (path to append a line to), write (text to append to `edit` instead),
delete (path to remove), fail (print an error result and exit 1).
delete (path to remove), fail (print an error result and exit 1), stdin_copy (file
receiving the prompt read on stdin).
"""
import json
@@ -15,9 +16,11 @@ import os
import sys
from pathlib import Path
sys.stdin.read()
prompt = sys.stdin.read()
config_path = Path(__file__).resolve().with_name("fake_claude.json")
config = json.loads(config_path.read_text()) if config_path.exists() else {}
if config.get("stdin_copy"):
Path(config["stdin_copy"]).write_text(prompt, encoding="utf-8")
if config.get("sentinel"):
Path(config["sentinel"]).write_text("invoked\n", encoding="utf-8")
+52
View File
@@ -473,6 +473,58 @@ class SandboxTests(CliCase):
self.assertEqual(self.fake.prs, [])
class ReviewOnlyTests(CliCase):
"""docs/vision.md is a listed document the drafter may read but not edit."""
def setUp(self):
super().setUp()
git(self.seed, "checkout", "-q", "main")
self.write(self.seed, "docs/vision.md", "Where `R/a.R` is going.\n")
git(self.seed, "add", ".")
git(self.seed, "commit", "-q", "-m", "vision")
git(self.seed, "push", "-q", "origin", "main")
git(self.seed, "checkout", "-q", "feat")
git(self.seed, "merge", "-q", "--ff-only", "main")
git(self.seed, "push", "-q", "origin", "feat")
self.env["INPUT_REVIEW_ONLY"] = "docs/vision.md"
self.prompt_file = Path(self._tmp.name) / "drafter-prompt"
def test_prompt_lists_it_as_read_only(self):
self.claude(stdin_copy=str(self.prompt_file))
self.assertEqual(self.run_pr(self.feature_commit()), 0)
prompt = self.prompt_file.read_text()
editable = prompt.split("Documents you may edit:")[1].split("Edit only")[0]
self.assertIn("docs/README.md", editable)
self.assertNotIn("docs/vision.md", editable)
self.assertIn("Documents you may read but not edit:\n\ndocs/vision.md", prompt)
def test_it_is_still_flagged_in_stage1(self):
self.claude()
self.assertEqual(self.run_pr(self.feature_commit()), 0)
self.assertIn("docs/vision.md", self.comment_bodies()[0])
def test_editing_it_fails_and_commits_nothing(self):
self.claude(edit="docs/vision.md")
self.assertEqual(self.run_pr(self.feature_commit()), 1)
self.assertTrue(any("docs/vision.md" in b for b in self.comment_bodies()))
self.assertNotIn(BRANCH, " ".join(self.remote_branches()))
self.assertEqual(git(self.work, "status", "--porcelain"), "")
self.assertEqual(self.fake.prs, [])
def test_deleting_it_fails(self):
self.claude(delete="docs/vision.md")
self.assertEqual(self.run_pr(self.feature_commit()), 1)
self.assertTrue((self.work / "docs" / "vision.md").exists())
self.assertEqual(self.fake.prs, [])
def test_new_file_matching_a_review_only_glob_is_refused(self):
self.env["INPUT_REVIEW_ONLY"] = "docs/v*.md"
self.claude(edit="docs/vnew.md")
self.assertEqual(self.run_pr(self.feature_commit()), 1)
self.assertFalse((self.work / "docs" / "vnew.md").exists())
self.assertEqual(self.fake.prs, [])
class SystemPromptTests(CliCase):
def setUp(self):
super().setUp()
+8
View File
@@ -153,6 +153,14 @@ class ClaudeMonthlyTests(MonthlyCase):
self.assertIn("R/a.R", self.fake.issues[0]["body"])
self.assertEqual(git(self.work, "status", "--porcelain"), "")
def test_review_only_doc_edit_fails_and_commits_nothing(self):
self.claude(edit="docs/README.md")
self.assertEqual(self.run_monthly("2026-12", INPUT_REVIEW_ONLY="docs/README.md"), 1)
self.assertEqual(self.fake.prs, [])
self.assertNotIn("monthly", " ".join(self.remote_branches()))
self.assertIn("docs/README.md", self.fake.issues[0]["body"])
self.assertEqual(git(self.work, "status", "--porcelain"), "")
def test_delivered_pr_closes_the_open_monthly_issue(self):
self.claude(fail=True)
self.assertEqual(self.run_monthly("2026-11"), 1)
+45 -3
View File
@@ -9,6 +9,7 @@ from docs_review.draft import (
build_prompt,
claude_argv,
diff_payload,
load_template,
outside_docs,
parse_claude_output,
parse_last_head,
@@ -59,14 +60,55 @@ class PromptTest(unittest.TestCase):
self.assertIn("monthly|none|", out)
def test_shipped_template_renders(self):
from pathlib import Path
t = Path(__file__).resolve().parent.parent / "prompts" / "task.md"
out = build_prompt(t.read_text(), mode="pr", pr=7, flags_json="{}", payload="{x}",
out = build_prompt(load_template("pr"), mode="pr", pr=7, flags_json="{}", payload="{x}",
docs=("a.md",), top_level=("README.md",), guide_path=None)
self.assertIn("```json", out)
self.assertIn("{x}", out)
self.assertNotIn("{mode}", out)
def test_review_only_section(self):
t = "{docs}|{review_only}"
none = build_prompt(t, mode="pr", pr=1, flags_json="{}", payload="",
docs=("a.md",), top_level=(), guide_path=None)
self.assertEqual(none, "a.md|")
out = build_prompt(t, mode="pr", pr=1, flags_json="{}", payload="",
docs=("a.md",), top_level=(), guide_path=None,
review_only=("v.md", "w.md"))
self.assertIn("Documents you may read but not edit:\n\nv.md\nw.md", out)
self.assertIn("declined", out)
class TemplateModeTest(unittest.TestCase):
def _render(self, mode, review_only=()):
return build_prompt(load_template(mode), mode=mode, pr=None if mode == "monthly" else 7,
flags_json="{}", payload="p", docs=("README.md", "docs/a.md"),
top_level=("README.md",), guide_path=None,
review_only=review_only)
def test_monthly_asks_for_enumeration_check_and_lists_review_only(self):
out = self._render("monthly", ("docs/vision.md",))
self.assertIn("check every enumeration", out)
self.assertIn("Glob", out)
self.assertIn("A list presented as complete must be complete", out)
self.assertIn("Documents you may read but not edit:\n\ndocs/vision.md", out)
self.assertIn("README.md", out)
for field in ("{top_level}", "{mode_text}", "{review_only}", "{docs}"):
self.assertNotIn(field, out)
def test_pr_has_no_enumeration_check(self):
out = self._render("pr", ("docs/vision.md",))
self.assertNotIn("enumeration", out)
self.assertIn("find what this pull request makes stale", out)
self.assertIn("Documents you may read but not edit:\n\ndocs/vision.md", out)
def test_review_only_section_absent_when_empty(self):
for mode in ("pr", "monthly"):
self.assertNotIn("read but not edit", self._render(mode))
def test_unknown_mode_raises(self):
with self.assertRaises(ValueError):
load_template("weekly")
class ArgvTest(unittest.TestCase):
def test_argv_matches_spec(self):
+22
View File
@@ -6,6 +6,7 @@ from docs_review.inputs import (
matches_any,
normalize_drafter,
parse_inputs,
split_review_only,
unmatched_patterns,
)
from tests.helpers import tmp_tree
@@ -64,6 +65,27 @@ class ParseInputsTest(unittest.TestCase):
self.assertIsNone(i.tracking_issue)
self.assertIsNone(i.doc_guide)
def test_review_only_defaults_to_empty(self):
self.assertEqual(parse_inputs({"INPUT_DOCS": "a.md"}).review_only, ())
def test_review_only_entries_within_docs(self):
i = parse_inputs({"INPUT_DOCS": "README.md\ndocs/*.md\npm/**/*.md",
"INPUT_REVIEW_ONLY": " docs/vision.md \n\nREADME.md\npm/v*.md\n"})
self.assertEqual(i.review_only, ("docs/vision.md", "README.md", "pm/v*.md"))
def test_review_only_entry_outside_docs_raises(self):
for entry in ("other/vision.md", "docs/sub/vision.md", "*.md"):
with self.assertRaisesRegex(ValueError, f"review_only.*{entry.replace('*', '[*]')}"):
parse_inputs({"INPUT_DOCS": "README.md\ndocs/*.md",
"INPUT_REVIEW_ONLY": f"docs/a.md\n{entry}"})
def test_split_review_only(self):
editable, read_only = split_review_only(
("README.md", "docs/a.md", "docs/vision.md"), ("docs/v*.md",))
self.assertEqual(editable, ("README.md", "docs/a.md"))
self.assertEqual(read_only, ("docs/vision.md",))
self.assertEqual(split_review_only(("a.md",), ()), (("a.md",), ()))
def test_non_integer_tracking_issue_raises(self):
with self.assertRaisesRegex(ValueError, "tracking_issue"):
parse_inputs({"INPUT_DOCS": "a.md", "INPUT_TRACKING_ISSUE": "abc"})