diff --git a/ops/shell/ousast.ps1 b/ops/shell/ousast.ps1 index 190e6d35..b8bd4af1 100644 --- a/ops/shell/ousast.ps1 +++ b/ops/shell/ousast.ps1 @@ -46,8 +46,9 @@ function ousast { $env:TARGET = $cwd $env:OUSAST_REPORTS = $runs if (-not $env:OUSAST_NETWORK) { $env:OUSAST_NETWORK = 'none' } - # /reports is the runs directory itself: the override puts the run beside a native one, to be pruned. - docker compose -f $compose run --rm -e OPENULTRASAST_RUNS_DIR=/reports ousast @mapped + # /reports is the runs directory itself: the override puts the run beside a native one, to be pruned. The + # retention goes in without a value: compose sets it only when the host has it. + docker compose -f $compose run --rm -e OPENULTRASAST_RUNS_DIR=/reports -e OPENULTRASAST_RUNS_RETENTION_DAYS ousast @mapped } # The LLM judge needs network and a key; opt in explicitly. diff --git a/ops/shell/ousast.sh b/ops/shell/ousast.sh index ffea08b9..a5ddc6cf 100644 --- a/ops/shell/ousast.sh +++ b/ops/shell/ousast.sh @@ -85,10 +85,13 @@ ousast() { done # /reports is the runs directory itself here, not a reports directory with runs under it: the override puts - # the run beside a native one, where the pruning of the default location finds it. + # the run beside a native one, where the scan in the image prunes the expired runs as a native scan does. The + # retention goes in without a value: compose sets it in the container only when the host has it, so a host + # that keeps every run with 0 keeps them through the wrapper too. TARGET="$PWD" OUSAST_REPORTS="$runs" \ OUSAST_NETWORK="${OUSAST_NETWORK:-none}" \ - docker compose -f "$compose" run --rm -e OPENULTRASAST_RUNS_DIR=/reports ousast "${args[@]}" + docker compose -f "$compose" run --rm -e OPENULTRASAST_RUNS_DIR=/reports \ + -e OPENULTRASAST_RUNS_RETENTION_DAYS ousast "${args[@]}" } # The LLM judge needs the network and a key; without them the model layer still entails and only the diff --git a/tests/test_run_pruning.py b/tests/test_run_pruning.py index 6f7fdf12..32a10d2a 100644 --- a/tests/test_run_pruning.py +++ b/tests/test_run_pruning.py @@ -302,7 +302,7 @@ def test_a_scan_that_compose_runs_without_the_wrapper_removes_nothing(tmp_path: 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() + assert f"OPENULTRASAST_RUNS_DIR={WRAPPER_RUNS_MOUNT}" in wrapper.read_text().split() def test_a_scan_with_an_empty_runs_dir_override_removes_the_expired_runs_from_the_default_location( diff --git a/tests/test_shell_wrapper.py b/tests/test_shell_wrapper.py index 351cf062..0b01f521 100644 --- a/tests/test_shell_wrapper.py +++ b/tests/test_shell_wrapper.py @@ -72,6 +72,18 @@ def test_the_container_writes_its_runs_to_the_users_cache(tmp_path): assert words.index("OPENULTRASAST_RUNS_DIR=/reports") < words.index("ousast") +def test_the_container_path_passes_the_retention_into_the_image(tmp_path): + """The wrapper passed the runs directory alone. A scan in the image prunes that directory with the retention + its own environment names, 30 days when the host's does not reach it: a host keeping every run with 0 would + lose the old ones through the wrapper.""" + result = ousast(tmp_path, (), "scan", ".") + assert result.returncode == 0, result.stderr + words = result.stdout.splitlines()[-1].split() + # Without a value: compose passes the variable on only when the host has it. + assert words.index("OPENULTRASAST_RUNS_RETENTION_DAYS") < words.index("ousast") + assert not any(word.startswith("OPENULTRASAST_RUNS_RETENTION_DAYS=") for word in words) + + def test_the_container_path_stops_when_home_is_not_set(tmp_path): """With HOME unset, `$HOME/.cache` became `/.cache`: the wrapper went on to the container just the same.""" result = ousast(tmp_path, (), "scan", ".", without_home=True)