fix: credential check, step summary, fetch hardening, case-insensitive repo match

- drafter: claude with neither CLAUDE_CODE_OAUTH_TOKEN nor ANTHROPIC_API_KEY set posts
  the stage 1 flags with the note 'drafter: claude but no Claude credential is set' and
  fails, without starting Claude.
- total_cost_usd and num_turns are printed and appended to GITHUB_STEP_SUMMARY.
- git.fetch puts --end-of-options before the branch; run_pr and run_monthly use it.
- The bot's own PRs match head.repo.full_name case-insensitively.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
jaredandClaude Opus 5.5 committed 2026-11-12 14:35:42 -05:00
1 parent ade847ba5b
commit a1f061ca6c
9 files changed
+112 -6

No files matched your search

+42
View File
@@ -54,6 +54,7 @@ class CliCase(unittest.TestCase):
"DOCS_REVIEW_CLAUDE_BIN": str(self.fake_claude),
"DOCS_REVIEW_BOT_TOKEN": "bot-token-value-123456",
"RUNNER_TEMP": str(tmp),
"ANTHROPIC_API_KEY": "test-api-key-value-123456",
}
def claude(self, **config):
@@ -221,6 +222,47 @@ class ClaudeDrafterTests(CliCase):
self.assertEqual(len(self.comment_bodies()), 1)
class CredentialAndSummaryTests(CliCase):
def setUp(self):
super().setUp()
self.claude(edit="docs/README.md")
def test_missing_credential_posts_stage1_note_and_fails(self):
sha = self.feature_commit()
env = {k: v for k, v in self.env.items()
if k not in ("CLAUDE_CODE_OAUTH_TOKEN", "ANTHROPIC_API_KEY")}
self.env = env
self.assertEqual(self.run_pr(sha, CLAUDE_CODE_OAUTH_TOKEN="", ANTHROPIC_API_KEY=""), 1)
bodies = self.comment_bodies()
self.assertEqual(len(bodies), 1)
self.assertIn("drafter: claude but no Claude credential is set", bodies[0])
self.assertIn("Touched", bodies[0])
self.assertFalse(self.sentinel.exists())
self.assertEqual(self.fake.prs, [])
def test_oauth_token_alone_is_enough(self):
sha = self.feature_commit()
self.env.pop("ANTHROPIC_API_KEY")
self.assertEqual(self.run_pr(sha, CLAUDE_CODE_OAUTH_TOKEN="oauth-token-value-1"), 0)
self.assertEqual(len(self.fake.prs), 1)
def test_cost_and_turns_reach_the_step_summary(self):
summary = Path(self.env["RUNNER_TEMP"]) / "step-summary.md"
summary.write_text("earlier step\n", encoding="utf-8")
sha = self.feature_commit()
self.assertEqual(self.run_pr(sha, GITHUB_STEP_SUMMARY=str(summary)), 0)
text = summary.read_text(encoding="utf-8")
self.assertTrue(text.startswith("earlier step\n"))
self.assertIn("total_cost_usd: 0.12", text)
self.assertIn("num_turns: 3", text)
def test_no_summary_file_without_the_variable(self):
sha = self.feature_commit()
self.env.pop("GITHUB_STEP_SUMMARY", None)
self.assertEqual(self.run_pr(sha), 0)
self.assertFalse((Path(self.env["RUNNER_TEMP"]) / "step-summary.md").exists())
class DocsPrLifecycleTests(CliCase):
def setUp(self):
super().setUp()
+2 -1
View File
@@ -22,7 +22,8 @@ class ExportFailureTest(unittest.TestCase):
tmp = Path(self._tmp.name)
self.repo = make_repo(tmp / "repo")
(tmp / "runner").mkdir()
self.env = {"RUNNER_TEMP": str(tmp / "runner"), "PATH": "/usr/bin:/bin"}
self.env = {"RUNNER_TEMP": str(tmp / "runner"), "PATH": "/usr/bin:/bin",
"ANTHROPIC_API_KEY": "test-api-key-value-123456"}
def draft_with(self, err):
made = []
+7
View File
@@ -174,6 +174,13 @@ class TestPrsAndIssues(unittest.TestCase):
self.assertIsNone(g.find_open_pr("docs-review/pr-12"))
self.assertIsNone(g.find_open_pr_prefix("docs-review/"))
def test_head_repo_matches_ignoring_case(self):
routes = {("GET", BASE + "/api/v1/user"): USER,
("GET", API + "/pulls?state=all&limit=50&page=1"):
[pr(5, "docs-review/pr-12", repo="O/R")]}
g, _ = client(routes)
self.assertEqual(g.find_pr("docs-review/pr-12")["number"], 5)
def test_open_pr_and_edit(self):
g, f = client({
("POST", API + "/pulls"): {"number": 12},
+18
View File
@@ -136,6 +136,24 @@ class TestGitHardening(unittest.TestCase):
git.run(["status"], self.repo)
self.assertNotIn("GIT_CONFIG_COUNT", calls[-1][1])
def test_fetch_ends_options_before_the_branch(self):
git.run(["push", "-q", "origin", "main"], self.repo)
calls = self._record()
git.fetch("main", self.repo)
argv, _ = calls[-1]
self.assertEqual(argv[-2:], [git.EOO, "main"])
self.assertEqual(git.run(["rev-parse", "FETCH_HEAD"], self.repo).strip(),
git.run(["rev-parse", "main"], self.repo).strip())
out = Path(self._tmp.name) / "x"
with self.assertRaises(git.GitError):
git.fetch(f"--upload-pack=touch {out}", self.repo)
self.assertFalse(out.exists())
def test_flows_fetch_only_through_the_helper(self):
from docs_review import run_monthly, run_pr
for module in (run_pr, run_monthly):
self.assertNotIn('["fetch"', inspect.getsource(module))
def test_push_without_token_adds_no_header(self):
calls = self._record()
git.push("main", self.repo, None)