Answer stability round 1: 0 🔴, 3 🟡 (0 misread); restrict a repo name, split the multi-behaviour tests, and word the prose findings of the prose round

This commit is contained in:
2026-11-18 15:02:43 +01:00
parent 42a6b6533f
commit 3cbcf358bd
6 changed files with 65 additions and 31 deletions
+37 -13
View File
@@ -8,7 +8,7 @@ sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
from do_epic.backend.protocol import EpicIssue
from do_epic.backend.fake import MemoryEpic
from do_epic.repo_pick import CLAUDE_LABEL, PICK_SCHEMA, ClaudeWork, HUMAN_LABEL, HumanTask, label_of, picked, recorded, Repo, Unclear
from do_epic.repo_pick import CLAUDE_LABEL, PICK_SCHEMA, REPO_PREFIX, ClaudeWork, HUMAN_LABEL, HumanTask, label_of, picked, recorded, Repo, Unclear
from claude_code.reply import Limited
from failure import Failure
from model_routing.ladder import Rung
@@ -45,25 +45,36 @@ class RepoPick(unittest.TestCase):
def pick(self, claude: Claude): # type: ignore[no-untyped-def]
return picked(self.store, self.issue(), RULE, RUNG, claude, "/rules")
def test_asks_claude_with_the_rule_and_the_item_and_records_the_pick_on_the_issue(self) -> None:
claude = says({"pick": "repo", "repo": "payments-api"})
self.assertEqual(self.pick(claude), Repo("payments-api"))
def test_records_the_claude_pick_as_a_label_on_the_issue(self) -> None:
self.assertEqual(self.pick(says({"pick": "repo", "repo": "payments-api"})), Repo("payments-api"))
self.assertEqual(self.issue().labels, ("api", "repo:payments-api"))
args, cwd, prompt = claude.calls[0]
def test_asks_claude_for_a_json_reply_on_the_given_rung_and_without_tools(self) -> None:
claude = says({"pick": "claude"})
self.pick(claude)
args, cwd, _ = claude.calls[0]
self.assertEqual(cwd, "/rules")
self.assertEqual(args[:9], ["-p", "--json-schema", json.dumps(PICK_SCHEMA), "--model", "claude-sonnet-5-5", "--effort", "medium", "--tools", ""])
def test_puts_the_rule_and_the_item_in_the_prompt(self) -> None:
claude = says({"pick": "claude"})
self.pick(claude)
prompt = claude.calls[0][2]
self.assertIn(RULE, prompt)
self.assertIn(f"## Item {self.key}: Count the runs.\n\nLabels: api\n\nWhy it counts.", prompt)
def test_tells_claude_an_items_labels_and_that_it_has_no_description(self) -> None:
def test_tells_claude_all_of_an_items_labels(self) -> None:
self.store.add_label(self.key, "web")
claude = says({"pick": "claude"})
self.pick(claude)
self.assertIn("Labels: api, web\n", claude.calls[0][2])
def test_tells_claude_an_item_has_no_labels_and_no_description(self) -> None:
store = MemoryEpic("ABC-12")
store.file("ABC-12", "Clean up the docs.", "", ())
claude = says({"pick": "claude"})
picked(store, store.read()[0], RULE, RUNG, claude, "/rules") # type: ignore[index]
self.assertIn("Labels: none\n\n(no description)\n", claude.calls[0][2])
self.store.add_label(self.key, "web")
self.pick(claude)
self.assertIn("Labels: api, web\n", claude.calls[1][2])
def test_records_a_pick_without_a_repo_as_claudes_work_or_a_human_task(self) -> None:
for output, pick, label in (({"pick": "claude"}, ClaudeWork(), CLAUDE_LABEL), ({"pick": "human"}, HumanTask(), HUMAN_LABEL)):
@@ -93,24 +104,37 @@ class RepoPick(unittest.TestCase):
self.assertEqual(self.issue().labels, ("api",))
def test_a_reply_that_is_no_pick_fails_and_records_nothing(self) -> None:
reason = self.pick(says({"pick": "repo", "repo": "two words" * 40}))
self.assertEqual(reason, Failure('the repo pick answered ' + json.dumps({"pick": "repo", "repo": "two words" * 40})[:200] + ', which is not a repo with a name without white space, claude, human, or unclear with a question'))
for output in (None, "repo", {"pick": "repo"}, {"pick": "repo", "repo": "two words"}, {"pick": "unclear"}, {"pick": "unclear", "question": " "}, {"pick": "elsewhere"}):
with self.subTest(output=output):
self.assertIsInstance(self.pick(says(output)), Failure)
self.assertEqual(self.issue().labels, ("api",))
def test_a_failed_run_a_usage_limit_and_a_failed_label_come_back_as_they_are(self) -> None:
def test_a_repo_name_that_could_leave_its_folder_or_name_a_host_is_no_pick(self) -> None:
for name in ("../../.ssh", "a/b", ".hidden", "-flag", "https://host/x.git", "host:repo"):
with self.subTest(name=name):
self.assertIsInstance(self.pick(says({"pick": "repo", "repo": name})), Failure)
self.assertIsNone(recorded(EpicIssue(self.key, "s", "", (REPO_PREFIX + name,), None, "To Do", False, "ABC-12")))
def test_a_reply_that_is_no_pick_says_what_it_got_in_its_first_200_characters(self) -> None:
output = {"pick": "repo", "repo": "two words" * 40}
self.assertEqual(self.pick(says(output)), Failure("the repo pick answered " + json.dumps(output)[:200] + '; expected pick "repo" with a repo name of letters, digits, dots, hyphens and underscores, "claude", "human", or "unclear" with a question'))
def test_a_failed_run_comes_back_as_it_is(self) -> None:
self.assertEqual(self.pick(Claude("", 1)), Failure("the repo pick exited 1"))
def test_a_usage_limit_comes_back_as_it_is(self) -> None:
limit = json.dumps({"type": "result", "is_error": True, "api_error_status": 429, "result": "You've hit your limit"})
self.assertIsInstance(self.pick(Claude(limit)), Limited)
def test_a_label_the_tracker_refuses_comes_back_as_it_is(self) -> None:
issue = self.issue()
self.store.fails = "Jira answered 503"
self.assertEqual(picked(self.store, issue, RULE, RUNG, says({"pick": "claude"}), "/rules"), Failure("Jira answered 503"))
def test_the_label_of_a_pick_reads_back_as_that_pick(self) -> None:
for pick in (Repo("payments-api"), ClaudeWork(), HumanTask()):
self.assertEqual(recorded(EpicIssue(self.key, "s", "", (label_of(pick),), None, "To Do", False, "ABC-12")), pick)
with self.subTest(pick=pick):
self.assertEqual(recorded(EpicIssue(self.key, "s", "", (label_of(pick),), None, "To Do", False, "ABC-12")), pick)
def test_a_label_with_the_prefix_alone_is_no_pick(self) -> None:
self.store.add_label(self.key, "repo:")