mirror of
https://github.com/norandom/OpenUltraSAST.git
synced 2026-12-04 02:38:18 +00:00
feat(contributor-scan): remove scan runs older than 30 days from the default cache (3.1, run retention)
By maintainer decision. Since 6edae3a a native scan leaves a run directory
under ~/.cache/openultrasast/runs/ and nothing removed them. After a scan's
manifest is written, with no OPENULTRASAST_RUNS_DIR set, the runs in that
default location that are older than 30 days are now removed. The age comes
from the UTC timestamp in the run id, never from file times, so a copied or
touched directory is not misjudged, and a run exactly 30 days old is kept.
Never touched: the scan's own run; anything not named exactly like a run
(only direct children of the runs root whose name is a run id); symlinks,
which are neither followed nor removed; and any location chosen with
OPENULTRASAST_RUNS_DIR, even when it resolves to the default.
OPENULTRASAST_RUNS_RETENTION_DAYS sets the number of days and 0 keeps every
run. A failed prune never fails the scan: it is one notice on the command
line, and the MCP scan and benchmark results now carry a notices key. A
retention longer than the calendar and a directory tree too deep to remove
are both turned into that same behaviour.
Known limits, on record: a removal that fails part-way leaves the run half
deleted and it is retried on every later scan; the prune stops at the first
failure; a clock set far ahead removes earlier runs; a filesystem mounted at
or under an expired run is emptied before the removal fails.
Tests: tests/test_run_pruning.py drives the function and the real command
line (34 tests); tests/test_mcp.py pins the notices. The reviewer attacked
the deletion path with about sixty hostile inputs and twenty-three mutations;
all are killed or kept safe.
This commit is contained in:
@@ -71,7 +71,7 @@ from .repos import resolve as resolve_repo
|
||||
from .repos import select as select_repo
|
||||
from .repos import verify as verify_repo
|
||||
from .ruleset import DEFAULT_RULESET_DIR, load_ruleset
|
||||
from .run import ScanRun, create_scan_run
|
||||
from .run import ScanRun, create_scan_run, prune_scan_runs
|
||||
from .scoring import build_score_artifact
|
||||
from .semantic import (
|
||||
OverlayRecord,
|
||||
@@ -816,6 +816,7 @@ def _run_scan(path: Path, config_path: Path, mode: str, fail_on: str) -> ScanOut
|
||||
),
|
||||
)
|
||||
runtime.finish(status="succeeded")
|
||||
prune_notices = prune_scan_runs(config, keep=run.root)
|
||||
return ScanOutcome(
|
||||
scan_id=run.scan_id,
|
||||
run_dir=run.root,
|
||||
@@ -828,7 +829,8 @@ def _run_scan(path: Path, config_path: Path, mode: str, fail_on: str) -> ScanOut
|
||||
f"language not covered: {item['language']} ({item['count']} files)"
|
||||
for item in runtime.state["degradations"]
|
||||
if item.get("reason") == "language_not_covered"
|
||||
),
|
||||
)
|
||||
+ prune_notices,
|
||||
)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user