Test the env-file-read spellings and log names that mutants survived

This commit is contained in:
2026-11-13 21:01:03 +01:00
parent 333ebe58b8
commit 7b59056c3d
3 changed files with 21 additions and 11 deletions
+8 -9
View File
@@ -22,20 +22,19 @@ def env_file_breaches(call: Call, home: str) -> list[Breach]:
def reads(call: Call, path: pathlib.Path, home: str) -> bool:
"""Whether a Read, a Grep or else a Bash command reads path."""
if call.tool == "Read":
return names(resolved(call.cwd, text(call.given, "file_path"), home), path)
if call.tool == "Grep":
searched = resolved(call.cwd, text(call.given, "path") or ".", home)
return names(searched, path) or holds(searched, path) and not ignored(path)
if call.tool == "Bash":
command = text(call.given, "command")
relative = os.path.relpath(path, home)
spellings = "|".join(re.escape(spelling) for spelling in (str(path), *(f"{prefix}/{relative}" for prefix in ("~", "$HOME", "${HOME}"))))
# Bounded on both sides, so a longer path that holds a spelling, such as ~/.claude/.envrc, is another file.
spelt = re.search(rf"(?<![\w./~-])(?:{spellings})(?![\w.-])", command)
named = (resolved(simple.directory, word, home) for simple in simple_commands(command, call.cwd, home) for word in simple.words)
return spelt is not None or any(names(word, path) for word in named)
return False
command = text(call.given, "command")
relative = os.path.relpath(path, home)
spellings = "|".join(re.escape(spelling) for spelling in (str(path), *(f"{prefix}/{relative}" for prefix in ("~", "$HOME", "${HOME}"))))
# Bounded on both sides, so a longer path that holds a spelling, such as ~/.claude/.envrc, is another file.
spelt = re.search(rf"(?<![\w./~-])(?:{spellings})(?![\w.-])", command)
named = (resolved(simple.directory, word, home) for simple in simple_commands(command, call.cwd, home) for word in simple.words)
return spelt is not None or any(names(word, path) for word in named)
def names(given: str, path: pathlib.Path) -> bool: