mirror of
https://github.com/norandom/OpenUltraSAST.git
synced 2026-12-03 18:28:19 +00:00
Where a scan writes. A native scan now creates its run under the user cache, ~/.cache/openultrasast/runs/<scan-id>/ by default ($XDG_CACHE_HOME when it is set and absolute), prints run_dir=<path> once, and no longer writes anything under the analysed tree. OPENULTRASAST_RUNS_DIR still wins: an absolute value is used as given, a relative one resolves against the working directory. Pre-push storage is unchanged. The calibration ledger, by maintainer decision: .openultrasast/calibration/ stays the store, and a scan writes the false-positive ledger into the tree only when its content would change. On a read-only tree the scan records ledger_not_written, with a sentence in the report, and completes; before, a read-only target with one rejected finding crashed before report.md existed. benchmarks/repos/measure.py follows the printed run directory. It read the run from under the scanned copy, which would have recorded every repository as failed, and it also read a stale run left in a copy. Tests: tests/test_scan_output_location.py drives the real CLI and compares the whole tree before and after; tests/test_repo_measure.py pins the measurement script; an autouse fixture keeps every test's scan runs out of the developer's cache; fourteen test files follow the run to its new place. README, docs/examples.md and the scan skill name the ledger as the one write a scan makes. _run_scan is touched by one line and stays over the complexity cap. Task 3.1 stays open for part B, the readable summary.
43 lines
1.7 KiB
Python
43 lines
1.7 KiB
Python
"""Phase 1 in-pipeline wiring: project score artifact + fail-loud CWE invariant."""
|
|
|
|
import json
|
|
from pathlib import Path
|
|
from types import SimpleNamespace
|
|
|
|
import pytest
|
|
|
|
from openultrasast import cli
|
|
from openultrasast.cli import main
|
|
from openultrasast.policy import PolicyError
|
|
|
|
|
|
def test_scan_writes_score_artifact_and_manifest_block(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
|
|
repo = tmp_path / "repo"
|
|
repo.mkdir()
|
|
(repo / "app.py").write_text("@app.route('/x')\ndef view():\n return eval(request.data)\n")
|
|
monkeypatch.setenv("OPENULTRASAST_RUNS_DIR", str(repo / ".runs"))
|
|
|
|
assert main(["scan", str(repo), "--mode", "quick"]) == 0
|
|
|
|
run_dir = sorted((repo / ".runs").iterdir())[-1]
|
|
score = json.loads((run_dir / "score.json").read_text())
|
|
manifest = json.loads((run_dir / "manifest.json").read_text())
|
|
|
|
assert isinstance(score["project_score"], int) and 0 <= score["project_score"] <= 100
|
|
assert set(score["gate"]) == {"min_score", "block_severity_reachable", "blocking", "passed"}
|
|
assert manifest["score"] == score
|
|
assert manifest["artifacts"]["score"] == "score.json"
|
|
|
|
|
|
def test_scan_fails_loud_when_an_enabled_rule_cwe_is_unmapped(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
|
|
repo = tmp_path / "repo"
|
|
repo.mkdir()
|
|
(repo / "app.py").write_text("x = 1\n")
|
|
monkeypatch.setenv("OPENULTRASAST_RUNS_DIR", str(repo / ".runs"))
|
|
unmapped = SimpleNamespace(rule_id="bogus", cwe="CWE-99999", status="enabled")
|
|
real_loader = cli.load_ruleset
|
|
monkeypatch.setattr(cli, "load_ruleset", lambda *a, **k: (*real_loader(*a, **k), unmapped))
|
|
|
|
with pytest.raises(PolicyError):
|
|
main(["scan", str(repo), "--mode", "quick"])
|