mirror of
https://github.com/norandom/OpenUltraSAST.git
synced 2026-12-03 18:28:19 +00:00
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 of312c09bpinned 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 of312c09b(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 ofd1f61fb(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.
56 lines
2.5 KiB
PowerShell
56 lines
2.5 KiB
PowerShell
# OpenUltraSAST as a local command. Dot-source this from your PowerShell profile:
|
|
#
|
|
# . C:\path\to\OpenUltraSAST\ops\shell\ousast.ps1
|
|
#
|
|
# Then use it from any directory:
|
|
#
|
|
# ousast scan .
|
|
# ousast scan src\api
|
|
#
|
|
# Docker is an implementation detail. Your working directory is mounted READ-ONLY and findings are written
|
|
# to %USERPROFILE%\.cache\openultrasast\runs, the only writable mount.
|
|
|
|
$script:OusastHome = if ($env:OUSAST_HOME) { $env:OUSAST_HOME }
|
|
else { Split-Path -Parent (Split-Path -Parent $PSScriptRoot) }
|
|
|
|
function ousast {
|
|
$compose = Join-Path $script:OusastHome 'docker-compose.yml'
|
|
if (-not (Test-Path $compose)) {
|
|
Write-Error "ousast: cannot find $compose (set OUSAST_HOME to the checkout)"; return
|
|
}
|
|
if (-not (Get-Command docker -ErrorAction SilentlyContinue)) {
|
|
Write-Error "ousast: docker is not installed"; return
|
|
}
|
|
|
|
$version = if ($env:OUSAST_VERSION) { $env:OUSAST_VERSION } else { 'dev' }
|
|
docker image inspect "openultrasast:$version" *> $null
|
|
if ($LASTEXITCODE -ne 0) {
|
|
Write-Host "ousast: building the analysis image once (~2 GB of engine; later runs are instant)"
|
|
Push-Location $script:OusastHome; docker compose build; Pop-Location
|
|
}
|
|
|
|
# Rewrite paths under the current directory to their mounted equivalent; leave anything outside alone
|
|
# and say so, rather than silently rewriting it into a path the container cannot see.
|
|
$cwd = (Get-Location).Path
|
|
$mapped = foreach ($a in $args) {
|
|
if (Test-Path $a) {
|
|
$abs = (Resolve-Path $a).Path
|
|
if ($abs -eq $cwd) { '/target' }
|
|
elseif ($abs.StartsWith($cwd)) { '/target' + $abs.Substring($cwd.Length).Replace('\', '/') }
|
|
else { Write-Warning "ousast: $a is outside $cwd and is not mounted"; $a }
|
|
} else { $a }
|
|
}
|
|
|
|
$runs = Join-Path $env:USERPROFILE '.cache\openultrasast\runs'
|
|
New-Item -ItemType Directory -Force -Path $runs | Out-Null
|
|
$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. 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.
|
|
function ousast-with-judge { $env:OUSAST_NETWORK = 'bridge'; ousast @args }
|