diff --git a/agents/conductors/batch/_batch.py b/agents/conductors/batch/_batch.py index c1a794e..05eaf53 100644 --- a/agents/conductors/batch/_batch.py +++ b/agents/conductors/batch/_batch.py @@ -117,8 +117,14 @@ def lane_absent_why(r: dict) -> str: def declared_repos(p: dict) -> list[str]: - """A parsed prompt's `Repos:` header and known target, normalised; its - survey `repos` when it declares neither.""" + """The repos a parsed prompt will touch, normalised: its `Repos:` header + when that names any known repo; otherwise its `Target:` when that is a + known repo; otherwise its survey `repos`. + + `Target:` is not unioned into a declared `Repos:` block: it is often only + an epic label (a prompt with `Target: autofit` whose `Repos:` lists only + PyAutoCortex), so adding it made the claim gate report a false conflict + on a repo the prompt never touches (PyAutoBrain#675).""" from _sizing import KNOWN_REPOS # noqa: E402 out = set() block = re.search(r"^Repos:\n((?:- .+\n)+)", p.get("text") or "", re.M) @@ -126,10 +132,12 @@ def declared_repos(p: dict) -> list[str]: r = normalise_repo(ln[1:].strip()) if r in KNOWN_REPOS: out.add(r) + if out: + return sorted(out) t = normalise_repo(p.get("target") or "") if t in KNOWN_REPOS: - out.add(t) - return sorted(out) or list(p.get("repos") or []) + return [t] + return list(p.get("repos") or []) def grade(path: Path, mind: Path, text: str | None = None) -> dict: diff --git a/tests/test_batch_declared_repos.py b/tests/test_batch_declared_repos.py new file mode 100644 index 0000000..cc0e481 --- /dev/null +++ b/tests/test_batch_declared_repos.py @@ -0,0 +1,55 @@ +"""`declared_repos` and the batch claim gate (PyAutoBrain#675). + +A prompt's `Target:` is often only an epic label: a prompt with +`Target: pyautoeyes` whose `Repos:` lists only PyAutoCortex never touches +PyAutoEyes, so a claim on PyAutoEyes must not hold it. +""" + +from __future__ import annotations + +import sys +from pathlib import Path + +BRAIN = Path(__file__).resolve().parents[1] +BATCH = BRAIN / "agents" / "conductors" / "batch" +sys.path.insert(0, str(BRAIN / "agents" / "faculties" / "sizing")) +sys.path.insert(0, str(BATCH)) +import _batch # noqa: E402 +import _orchestrator as orch # noqa: E402 +from _sizing import normalise_repo # noqa: E402 + +ACTIVE = ("# Active\n\n## eyes-work\n- prompt: active/feature/pyautoeyes/eyes-work.md\n" + "- session: claude-code desktop (WSL)\n- repos:\n - PyAutoEyes\n") + + +def _prompt(target: str, repos: list[str] | None) -> dict: + text = f"Target: {target}\n" + if repos is not None: + text += "Repos:\n" + "".join(f"- {r}\n" for r in repos) + return {"target": target, "text": text + "\nBody.\n", "repos": ["survey_only"]} + + +def test_repos_block_wins_over_an_epic_label_target(): + p = _prompt("pyautoeyes", ["PyAutoCortex"]) + assert _batch.declared_repos(p) == [normalise_repo("PyAutoCortex")] + + +def test_claim_on_the_target_does_not_hold_a_prompt_that_never_touches_it(): + sections = orch.claim_sections(ACTIVE) + cortex_only = _batch.declared_repos(_prompt("pyautoeyes", ["PyAutoCortex"])) + assert orch._held_for(sections, "cortex-ledger", cortex_only) is None + touches_eyes = _batch.declared_repos(_prompt("pyautoeyes", ["PyAutoEyes", "PyAutoCortex"])) + assert orch._held_for(sections, "eyes-follow-up", touches_eyes) == ("PyAutoEyes", "eyes-work") + + +def test_no_repos_block_falls_back_to_target(): + assert _batch.declared_repos(_prompt("pyautoeyes", None)) == [normalise_repo("pyautoeyes")] + + +def test_repos_block_of_unknown_names_falls_back_to_target(): + p = _prompt("pyautoeyes", ["not_a_repo", "another_unknown"]) + assert _batch.declared_repos(p) == [normalise_repo("pyautoeyes")] + + +def test_unknown_target_and_no_repos_falls_back_to_survey(): + assert _batch.declared_repos(_prompt("epic-label", None)) == ["survey_only"]