Answer stability round 2: 0 🔴, 4 🟡 (0 misread); claudeMdExcludes is read from the user's settings too and covers rule files, and the mutants it names are killed
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
usage: run-tests [<pytest args>...]
|
||||
|
||||
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: <path>`. Where pytest
|
||||
|
||||
@@ -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))
|
||||
|
||||
@@ -4,7 +4,8 @@ usage: wait-for <file> [<pattern>] [--timeout <seconds>]
|
||||
|
||||
<pattern> is a Python regular expression, searched for in each line; it prints the first line that
|
||||
holds a match. Without <pattern>, 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.
|
||||
|
||||
Reference in New Issue
Block a user