Files
mandy/tests/test_docs_pr_template.py
kotorvr 7f1f93c944 PR template test: check the template only; drop "with which tool"
The test pinned four phrasings of AGENTS.md, so a harmless rewording there
would fail it (and, once docs-only pull requests run every tests/test_docs_*.py,
turn an AGENTS.md-only pull request red). It now checks only that the
template has a `Depends on:` and an `AI-assisted:` prompt line.

The AI-assisted prompt no longer asks for the tool: no document asks for that.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-22 21:10:10 +00:00

37 lines
1.6 KiB
Python

"""The pull request template prompts for a `Depends on:` line and for whether the work was AI-assisted.
python -I tests/test_docs_pr_template.py
The coordination issue builds its merge chains from `Depends on: #N` lines, and AGENTS.md asks a pull request to
say that it was AI-assisted; without a prompt in `.github/pull_request_template.md` those are the lines authors
leave out. This reads the template only, so rewording AGENTS.md or CONTRIBUTING.md cannot fail it. No game files.
"""
import os
import re
import unittest
ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
TEMPLATE = os.path.join(".github", "pull_request_template.md")
# A prompt is a line of its own that starts with the words an author fills in.
PROMPTS = ("Depends on:", "AI-assisted:")
def missing_prompts(template):
"""The prompts of PROMPTS that no line of `template` starts with."""
return [p for p in PROMPTS if not re.search("^" + re.escape(p), template, re.M)]
class PullRequestTemplateTest(unittest.TestCase):
def test_template_has_both_prompts(self):
with open(os.path.join(ROOT, TEMPLATE), encoding="utf-8") as f:
self.assertEqual(missing_prompts(f.read()), [])
def test_a_template_without_a_prompt_is_reported(self):
self.assertEqual(missing_prompts("### Tested\n"), ["Depends on:", "AI-assisted:"])
# A mention inside another sentence is not a prompt: the line has to start with it.
self.assertEqual(missing_prompts("no Depends on: here\nAI-assisted: no\n"), ["Depends on:"])
if __name__ == "__main__":
unittest.main()