Rewrite CLI around action runtime
This commit is contained in:
45
tests/test_static_mutation_guard.py
Normal file
45
tests/test_static_mutation_guard.py
Normal file
@@ -0,0 +1,45 @@
|
||||
"""Static guard for direct filesystem mutation outside adapters/actions."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import re
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
MUTATING_PATTERNS = (
|
||||
re.compile(r"\.(mkdir|unlink|write_text|write_bytes|symlink_to|chmod)\("),
|
||||
re.compile(r"\b(os\.replace|shutil\.rmtree|shutil\.copy2|shutil\.copytree)\("),
|
||||
re.compile(r"runtime\.fs\.(create_symlink|remove_symlink|write_json|write_text|write_bytes|copy_file|copy_tree|remove_file|remove_tree)\("),
|
||||
)
|
||||
|
||||
ALLOWED_PREFIXES = (
|
||||
Path("src/flow/adapters"),
|
||||
Path("src/flow/actions"),
|
||||
Path("tests"),
|
||||
)
|
||||
|
||||
ALLOWED_FILES = {
|
||||
Path("src/flow/core/paths.py"),
|
||||
}
|
||||
|
||||
SKIPPED_LEGACY_COMMANDS = {
|
||||
Path("src/flow/commands/completion.py"),
|
||||
}
|
||||
|
||||
|
||||
def test_no_direct_filesystem_mutation_outside_action_boundary():
|
||||
root = Path(__file__).resolve().parents[1]
|
||||
offenders: list[str] = []
|
||||
for path in sorted((root / "src" / "flow").rglob("*.py")):
|
||||
rel = path.relative_to(root)
|
||||
if rel in ALLOWED_FILES or rel in SKIPPED_LEGACY_COMMANDS:
|
||||
continue
|
||||
if any(rel.is_relative_to(prefix) for prefix in ALLOWED_PREFIXES):
|
||||
continue
|
||||
for line_no, line in enumerate(path.read_text(encoding="utf-8").splitlines(), 1):
|
||||
if "Service(" in line:
|
||||
continue
|
||||
if any(pattern.search(line) for pattern in MUTATING_PATTERNS):
|
||||
offenders.append(f"{rel}:{line_no}: {line.strip()}")
|
||||
|
||||
assert offenders == []
|
||||
Reference in New Issue
Block a user