diff --git a/ops/README.md b/ops/README.md index d0095173..43cb0c6a 100644 --- a/ops/README.md +++ b/ops/README.md @@ -27,8 +27,10 @@ ousast-with-judge scan . --mode standard # container network on, so the model The wrapper rewrites paths under your working directory to their mounted equivalents, so `src/api` means what you expect. Anything outside the mount is passed through unchanged with a warning rather than silently -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. +rewritten into a path the container cannot see. Your directory is mounted **read-only**. The wrapper writes its +runs to `~/.cache/openultrasast/runs` (`%USERPROFILE%\.cache\openultrasast\runs` on Windows), the default location +of a native scan, and mounts that directory as the one writable mount, so nothing is written to your directory. +The image builds itself on first use and says so. 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 diff --git a/ops/shell/ousast.ps1 b/ops/shell/ousast.ps1 index 96fcc921..190e6d35 100644 --- a/ops/shell/ousast.ps1 +++ b/ops/shell/ousast.ps1 @@ -8,7 +8,7 @@ # ousast scan src\api # # Docker is an implementation detail. Your working directory is mounted READ-ONLY and findings are written -# to .\.ousast, the only writable mount. +# 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) } @@ -41,11 +41,13 @@ function ousast { } else { $a } } - New-Item -ItemType Directory -Force -Path (Join-Path $cwd '.ousast') | Out-Null + $runs = Join-Path $env:USERPROFILE '.cache\openultrasast\runs' + New-Item -ItemType Directory -Force -Path $runs | Out-Null $env:TARGET = $cwd - $env:OUSAST_REPORTS = Join-Path $cwd '.ousast' + $env:OUSAST_REPORTS = $runs if (-not $env:OUSAST_NETWORK) { $env:OUSAST_NETWORK = 'none' } - docker compose -f $compose run --rm ousast @mapped + # /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 } # The LLM judge needs network and a key; opt in explicitly. diff --git a/ops/shell/ousast.sh b/ops/shell/ousast.sh index 4292993d..589bcebe 100644 --- a/ops/shell/ousast.sh +++ b/ops/shell/ousast.sh @@ -11,8 +11,9 @@ # evaluating this tool should not have to install either to try it. What they get instead is a command. # # The one thing worth knowing: your working directory is mounted READ-ONLY, and findings are written to -# ./.ousast, which is the only writable mount. A tool that reads your source to tell you about it has no -# business being able to change it. +# ~/.cache/openultrasast/runs, where a native scan writes them too. That directory is mounted at /reports, the +# only writable mount, so nothing is written to the directory being scanned. A tool that reads your source to +# tell you about it has no business being able to change it. # Resolve this script's own location so the function works from anywhere, under bash or zsh. if [ -n "${BASH_SOURCE[0]:-}" ]; then @@ -71,10 +72,13 @@ ousast() { fi done - mkdir -p "$PWD/.ousast" - TARGET="$PWD" OUSAST_REPORTS="$PWD/.ousast" \ + 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" \ OUSAST_NETWORK="${OUSAST_NETWORK:-none}" \ - docker compose -f "$compose" run --rm ousast "${args[@]}" + docker compose -f "$compose" run --rm -e OPENULTRASAST_RUNS_DIR=/reports 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_shell_wrapper.py b/tests/test_shell_wrapper.py index b13c7826..c7bb668c 100644 --- a/tests/test_shell_wrapper.py +++ b/tests/test_shell_wrapper.py @@ -8,17 +8,18 @@ ROOT = Path(__file__).resolve().parents[1] WRAPPER = ROOT / "ops/shell/ousast.sh" STUB = """#!/bin/sh -echo "{name} cwd=$PWD args=$*" +echo "{name} cwd=$PWD args=$*${{OUSAST_REPORTS:+ reports=$OUSAST_REPORTS}}" """ def ousast(tmp_path, executables, *arguments): - """`ousast ` in tmp_path/project. OUSAST_HOME is a checkout that holds only what the wrapper looks - for, the interpreter under its .venv is a stub, and so is each executable named, and docker, on PATH.""" - home = tmp_path / "checkout" - home.mkdir() - (home / "docker-compose.yml").write_text("services: {}\n") - python = home / ".venv" / "bin" / "python" + """`ousast ` in tmp_path/project, with tmp_path as HOME. OUSAST_HOME is a checkout that holds only what + the wrapper looks for, the interpreter under its .venv is a stub, and so is each executable named, and docker, + on PATH.""" + checkout = tmp_path / "checkout" + checkout.mkdir() + (checkout / "docker-compose.yml").write_text("services: {}\n") + python = checkout / ".venv" / "bin" / "python" python.parent.mkdir(parents=True) python.write_text(STUB.format(name="python")) python.chmod(0o755) @@ -33,7 +34,7 @@ def ousast(tmp_path, executables, *arguments): return subprocess.run( ["bash", "-c", script], cwd=project, - env={"PATH": f"{bin_dir}:/usr/bin:/bin", "OUSAST_HOME": str(home)}, + env={"PATH": f"{bin_dir}:/usr/bin:/bin", "OUSAST_HOME": str(checkout), "HOME": str(tmp_path)}, capture_output=True, text=True, ) @@ -55,3 +56,15 @@ def test_the_native_path_needs_joern_as_well_as_joern_parse(tmp_path): assert result.returncode == 0, result.stderr calls = [line.split()[0] for line in result.stdout.splitlines()] assert "python" not in calls and "docker" in calls + + +def test_the_container_writes_its_runs_to_the_users_cache(tmp_path): + """The wrapper wrote its runs to ./.ousast, inside the repository it was scanning.""" + result = ousast(tmp_path, "scan", ".") + runs = tmp_path / ".cache" / "openultrasast" / "runs" + assert result.returncode == 0, result.stderr + assert runs.is_dir() and not any((tmp_path / "project").iterdir()) + words = result.stdout.splitlines()[-1].split() + assert words[0] == "docker" and words[-1] == f"reports={runs}" + # Without the override the run lands under runs/runs, where no pruning looks. + assert words.index("OPENULTRASAST_RUNS_DIR=/reports") < words.index("ousast")