fix(push): the background child is started with -P, as the wrapper is (item 5b)

The maintainer's answer of 2026-11-27 to question 3 of the ninth session's menu, "Add -P there
too", as offered: one line, a test first, a reviewer.

src/openultrasast/push/background.py starts the detached replay of `ousast pre-push --engine
background` with the interpreter, -m and openultrasast.cli, from the pushed repository. With -m
alone the working directory is first on the interpreter's path, so a file of the pushed repository
could stand in for a module the CLI imports. The wrapper's native path had the same fault and was
fixed with -P in a6e8e26; the reviewer of that commit found this one and it was left alone.

The child is now started with -P, which keeps that directory off the path. The flag needs Python
3.11, the project's floor (pyproject.toml).

Measured by the new test, with a real child process: tests/test_push_background.py puts a json.py
that exits into the pushed repository and starts the child. On a git archive of HEAD the child's
log is "SHADOW-EXECUTED" and its artifact is never written (s10_c3_red2.out). With the change the
artifact is written and the log does not hold that line, on this host's default PATH, where Joern is
not found (the child ends in about 1 s), and with Joern 4.0.625 and its JavaScript
frontend on PATH, where the child uses its whole deadline (s10_c3_green2.out, s10_c3_green3.out).
The five push test files give 106 passed. ruff, mypy, the three gates and compileall pass, and the
gates print what they printed before (s10_c3b_exits.txt). `git diff --check` exits 0. No
whole-suite run: that is step 9.

An independent reviewer blocked the first round on the test: its wait equalled the child's
deadline, so it was red on a host where the engine can build a JavaScript graph (1 failed,
4 passed). The child's deadline is now 5 s. The second round approved the final diff.

Found and not fixed, for the maintainer:
- The container path has the fault too, by one probe. docker-compose.yml:37 sets the working
  directory to /work, and the wrapper's own comment (ops/shell/ousast.sh:13-16 and :34-35) says
  the container runs in the caller's directory. On the local openultrasast:dev image
  3f959b31f2f2, network none, a tree that holds such a json.py mounted at /work: the image's own
  entrypoint (Dockerfile:46, python -m openultrasast.cli) prints SHADOW-EXECUTED for --help and
  exits 1; the same tree with -P prints the usage (s10_c3_container_probe.out). The wrapper and
  compose were not run, and the published image was not probed.
- ops/ax/smoke-run.sh:9 and :12, ops/ax/up.sh:14 and ops/ax/probe-placement.sh:16 run this
  checkout's code with -m and without -P, in the caller's directory (by reading): the CLI at
  smoke-run.sh:12, openultrasast.plane.profile at the other three.
- src/openultrasast/plane/runner.py:678 starts a task's module with -m from the task's first
  workspace (by reading). Whether a file of that workspace can stand in for a module the task
  imports was not measured.
- The two launches in src/openultrasast/search/demo.py use -I, which keeps the directory off the
  path.
This commit is contained in:
Marius Ciepluch
2026-11-27 17:49:08 +01:00
parent f6b1406541
commit 739688730f
2 changed files with 25 additions and 0 deletions
+3
View File
@@ -67,8 +67,11 @@ def start(
return {"status": "busy", "head": str(running.get("head", "")), "directory": str(directory)}
target = directory / f"{head}.json"
log = directory / f"{head}.log"
# -P keeps the repository off the interpreter's path: -m alone puts the working directory first, so
# a file of the pushed repository could stand in for a module the CLI imports.
command = [
sys.executable,
"-P",
"-m",
"openultrasast.cli",
"pre-push",
+22
View File
@@ -5,6 +5,7 @@ from __future__ import annotations
import json
import os
import time
from pathlib import Path
from test_push_runner import history
@@ -55,6 +56,27 @@ def test_one_background_engine_at_a_time(tmp_path):
assert "is still busy, so none was started" in delivery.text
def test_the_background_child_does_not_import_a_module_of_the_pushed_repository(tmp_path):
"""`-m` alone puts the working directory first on the interpreter's path, and the child runs in the pushed
repository: a file there could stand in for a module the CLI imports. That is the fault fixed for the
wrapper in a6e8e26; the child is started with `-P`, which keeps that directory off the path.
"""
root, base, head, _ = history(tmp_path)
(root / "json.py").write_text('import sys\nsys.exit("SHADOW-EXECUTED")\n')
artifact = tmp_path / "a" / "push.json"
# A short deadline for the child, and a longer wait: where the engine is installed the child uses its
# whole deadline and then writes the artifact.
state = background.start(root, base=base, head=head, artifact=artifact, deadline_seconds=5)
assert state["status"] == "started"
target = Path(state["artifact"])
deadline = time.monotonic() + 60
while not target.exists() and time.monotonic() < deadline:
time.sleep(0.2)
log = Path(state["log"]).read_text()
assert "SHADOW-EXECUTED" not in log
assert target.exists(), log
def test_previous_summarises_advisory_engine_findings(tmp_path):
root = tmp_path / "repo"
root.mkdir()