Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions scripts/mutation_gate.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,11 @@ def _invalidate_bytecode(path: Path) -> None:
def _survives(
path: Path, tree: ast.Module, src: str, mutant: _Mutant, data: coverage.CoverageData
) -> bool:
# Safety: only ever rewrite files inside the package under test. The file list
# comes from `git diff`, so this can't normally escape, but guard against a path
# that resolves outside aai_cli/ before we write to it.
if not path.resolve().is_relative_to(Path(_PKG).resolve()):
raise ValueError(f"refusing to mutate a file outside {_PKG}/: {path}")
mutant.apply()
try:
path.write_text(ast.unparse(tree), encoding="utf-8")
Expand Down
Loading