Answer stability round 1: 1 🔴, 12 🟡 (0 misread); wait-for waits out a half-written line, prepare-scoring honours claudeMdExcludes, and a merge by another method waits for the checks
CI / tests (pull_request) Successful in 2m38s

This commit is contained in:
2026-11-12 09:13:37 +01:00
parent 37f19d1677
commit 58133e69fe
8 changed files with 90 additions and 23 deletions
+1 -1
View File
@@ -88,7 +88,7 @@ skills/comprehension-panel/seat-prompts.md builds them. It prints the worktree's
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
the panel's SKILL.md. --preloaded replaces {{preloaded}}, which by default names each CLAUDE.md, its
the panel's SKILL.md. --preloaded replaces {{preloaded}}, which by default names each CLAUDE.md the main checkout's claudeMdExcludes doesn't exclude, its
imports and each rule file without `paths:` that Claude Code loads into a seat. 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.
+17 -2
View File
@@ -1,4 +1,5 @@
"""Set up a scoring run: the worktree its seats read and each seat's prompt, filled from skills/comprehension-panel/seat-prompts.md."""
import json
import pathlib
import re
import shutil
@@ -96,16 +97,30 @@ def file_globs(paths: list[str]) -> str:
def preloaded_files(main: pathlib.Path, home: pathlib.Path) -> str:
"""The files Claude Code loads into a seat started in main before its first tool call: each CLAUDE.md, the files it imports, and each rule file without `paths:`."""
"""The files Claude Code loads into a seat started in main before its first tool call: each CLAUDE.md that main's settings don't exclude, the files it imports, and each rule file without `paths:`."""
excludes = claude_md_excludes(main)
found = []
for shown, claude_md, rules in (("~/.claude/", home / ".claude" / CLAUDE_MD, home / ".claude" / "rules"), ("", main / CLAUDE_MD, main / ".claude" / "rules")):
if claude_md.is_file():
if claude_md.is_file() and not any(claude_md.full_match(pattern) for pattern in excludes):
found.append(f"`{shown}{CLAUDE_MD}`")
found += [f"`{shown}{name}`, which it imports" for name in re.findall(r"^@(\S+)", claude_md.read_text(), re.M)]
found += [f"`{shown}{rule.relative_to(claude_md.parent)}`" for rule in sorted(rules.glob("*.md")) if not re.search(r"^paths:", rule.read_text(), re.M)]
return listed(found, "and") if found else "none"
def claude_md_excludes(main: pathlib.Path) -> list[str]:
"""The `claudeMdExcludes` globs of main's .claude/settings.json and settings.local.json, which keep a matching CLAUDE.md out of a session."""
globs = []
for name in ("settings.json", "settings.local.json"):
try:
settings = json.loads((main / ".claude" / name).read_text())
except (OSError, ValueError):
continue
excludes = settings.get("claudeMdExcludes") if isinstance(settings, dict) else None
globs += [glob for glob in excludes if isinstance(glob, str)] if isinstance(excludes, list) else []
return globs
def prompt_parts() -> dict[str, str] | Failure:
"""seat-prompts.md's opening, shared brief and each report as their fenced text, and each seat's background, keyed by heading or label."""
path = PANEL / "seat-prompts.md"
+14 -1
View File
@@ -9,7 +9,7 @@ import unittest
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
from larv_review.scoring_setup import bullets, file_globs, prepare_scoring, project_values, score_bullets, section
from larv_review.scoring_setup import bullets, file_globs, preloaded_files, prepare_scoring, project_values, score_bullets, section
from failure import Failure
from test_env import isolated_env
@@ -141,6 +141,19 @@ class PrepareScoring(unittest.TestCase):
junior = (self.root / ".local" / "state" / "larv-review" / "proj" / "scoring" / "junior-a.md").read_text()
self.assertIn("from a DIFFERENT version (main): `CLAUDE.md` and `AGENTS.md`, which it imports.", junior)
def test_leaves_out_a_claude_md_the_project_settings_exclude(self):
(self.root / ".claude").mkdir()
(self.root / ".claude" / "CLAUDE.md").write_text("# Home\n")
(self.root / ".claude" / "rules").mkdir()
rule = "always"
(self.root / ".claude" / "rules" / f"{rule}.md").write_text("# Always\n")
(self.checkout / ".claude").mkdir()
(self.checkout / ".claude" / "settings.json").write_text('{"claudeMdExcludes": ["**/.claude/CLAUDE.md"]}\n')
(self.checkout / ".claude" / "settings.local.json").write_text("not json")
self.assertEqual(preloaded_files(self.checkout, self.root), f"`~/.claude/rules/{rule}.md`")
(self.checkout / ".claude" / "settings.json").write_text('{"claudeMdExcludes": [3]}\n')
self.assertEqual(preloaded_files(self.checkout, self.root), f"`~/.claude/CLAUDE.md` and `~/.claude/rules/{rule}.md`")
if __name__ == "__main__":
unittest.main()
+15
View File
@@ -1,6 +1,7 @@
import contextlib
import importlib.util
import io
from unittest import mock
import os
import pathlib
import re
@@ -59,6 +60,20 @@ class Report(unittest.TestCase):
self.assertEqual(main.report("usage: pytest\nerror: unrecognized arguments\n"), [])
class Main(unittest.TestCase):
def test_prints_the_help_for_h_or_help_first_and_runs_anything_else(self):
for argv in (["-h"], ["--help"], ["--help", "bin/x"]):
with self.subTest(argv=argv):
out = io.StringIO()
with contextlib.redirect_stdout(out), mock.patch.object(main, "run") as run:
self.assertEqual(main.main(argv), 0)
self.assertEqual(out.getvalue(), main.__doc__.strip() + "\n")
run.assert_not_called()
with mock.patch.object(main, "run", return_value=1) as run:
self.assertEqual(main.main(["bin/x", "-h"]), 1)
run.assert_called_once_with(["bin/x", "-h"])
class RunWithAStandIn(unittest.TestCase):
"""run with a stand-in for pytest: a Python script given the arguments run passes on."""
+22 -9
View File
@@ -27,14 +27,19 @@ class Clock(typing.Protocol):
def sleep(self, seconds: float) -> None: ...
def line_in(path: pathlib.Path, pattern: re.Pattern[str] | None) -> str | None | Failure:
"""The first line matching pattern, or without one the last line, where the file holds anything; else None."""
def text_of(path: pathlib.Path) -> str | None | Failure:
"""What the file holds; None where it doesn't exist."""
try:
lines = path.read_text(errors="replace").splitlines()
return path.read_text(errors="replace")
except FileNotFoundError:
return None
except OSError as error:
return Failure(f"cannot read {path}: {error.strerror}")
def line_in(text: str, pattern: re.Pattern[str] | None) -> str | None:
"""The first line of text matching pattern, or without one its last line; None where there is none."""
lines = text.splitlines()
if pattern is None:
return lines[-1] if lines else None
return next((line for line in lines if pattern.search(line)), None)
@@ -44,18 +49,26 @@ def waited(file: str, pattern: str | None, timeout: float, clock: Clock = time)
path = pathlib.Path(file)
compiled = re.compile(pattern) if pattern is not None else None
deadline = clock.monotonic() + timeout
while (found := line_in(path, compiled)) is None:
before = None
while True:
text = text_of(path)
if isinstance(text, Failure):
return text
# A last line without its newline may still be being written: it counts once a poll finds it unchanged.
settled = text is None or text.endswith("\n") or text == before
whole = text if settled or text is None else text[:text.rfind("\n") + 1]
# Without a pattern the last line is wanted, so an unsettled one waits.
if whole is not None and (settled or compiled is not None) and (found := line_in(whole, compiled)) is not None:
return found
before = text
left = deadline - clock.monotonic()
if left <= 0:
if not path.exists():
if text is None:
return Failure(f"{file} did not appear in {timeout:g} s")
last = line_in(path, None)
if isinstance(last, Failure):
return last
last = line_in(text, None)
wanted = f"no line matching `{pattern}`" if pattern is not None else "nothing"
return Failure(f"{file} held {wanted} after {timeout:g} s" + (f"; its last line: {last}" if last is not None else ""))
clock.sleep(min(POLL_SECONDS, left))
return found
def arguments(argv: list[str]) -> tuple[str, str | None, float] | Failure:
+17 -6
View File
@@ -4,7 +4,6 @@ import pathlib
import subprocess
import sys
import tempfile
import threading
import unittest
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
@@ -59,6 +58,17 @@ class WaitFor(unittest.TestCase):
def test_gives_up_on_a_file_that_never_appears(self):
self.assertEqual(main.waited(str(self.file), None, 5, Clock()), Failure(f"{self.file} did not appear in 5 s"))
def test_waits_for_a_half_written_last_line_to_end(self):
self.file.write_text("running\n== 3 passed in")
clock = Clock(lambda: self.file.write_text("running\n== 3 passed in 1s ==\n"))
self.assertEqual(main.waited(str(self.file), "passed", 60, clock), "== 3 passed in 1s ==")
def test_takes_a_last_line_without_a_newline_once_a_poll_finds_it_unchanged(self):
self.file.write_text("# Report\nNo findings.")
clock = Clock()
self.assertEqual(main.waited(str(self.file), None, 60, clock), "No findings.")
self.assertEqual(clock.now, main.POLL_SECONDS)
def test_reads_a_line_that_is_not_utf_8(self):
self.file.write_bytes(b"caf\xe9 passed\n")
self.assertEqual(main.waited(str(self.file), "passed", 60, Clock()), "caf\ufffd passed")
@@ -85,6 +95,8 @@ class WaitFor(unittest.TestCase):
for argv, expected in (
([str(self.file), "passed", "--timeout", "5"], (0, "== 1 passed ==\n", "")),
(["--help"], (0, main.__doc__.strip() + "\n", "")),
(["-h"], (0, main.__doc__.strip() + "\n", "")),
(["--help", str(self.file)], (0, main.__doc__.strip() + "\n", "")),
([str(self.file), "("], (1, "", "wait-for: cannot read the pattern `(`: missing ), unterminated subpattern at position 0\n")),
):
with self.subTest(argv=argv):
@@ -96,6 +108,7 @@ class WaitFor(unittest.TestCase):
def test_arguments_take_the_timeout_anywhere_and_refuse_a_bad_one(self):
self.assertEqual(main.arguments(["--timeout", "1.5", "f", "p"]), ("f", "p", 1.5))
self.assertEqual(main.arguments(["f"]), ("f", None, 540.0))
self.assertEqual(main.arguments(["f", "--timeout", "0.5"]), ("f", None, 0.5))
for timeout in ("0", "-1", "x", "1.", None):
with self.subTest(timeout=timeout):
argv = ["f", "--timeout"] + ([timeout] if timeout else [])
@@ -104,11 +117,9 @@ class WaitFor(unittest.TestCase):
with self.subTest(argv=argv):
self.assertEqual(main.arguments(argv), Failure(main.USAGE))
def test_the_command_waits_for_a_file_another_process_writes(self):
writer = threading.Timer(0.5, lambda: self.file.write_text("== 1 passed in 0.1s ==\n"))
writer.start()
self.addCleanup(writer.cancel)
result = subprocess.run([sys.executable, str(TOOL), str(self.file), "passed", "--timeout", "20"], capture_output=True, text=True)
def test_the_command_prints_the_line_a_file_holds(self):
self.file.write_text("== 1 passed in 0.1s ==\n")
result = subprocess.run([sys.executable, str(TOOL), str(self.file), "passed", "--timeout", "20"], capture_output=True, text=True, timeout=10)
self.assertEqual((result.returncode, result.stdout, result.stderr), (0, "== 1 passed in 0.1s ==\n", ""))
def test_refuses_a_bad_pattern_timeout_or_argument_count_waiting_for_nothing(self):