Add run-analysis helper script and tests

This commit is contained in:
Jordan Wages 2025-07-19 02:19:08 -05:00
commit 2e7e75e4ce
3 changed files with 77 additions and 0 deletions

View file

@ -0,0 +1,32 @@
import os
import subprocess
from pathlib import Path
REPO_ROOT = Path(__file__).resolve().parents[1]
SCRIPT = REPO_ROOT / "run-analysis.sh"
def test_script_invokes_commands(tmp_path):
# create stub virtualenv so the script skips creation
venv = tmp_path / ".venv" / "bin"
venv.mkdir(parents=True)
(venv / "activate").write_text(":")
calls = tmp_path / "calls.txt"
python_stub = tmp_path / "python"
python_stub.write_text(f"#!/usr/bin/env bash\necho \"$*\" >> \"{calls}\"\n")
python_stub.chmod(0o755)
(tmp_path / "python3").write_text(f"#!/usr/bin/env bash\nexit 0\n")
(tmp_path / "python3").chmod(0o755)
env = os.environ.copy()
env["PATH"] = f"{tmp_path}:" + env.get("PATH", "")
subprocess.run([str(SCRIPT)], cwd=tmp_path, env=env, check=True)
lines = calls.read_text().strip().splitlines()
assert lines == [
"scripts/analyze.py check-missing-domains",
"scripts/analyze.py suggest-cache",
"scripts/analyze.py detect-threats",
]