fix(contributor-scan): the wrapper's native path runs in the caller's directory (item 5a)

`ousast scan .` through ops/shell/ousast.sh with a native install scanned the wrong
tree. The native path changed into the checkout before it passed the arguments on, so
`.` was the OpenUltraSAST checkout and a relative file name was looked up there. The
eighth session showed it with a stub interpreter in place of `.venv/bin/python`
(`cwd=/tmp/opencode/s8_fakehome args=-m openultrasast.cli scan .`). The check also
looked for `joern-parse` only, while the batch queries run `joern`: with `joern-parse`
alone on PATH every batch query failed and a standard scan still exited 0 (2026-11-26,
14 findings where the working launcher gives 15).

The native path now runs the checkout's interpreter by its absolute path, in the
caller's directory, as the container path does, and it is taken only when `joern` is on
PATH as well. So `.`, relative names and relative options mean the caller's files. The
reviewer found, and a run confirmed, what dropping the `cd` brings: `-m` alone puts the
working directory first on the interpreter's path, so a file of the scanned tree could
stand in for a module the CLI imports (a `json.py` in the caller's directory: `ousast
--help` printed SHADOW-EXECUTED and exited 3). The interpreter is started with `-P`,
which keeps that directory off the path; the flag needs Python 3.11, the project's
floor (pyproject.toml).

Changes a caller sees, beyond the one the decision named:
- The checkout's .env is no longer read on the native path; the CLI reads .env from the
  working directory, which is now the caller's. ops/README.md says so.
- `ousast pairs` and `ousast repos` no longer find their defaults outside the
  checkout, because `benchmarks/` is read relative to the working directory. Measured
  for `pairs`: through the wrapper natively, and on the container path, `pairs --slice
  vibe-py` ends with "pair catalog is not a file: benchmarks/pairs/catalog.toml",
  exit 1, so the container path already behaved this way. `repos` by reading. Run from
  the checkout root they find their defaults again (by reading; not run). The header's
  `ousast pairs --slice vibe-py` example is removed. This is a reading the maintainer
  may correct.
- The message for a machine without Docker names both executables.

Tests: the new tests/test_shell_wrapper.py runs the wrapper by bash with a stub of the
interpreter, `joern`, `joern-parse` and `docker` ahead of /usr/bin and /bin on PATH.
Its two tests failed before the change (2 failed: the interpreter ran in the fake
checkout, and the native path was taken without `joern`), and the first failed again
until `-P` was passed (1 failed). With the real venv and Joern 4.0.625 on PATH, from a
directory without .env: `ousast scan examples --mode quick` on a fresh copy of libpng's
contrib/examples gives file_targets=4, findings=4, exit 0, before and after the flag,
the figures of the eighth session. The eight tests of tests/test_docs_site.py and
tests/test_removed_plane_references.py pass, `mkdocs build --strict` exits 0, ruff
format, ruff check, mypy, the three gates and compileall pass, and the gates print what
they printed before the change. An independent reviewer approved the change in the
second round; its two findings of the first round led to the `-P` flag and to the
removal of the header example.

Found by the reviewer and left alone, outside this decision: the background child of
`ousast pre-push` (src/openultrasast/push/background.py) starts the CLI with `-m` and
without `-P`, from the pushed repository.
This commit is contained in:
Marius Ciepluch
2026-11-26 17:29:16 +01:00
parent ea8d3d2e6e
commit a6e8e2615a
3 changed files with 69 additions and 8 deletions
+3 -2
View File
@@ -30,8 +30,9 @@ you expect. Anything outside the mount is passed through unchanged with a warnin
rewritten into a path the container cannot see. Your directory is mounted **read-only**; findings go to
`./.ousast`, the one writable mount. The image builds itself on first use and says so.
If `joern-parse` is already on your PATH and a local venv exists, the wrapper uses those instead — someone who
installed the engine deliberately should not be quietly routed through a container. Set
If `joern` and `joern-parse` are already on your PATH and a local venv exists, the wrapper uses those instead,
from your directory — someone who installed the engine deliberately should not be quietly routed through a
container. A native run reads `.env` from your directory, not from the checkout. Set
`OUSAST_PREFER_NATIVE=0` to always containerise.
## Two ways to get the engine
+9 -6
View File
@@ -6,7 +6,6 @@
#
# ousast scan .
# ousast scan src/api
# ousast pairs --slice vibe-py
#
# Docker is an implementation detail on purpose. The engine is a JVM and ~2 GB of Joern, and a contributor
# evaluating this tool should not have to install either to try it. What they get instead is a command.
@@ -31,15 +30,19 @@ ousast() {
fi
# A native install wins when it is there: it is faster, and someone who installed Joern deliberately
# should not be quietly routed through a container.
if [ "${OUSAST_PREFER_NATIVE:-1}" = "1" ] && command -v joern-parse >/dev/null 2>&1 \
&& [ -x "$OUSAST_HOME/.venv/bin/python" ]; then
( cd "$OUSAST_HOME" && .venv/bin/python -m openultrasast.cli "$@" )
# should not be quietly routed through a container. It runs in the caller's directory, as the container
# does, so `.`, relative names and relative options mean the caller's files. -P keeps that directory off
# the interpreter's path, where a file of it could stand in for a module the CLI imports. Joern is looked
# for as well: the batch queries run `joern`, and with `joern-parse` alone every one fails while the scan
# still exits 0.
if [ "${OUSAST_PREFER_NATIVE:-1}" = "1" ] && command -v joern >/dev/null 2>&1 \
&& command -v joern-parse >/dev/null 2>&1 && [ -x "$OUSAST_HOME/.venv/bin/python" ]; then
"$OUSAST_HOME/.venv/bin/python" -P -m openultrasast.cli "$@"
return $?
fi
if ! command -v docker >/dev/null 2>&1; then
echo "ousast: docker is not installed, and no local joern-parse was found" >&2
echo "ousast: docker is not installed, and no local joern and joern-parse were found" >&2
return 1
fi