Merge remote-tracking branch 'origin/main' into item-454

This commit is contained in:
Lilleman
2026-11-20 18:55:08 +01:00
19 changed files with 86 additions and 49 deletions
+1 -1
View File
@@ -208,7 +208,7 @@ def judge_args(rung: Rung, driver: str) -> list[str]:
return [
"--json-schema", json.dumps(judge_schema(driver)),
*rung.flags(),
"--tools", "",
"--tools", "", "--strict-mcp-config",
]
+1 -1
View File
@@ -104,7 +104,7 @@ def command_of(pid: int, shells: list[Shell]) -> str:
def investigated(shells: list[Shell], rung: Rung, root: str, effects: Effects) -> dict[str, typing.Any] | Failure:
"""A headless claude's verdict on the worker holding shells, as SCHEMA has it, or why there is none. It runs without tools, so it judges only the evidence it is handed."""
evidence = "\n\n".join(f"Shell {shell.pid}: {shell.command}\nIts processes, as pid, state, CPU and command line:\n{chr(10).join(shell.processes) or 'none'}\nThe end of its output:\n{shell.output or 'none'}" for shell in shells)
reply = claude_reply(effects.claude, ["--json-schema", json.dumps(SCHEMA), *rung.flags(), "--tools", ""], root, PROMPT + "\n" + evidence, "the stuck check")
reply = claude_reply(effects.claude, ["--json-schema", json.dumps(SCHEMA), *rung.flags(), "--tools", "", "--strict-mcp-config"], root, PROMPT + "\n" + evidence, "the stuck check")
if isinstance(reply, Limited):
return Failure(f"claude hit a limit: {reply.said}")
if isinstance(reply, Failure):
+5
View File
@@ -139,6 +139,11 @@ class JudgePrompt(unittest.TestCase):
"""What the judge of a-driver reads of a transcript holding entries."""
return judge.Brief("Do it.", "## Goals", records, "the project's decisions", answer_destinations, kinds(*entries), escalated_at, "a-driver")
def test_runs_with_no_tools_and_loads_no_mcp_server(self):
args = judge.judge_args(Rung("claude-opus-5-5", "medium"), "a-driver")
self.assertEqual(args[args.index("--tools") + 1 :], ["", "--strict-mcp-config"])
self.assertNotIn("--mcp-config", args)
def test_shows_the_transcripts_tail_and_returns_what_it_showed(self):
entries = [assistant({"type": "text", "text": "old " + "x" * judge.JUDGE_PROMPT_CHARS}), assistant({"type": "text", "text": "new"})]
prompt, grounds = judge.judge_prompt(self.brief(entries, 0))
+7 -2
View File
@@ -36,7 +36,11 @@ class StuckWorkers(unittest.TestCase):
if each_check:
streamed.shells = lambda: [each_check.pop(0)]
fake = FakeEffects(streams=[streamed], claude=replies)
effects = dataclasses.replace(fake.effects(), now=lambda: clock[0])
self.claude_folders = []
def claude(args, cwd, stdin):
self.claude_folders.append(cwd)
return fake.effects().claude(args, cwd, stdin)
effects = dataclasses.replace(fake.effects(), now=lambda: clock[0], claude=claude)
with tempfile.TemporaryDirectory() as folder, contextlib.redirect_stdout(io.StringIO()) as said, contextlib.redirect_stderr(io.StringIO()) as failed:
archive = archive or pathlib.Path(folder, "transcripts", "project")
worker.run_worker("/r", [], {}, archive, RUNG, effects)
@@ -47,7 +51,8 @@ class StuckWorkers(unittest.TestCase):
streamed, fake, said, _, record = self.worker_with(ASSISTANT, None, None, None, held=[shell()], replies=[verdict()])
[(args, prompt)] = fake.made("claude")
self.assertEqual(args[args.index("--model") + 1 :][:3], ["claude-opus-5-5", "--effort", "medium"])
self.assertEqual(args[args.index("--tools") + 1], "")
self.assertEqual(args[args.index("--tools") + 1 :][:2], ["", "--strict-mcp-config"])
self.assertEqual(self.claude_folders, ["/r"])
self.assertEqual(json.loads(args[args.index("--json-schema") + 1])["properties"]["verdict"]["enum"], ["working", "waiting on a person", "stuck"])
self.assertTrue(prompt.endswith("\n\nShell 7: bin/run-tests\nIts processes, as pid, state, CPU and command line:\n8 S 2.0 s python3 -m pytest\n9 S 0.0 s sh -c trap '' INT; sleep 999\nThe end of its output:\ncollected 40 items"))
line = "stuck check: a headless claude judged the worker stuck, naming process 8 (python3 -m pytest): pytest waits on a shell that ignores SIGINT" + sign(1600, 1600)
+1 -1
View File
@@ -33,7 +33,7 @@ class Scores:
def asked(issue: EpicIssue, rule: str, goals: str, language: str, rung: Rung, claude: Claude, cwd: str) -> Scores | Failure | Limited:
"""The scores claude gives the issue. rule is the text every plan item is scored by, and goals says which goals the issue may move and how to name each. Nothing is written: the caller checks the answer against the plan's format and sets it."""
reply = claude_reply(claude, ["--json-schema", json.dumps(SCHEMA), *rung.flags(), "--tools", ""], cwd, prompt(issue, rule, goals, language), "the scoring")
reply = claude_reply(claude, ["--json-schema", json.dumps(SCHEMA), *rung.flags(), "--tools", "", "--strict-mcp-config"], cwd, prompt(issue, rule, goals, language), "the scoring")
return reply if isinstance(reply, Failure | Limited) else answer_of(structured_output(reply))
+1 -1
View File
@@ -102,7 +102,7 @@ def picked(store: EpicStore, issue: EpicIssue, team: LabelRepos, rule: str, rung
known = recorded(issue, team)
if known is not None:
return known
reply = claude_reply(claude, ["--json-schema", json.dumps(PICK_SCHEMA), *rung.flags(), "--tools", ""], cwd, prompt(rule, issue), "the repo pick")
reply = claude_reply(claude, ["--json-schema", json.dumps(PICK_SCHEMA), *rung.flags(), "--tools", "", "--strict-mcp-config"], cwd, prompt(rule, issue), "the repo pick")
if isinstance(reply, Failure | Limited):
return reply
answer = answer_of(structured_output(reply))
+1 -1
View File
@@ -123,7 +123,7 @@ def finished(issues: list[EpicIssue], key: str) -> bool:
def prediction(issue: EpicIssue, by_person: bool, rule: str, language: str, checkouts: tuple[str, ...], rung: Rung, claude: Claude, cwd: str) -> Prediction | Failure | Limited:
"""The repos claude predicts the item changes, from the code in checkouts."""
flags = ["--json-schema", json.dumps(SPLIT_SCHEMA), *rung.flags(), "--tools", "Read,Grep,Glob", *(arg for each in checkouts for arg in ("--add-dir", each))]
flags = ["--json-schema", json.dumps(SPLIT_SCHEMA), *rung.flags(), "--tools", "Read,Grep,Glob", "--strict-mcp-config", *(arg for each in checkouts for arg in ("--add-dir", each))]
reply = claude_reply(claude, flags, cwd, prompt(issue, by_person, rule, language, checkouts), "the repo split")
return reply if isinstance(reply, Failure | Limited) else answer_of(structured_output(reply))
+2 -2
View File
@@ -53,12 +53,12 @@ class TheCall(unittest.TestCase):
self.assertEqual(self.ask(claude), answer_of(ANSWER))
args, cwd, _ = claude.calls[0]
self.assertEqual(cwd, "/state/scoring")
self.assertEqual(args[:9], ["-p", "--json-schema", json.dumps(SCHEMA), "--model", "claude-sonnet-5-5", "--effort", "medium", "--tools", ""])
self.assertEqual(args[:10], ["-p", "--json-schema", json.dumps(SCHEMA), "--model", "claude-sonnet-5-5", "--effort", "medium", "--tools", "", "--strict-mcp-config"])
def test_names_the_scoring_where_claude_fails(self) -> None:
failed = self.ask(Claude("", 1))
assert isinstance(failed, Failure), failed
self.assertIn("the scoring", failed.reason)
self.assertEqual(failed.reason, "the scoring exited 1")
def test_puts_the_rule_the_goals_the_language_and_the_item_in_the_prompt(self) -> None:
text = prompt(ISSUE, "L is the chance of a defect.", "An item moves only these: `epic 1`.", "Swedish")
+1 -1
View File
@@ -57,7 +57,7 @@ class RepoPick(unittest.TestCase):
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", ""])
self.assertEqual(args[:10], ["-p", "--json-schema", json.dumps(PICK_SCHEMA), "--model", "claude-sonnet-5-5", "--effort", "medium", "--tools", "", "--strict-mcp-config"])
def test_puts_the_rule_and_the_item_in_the_prompt(self) -> None:
claude = says({"pick": "claude"})
+2 -2
View File
@@ -156,8 +156,8 @@ class Split_(unittest.TestCase):
self.run_split(claude)
args, cwd, prompt = claude.calls[0]
self.assertEqual(cwd, "/rules")
self.assertEqual(args[:12], ["-p", "--json-schema", json.dumps(SPLIT_SCHEMA), "--model", "claude-sonnet-5-5", "--effort", "medium", "--tools", "Read,Grep,Glob", "--add-dir", "/repos/api", "--add-dir"])
self.assertEqual(args[12], "/repos/web")
self.assertEqual(args[:13], ["-p", "--json-schema", json.dumps(SPLIT_SCHEMA), "--model", "claude-sonnet-5-5", "--effort", "medium", "--tools", "Read,Grep,Glob", "--strict-mcp-config", "--add-dir", "/repos/api", "--add-dir"])
self.assertEqual(args[13], "/repos/web")
self.assertIn(RULE, prompt)
self.assertIn("## Item ABC-100: Count the runs.", prompt)
self.assertIn("write each part's change in Swedish.", prompt)
+39
View File
@@ -0,0 +1,39 @@
import ast
import pathlib
import subprocess
import sys
import unittest
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
from repo_checks import ROOT
def denies_tools_without_strict_mcp(source: str) -> bool:
"""Whether the source passes "--tools" more often than "--strict-mcp-config", so a call that denies tools would load the MCP servers of the user's or the project's config."""
strings = [node.value for node in ast.walk(ast.parse(source)) if isinstance(node, ast.Constant) and isinstance(node.value, str)]
return strings.count("--tools") > strings.count("--strict-mcp-config")
class HeadlessMcp(unittest.TestCase):
def test_each_file_that_passes_tools_passes_strict_mcp_config_too(self):
# Untracked files count too, so a new call is checked before its first commit.
listed = subprocess.run(["git", "ls-files", "--cached", "--others", "--exclude-standard", "*.py"], capture_output=True, check=True, cwd=ROOT, text=True).stdout.split()
self.assertIn("reviewer-merge-trials/analyze.py", listed)
self.assertIn("bin/agent_cycle/judge.py", listed)
files = [name for name in listed if not pathlib.PurePath(name).name.startswith("test_")]
lacking = {name for name in files if denies_tools_without_strict_mcp((ROOT / name).read_text(encoding="utf-8"))}
self.assertEqual(lacking, set(), "add --strict-mcp-config beside --tools, so no MCP server loads where the prompt holds text an outsider can write")
def test_a_file_with_tools_and_no_strict_mcp_config_is_found(self):
self.assertTrue(denies_tools_without_strict_mcp('args = ["--tools", ""]'))
self.assertFalse(denies_tools_without_strict_mcp('args = ["--tools", "", "--strict-mcp-config"]'))
self.assertFalse(denies_tools_without_strict_mcp('args = ["-p"]'))
def test_a_second_call_without_the_flag_is_found_in_a_file_where_another_call_has_it(self):
self.assertTrue(denies_tools_without_strict_mcp('a = ["--tools", "", "--strict-mcp-config"]\nb = ["--tools", ""]'))
self.assertFalse(denies_tools_without_strict_mcp('a = ["--tools", "", "--strict-mcp-config"]\nb = ["--tools", "", "--strict-mcp-config"]'))
if __name__ == "__main__":
unittest.main()
+1 -1
View File
@@ -191,7 +191,7 @@ def match(findings: tuple[str, ...], replay_report: str, root: str, rung: Rung,
"A finding it raises only as 🟢 or ❓, or not at all, is not listed.\n\n"
f"The findings:\n{numbered}\n\nThe other report:\n{replay_report}"
)
args = ["--json-schema", json.dumps(MATCH_SCHEMA), *rung.flags(), "--tools", ""]
args = ["--json-schema", json.dumps(MATCH_SCHEMA), *rung.flags(), "--tools", "", "--strict-mcp-config"]
reply = claude_reply(effects.claude, args, root, prompt, "claude")
if isinstance(reply, Failure | Limited):
return reply
+1 -1
View File
@@ -179,7 +179,7 @@ class Match(unittest.TestCase):
self.assertEqual(cwd, "/code/p")
self.assertIn("1. 🔴 a\n\n2. 🟡 b\n\nThe other report:\nthe other report", prompt)
self.assertEqual(json.loads(args[args.index("--json-schema") + 1]), replay.MATCH_SCHEMA)
self.assertEqual(args[args.index("--tools") + 1], "")
self.assertEqual(args[args.index("--tools") + 1 :][:2], ["", "--strict-mcp-config"])
self.assertEqual(args[args.index("--model"):args.index("--model") + 4], REFERENCE.flags())
def test_takes_the_numbers_in_range_and_fails_on_a_reply_of_another_shape(self):