Merge remote-tracking branch 'origin/main' into item-460
CI / tests (pull_request) Has been cancelled

This commit is contained in:
Lilleman
2026-11-20 00:06:58 +01:00
15 changed files with 278 additions and 76 deletions
+13 -5
View File
@@ -5,7 +5,7 @@ import dataclasses
import typing
from forge.reviews import ANSWERED, APPROVED, CHANGES_REQUESTED, review_decision, REVIEW_REQUIRED, waiting_threads
from forge.pulls import CheckFailed, checks_now, open_pull, Pending, required_checks
from forge.pulls import CheckFailed, checks_now, open_pull, Pending, required_checks, unmergeable
from failure import Failure
from forge.commands import forge_of, Run
@@ -39,10 +39,15 @@ class Unopened(Open):
"""An Open whose worktree stands though no pull request is open at its head: one that was merged or closed, whose chunk still has its worktree to remove."""
@dataclasses.dataclass(frozen=True)
class Unmergeable(Open):
"""An Open whose pull request awaits a person's merge and doesn't merge into its base as it stands: its worker levels the branch."""
def gate(branch: str, checkout: str, at: typing.Callable[[str], Run], by_human: bool) -> Gate | Open | Failure:
"""What the chunk on branch waits on, in a worktree of checkout; at gives the runner of commands in a folder, and by_human says the project's config leaves the merge to a person (`merge = "human"`). A Failure where git or the forge cannot be read, which doesn't say anything about the gate.
A draft never waits on a gate: its worker still works on it. On Gitea only the checks are a gate, since chunk-pr reads approvals on GitHub only (`chunk_pr.approval.awaited`). Changes a reviewer requested are news until the worker answered them (`forge.reviews.answered`); from then on the pull request awaits a new review. Where a person merges, a pull request with nothing else to wait on awaits that merge, and the chunk has news again once the pull request is no longer open.
A draft never waits on a gate: its worker still works on it. On Gitea only the checks are a gate, since chunk-pr reads approvals on GitHub only (`chunk_pr.approval.awaited`). Changes a reviewer requested are news until the worker answered them (`forge.reviews.answered`); from then on the pull request awaits a new review. Where a person merges, a pull request with nothing else to wait on awaits that merge. The chunk has news again once the pull request is no longer open. It has news too once the pull request no longer merges into its base as it stands (`forge.pulls.unmergeable`): the worker then levels the branch for that person.
"""
worktree = worktree_of(branch, at(checkout))
if not isinstance(worktree, str):
@@ -77,9 +82,12 @@ def gate(branch: str, checkout: str, at: typing.Callable[[str], Run], by_human:
return Open(f"a reviewer's comment on pull request #{pull} waits for an answer, in {', '.join(waiting)}")
if decision in (ANSWERED, REVIEW_REQUIRED):
return Gate(worktree, pull, NEW_REVIEW if decision == ANSWERED else APPROVAL)
if by_human:
return Gate(worktree, pull, MERGE)
return Open(f"pull request #{pull} passed its checks" + (" and is approved" if decision == APPROVED else ""))
if not by_human:
return Open(f"pull request #{pull} passed its checks" + (" and is approved" if decision == APPROVED else ""))
blocked = unmergeable(forge, pull, run)
if isinstance(blocked, Failure):
return blocked
return Unmergeable(f"pull request #{pull} {blocked}; run chunk-pr merge again to level the branch") if blocked else Gate(worktree, pull, MERGE)
def worktree_of(branch: str, run: Run) -> str | None | Failure:
+6 -2
View File
@@ -287,7 +287,7 @@ def chunk_run(key: str, epic: EpicRun) -> Stop:
def parked_through(repo: str, loop: Loop, epic: EpicRun, told: str | None, finished: bool) -> str | Stop:
"""Keeps the chunk in loop's window parked. Its work is in the repo called repo. It stays parked for as long as its pull request waits on a gate, and returns once its worker has something to do: what to tell that worker, or empty where the chunk was never parked. told is the news its last cycle's worker got, None where the window just started, and finished says the judge ruled the chunk finished. A window that just started parks the chunk only if its file says so: the forge isn't read for a chunk that starts afresh.
Where a person merges, a worker ends its run with the pull request open, so the judge may rule the chunk finished before it is. For such a finished chunk, a gate that cannot be read is read again until it can, and a pull request no longer open, in a worktree that still stands, is news the worker hasn't been told: the worker removes the worktree.
Where a person merges, a worker ends its run with the pull request open, so the judge may rule the chunk finished before it is. For such a finished chunk, a gate that cannot be read is read again until it can, and a pull request no longer open, in a worktree that still stands, is news the worker hasn't been told: the worker removes the worktree. A pull request that doesn't merge into its base is news after every cycle that leaves it so: the worker levels the branch.
A chunk parks in three steps: its file is written, its window is shown as parked, and the epic's next chunks start in the slot it frees. It resumes in the reverse order: `scheduler.resume` gives it a running slot, then its file is removed. So a window that ends in between finds the chunk parked when it starts again.
"""
@@ -305,7 +305,11 @@ def parked_through(repo: str, loop: Loop, epic: EpicRun, told: str | None, finis
if not isinstance(entered, gates.Gate):
if isinstance(entered, Failure):
say(f"cannot tell whether the chunk's pull request waits on a gate, so the chunk isn't parked: {entered.reason}", epic.effects, stdout=True)
uncleaned = f"{chunk_prompt.DRIVER} keeps the chunk open while its worktree stands: {entered.news}." if finished and poll.by_human and isinstance(entered, gates.Unopened) else ""
if not (finished and poll.by_human and isinstance(entered, (gates.Unopened, gates.Unmergeable))):
return ""
if isinstance(entered, gates.Unmergeable):
return f"{chunk_prompt.DRIVER} keeps the chunk open while its pull request doesn't merge into its base: {entered.news}."
uncleaned = f"{chunk_prompt.DRIVER} keeps the chunk open while its worktree stands: {entered.news}."
return "" if uncleaned in (told or "") else uncleaned
if failed := poll.record(entered):
return Stop(1, failed.reason)
+24 -4
View File
@@ -5,7 +5,7 @@ import unittest
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
from do_epic.gates import APPROVAL, CHECKS, gate, Gate, MERGE, NEW_REVIEW, Open, Unopened
from do_epic.gates import APPROVAL, CHECKS, gate, Gate, MERGE, NEW_REVIEW, Open, Unmergeable, Unopened
from failure import Failure
WORKTREES = "worktree /code/billing\nHEAD aaa\nbranch refs/heads/main\n\nworktree /code/billing-ABC-21\nHEAD abc\nbranch refs/heads/ABC-21\n"
@@ -28,7 +28,7 @@ def comment(by: str, at: str) -> dict:
class Forge:
"""Stands in for git and the forge's CLI in the checkout and the chunk's worktree; `ran` holds each folder a command ran in. Only the CLI of origin's forge answers: `gh` fails on a Gitea origin, and `tea` on a GitHub one."""
def __init__(self, origin: str = "git@github.com:o/billing.git", pulls: str = f"7\t{HEAD}\tfalse\n", draft: bool = False, decision: str = "REVIEW_REQUIRED", buckets: tuple[str, ...] = ("pass",), threads: tuple[dict, ...] = (), status: str = '{"state": "success", "total_count": 1}', worktrees: str = WORKTREES, fails: str = "", reviews: tuple[dict, ...] = (), comments: tuple[dict, ...] = (), title: str = "Add x") -> None:
def __init__(self, origin: str = "git@github.com:o/billing.git", pulls: str = f"7\t{HEAD}\tfalse\n", draft: bool = False, decision: str = "REVIEW_REQUIRED", buckets: tuple[str, ...] = ("pass",), threads: tuple[dict, ...] = (), status: str = '{"state": "success", "total_count": 1}', mergeable: str = "MERGEABLE", merge_state: str = "CLEAN", worktrees: str = WORKTREES, fails: str = "", reviews: tuple[dict, ...] = (), comments: tuple[dict, ...] = (), title: str = "Add x") -> None:
self.cli = "gh" if "github.com" in origin else "tea"
self.ran: list[str] = []
self.commands: list[list[str]] = []
@@ -39,11 +39,11 @@ class Forge:
"git rev-parse": HEAD + "\n",
"git symbolic-ref": "origin/main\n",
"gh pr list": pulls,
"gh pr view": json.dumps({"isDraft": draft, "reviewDecision": decision, "author": {"login": "worker"}, "reviews": list(reviews), "comments": list(comments)}),
"gh pr view": json.dumps({"isDraft": draft, "reviewDecision": decision, "author": {"login": "worker"}, "reviews": list(reviews), "comments": list(comments), "mergeable": mergeable, "mergeStateStatus": merge_state}),
"gh pr checks": json.dumps([{"bucket": bucket} for bucket in buckets]),
"gh api graphql": json.dumps({"data": {"repository": {"pullRequest": {"author": {"login": "worker"}, "reviewThreads": {"nodes": list(threads)}}}}}),
"tea api repos/{owner}/{repo}/pulls?state=open&limit=50": json.dumps([{"number": 7, "merged": False, "head": {"label": "ABC-21", "sha": HEAD, "repo": {"full_name": "o/billing"}}, "base": {"repo": {"full_name": "o/billing"}}}]),
"tea api repos/{owner}/{repo}/pulls/7": json.dumps({"number": 7, "title": title}),
"tea api repos/{owner}/{repo}/pulls/7": json.dumps({"number": 7, "title": title, "mergeable": mergeable == "MERGEABLE"}),
"tea api repos/{owner}/{repo}/branches/main": '{"name": "main"}',
"tea api repos/{owner}/{repo}/commits/" + HEAD + "/status": status,
}
@@ -79,6 +79,26 @@ class GateOfAChunk(unittest.TestCase):
self.assertEqual(forge.gate(by_human=True), Gate("/code/billing-ABC-21", "7", MERGE))
self.assertEqual(Forge(decision="APPROVED").gate(by_human=False), Open("pull request #7 passed its checks and is approved"))
def test_where_a_person_merges_a_pull_request_that_no_longer_merges_into_its_base_is_news_to_level_it(self):
gitea = "https://gitea.larvit.se/o/billing.git"
again = "run chunk-pr merge again to level the branch"
self.assertEqual(Forge(decision="APPROVED", mergeable="CONFLICTING", merge_state="DIRTY").gate(by_human=True), Unmergeable(f"pull request #7 conflicts with its base branch; {again}"))
self.assertEqual(Forge(gitea, mergeable="CONFLICTING").gate(by_human=True), Unmergeable(f"pull request #7 conflicts with its base branch; {again}"))
self.assertEqual(Forge(decision="", merge_state="BEHIND").gate(by_human=True), Unmergeable(f"pull request #7 is behind its base branch, whose protection requires it up to date; {again}"))
def test_where_a_person_merges_a_pull_request_awaits_that_merge_while_github_computes_whether_it_merges(self):
self.assertEqual(Forge(decision="APPROVED", mergeable="UNKNOWN", merge_state="UNKNOWN").gate(by_human=True), Gate("/code/billing-ABC-21", "7", MERGE))
def test_where_a_person_merges_a_mergeability_that_cannot_be_read_is_a_failure(self):
forge = Forge("https://gitea.larvit.se/o/billing.git")
forge.answers["tea api repos/{owner}/{repo}/pulls/7"] = '{"number": 7, "title": "Add x"}'
self.assertEqual(forge.gate(by_human=True), Failure("tea api answered pull request 7 in a shape that can't be read: {'number': 7, 'title': 'Add x'}"))
def test_where_the_chunk_merges_nobody_reads_whether_the_pull_request_merges(self):
forge = Forge(decision="APPROVED", mergeable="CONFLICTING")
self.assertEqual(forge.gate(), Open("pull request #7 passed its checks and is approved"))
self.assertNotIn(["gh", "pr", "view", "7", "--json", "mergeable,mergeStateStatus"], forge.commands)
def test_where_a_person_merges_every_other_gate_and_all_news_stay_as_they_are(self):
same = (Forge(), Forge(buckets=("pending",)), Forge(draft=True), Forge(decision="CHANGES_REQUESTED"), Forge(threads=(thread(False, "reviewer"),)), Forge(buckets=("fail",)), Forge(pulls=""))
for forge in same:
+14
View File
@@ -746,6 +746,20 @@ class AChunkWhosePullRequestWaitsOnAGate(DoEpicTest):
self.assertIn(fact, prompts[1].split("\n\n")[0])
self.assertNotIn("parked: ", out)
def test_where_a_person_merges_a_finished_chunk_whose_pull_request_no_longer_merges_is_told_until_it_does(self) -> None:
self.repo_config.write_text(self.repo_config.read_text(encoding="utf-8") + 'merge = "human"\n', encoding="utf-8")
for unmergeable, why in (({"mergeable": "CONFLICTING"}, "conflicts with its base branch"), ({"merge_state": "BEHIND"}, "is behind its base branch")):
with self.subTest(why=why):
self.forges = [awaiting(decision="APPROVED", **unmergeable), awaiting(decision="APPROVED", **unmergeable), CLEANED]
self.gate_reads = 0
fake = FakeEffects(streams=[self.worker(), self.worker(), self.worker()], claude=[judged("finished"), judged("finished"), judged("finished")], git=UNREAD, windows=PARKED_WINDOW)
code, out, err, prompts = self.parked_run(fake)
self.assertEqual((code, len(prompts)), (0, 3), err)
for prompt in prompts[1:]:
for fact in ("keeps the chunk open while its pull request doesn't merge into its base", f"pull request #7 {why}", "run chunk-pr merge again"):
self.assertIn(fact, prompt.split("\n\n")[0])
self.assertNotIn("parked: ", out)
def test_where_a_person_merges_an_unfinished_chunk_goes_on_without_news_or_a_wait(self) -> None:
self.repo_config.write_text(self.repo_config.read_text(encoding="utf-8") + 'merge = "human"\n', encoding="utf-8")
self.forges = [awaiting(pulls=""), awaiting(decision="APPROVED", fails="gh pr checks"), CLEANED]
+29 -1
View File
@@ -1,4 +1,4 @@
"""Finding a pull request from origin's own branch, and waiting for the checks on its head commit."""
"""Finding a pull request from origin's own branch, reading whether it merges into its base, and waiting for the checks on its head commit."""
import dataclasses
import fnmatch
import json
@@ -44,6 +44,34 @@ def pull_at(forge: Forge, branch: str, head: str, state: typing.Literal["open",
return Failure(f"tea api listed pull requests in a shape that can't be read: {str(pulls)[:200]}")
# Why a pull request doesn't merge into its base as it stands, as the words after "pull request #<N>".
CONFLICTS = "conflicts with its base branch"
BEHIND = "is behind its base branch, whose protection requires it up to date"
def unmergeable(forge: Forge, number: str, run: Run) -> str | None | Failure:
"""Why pull request number doesn't merge into its base as it stands: CONFLICTS or BEHIND. None where it merges, and while GitHub still computes whether it does.
GitHub reports a pull request as behind only where the base's protection requires an up-to-date branch. Gitea's `mergeable` never tells that case. Gitea also answers false for the seconds it checks for conflicts after a push to either branch, which reads as CONFLICTS here.
"""
if forge == "gh":
viewed = run(["gh", "pr", "view", number, "--json", "mergeable,mergeStateStatus"])
if isinstance(viewed, Failure):
return viewed
try:
state = json.loads(viewed)
return CONFLICTS if state["mergeable"] == "CONFLICTING" else BEHIND if state["mergeStateStatus"] == "BEHIND" else None
except (ValueError, KeyError, TypeError):
return Failure(f"gh pr view printed no mergeability: {viewed.strip()[:200]}")
pull = gitea(run, f"repos/{{owner}}/{{repo}}/pulls/{number}")
if isinstance(pull, Failure):
return pull
try:
return CONFLICTS if pull["mergeable"] is False else None
except (KeyError, TypeError):
return Failure(f"tea api answered pull request {number} in a shape that can't be read: {str(pull)[:200]}")
def required_checks(forge: Forge, base: str, run: Run) -> set[str] | Failure:
"""The checks, or glob patterns of checks, that the forge's protection of the branch base requires before a merge. None on GitHub, where gh's watch covers them.
+37 -1
View File
@@ -6,7 +6,7 @@ import unittest
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
from forge.pulls import CheckFailed, checks_now, checks_passed, open_pull, Pending, POLL_SECONDS, required_checks, WAIT_SECONDS
from forge.pulls import BEHIND, CheckFailed, checks_now, checks_passed, CONFLICTS, open_pull, Pending, POLL_SECONDS, required_checks, unmergeable, WAIT_SECONDS
from failure import Failure
from forge.commands import forge_of, gitea, url_beside
@@ -47,6 +47,42 @@ class OpenPull(unittest.TestCase):
self.assertEqual(open_pull("tea", "item-3", "abc", lambda command: LONG).reason, f"tea api listed pull requests in a shape that can't be read: {LONG[:200]}")
class Unmergeable(unittest.TestCase):
def gh(self, mergeable: str, state: str) -> str | None | Failure:
commands: list[list[str]] = []
answer = unmergeable("gh", "7", lambda command: commands.append(command) or f'{{"mergeable": "{mergeable}", "mergeStateStatus": "{state}"}}')
self.assertEqual(commands, [["gh", "pr", "view", "7", "--json", "mergeable,mergeStateStatus"]])
return answer
def test_a_github_pull_request_that_conflicts_with_its_base_says_so(self):
self.assertEqual(self.gh("CONFLICTING", "DIRTY"), CONFLICTS)
def test_a_github_pull_request_behind_a_base_that_requires_it_up_to_date_says_so(self):
self.assertEqual(self.gh("MERGEABLE", "BEHIND"), BEHIND)
def test_a_github_pull_request_merges_whatever_else_holds_it_and_while_github_computes(self):
for mergeable, state in (("MERGEABLE", "CLEAN"), ("MERGEABLE", "BLOCKED"), ("MERGEABLE", "UNSTABLE"), ("UNKNOWN", "UNKNOWN")):
with self.subTest(mergeable=mergeable, state=state):
self.assertIsNone(self.gh(mergeable, state))
def test_a_gitea_pull_request_conflicts_only_where_gitea_says_it_is_not_mergeable(self):
commands: list[list[str]] = []
self.assertEqual(unmergeable("tea", "7", lambda command: commands.append(command) or '{"number": 7, "mergeable": false}'), CONFLICTS)
self.assertEqual(commands, [["tea", "api", "repos/{owner}/{repo}/pulls/7"]])
self.assertIsNone(unmergeable("tea", "7", lambda command: '{"number": 7, "mergeable": true}'))
def test_fails_where_the_forge_cannot_be_read_or_answers_in_another_shape(self):
unread = Failure("no network")
for forge in ("gh", "tea"):
with self.subTest(forge=forge):
self.assertIs(unmergeable(forge, "7", lambda command: unread), unread)
self.assertEqual(unmergeable("gh", "7", lambda command: LONG).reason, f"gh pr view printed no mergeability: {LONG[:200]}")
self.assertEqual(unmergeable("gh", "7", lambda command: "not json").reason, "gh pr view printed no mergeability: not json")
self.assertEqual(unmergeable("gh", "7", lambda command: '{"mergeable": "MERGEABLE"}').reason, 'gh pr view printed no mergeability: {"mergeable": "MERGEABLE"}')
self.assertEqual(unmergeable("tea", "7", lambda command: LONG).reason, f"tea api answered pull request 7 in a shape that can't be read: {LONG[:200]}")
self.assertEqual(unmergeable("tea", "7", lambda command: '{"number": 7}').reason, "tea api answered pull request 7 in a shape that can't be read: {'number': 7}")
def tea(statuses: typing.Iterable[str], branch: str = '{"name": "main"}') -> typing.Callable[[list[str]], str]:
"""A tea answering each read of the head's status with the next of statuses, and of branch main with branch."""
answers = iter(statuses)
+3 -2
View File
@@ -91,8 +91,9 @@ prepare-scoring sets up a scoring run in the chunk's review folder: a detached w
checkout's HEAD, which the seats read, and one prompt file per seat beside it, as
skills/comprehension-panel/seat-prompts.md builds them. It prints the worktree's path and each
prompt's. It takes {{language}}, {{kind}}, {{domain}}, {{domain docs}} and {{3am question}} from the
checkout's AGENTS.md → "Scoring run". claude-config keeps no AGENTS.md, so there it takes them from
seat-prompts.md → "claude-config's values". It fills the other placeholders from the worktree and
project's working-rules file → "Scoring run", which is the checkout's AGENTS.md unless the config
names another. Where that file holds no such section, as in claude-config, it takes them from the
checkout's seat-prompts.md → "claude-config's values". It fills the other placeholders from the worktree and
the panel's SKILL.md. Where any one of the five values is missing, it exits 1 and doesn't write
anything. Where a setup that record-scoring never removed is still there, it removes it first and
says so.
+10 -6
View File
@@ -61,9 +61,12 @@ def score_bullets(skill: str) -> tuple[list[str], list[str]] | Failure:
return anchors, [line.replace("**", "") for _, line in dimensions]
VALUES_HEADING = r"(\d+\.\s+)?Scoring run|.+'s values"
def project_values(text: str, source: str) -> dict[str, str] | Failure:
"""Each value seat-prompts.md fills from the project, from the section of text, read from source, headed `Scoring run` or `<name>'s values`."""
lines = section(text, r"(\d+\.\s+)?Scoring run|.+'s values")
lines = section(text, VALUES_HEADING)
if lines is None:
return Failure(f"{source} has no \"Scoring run\" section to fill the seats' prompts from; add one with {listed([f'{{{name}}}' for name in VALUE_NAMES], 'and')}")
values = {}
@@ -141,14 +144,15 @@ def prepare_scoring(worktree: str, home: pathlib.Path, run: Git = git) -> str |
rules = read(source) if source.is_file() else ""
if isinstance(rules, Failure):
return rules
values = project_values(rules, source.name)
# Where the working rules hold no values, as with AGENTS.md missing or this repo's decisions.md head, this repo keeps them in seat-prompts.md: .claude/rules/this-repo-keeps-no-agents-md.md.
if isinstance(values, Failure) and (own := pathlib.Path(worktree) / "skills" / "comprehension-panel" / "seat-prompts.md").is_file():
own_text = read(own)
values = own_text if isinstance(own_text, Failure) else project_values(own_text, own.name)
# This repo keeps the values in seat-prompts.md, so its working rules hold none: .claude/rules/this-repo-keeps-no-agents-md.md.
if section(rules, VALUES_HEADING) is None and (own := pathlib.Path(worktree) / "skills" / "comprehension-panel" / "seat-prompts.md").is_file():
source, rules = own, read(own)
if isinstance(rules, Failure):
return rules
skill = read(PANEL / "SKILL.md")
if isinstance(skill, Failure):
return skill
values = project_values(rules, source.name)
if isinstance(values, Failure):
return values
parts = prompt_parts()
+30 -11
View File
@@ -157,17 +157,6 @@ class PrepareScoring(unittest.TestCase):
self.assertIn("Your background: ~2 years in Go,", junior)
self.assertIn("every non-test tracked file: `bin/**`, `AGENTS.md` and `README.md`. Do NOT open plan/todo.md, docs/decisions.md or docs/reading-cost.md (the plan, the decision log and past chunks' reading cost), nor any review output.", junior)
def test_takes_the_values_from_seat_prompts_where_the_working_rules_hold_none_and_the_repo_keeps_them_there(self):
self.commit("# Working rules, with no values\n")
self.assertIsInstance(failed := self.prepare(), Failure, failed)
panel = self.checkout / "skills" / "comprehension-panel"
panel.mkdir(parents=True)
(panel / "seat-prompts.md").write_text("# Seats\n\n## The repo's values\n\n- `{language}`: Go\n- `{kind}`: a CLI\n- `{domain}`: parsing\n- `{domain docs}`: the spec\n- `{3am question}`: the parse hangs\n")
self.commit()
ran = self.prepare()
assert isinstance(ran, str), ran
self.assertIn("Your background: ~2 years in Go,", pathlib.Path(ran.splitlines()[2]).read_text())
def test_forbids_any_record_of_a_past_panel_where_the_config_puts_every_record_outside_the_checkout(self):
self.config.write_text(self.config.read_text().replace('"checkout:', '"folder:').replace('"folder:README.md"', '"checkout:README.md"'))
(self.config.parent / "AGENTS.md").write_text("# A\n\n## Scoring run\n\n- Language: Go\n- Kind: a CLI\n- Domain: parsing\n- Domain docs: the spec\n- 3am question: the parse hangs\n")
@@ -176,6 +165,28 @@ class PrepareScoring(unittest.TestCase):
assert isinstance(ran, str), ran
self.assertIn("every non-test tracked file: `bin/**` and `README.md`. Do NOT open any record of a past panel, nor any review output.", pathlib.Path(ran.splitlines()[2]).read_text())
def test_takes_the_values_from_the_checkouts_seat_prompts_where_the_working_rules_hold_none(self):
own = self.checkout / "skills" / "comprehension-panel" / "seat-prompts.md"
own.parent.mkdir(parents=True)
own.write_text("# Seats\n\n## proj's values\n\n- Language: Go\n- Kind: a CLI\n- Domain: parsing\n- Domain docs: the spec\n- 3am question: the parse hangs\n")
for rules in ("# Working rules, with no values\n", None):
with self.subTest(rules=rules):
(self.checkout / "AGENTS.md").unlink(missing_ok=True)
self.commit(rules)
ran = self.prepare()
assert isinstance(ran, str), ran
self.assertIn("Your background: ~2 years in Go, first codebase of this kind (a CLI)", pathlib.Path(ran.splitlines()[2]).read_text())
self.assertIsNone(removed_setup(str(self.checkout), self.root, functools.partial(git, env=self.env)))
def test_keeps_the_working_rules_values_where_the_checkout_has_seat_prompts_too(self):
own = self.checkout / "skills" / "comprehension-panel" / "seat-prompts.md"
own.parent.mkdir(parents=True)
own.write_text("## proj's values\n\n- Language: Go\n- Kind: a CLI\n- Domain: parsing\n- Domain docs: the spec\n- 3am question: the parse hangs\n")
self.commit("## Scoring run\n\n- Language: Python\n- Kind: a CLI\n- Domain: parsing\n- Domain docs: the spec\n- 3am question: the parse hangs\n")
ran = self.prepare()
assert isinstance(ran, str), ran
self.assertIn("Your background: ~2 years in Python,", pathlib.Path(ran.splitlines()[2]).read_text())
def test_refuses_writing_nothing_where_the_project_gives_no_values(self):
self.commit()
ran = self.run_tool("prepare-scoring")
@@ -192,6 +203,14 @@ class PrepareScoring(unittest.TestCase):
assert isinstance(unread, Failure), unread
self.assertTrue(unread.reason.startswith(f"cannot read {self.checkout}/AGENTS.md: "), unread.reason)
self.assertEqual(len(self.git("worktree", "list").splitlines()), 1)
own = self.checkout / "skills" / "comprehension-panel" / "seat-prompts.md"
own.parent.mkdir(parents=True)
own.write_bytes(b"\xff")
(self.checkout / "AGENTS.md").write_text("# Working rules, with no values\n")
unread = self.prepare()
assert isinstance(unread, Failure), unread
self.assertTrue(unread.reason.startswith(f"cannot read {own}: "), unread.reason)
self.assertEqual(len(self.git("worktree", "list").splitlines()), 1)
if __name__ == "__main__":