From 1f8b33d485a0f6021eaa0198c860bdfc82d7156e Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Thu, 12 Nov 2026 09:34:49 +0100 Subject: [PATCH] =?UTF-8?q?Answer=20stability=20round=202:=200=20?= =?UTF-8?q?=F0=9F=94=B4,=204=20=F0=9F=9F=A1=20(0=20misread);=20claudeMdExc?= =?UTF-8?q?ludes=20is=20read=20from=20the=20user's=20settings=20too=20and?= =?UTF-8?q?=20covers=20rule=20files,=20and=20the=20mutants=20it=20names=20?= =?UTF-8?q?are=20killed?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/chunk_pr/test_chunk_pr.py | 7 +++++++ bin/larv_review/scoring_setup.py | 22 ++++++++++++++-------- bin/larv_review/test_scoring_setup.py | 25 +++++++++++++++++++++++-- bin/run_tests/main.py | 2 +- bin/run_tests/test_run_tests.py | 5 ----- bin/wait_for/main.py | 3 ++- 6 files changed, 47 insertions(+), 17 deletions(-) diff --git a/bin/chunk_pr/test_chunk_pr.py b/bin/chunk_pr/test_chunk_pr.py index dd1ccc6f..d41631d7 100644 --- a/bin/chunk_pr/test_chunk_pr.py +++ b/bin/chunk_pr/test_chunk_pr.py @@ -296,6 +296,13 @@ class Merge(unittest.TestCase): self.assertNotIn(TEA_STATUS, checkout.ran) self.assertEqual(checkout.acted(), []) + def test_an_unknown_default_branch_leaves_it_unmerged_reading_no_checks(self): + checkout = Checkout(GITEA, open=True) + checkout.answers[("git", "symbolic-ref", "--short", "refs/remotes/origin/HEAD")] = Failure("no such ref") + self.assertEqual(merged(checkout, self.fail), Failure("origin records no default branch; set it with `git remote set-head origin --auto`: no such ref")) + self.assertNotIn(TEA_STATUS, checkout.ran) + self.assertEqual(checkout.acted(), []) + def test_gitea_checks_that_never_pass_leave_it_unmerged(self): checkout = self.protected(*[[("CI / tests (pull_request)", "pending")]] * 1000) failed = merged(checkout, lambda _: None) diff --git a/bin/larv_review/scoring_setup.py b/bin/larv_review/scoring_setup.py index 486f9829..efaefc69 100644 --- a/bin/larv_review/scoring_setup.py +++ b/bin/larv_review/scoring_setup.py @@ -97,23 +97,29 @@ 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 that main's settings don't exclude, the files it imports, and each rule file without `paths:`.""" - excludes = claude_md_excludes(main) + """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:`, leaving out those `claudeMdExcludes` names.""" + excludes = claude_md_excludes(main, home) found = [] + + def kept(path: pathlib.Path) -> bool: + return not any(path.full_match(pattern) for pattern in excludes) + 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() and not any(claude_md.full_match(pattern) for pattern in excludes): + if claude_md.is_file() and kept(claude_md): 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)] + found += [f"`{shown}{rule.relative_to(claude_md.parent)}`" for rule in sorted(rules.glob("*.md")) if kept(rule) and 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.""" +def claude_md_excludes(main: pathlib.Path, home: pathlib.Path) -> list[str]: + """The `claudeMdExcludes` globs of the user's settings and main's project and local settings, merged as Claude Code merges them across layers. + + Managed settings are left out, since they may come from the claude.ai console or an MDM policy, where no file shows them.""" globs = [] - for name in ("settings.json", "settings.local.json"): + for path in (home / ".claude" / "settings.json", main / ".claude" / "settings.json", main / ".claude" / "settings.local.json"): try: - settings = json.loads((main / ".claude" / name).read_text()) + settings = json.loads(path.read_text()) except (OSError, ValueError): continue excludes = settings.get("claudeMdExcludes") if isinstance(settings, dict) else None diff --git a/bin/larv_review/test_scoring_setup.py b/bin/larv_review/test_scoring_setup.py index 5fbad317..2e2311c3 100644 --- a/bin/larv_review/test_scoring_setup.py +++ b/bin/larv_review/test_scoring_setup.py @@ -9,7 +9,7 @@ import unittest sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1])) -from larv_review.scoring_setup import bullets, CLAUDE_MD, file_globs, preloaded_files, prepare_scoring, project_values, score_bullets, section +from larv_review.scoring_setup import bullets, CLAUDE_MD, file_globs, preloaded_files, prepare_scoring, project_values, removed_setup, score_bullets, section from failure import Failure from test_env import isolated_env @@ -39,7 +39,7 @@ class ProjectValues(unittest.TestCase): self.assertEqual(project_values(spelling, "AGENTS.md"), VALUES) def test_keeps_a_colon_an_x_and_an_ellipsis_in_a_value_and_skips_a_bullet_without_a_colon(self): - text = "## Scoring run\n\n- Kind\n- Language: Python\n- Kind: a CLI: small\n- Domain: LaTeX\n- Domain docs: the spec\n- 3am question: it hangs...\n" + text = "## Scoring run\n\n- Language: Python\n- Kind: a CLI: small\n- Kind\n- Domain: LaTeX\n- Domain docs: the spec\n- 3am question: it hangs...\n" self.assertEqual(project_values(text, "AGENTS.md"), {**VALUES, "kind": "a CLI: small", "domain": "LaTeX", "3am question": "it hangs..."}) def test_names_the_values_a_section_lacks_and_a_file_without_one(self): @@ -126,6 +126,16 @@ class PrepareScoring(unittest.TestCase): self.assertNotEqual((folder / "mid-a.md").read_text(), "stale") self.assertEqual(len(self.git("worktree", "list").splitlines()), 2) + def test_says_it_could_not_remove_a_checkout_git_does_not_hold(self): + self.commit() + checkout = self.root / ".local" / "state" / "larv-review" / "proj" / "scoring" / "checkout" + checkout.mkdir(parents=True) + with mock.patch.dict(os.environ, self.env, clear=True): + removed = removed_setup(str(self.checkout)) + self.assertIsInstance(removed, Failure) + self.assertTrue(removed.reason.startswith(f"could not remove the scoring worktree {checkout}: "), removed.reason) + self.assertTrue(checkout.exists()) + def test_refuses_writing_nothing_where_the_project_gives_no_values(self): self.commit() ran = self.run_tool("prepare-scoring") @@ -154,6 +164,17 @@ class PrepareScoring(unittest.TestCase): (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`") + def test_names_each_import_and_each_rule_without_paths_leaving_out_what_the_user_settings_exclude(self): + (self.root / ".claude" / "rules").mkdir(parents=True) + (self.root / ".claude" / "settings.json").write_text('{"claudeMdExcludes": ["**/rules/skipped.md"]}') + (self.root / ".claude" / "rules" / "skipped.md").write_text("# Skipped\n") + (self.checkout / "CLAUDE.md").write_text("# Project\n\n@AGENTS.md\n@docs/x.md\n") + (self.checkout / ".claude" / "rules").mkdir(parents=True) + (self.checkout / ".claude" / "rules" / "always.md").write_text("# Always\n") + (self.checkout / ".claude" / "rules" / "scoped.md").write_text("---\npaths: ['*.py']\n---\n") + imports, rule = "`AGENTS.md`, which it imports, `docs/x.md`, which it imports", "always" + self.assertEqual(preloaded_files(self.checkout, self.root), f"`{CLAUDE_MD}`, {imports} and `.claude/rules/{rule}.md`") + def test_reads_the_excludes_of_both_settings_files_and_names_none_where_nothing_loads(self): (self.root / ".claude").mkdir() (self.root / ".claude" / "CLAUDE.md").write_text("# Home\n") diff --git a/bin/run_tests/main.py b/bin/run_tests/main.py index 4d258ea3..6bc51c5e 100644 --- a/bin/run_tests/main.py +++ b/bin/run_tests/main.py @@ -2,7 +2,7 @@ usage: run-tests [...] -It runs pytest, pinned with pytest-xdist in four workers through uvx, on the arguments given, +It runs pytest, pinned with pytest-xdist in one worker per CPU of a heavy slot through uvx, on the arguments given, adding the repo's bin/ folder where none of them names a path that exists. It saves the whole output to a new file. It prints each failing test's name, its first error lines and where it failed, then pytest's short test summary and summary line, then `Full log: `. Where pytest diff --git a/bin/run_tests/test_run_tests.py b/bin/run_tests/test_run_tests.py index 2548a997..139f316e 100644 --- a/bin/run_tests/test_run_tests.py +++ b/bin/run_tests/test_run_tests.py @@ -11,7 +11,6 @@ import unittest sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1])) -from machine_load.slots import CPUS_PER_SLOT from run_tests import main BIN = pathlib.Path(__file__).resolve().parents[1] @@ -33,10 +32,6 @@ class PytestArgs(unittest.TestCase): self.assertEqual(main.pytest_args([str(test_file)]), [str(test_file)]) self.assertEqual(main.pytest_args(["-x", f"{test_file}::T::test_a"]), ["-x", f"{test_file}::T::test_a"]) - def test_the_command_pins_pytest_and_fills_one_heavy_slot(self): - self.assertEqual(main.PYTEST[1:], ["--python", main.PYTEST[2], "--with", "pytest-xdist==3.8.0", "pytest==9.2.0", "-n", str(CPUS_PER_SLOT)]) - self.assertEqual(main.PYTEST[0], "uvx") - def errors(count: int) -> str: return "".join(f"E line {n}\n" for n in range(count)) diff --git a/bin/wait_for/main.py b/bin/wait_for/main.py index ce48e55d..dc042dac 100644 --- a/bin/wait_for/main.py +++ b/bin/wait_for/main.py @@ -4,7 +4,8 @@ usage: wait-for [] [--timeout ] is a Python regular expression, searched for in each line; it prints the first line that holds a match. Without , it waits until the file holds anything, and prints its last -line. It checks every 2 seconds and gives up after --timeout seconds, 540 by default, so it fits +line. A last line without its newline counts once a check finds the file unchanged, since the +job may still be writing it. It checks every 2 seconds and gives up after --timeout seconds, 540 by default, so it fits one foreground call of the Bash tool, whose limit is 600 seconds. Exit 0 on the line, 1 on the timeout, bad arguments or a file it cannot read, saying why.