fix: local drafter review round 1
- Refuse to run pi as root when DOCS_REVIEW_DRAFTER_USER is unset. - Keep a record of the run: parse partial output on timeout, add the first redacted stderr line to failures, and report summed output and peak input tokens with turns in the log and step summary. - Delete top-level .pi* entries from the sandbox before drafting and refuse a draft that recreates one. - Probe: an HTTP error, redirect or non-JSON answer is a hard failure; only connection failures and an empty model list are soft. Refuse model ids starting with "-" and pass --model=<id>. - README: mid-run model swap note, hard-failure cases, rewrap. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
28b993cb23
commit
7095db060e
9 files changed
+330
-86
No files matched your search
+45
-1
@@ -52,7 +52,7 @@ class LocalPrTests(LocalSetup, test_cli.CliCase):
|
||||
self.assertIn("Edited by the local drafter.",
|
||||
git(self.remote, "show", f"{BRANCH}:docs/README.md"))
|
||||
argv = json.loads(self.argv_file.read_text())
|
||||
self.assertEqual(argv[argv.index("--model") + 1], "org/model-a")
|
||||
self.assertIn("--model=org/model-a", argv)
|
||||
self.assertNotIn(KEY, " ".join(argv))
|
||||
self.assertIn("Drafted by pi with org/model-a: 2 turns.",
|
||||
self.fake.prs[0]["body"].splitlines()[-1])
|
||||
@@ -92,6 +92,14 @@ class LocalPrTests(LocalSetup, test_cli.CliCase):
|
||||
self.assertEqual(self.run_pr(self.feature_commit()), 1)
|
||||
self.assertIn(local.REJECTED_NOTE, self.comment_bodies()[0])
|
||||
|
||||
def test_root_without_a_drafter_user_fails_hard(self):
|
||||
self.pi()
|
||||
self.env.pop("DOCS_REVIEW_DRAFTER_USER", None)
|
||||
with up(), mock.patch.object(local.os, "geteuid", return_value=0):
|
||||
self.assertEqual(self.run_pr(self.feature_commit()), 1)
|
||||
self.assertIn("DOCS_REVIEW_DRAFTER_USER", self.comment_bodies()[0])
|
||||
self.assertFalse(self.sentinel.exists())
|
||||
|
||||
def test_missing_key_fails_before_probing(self):
|
||||
self.pi()
|
||||
self.env["LOCAL_MODEL_API_KEY"] = ""
|
||||
@@ -100,6 +108,42 @@ class LocalPrTests(LocalSetup, test_cli.CliCase):
|
||||
probe.assert_not_called()
|
||||
self.assertIn("LOCAL_MODEL_API_KEY is not set", self.comment_bodies()[0])
|
||||
|
||||
def test_tokens_and_turns_reach_the_step_summary(self):
|
||||
summary = Path(self._tmp.name) / "step-summary.md"
|
||||
self.pi(edit="docs/README.md")
|
||||
with up():
|
||||
self.assertEqual(self.run_pr(self.feature_commit(),
|
||||
GITHUB_STEP_SUMMARY=str(summary)), 0)
|
||||
text = summary.read_text()
|
||||
self.assertIn("num_turns: 2", text)
|
||||
self.assertIn("output_tokens: 40", text)
|
||||
self.assertIn("max_input_tokens: 100", text)
|
||||
self.assertNotIn("total_cost_usd", text)
|
||||
|
||||
def test_project_pi_config_is_removed_from_the_sandbox(self):
|
||||
self.write(self.seed, ".pi/settings.json", '{"defaultModel": "other"}\n')
|
||||
self.write(self.seed, ".pi/extensions/x.ts", "export default () => {}\n")
|
||||
self.write(self.seed, ".pi.json", "{}\n")
|
||||
listing = Path(self._tmp.name) / "listing"
|
||||
self.pi(edit="docs/README.md", list_file=str(listing))
|
||||
with up():
|
||||
self.assertEqual(self.run_pr(self.feature_commit()), 0)
|
||||
names = listing.read_text().split()
|
||||
self.assertNotIn(".pi", names)
|
||||
self.assertNotIn(".pi.json", names)
|
||||
self.assertIn("docs", names)
|
||||
self.assertEqual(len(self.fake.prs), 1)
|
||||
self.assertNotIn(".pi/settings.json", git(self.remote, "show", "--stat",
|
||||
"--format=", BRANCH))
|
||||
|
||||
def test_recreating_pi_config_is_refused(self):
|
||||
self.env["INPUT_DOCS"] = "docs/*.md\n**/*.md"
|
||||
self.pi(edit=".pi/notes.md")
|
||||
with up():
|
||||
self.assertEqual(self.run_pr(self.feature_commit()), 1)
|
||||
self.assertTrue(any(".pi/notes.md" in b for b in self.comment_bodies()))
|
||||
self.assertEqual(self.fake.prs, [])
|
||||
|
||||
def test_drafter_that_ran_and_failed_is_exit_1(self):
|
||||
self.pi(fail=True)
|
||||
with up():
|
||||
|
||||
Reference in new issue
Block a user