mirror of
https://github.com/norandom/OpenUltraSAST.git
synced 2026-12-03 18:28:19 +00:00
fix(shell): the wrapper says so when it cannot make its runs directory (item 5b)
The maintainer's answer 4 of 2026-11-27, "Guard it" (.kiro/handover.md:1409-1413), as
offered: "a clear message when HOME is unset, and a failed mkdir stops the wrapper
with exit 1; a test first." The fault it answers, in the same words: "With HOME unset
the wrapper now fails ($HOME/.cache becomes /.cache), where it wrote ./.ousast
before; a failed mkdir is not checked, as before."
What changed
- ops/shell/ousast.sh, the container path: the wrapper returns 1 with "ousast: HOME is
not set, so there is no ~/.cache/openultrasast/runs to write the runs to" when HOME
is unset or empty, and with "ousast: cannot create <runs>, where the runs are
written" when mkdir -p fails (mkdir's own line comes first).
- The two lines that set `runs` and ran mkdir -p moved up to that place, from after the
build. The placement is the session's reading of "stops the wrapper": a cold build
pulls ~2 GB, and a run that cannot write its runs should say so before it waits.
- The native path names no HOME and is not touched.
Tests (tests/test_shell_wrapper.py)
- test_the_container_path_stops_when_home_is_not_set: exit 1, that one line on
stderr, nothing on stdout, so neither the build nor the container is started.
- test_a_runs_directory_that_cannot_be_made_stops_the_wrapper: a file where
$HOME/.cache should be; exit 1, the wrapper's line last on stderr, nothing on stdout.
- The helper `ousast` takes `without_home`. The docker stub answers `image inspect`
with exit 1, so the wrapper takes its build branch in each test that reaches the
build (the second and the third); before that, "nothing on stdout" said nothing
about the build.
- RED, on an archive of HEAD with the final test file (s10_c4_red5.out): 2 failed, 3
passed, each `assert 0 == 1`. For the reason of the fault: the wrapper builds, mkdir
is refused ("/.cache: Permission denied", run as uid 1000) or fails ("Not a
directory"), the wrapper goes on to the container (with reports=/.cache/... when
HOME is unset), and the exit status is 0.
- GREEN, on the working tree (s10_c4_green5.out): 5 passed.
- A mutant with the guard behind the build fails both new tests on the build's line
(/tmp/opencode/s10_c4_mutant.py, output s10_c4_mut.out), so the tests pin the
placement; with another shebang in STUB it fails the same way (s10_c4_nopin.out).
- Gates (s10_c4e_exits.txt): ten zeros; the three gate outputs equal the baseline's.
Measured outside the stubs (/tmp/opencode/s10_c4_probe.sh, output s10_c4_probe.out):
real bash on this machine, the native path switched off so that no probe can scan.
HOME unset, HOME empty, and bash under set -u with HOME unset each print the one line
and exit 1; a file at $HOME/.cache prints mkdir's line, then the wrapper's, exit 1.
By reading, not measured
- zsh can source the wrapper as well. The block uses `[ -z "${HOME:-}" ]`, `local`,
`if ! mkdir -p`, `echo ... >&2` and `return 1`; zsh is not installed here, so no
probe ran.
- A run as root with HOME unset had another shape on HEAD: mkdir -p /.cache succeeds
there, so the runs went to the filesystem root with no error. The guard closes it
the same way. This session's runs are as uid 1000.
Found and not fixed, for the maintainer
- The helper's second parameter is `executables`. The third test passes "scan" there
(tests/test_shell_wrapper.py:65, HEAD:63), which makes four stubs named s, c, a and
n beside docker's. Nothing calls them. The new tests pass an empty tuple.
- A runs directory that exists but cannot be written to passes the guard: mkdir -p
exits 0 on it (s10_c4_readonly_runs.out), and the wrapper goes on to docker. The
decision says "a failed mkdir".
- The container path reads $HOME/.cache alone and ignores XDG_CACHE_HOME, which the
native path honours (src/openultrasast/config.py:198-203); README.md:189-190 and
docs/examples.md:3-5 state the rule for every run. From before this commit.
- ops/shell/ousast.ps1:44-45 has the same shape, a New-Item whose result is not
checked, after the build. Read, not run: pwsh is not installed.
- The wrapper's message for an unset HOME (ops/shell/ousast.sh:53) describes the
container path, which reads $HOME alone. Without HOME, Python's Path.home() and
bash's `~` still give /home/mc on this machine (s10_c4_pathhome.out), and a native
scan's default runs directory comes from the former unless XDG_CACHE_HOME is set to
an absolute path (src/openultrasast/config.py:198-203 and :216-226). As decided.
Review
- Review: four rounds against 7396887, all by one reviewer subagent. Round one
approved the change with seven remarks; six were carried into the test file and
this message, and the seventh is the last bullet above. A probe of the reviewer
started one container by mistake, against the brief: it failed at creating its run
directory, and nothing of it remains (/tmp/opencode/s10_c4_after_review_docker.out).
Round two approved the code and the tests on one condition, met in this message
("in every test" became "in each test that reaches the build"), and remarked that
the docker stub's shebang was its second line. Round three approved the tree as it
stood and remarked that the stub's inserted line depended on the shebang's text.
Round four approved the final tree. Docker was not run in rounds two to four.
This commit is contained in:
+12
-2
@@ -47,6 +47,18 @@ ousast() {
|
||||
return 1
|
||||
fi
|
||||
|
||||
# The runs go under HOME. Both checks come before the build: on a cold one it pulls ~2 GB, and a run that
|
||||
# cannot write its runs should say so first.
|
||||
if [ -z "${HOME:-}" ]; then
|
||||
echo "ousast: HOME is not set, so there is no ~/.cache/openultrasast/runs to write the runs to" >&2
|
||||
return 1
|
||||
fi
|
||||
local runs="$HOME/.cache/openultrasast/runs"
|
||||
if ! mkdir -p "$runs"; then
|
||||
echo "ousast: cannot create $runs, where the runs are written" >&2
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Build once, the first time. The run says why it waits, then the build's progress shows: on a cold build it
|
||||
# is the only sign that a long download is running.
|
||||
if ! docker image inspect "openultrasast:${OUSAST_VERSION:-dev}" >/dev/null 2>&1; then
|
||||
@@ -72,8 +84,6 @@ ousast() {
|
||||
fi
|
||||
done
|
||||
|
||||
local runs="$HOME/.cache/openultrasast/runs"
|
||||
mkdir -p "$runs"
|
||||
# /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.
|
||||
TARGET="$PWD" OUSAST_REPORTS="$runs" \
|
||||
|
||||
Reference in New Issue
Block a user