fix(shell): the wrapper passes the retention days into the image (item 5b)

The maintainer's second decision on answer 7, taken on 2026-11-27 while the scan path
change (312c09b) was reviewed. Put with the question tool, in this question: "Answer 7
... is built, measured and reviewed, with one consequence the decision does not cover.
The wrapper passes only OPENULTRASAST_RUNS_DIR into the image, never
OPENULTRASAST_RUNS_RETENTION_DAYS. ... How should the retention reach the image?" The
option chosen, in full: "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. The scan in the image then
honours the host's setting, 0 included. Measured: compose passes a variable named
without a value only when the host sets it. This commit stays the scan path alone; the
wrapper is the next commit." Not chosen: "Document it", "Hold answer 7".

What changed.
- ops/shell/ousast.sh: the compose run passes -e OPENULTRASAST_RUNS_RETENTION_DAYS,
  without a value, beside the runs directory's override; the comment above it says why.
- ops/shell/ousast.ps1: the same option, edited by reading: no PowerShell is installed
  here.
- tests/test_shell_wrapper.py: test_the_container_path_passes_the_retention_into_the_image.
- tests/test_run_pruning.py: the guard test of 312c09b pinned one text,
  "-e OPENULTRASAST_RUNS_DIR=/reports ousast". With the new option between the two it
  now pins the word OPENULTRASAST_RUNS_DIR=<WRAPPER_RUNS_MOUNT> wherever it stands in
  the wrapper's text.

Measured, through the wrapper function itself. The script is /tmp/opencode/s10_c8_probe.sh
and its files are under /tmp/opencode/s10_c8_probe/, one per measurement; those of the
wrapper runs start with the command and then with the line that ran. bash sources the
working tree's ops/shell/ousast.sh and runs `ousast scan examples --mode quick` with
HOME at a scratch directory, so the runs directory the wrapper mounts at /reports is a
scratch one; the real ~/.cache/openultrasast/runs was not touched
(/tmp/opencode/s10_c8_real_runs.out). The image is openultrasast:dev (3f959b31f2f2) with
the working tree's package copied over it, under a tag that OUSAST_VERSION gives to
compose, so the wrapper finds an image and does not build. Network off. No key is in the
shell's environment; compose reads the checkout's .env by default, and that file names
both keys, which docker-compose.yml:44-45 pass on, so the containers may have had them:
not looked at, and no measurement depends on it (quick mode, network none). Compose
5.5.1. Each scratch runs directory held a run of 40 days ago, a run of 5 days ago and a
directory called notes. The stamps run from 18:54:48Z to 18:54:58Z.
- Retention unset on the host (10_changed_unset.out): "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_changed_unset_after.out).
- Retention 0 on the host (20_changed_zero.out, 21_changed_zero_after.out): no notice;
  the expired run stays, with the run of 5 days ago, the new run and notes.
- Retention 3 on the host (30_changed_three.out): "notice: removed 2 runs older
  than 3 days from /reports"; both old runs are gone (31_changed_three_after.out).
- The control: HEAD's wrapper (312c09b) with retention 0 on the host (40_head_zero.out):
  "notice: removed 1 run older than 30 days from /reports". That is the gap this
  commit closes (41_head_zero_after.out).
- What the container sees of the variable under the wrapper's two options, asked of the
  image's Python (50_variable_unset.out, 51_variable_zero.out, 52_variable_empty.out):
  unset, "set to 0" and empty, as on the host. An empty value reads as not set
  (config.py, _runs_retention_days).
- The wrapper the probe ran is the tree's, and the package it was built from equals the
  tree's (03_probe_sources.out is a bare list of digests).
- The probe image is removed (90_remove_probe.out); no container remains
  (91_containers_after.out), and openultrasast:dev alone is left (92_images_after.out).

Tests. RED: an archive of HEAD (src, ops, tests, pyproject.toml) with the new test, the
package imported from the archive and the wrapper HEAD's (s10_c8_red2.out: 1 failed,
6 passed, at "ValueError: 'OPENULTRASAST_RUNS_RETENTION_DAYS' is not in list").
GREEN on the final tree: 78 passed over tests/test_shell_wrapper.py,
tests/test_run_pruning.py, tests/test_task_images.py, tests/test_docs_site.py and
tests/test_removed_plane_references.py (s10_c8_green4.out; the command is not in the
file). Mutants, the tree with one line changed, run on the two wrapper and pruning
test files (the copies are /tmp/opencode/s10_c8_mutB and s10_c8_mutD):
- WRAPPER_RUNS_MOUNT = "/reports2" fails the guard and the first test of 312c09b
  (s10_c8_mutB2.out: 2 failed, 41 passed);
- the wrapper's word changed to OPENULTRASAST_RUNS_DIR=/reports2 fails the guard and
  the wrapper test of d1f61fb (s10_c8_mutD2.out: 2 failed, 41 passed).
Two earlier GREEN runs failed on the guard as it was (s10_c8_green.out,
s10_c8_green2.out): that is the change to tests/test_run_pruning.py.

Checks on the final tree: ruff format, ruff check, mypy, compileall and the three gates
pass, and the gates print what they printed before the change (s10_c8b_exits.txt);
bash -n on ops/shell/ousast.sh exits 0.

- Review: two rounds by a reviewer subagent, reading and re-running, no docker. Round one
  approved the four files and conditioned the commit on the message: "Network off, no
  key" was unsupported, since compose reads the checkout's .env, which names both keys,
  and the review line was a placeholder. Round two checked the tree after the optional
  remarks were taken (the guard takes the word exactly; the shell command is on two
  lines) and found the code right: GREEN 78 passed again, both mutants 2 failed and 41
  passed, the probe's second run read as stated. One condition remained: the stamps at
  line 39, 18:54:48Z to 18:54:58Z.

By reading, not measured.
- ops/shell/ousast.ps1: no PowerShell is installed here.
- No page says what the wrapper passes into the image, so none needed a change:
  README.md and docs/examples.md say that OPENULTRASAST_RUNS_RETENTION_DAYS sets the
  days and that 0 keeps every run, and through the wrapper that is now true.
- A value the host sets that is not a whole number of days now stops the scan in the
  image with the message a native scan gives (config.py, _runs_retention_days); before
  it did not reach the image.

Not checked: the whole test suite; Windows and ops/shell/ousast.ps1; whether the keys
of the checkout's .env reached the probe's containers.
This commit is contained in:
Marius Ciepluch
2026-11-27 19:59:50 +01:00
parent 312c09bdbf
commit efa311a112
4 changed files with 21 additions and 5 deletions
+3 -2
View File
@@ -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.
+5 -2
View File
@@ -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
+1 -1
View File
@@ -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(
+12
View File
@@ -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)