Answer stability round 1: 1 🔴, 2 🟡 (0 misread); post a person's comment once the sub-tasks exist, count filed sub-tasks towards the split, and refuse a blank change
CI / tests (pull_request) Successful in 3m20s
CI / tests (pull_request) Successful in 3m20s
This commit is contained in:
+17
-16
@@ -7,7 +7,7 @@ import json
|
||||
from claude_code.reply import Claude, claude_reply, Limited
|
||||
from do_epic.backend.protocol import EpicIssue, EpicStore
|
||||
from failure import Failure
|
||||
from do_epic.repo_pick import label_of, Repo, REPO_NAME
|
||||
from do_epic.repo_pick import label_of, of_label, Repo, REPO_NAME
|
||||
from model_routing.ladder import Rung
|
||||
from claude_code.entries import structured_output
|
||||
|
||||
@@ -62,35 +62,36 @@ class Split:
|
||||
def split(store: EpicStore, issue: EpicIssue, by_person: bool, rule: str, language: str, checkouts: tuple[str, ...], rung: Rung, claude: Claude, cwd: str) -> Split | Failure | Limited:
|
||||
"""Splits the epic's child issue into a sub-task per repo it changes, where that is more than one. by_person says a person filed the issue, and checkouts are the epic's repos that claude may read. An item that changes one repo or none is left as it is, for repo_pick, and one already marked SPLIT_LABEL is left alone.
|
||||
|
||||
A run that failed after filing some sub-tasks is finished by the next run, which files the sub-tasks that are lacking. The comment on a person's issue is posted when the issue has no sub-task yet, before the first is filed. Where the comment fails, nothing is filed; where the first filing fails after the comment posted, the next run posts the comment again."""
|
||||
A sub-task of the item already labelled for a repo counts as that repo's, so a run that failed after filing some sub-tasks, or a person's own sub-task, leaves the next run to file only the lacking ones. The comment on a person's issue is posted once its sub-tasks are filed, just before the item is marked. A failure after the comment but before the mark posts it again on the next run."""
|
||||
if SPLIT_LABEL in issue.labels:
|
||||
return Split((), ())
|
||||
predicted = prediction(issue, by_person, rule, language, checkouts, rung, claude, cwd)
|
||||
if isinstance(predicted, Failure | Limited) or len(predicted.parts) < 2:
|
||||
return Split((), ()) if isinstance(predicted, Prediction) else predicted
|
||||
if isinstance(predicted, Failure | Limited):
|
||||
return predicted
|
||||
read = store.read()
|
||||
if isinstance(read, Failure):
|
||||
return read
|
||||
own = [task for task in read if task.parent == issue.key]
|
||||
if by_person and not own:
|
||||
if not predicted.comment:
|
||||
return Failure("the repo split gave no comment for the team on a person's issue")
|
||||
posted = store.comment(issue.key, predicted.comment)
|
||||
if isinstance(posted, Failure):
|
||||
return posted
|
||||
have = {label for task in own for label in task.labels}
|
||||
have = {pick.name for task in read if task.parent == issue.key for label in task.labels if isinstance(pick := of_label(label), Repo)}
|
||||
repos = tuple(dict.fromkeys([*have, *(part.repo for part in predicted.parts)]))
|
||||
if len(repos) < 2:
|
||||
return Split((), ())
|
||||
if by_person and not predicted.comment:
|
||||
return Failure("the repo split gave no comment for the team on a person's issue")
|
||||
filed: list[str] = []
|
||||
for part in predicted.parts:
|
||||
if label_of(Repo(part.repo)) in have:
|
||||
if part.repo in have:
|
||||
continue
|
||||
key = store.file(issue.key, task_summary(part.repo, issue.summary), part.change, (label_of(Repo(part.repo)),))
|
||||
if isinstance(key, Failure):
|
||||
return Failure(f"cannot file the sub-task for {part.repo} under {issue.key}: {key.reason}; {sub_tasks_filed(filed)}; run split again to file the rest")
|
||||
filed.append(key)
|
||||
posted = store.comment(issue.key, predicted.comment) if by_person else None
|
||||
if isinstance(posted, Failure):
|
||||
return Failure(f"cannot comment on {issue.key}: {posted.reason}; {sub_tasks_filed(filed)}; run split again to post it")
|
||||
marked = store.add_label(issue.key, SPLIT_LABEL)
|
||||
if isinstance(marked, Failure):
|
||||
return Failure(f"cannot mark {issue.key} as split: {marked.reason}; {sub_tasks_filed(filed)}; run split again to mark it")
|
||||
return Split(tuple(part.repo for part in predicted.parts), tuple(filed))
|
||||
return Split(repos, tuple(filed))
|
||||
|
||||
|
||||
def sub_tasks_filed(keys: list[str]) -> str:
|
||||
@@ -126,8 +127,8 @@ def answer_of(output: object) -> Prediction | Failure:
|
||||
parts: dict[str, Part] = {}
|
||||
for each in raw if isinstance(raw, list) else [None]:
|
||||
repo, change = (each.get("repo"), each.get("change")) if isinstance(each, dict) else (None, None)
|
||||
if not (isinstance(repo, str) and REPO_NAME.fullmatch(repo) and isinstance(change, str)):
|
||||
return Failure(f"the repo split answered {json.dumps(output)[:200]}; expected parts, each with a repo name of letters, digits, dots, hyphens and underscores and a change")
|
||||
if not (isinstance(repo, str) and REPO_NAME.fullmatch(repo) and isinstance(change, str) and change.strip()):
|
||||
return Failure(f"the repo split answered {json.dumps(output)[:200]}; expected parts, each with a repo name of letters, digits, dots, hyphens and underscores and a change that holds text")
|
||||
parts.setdefault(repo, Part(repo, change.strip()))
|
||||
return Prediction(tuple(parts.values()), comment.strip() if isinstance(comment, str) else "")
|
||||
|
||||
|
||||
+25
-11
@@ -56,7 +56,7 @@ class Split_(unittest.TestCase):
|
||||
self.assertEqual(self.issue().labels, ("api", SPLIT_LABEL))
|
||||
self.assertEqual(self.store.comments, {})
|
||||
|
||||
def test_comments_on_a_persons_issue_for_the_team_before_filing(self) -> None:
|
||||
def test_comments_on_a_persons_issue_for_the_team_once_its_sub_tasks_are_filed(self) -> None:
|
||||
self.run_split(says(TWO), by_person=True)
|
||||
self.assertEqual(self.store.comments, {self.key: ["Delat per repo: api och web."]})
|
||||
self.assertEqual(len(self.tasks()), 2)
|
||||
@@ -70,10 +70,25 @@ class Split_(unittest.TestCase):
|
||||
self.store.fails_files = True
|
||||
self.assertEqual(self.run_split(says(TWO)), Failure(f"cannot file the sub-task for api under {self.key}: Jira answered 500; this run filed no sub-task; run split again to file the rest"))
|
||||
|
||||
def test_a_comment_that_fails_files_nothing(self) -> None:
|
||||
def test_a_comment_that_fails_leaves_the_item_unmarked_and_the_next_run_files_nothing_again(self) -> None:
|
||||
self.store.comment = lambda key, text: Failure("Jira answered 500") # type: ignore[method-assign]
|
||||
self.assertEqual(self.run_split(says(TWO), by_person=True), Failure("Jira answered 500"))
|
||||
self.assertEqual(self.tasks(), [])
|
||||
failed = self.run_split(says(TWO), by_person=True)
|
||||
first, second = (task.key for task in self.tasks())
|
||||
self.assertEqual(failed, Failure(f"cannot comment on {self.key}: Jira answered 500; this run filed {first}, {second}; run split again to post it"))
|
||||
self.assertEqual(self.issue().labels, ("api",))
|
||||
del self.store.comment
|
||||
done = self.run_split(says(TWO), by_person=True)
|
||||
self.assertEqual((done, len(self.tasks()), self.store.comments[self.key], self.issue().labels), (Split(("api", "web"), ()), 2, ["Delat per repo: api och web."], ("api", SPLIT_LABEL)))
|
||||
|
||||
def test_a_person_who_filed_a_sub_task_for_one_repo_still_gets_the_comment_and_the_rest_are_filed(self) -> None:
|
||||
self.store.file(self.key, "Own task.", "", ("repo:api",))
|
||||
done = self.run_split(says(TWO), by_person=True)
|
||||
self.assertEqual((done.repos, [task.labels for task in self.tasks()], self.store.comments[self.key]), (("api", "web"), [("repo:api",), ("repo:web",)], ["Delat per repo: api och web."]))
|
||||
|
||||
def test_a_sub_task_already_filed_counts_towards_the_split_whatever_the_new_prediction_says(self) -> None:
|
||||
self.store.file(self.key, "Own task.", "", ("repo:api",))
|
||||
done = self.run_split(says({"parts": [{"repo": "web", "change": "Show the count."}]}))
|
||||
self.assertEqual((done.repos, [task.labels for task in self.tasks()]), (("api", "web"), [("repo:api",), ("repo:web",)]))
|
||||
|
||||
def test_splits_nothing_where_the_item_changes_one_repo_or_none(self) -> None:
|
||||
for parts in ([], [{"repo": "api", "change": "Serve the count."}], [{"repo": "api", "change": "a"}, {"repo": "api", "change": "b"}]):
|
||||
@@ -87,12 +102,11 @@ class Split_(unittest.TestCase):
|
||||
self.assertEqual(self.run_split(claude), Split((), ()))
|
||||
self.assertEqual((claude.calls, self.tasks()), ([], []))
|
||||
|
||||
def test_a_first_filing_that_fails_after_the_comment_posts_the_comment_again_on_the_next_run(self) -> None:
|
||||
def test_a_filing_that_keeps_failing_posts_no_comment(self) -> None:
|
||||
self.store.fails_files = True
|
||||
self.assertIsInstance(self.run_split(says(TWO), by_person=True), Failure)
|
||||
self.store.fails_files = False
|
||||
self.run_split(says(TWO), by_person=True)
|
||||
self.assertEqual(self.store.comments[self.key], ["Delat per repo: api och web."] * 2)
|
||||
for _ in range(2):
|
||||
self.assertIsInstance(self.run_split(says(TWO), by_person=True), Failure)
|
||||
self.assertEqual(self.store.comments, {})
|
||||
|
||||
def test_a_failed_filing_names_what_was_filed_and_a_second_run_files_only_the_rest(self) -> None:
|
||||
self.store.jammed = True
|
||||
@@ -144,7 +158,7 @@ class Split_(unittest.TestCase):
|
||||
self.assertIn("The item is a person's issue: also give a comment, in Swedish,", claude.calls[0][2])
|
||||
|
||||
def test_fails_on_an_answer_without_parts_or_with_a_repo_name_that_is_a_path(self) -> None:
|
||||
for output in ({}, "nope", {"parts": "api"}, {"parts": [{"repo": "../x", "change": "c"}]}, {"parts": [{"repo": "api"}]}, {"parts": [3]}):
|
||||
for output in ({}, "nope", {"parts": "api"}, {"parts": [{"repo": "../x", "change": "c"}]}, {"parts": [{"repo": "api"}]}, {"parts": [3]}, {"parts": [{"repo": "api", "change": " "}]}):
|
||||
with self.subTest(output=output):
|
||||
self.assertIsInstance(self.run_split(says(output)), Failure)
|
||||
self.assertEqual(self.tasks(), [])
|
||||
@@ -152,7 +166,7 @@ class Split_(unittest.TestCase):
|
||||
def test_an_answer_that_fails_is_quoted_up_to_two_hundred_characters(self) -> None:
|
||||
output = {"parts": "x" * 300}
|
||||
failed = self.run_split(says(output))
|
||||
self.assertEqual(failed, Failure(f"the repo split answered {json.dumps(output)[:200]}; expected parts, each with a repo name of letters, digits, dots, hyphens and underscores and a change"))
|
||||
self.assertEqual(failed, Failure(f"the repo split answered {json.dumps(output)[:200]}; expected parts, each with a repo name of letters, digits, dots, hyphens and underscores and a change that holds text"))
|
||||
|
||||
def test_a_label_that_fails_after_the_sub_tasks_names_them_and_leaves_the_item_unmarked(self) -> None:
|
||||
self.store.add_label = lambda key, label: Failure("Jira answered 500") if label == SPLIT_LABEL else None # type: ignore[method-assign]
|
||||
|
||||
Reference in New Issue
Block a user