mirror of
https://github.com/norandom/OpenUltraSAST.git
synced 2026-12-03 02:08:18 +00:00
fix(scan): a scan in the image prunes the wrapper's runs directory too (item 5b)
The maintainer's answer 7 of 2026-11-27 (the ninth session's menu). The label is in .kiro/specs/contributor-scan/spec.json (80abac5). The record, .kiro/handover.md:1335-1337 (not tracked), in full: 7. The wrapper's runs are never pruned by a scan in the image. Answer: "Image scan prunes too": a scan in the image prunes its runs directory when the wrapper's override is set; a change in the scan path, a test first. Not chosen: "Document: never pruned" (the session's recommendation); "Queue in step 8"; "Leave it". The option as offered (handover.md:1435-1436): "the scan path prunes its runs directory when the wrapper's override is set; a code change, a test first." A second decision, taken on this change. The reviewer found that the wrapper passes no OPENULTRASAST_RUNS_RETENTION_DAYS into the image, so with this change alone a scan through the wrapper would remove runs older than 30 days from ~/.cache/openultrasast/runs, native runs included, even for a user who keeps every run natively with 0. Asked, the maintainer chose "Pass it through (Recommended)": the wrappers pass OPENULTRASAST_RUNS_RETENTION_DAYS into the container, one more -e in ops/shell/ousast.sh and ops/shell/ousast.ps1, a test first. That is the next commit. This one is the scan path alone, as answer 7 says. The wrapper builds its image only when it is missing (ops/shell/ousast.sh:64-67), so until the image is rebuilt the wrapper's scans run the code shipped in it and remove nothing (measured below). The fault. The shell wrapper mounts ~/.cache/openultrasast/runs at /reports and passes -e OPENULTRASAST_RUNS_DIR=/reports (d1f61fb). prune_scan_runs returned nothing whenever OPENULTRASAST_RUNS_DIR was set, so a scan in the image never removed an expired run: the wrapper's runs were removed only by a later native scan on the default location. What changed. - src/openultrasast/config.py: WRAPPER_RUNS_MOUNT = "/reports" and runs_dir_is_the_wrappers(), true when OPENULTRASAST_RUNS_DIR is that path. - src/openultrasast/run.py: prune_scan_runs prunes config.runs_dir when the override is unset (as before) or is the wrapper's. Any other override still removes nothing. - README.md, docs/examples.md and .agents/skills/openultrasast-scan/SKILL.md said that nothing is removed from a location chosen with OPENULTRASAST_RUNS_DIR; each says now that the shell wrapper is the one exception. The decision says "a change in the scan path"; these three sentences state the rule the change alters, and would be false without them. - tests/test_run_pruning.py: its module docstring, and three tests (below). The session's readings of the decision, to be confirmed by the maintainer. 1. "The wrapper's override" is recognised by its value. Both wrappers pass exactly /reports (ops/shell/ousast.sh:91, ops/shell/ousast.ps1:50), and nothing in the container's environment tells the wrapper's run from a compose run started by hand. Two consequences, by reading: a native scan with OPENULTRASAST_RUNS_DIR=/reports is pruned as well; and a compose run started by hand with the same -e and the default ./reports mounted prunes run-shaped directories older than 30 days under the checkout's reports/ (docker-compose.yml:33-34). 2. The compose file's own value, /reports/runs (docker-compose.yml:47), is a chosen location and is not pruned: there ./reports on the host is mounted, which may hold more than runs. This amends the run retention decided on 2026-11-24 (spec.json, approval_history entry six: "after each scan, with no OPENULTRASAST_RUNS_DIR set, runs in the default location older than 30 days are removed"): the wrapper's mount is pruned as well. Measured, in an image. The script is /tmp/opencode/s10_c7_probe.sh and its files are under /tmp/opencode/s10_c7_probe/, one per measurement; the files of the four scans and of the listings after them start with the command they ran. The four scans' stamps run from 17:57:27Z to 17:57:32Z; the listings carry none. The probe image is openultrasast:dev (3f959b31f2f2, uid 1000) with the working tree's package copied over it: 295 files, equal to the tree by sha256 (03_probe_sources.out is a bare list of digests; the comparison is /tmp/opencode/s10_c7_sources_cmp.out, which starts with its command). Every runs directory is a scratch directory mounted at /reports; the real ~/.cache/openultrasast/ runs was not mounted. Network off, no key. The subject is a fresh copy of the four C files and their README (04_subject.out). Each scratch runs directory held a run of 40 days ago, a run of 5 days ago and a directory called notes. - With the wrapper's override, on the probe image (10_wrapper_override.out): exit 0, file_targets=4, findings=4, and the line "notice: removed 1 run older than 30 days from /reports". The expired run is gone; the run of 5 days ago, the new run and notes remain (11_wrapper_override_after.out). - With the compose file's /reports/runs (20_compose_override.out, 21_compose_override_after.out): no notice, all three entries remain. - With the wrapper's override on the shipped image (30_shipped_image.out, 31_shipped_image_after.out): no notice, all three remain: the fault as shipped. - With the wrapper's override and OPENULTRASAST_RUNS_RETENTION_DAYS=0 passed into the container (40_retention_zero.out, 41_retention_zero_after.out): no notice, all three remain. - The probe image is removed (90_remove_probe.out); no container remains (91_containers_after.out). The wrapper itself was not run. Tests (tests/test_run_pruning.py). - test_a_scan_through_the_wrapper_removes_the_expired_runs_from_the_mounted_runs_directory calls prune_scan_runs, as cli.py:720 does, with OPENULTRASAST_RUNS_DIR=/reports and a runs directory that stands in for /reports, which only root can make on the host. It expects one notice, and the run of 5 days ago and the current run to remain. - test_a_scan_that_compose_runs_without_the_wrapper_removes_nothing: /reports/runs removes nothing and says nothing. - test_the_wrapper_passes_the_override_that_a_scan_prunes: the shell wrapper's command holds "-e OPENULTRASAST_RUNS_DIR=" + WRAPPER_RUNS_MOUNT, so its word and the scan's mount point cannot drift apart. Nothing reads the PowerShell wrapper's. RED. An archive of HEAD (src, tests, pyproject.toml) with the first test as written, the package imported from the archive (s10_c7_red_where.out): 1 failed, 1 passed; the passed one was a throwaway test that printed where the package came from and was removed after. The failure is at "assert () == ('removed 1 run older than 30 days from .../reports',)" (s10_c7_red.out). The command, run from the archive's directory, where the throwaway test was tests/test_zz_where.py: env -u OPENROUTER_API_KEY -u DEEPSEEK_API_KEY PYTHONPATH=/tmp/opencode/s10_c7_head/src /home/mc/Source/OpenUltraSAST/.venv/bin/python -m pytest -q -p no:cacheprovider tests/test_run_pruning.py tests/test_zz_where.py -k "where or through_the_wrapper" GREEN: 250 passed on the final tree (s10_c7_green4.out; the command is not in the file) over tests/test_run_pruning.py tests/test_scan_output_location.py tests/test_config.py tests/test_run.py tests/test_mcp.py tests/test_agent_skills.py tests/test_shell_wrapper.py tests/test_task_images.py tests/test_benchmark.py tests/test_benchmark_artifact_contract.py tests/test_model_scope.py tests/test_pair_harvest.py. Mutants, to show the two guards bite: the tree's sources with one line changed and the final test file (the copies are /tmp/opencode/s10_c7_mutA, mutB, mutC). - the predicate "_runs_dir_override().startswith(WRAPPER_RUNS_MOUNT)" fails the compose test alone (s10_c7_mutA2.out: 1 failed, 36 passed); - WRAPPER_RUNS_MOUNT = "/reports2" fails the wrapper test and the first test (s10_c7_mutB2.out: 2 failed, 35 passed); - HEAD's condition, "if runs_dir_is_overridden():", fails the first test alone, at the assertion above (s10_c7_mutC2.out: 1 failed, 36 passed). Checks on the final tree. mkdocs build --strict exits 0 (s10_c7_mkdocs2.out; its examples page is byte-identical to the first build's); ruff format, ruff check, mypy, compileall and the three gates pass, and the gates print what they printed before the change (s10_c7d_exits.txt). Three files date from before the test module's docstring was edited, on documentation unchanged since: the first build's examples page holds each of the three added phrases once and the old wording zero times (s10_c7_site_sentence.out), and tests/test_docs_site.py with tests/test_removed_plane_references.py gave 8 passed (s10_c7_docs_tests.out). An earlier gates run found an unused name in the first test (s10_c7_ruff_check.out); it is removed. - Review: two rounds by a reviewer subagent, reading and re-running, no docker. Round one found the code right for answer 7 (RED reproduced on an archive of HEAD, 250 passed over the 12 files, the three mutants failing as stated) and conditioned the commit on a decision: the wrapper passed no retention variable into the image, so this change alone broke "0 keeps every run" on the wrapper path. Asked, the maintainer chose "Pass it through (Recommended)"; the wrapper's commit follows at once, before other work and any push. Round two found the delta to be the test module's docstring; re-ran the 12 files (250 passed), the docs tests, ruff, mypy, mkdocs and the three mutants; checked the round-two evidence against the test file's last change and every sentence of this message, and had two false sentences corrected: the spec.json path and the RED command. By reading, not measured. - cli.py:720 passes the config whose runs_dir is /reports in the image (config.py, _runs_dir), so the scan in the image prunes that directory. - ops/shell/ousast.ps1:50 passes the same override; PowerShell is not installed here. - A failed removal still costs the scan nothing: prune_scan_runs catches OSError and RecursionError, and tests/test_run_pruning.py has two scans whose removal fails. - `ousast benchmark` in the image goes through the same line (cli.py:1123, then cli.py:720) and prunes once per benchmark scan. That is answer 7's rule. Found and not fixed, for the maintainer. - The notice names the path the scan sees, /reports, not the host's ~/.cache/openultrasast/runs. Not checked: the whole test suite; the wrapper and a compose run (the image was run with docker run on scratch mounts); a removal that fails inside the container; Windows and ops/shell/ousast.ps1; a native scan with OPENULTRASAST_RUNS_DIR=/reports.
This commit is contained in:
@@ -20,7 +20,9 @@ it wrote.
|
|||||||
(`$XDG_CACHE_HOME/openultrasast/runs/` when that variable is set to an absolute path; `OPENULTRASAST_RUNS_DIR`
|
(`$XDG_CACHE_HOME/openultrasast/runs/` when that variable is set to an absolute path; `OPENULTRASAST_RUNS_DIR`
|
||||||
overrides it). After a scan, with no `OPENULTRASAST_RUNS_DIR` set, the runs in that default location older than
|
overrides it). After a scan, with no `OPENULTRASAST_RUNS_DIR` set, the runs in that default location older than
|
||||||
30 days are removed (`OPENULTRASAST_RUNS_RETENTION_DAYS` sets the number of days and `0` keeps every run), and
|
30 days are removed (`OPENULTRASAST_RUNS_RETENTION_DAYS` sets the number of days and `0` keeps every run), and
|
||||||
nothing is removed from a location chosen with `OPENULTRASAST_RUNS_DIR`.
|
nothing is removed from a location chosen with `OPENULTRASAST_RUNS_DIR`, except through the shell wrapper: it
|
||||||
|
mounts `~/.cache/openultrasast/runs` at `/reports` in the image, and a scan through it removes the expired runs
|
||||||
|
there as well.
|
||||||
5. Report the finding count, how many the verifier accepted, and **every** recorded degradation
|
5. Report the finding count, how many the verifier accepted, and **every** recorded degradation
|
||||||
(`manifest.json`, key `degradations`). No findings plus a degradation is not a clean scan: the scan
|
(`manifest.json`, key `degradations`). No findings plus a degradation is not a clean scan: the scan
|
||||||
answered a smaller question than it was asked.
|
answered a smaller question than it was asked.
|
||||||
|
|||||||
@@ -193,7 +193,9 @@ one is resolved against the current working directory, never against the directo
|
|||||||
After a scan writes its run to the default location, with no `OPENULTRASAST_RUNS_DIR` set, the runs
|
After a scan writes its run to the default location, with no `OPENULTRASAST_RUNS_DIR` set, the runs
|
||||||
there older than 30 days are removed, and `ousast` prints one `notice:` line when it removes any;
|
there 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
|
`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 does not read the files
|
ever removed from a location chosen with `OPENULTRASAST_RUNS_DIR`, except through the shell wrapper:
|
||||||
|
it mounts `~/.cache/openultrasast/runs` at `/reports` in the image, and a scan through it removes the
|
||||||
|
expired runs there as well. A scan does not read the files
|
||||||
under its runs directory when that directory lies inside the scanned path; when this leaves source
|
under its runs directory when that directory lies inside the scanned path; when this leaves source
|
||||||
files out of the scan, `ousast` prints one `notice:` line naming the directory and how many.
|
files out of the scan, `ousast` prints one `notice:` line naming the directory and how many.
|
||||||
|
|
||||||
|
|||||||
+3
-1
@@ -8,7 +8,9 @@ the current working directory, never against the target. Once a scan has written
|
|||||||
default location, with no `OPENULTRASAST_RUNS_DIR` set, the runs there that are older than 30 days
|
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;
|
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
|
`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 does not read the files
|
ever removed from a location chosen with `OPENULTRASAST_RUNS_DIR`, except through the shell wrapper:
|
||||||
|
it mounts `~/.cache/openultrasast/runs` at `/reports` in the image, and a scan through it removes the
|
||||||
|
expired runs there as well. A scan does not read the files
|
||||||
under its runs directory when that directory lies inside the scanned path; when this leaves source
|
under its runs directory when that directory lies inside the scanned path; when this leaves source
|
||||||
files out of the scan, `ousast` prints one `notice:` line naming the directory and how many.
|
files out of the scan, `ousast` prints one `notice:` line naming the directory and how many.
|
||||||
`ousast benchmark` writes its run to the same directory, as `<runs_dir>/<benchmark-run-id>/` beside
|
`ousast benchmark` writes its run to the same directory, as `<runs_dir>/<benchmark-run-id>/` beside
|
||||||
|
|||||||
@@ -208,8 +208,24 @@ def _runs_dir_override() -> str:
|
|||||||
return os.environ.get("OPENULTRASAST_RUNS_DIR", "")
|
return os.environ.get("OPENULTRASAST_RUNS_DIR", "")
|
||||||
|
|
||||||
|
|
||||||
|
WRAPPER_RUNS_MOUNT = "/reports"
|
||||||
|
|
||||||
|
|
||||||
|
def runs_dir_is_the_wrappers() -> bool:
|
||||||
|
"""Whether `OPENULTRASAST_RUNS_DIR` is the shell wrapper's: the runs directory, mounted in the image.
|
||||||
|
|
||||||
|
The wrappers pass `/reports` (`ops/shell/ousast.sh`), where the compose file mounts the directory a native
|
||||||
|
scan writes to by default, so a scan prunes it as it prunes the default location.
|
||||||
|
"""
|
||||||
|
return Path(_runs_dir_override()) == Path(WRAPPER_RUNS_MOUNT)
|
||||||
|
|
||||||
|
|
||||||
def runs_dir_is_overridden() -> bool:
|
def runs_dir_is_overridden() -> bool:
|
||||||
"""Whether `OPENULTRASAST_RUNS_DIR` names where runs go. Wherever it points, that location is never pruned."""
|
"""Whether `OPENULTRASAST_RUNS_DIR` names where runs go.
|
||||||
|
|
||||||
|
Wherever it points, that location is not pruned; the wrapper's mount is the one exception
|
||||||
|
(`runs_dir_is_the_wrappers`).
|
||||||
|
"""
|
||||||
return bool(_runs_dir_override())
|
return bool(_runs_dir_override())
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ from datetime import UTC, datetime, timedelta
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from uuid import uuid4
|
from uuid import uuid4
|
||||||
|
|
||||||
from .config import ResolvedConfig, runs_dir_is_overridden, write_resolved_config
|
from .config import ResolvedConfig, runs_dir_is_overridden, runs_dir_is_the_wrappers, write_resolved_config
|
||||||
|
|
||||||
_RUN_ID = re.compile(r"(\d{8}T\d{6}Z)-[0-9a-f]{8}")
|
_RUN_ID = re.compile(r"(\d{8}T\d{6}Z)-[0-9a-f]{8}")
|
||||||
|
|
||||||
@@ -70,11 +70,12 @@ def prune_old_runs(runs_root: Path, *, keep: Path | None = None, retention_days:
|
|||||||
def prune_scan_runs(config: ResolvedConfig, *, keep: Path) -> tuple[str, ...]:
|
def prune_scan_runs(config: ResolvedConfig, *, keep: Path) -> tuple[str, ...]:
|
||||||
"""Remove the expired runs once a scan has written its own; returns what the scan is to say about it.
|
"""Remove the expired runs once a scan has written its own; returns what the scan is to say about it.
|
||||||
|
|
||||||
Only the default location is pruned: while `OPENULTRASAST_RUNS_DIR` is set, wherever it points, every run
|
Two locations are pruned: the default one, and the shell wrapper's runs directory, which is the user's runs
|
||||||
stays. Nothing is said when nothing was removed, and a removal that fails is said once and costs the scan
|
directory mounted in the image (`runs_dir_is_the_wrappers`). While `OPENULTRASAST_RUNS_DIR` points anywhere
|
||||||
nothing.
|
else, wherever it points, every run stays. Nothing is said when nothing was removed, and a removal that
|
||||||
|
fails is said once and costs the scan nothing.
|
||||||
"""
|
"""
|
||||||
if runs_dir_is_overridden():
|
if runs_dir_is_overridden() and not runs_dir_is_the_wrappers():
|
||||||
return ()
|
return ()
|
||||||
root = Path(config.runs_dir)
|
root = Path(config.runs_dir)
|
||||||
try:
|
try:
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
"""What a scan removes from its cache (contributor-scan Requirement 5.3, decision of 2026-11-24): once its run
|
"""What a scan removes from its cache (contributor-scan Requirement 5.3, decisions of 2026-11-24 and 2026-11-27):
|
||||||
is written, the expired runs go from the default location, and nothing else does."""
|
once its run is written, the expired runs go from the default location and from the shell wrapper's mount of it,
|
||||||
|
and nothing else does."""
|
||||||
|
|
||||||
import errno
|
import errno
|
||||||
import os
|
import os
|
||||||
@@ -13,7 +14,7 @@ import pytest
|
|||||||
from test_scan_output_location import _scan, _target, _user_cache
|
from test_scan_output_location import _scan, _target, _user_cache
|
||||||
|
|
||||||
from openultrasast import run
|
from openultrasast import run
|
||||||
from openultrasast.config import ResolvedConfig, load_config
|
from openultrasast.config import WRAPPER_RUNS_MOUNT, ResolvedConfig, load_config
|
||||||
from openultrasast.run import prune_old_runs, prune_scan_runs
|
from openultrasast.run import prune_old_runs, prune_scan_runs
|
||||||
|
|
||||||
NOW = datetime(2026, 11, 24, 12, tzinfo=UTC)
|
NOW = datetime(2026, 11, 24, 12, tzinfo=UTC)
|
||||||
@@ -268,6 +269,42 @@ def test_a_scan_with_the_runs_dir_override_pointing_at_the_default_location_remo
|
|||||||
assert _notices(out) == []
|
assert _notices(out) == []
|
||||||
|
|
||||||
|
|
||||||
|
def test_a_scan_through_the_wrapper_removes_the_expired_runs_from_the_mounted_runs_directory(
|
||||||
|
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
|
||||||
|
) -> None:
|
||||||
|
"""What a scan in the image sees through the shell wrapper. The runs directory is a stand-in for `/reports`,
|
||||||
|
which only root can make on the host."""
|
||||||
|
monkeypatch.setenv("OPENULTRASAST_RUNS_DIR", "/reports")
|
||||||
|
monkeypatch.delenv(RETENTION, raising=False)
|
||||||
|
mounted = tmp_path / "reports"
|
||||||
|
_earlier_run(mounted, 40)
|
||||||
|
last_week = _earlier_run(mounted, 5)
|
||||||
|
current = _run(mounted, _run_id(datetime.now(UTC), "badc0de0"))
|
||||||
|
|
||||||
|
notices = prune_scan_runs(ResolvedConfig(runs_dir=str(mounted)), keep=current)
|
||||||
|
|
||||||
|
assert notices == (f"removed 1 run older than 30 days from {mounted}",)
|
||||||
|
assert sorted(mounted.iterdir()) == [last_week, current]
|
||||||
|
|
||||||
|
|
||||||
|
def test_a_scan_that_compose_runs_without_the_wrapper_removes_nothing(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
|
||||||
|
"""The compose file's own `OPENULTRASAST_RUNS_DIR`, `/reports/runs`: a location chosen, where nothing is removed."""
|
||||||
|
monkeypatch.setenv("OPENULTRASAST_RUNS_DIR", "/reports/runs")
|
||||||
|
monkeypatch.delenv(RETENTION, raising=False)
|
||||||
|
runs = tmp_path / "reports" / "runs"
|
||||||
|
expired = _earlier_run(runs, 40)
|
||||||
|
current = _run(runs, _run_id(datetime.now(UTC), "badc0de0"))
|
||||||
|
|
||||||
|
assert prune_scan_runs(ResolvedConfig(runs_dir=str(runs)), keep=current) == ()
|
||||||
|
assert sorted(runs.iterdir()) == [expired, current]
|
||||||
|
|
||||||
|
|
||||||
|
def test_the_wrapper_passes_the_override_that_a_scan_prunes() -> None:
|
||||||
|
"""The wrapper's word and the scan's mount point must not drift apart: the scan prunes `/reports` by that name."""
|
||||||
|
wrapper = Path(__file__).resolve().parents[1] / "ops" / "shell" / "ousast.sh"
|
||||||
|
assert f"-e OPENULTRASAST_RUNS_DIR={WRAPPER_RUNS_MOUNT} ousast" in wrapper.read_text()
|
||||||
|
|
||||||
|
|
||||||
def test_a_scan_with_an_empty_runs_dir_override_removes_the_expired_runs_from_the_default_location(
|
def test_a_scan_with_an_empty_runs_dir_override_removes_the_expired_runs_from_the_default_location(
|
||||||
tmp_path: Path, monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str]
|
tmp_path: Path, monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str]
|
||||||
) -> None:
|
) -> None:
|
||||||
|
|||||||
Reference in New Issue
Block a user