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:
Marius Ciepluch
2026-11-24 17:51:37 +01:00
parent efa2b62bff
commit 17d46c0f93
9 changed files with 478 additions and 7 deletions
+5 -1
View File
@@ -4,7 +4,11 @@ Each example stands on its own. A scan writes its run under
`~/.cache/openultrasast/runs/<scan-id>/`, or under `$XDG_CACHE_HOME/openultrasast/runs/` when
that variable is set to an absolute path, and prints that path. `OPENULTRASAST_RUNS_DIR`
overrides the location: an absolute path is used as given, and a relative one is resolved against
the current working directory, never against the target.
the current working directory, never against the target. Once a scan has written its run to the
default location, with no `OPENULTRASAST_RUNS_DIR` set, the runs there that are older than 30 days
are removed, and `ousast` prints one `notice:` line when it removes any;
`OPENULTRASAST_RUNS_RETENTION_DAYS` sets the number of days (`0` keeps every run), and nothing is
ever removed from a location chosen with `OPENULTRASAST_RUNS_DIR`.
A scan that rejects or holds a finding writes one file into the scanned tree, and only when that
file's content would change: