mirror of
https://github.com/norandom/OpenUltraSAST.git
synced 2026-12-04 02:38:18 +00:00
feat(contributor-scan): a scan writes its run to the user cache, and the ledger only when it learns (3.1, part A)
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.
This commit is contained in:
+43
-1
@@ -6,7 +6,7 @@ from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
from openultrasast.config import RetiredConfigError, load_config, load_dotenv, write_resolved_config
|
||||
from openultrasast.config import ResolvedConfig, RetiredConfigError, load_config, load_dotenv, write_resolved_config
|
||||
|
||||
|
||||
def test_load_config_reads_toml(tmp_path: Path) -> None:
|
||||
@@ -185,3 +185,45 @@ def test_load_dotenv_sets_missing_keys_only(tmp_path: Path, monkeypatch) -> None
|
||||
|
||||
assert os.environ["OPENROUTER_API_KEY"] == "already-set"
|
||||
assert os.environ["S3_REGION"] == "us-east-1"
|
||||
|
||||
|
||||
def test_runs_dir_defaults_to_the_user_cache(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
monkeypatch.delenv("OPENULTRASAST_RUNS_DIR", raising=False)
|
||||
monkeypatch.setenv("XDG_CACHE_HOME", str(tmp_path / "cache"))
|
||||
|
||||
assert Path(load_config(None).runs_dir) == tmp_path / "cache" / "openultrasast" / "runs"
|
||||
|
||||
|
||||
@pytest.mark.parametrize("xdg", ["", "relative/cache"])
|
||||
def test_an_empty_or_relative_xdg_cache_home_falls_back_to_the_home_cache(
|
||||
tmp_path: Path, monkeypatch: pytest.MonkeyPatch, xdg: str
|
||||
) -> None:
|
||||
monkeypatch.delenv("OPENULTRASAST_RUNS_DIR", raising=False)
|
||||
monkeypatch.setenv("HOME", str(tmp_path))
|
||||
monkeypatch.setenv("XDG_CACHE_HOME", xdg)
|
||||
|
||||
assert Path(load_config(None).runs_dir) == tmp_path / ".cache" / "openultrasast" / "runs"
|
||||
|
||||
|
||||
def test_the_runs_dir_override_wins_and_an_absolute_one_is_used_as_given(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
monkeypatch.setenv("XDG_CACHE_HOME", str(tmp_path / "cache"))
|
||||
link = tmp_path / "link"
|
||||
link.symlink_to(tmp_path, target_is_directory=True)
|
||||
monkeypatch.setenv("OPENULTRASAST_RUNS_DIR", str(link / "runs"))
|
||||
|
||||
assert Path(load_config(None).runs_dir) == link / "runs"
|
||||
|
||||
|
||||
def test_a_relative_runs_dir_override_is_taken_from_the_working_directory(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
working = tmp_path / "working"
|
||||
working.mkdir()
|
||||
monkeypatch.chdir(working)
|
||||
monkeypatch.setenv("OPENULTRASAST_RUNS_DIR", ".runs")
|
||||
|
||||
assert Path(load_config(None).runs_dir) == working / ".runs"
|
||||
|
||||
|
||||
def test_a_config_built_without_the_loader_follows_the_same_override(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
monkeypatch.setenv("OPENULTRASAST_RUNS_DIR", str(tmp_path / "runs"))
|
||||
|
||||
assert ResolvedConfig().runs_dir == str(tmp_path / "runs")
|
||||
|
||||
Reference in New Issue
Block a user