Files
Open_Ultra_SAST/tests/test_model_execution.py
T
Marius CiepluchandClaude Opus 5 0c71c956fd feat(model-grounded-detection): group 6, the execution tier as a seam not a build
The rung this project deliberately does not build. Clearwing already runs
sandbox lifecycles, container pools, sanitizer images, PoC replay and stability
classification, and the corrective brief concluded -- from this project's own
defect history -- that reimplementing that machinery is where we go wrong. So
model/execution.py decides eligibility, calls an adopted tool, and records what
happened. A test asserts structurally that it imports no container or
subprocess machinery and defines no build/run/compile/patch function, because
the failure mode to prevent is this file quietly growing a sandbox.

Eligibility is narrow in both directions: only a family a static model cannot
arbitrate (memory safety in C, where the bug turns on runtime layout -- Req
10.3 forbids any web/logic family depending on this tier, and each now has
taint, dominance or constant abstraction instead), and only a finding the model
left undecided. The tier escalates uncertainty; it never re-checks a verdict.

One deliberate asymmetry: a failure to reproduce is NOT a refutation. A sandbox
that does not trigger a bug has not shown the bug is absent, only that this
attempt did not trigger it, so the candidate stays where the model left it.
Reading a failed reproduction as a clean bill of health is the same error class
as reading an absent engine as "no vulnerability".

With no adopted tool present -- the normal case -- the rung is never reached and
clearwing_unavailable is recorded.

All 16 tasks of model-grounded-detection are now done. 720 passing, mypy/ruff
clean, gates byte-identical, zero orphaned modules.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01T7XD7x5KonMdmGRkp63EQG
2026-09-08 16:58:03 +02:00

117 lines
4.9 KiB
Python

"""model-grounded-detection task 6.1: the execution tier is deferred, adopted, and narrow (Req 10).
The rung this project does NOT build. Clearwing already runs sandboxes, container pools, sanitizer images and
PoC stability, and this session's own history says reimplementing that class of machinery is where we go
wrong. So `execution_confirmed` exists as a rung, the seam calls an adopted tool, and the eligibility rule is
deliberately narrow: only a finding the static model could not decide, in a family a static model genuinely
cannot arbitrate.
Everything here runs with Clearwing absent, which is the normal case.
"""
from __future__ import annotations
import pytest
def _finding(family="memory", rung="suspicion"): # type: ignore[no-untyped-def]
from openultrasast.model.execution import Candidate
return Candidate(finding_id="f1", family=family, rung=rung, path="a.c", line=10)
def test_only_a_family_a_static_model_cannot_arbitrate_is_eligible() -> None:
"""Req 10.3: no web/logic class depends on this tier. They have taint, dominance and constant abstraction."""
from openultrasast.model.execution import eligible
assert eligible(_finding(family="memory")) is True
for family in ("injection", "access_control", "path", "config_secrets", "output_encoding"):
assert eligible(_finding(family=family)) is False, f"{family} must be arbitrated statically"
def test_a_finding_the_model_already_decided_is_not_escalated() -> None:
"""Req 10.1: the tier is reached only where the model could not decide -- never to double-check itself."""
from openultrasast.model.execution import eligible
assert eligible(_finding(rung="suspicion")) is True
assert eligible(_finding(rung="model_entailed")) is False
assert eligible(_finding(rung="model_corroborated")) is False
def test_without_clearwing_the_rung_is_never_reached_and_the_reason_is_recorded(monkeypatch: pytest.MonkeyPatch) -> None:
"""Req 11.3: an absent capability degrades to a recorded reason, never a traceback and never a verdict."""
from openultrasast.model.execution import confirm, resolve_execution_backend
monkeypatch.setenv("OPENULTRASAST_CLEARWING", "off")
backend = resolve_execution_backend()
assert backend.available() is False
outcome = confirm(_finding(), backend=backend)
assert outcome.rung is None, "no engine, no rung"
assert "clearwing_unavailable" in outcome.reason
def test_an_ineligible_finding_is_not_sent_to_the_sandbox_even_when_one_exists() -> None:
from openultrasast.model.execution import confirm
class _Backend:
def __init__(self) -> None:
self.calls = 0
def available(self) -> bool:
return True
def reproduce(self, candidate: object) -> bool:
self.calls += 1
return True
backend = _Backend()
outcome = confirm(_finding(family="injection"), backend=backend)
assert outcome.rung is None and backend.calls == 0
assert "not_eligible" in outcome.reason
def test_a_reproduced_candidate_reaches_execution_confirmed() -> None:
from openultrasast.model.execution import confirm
from openultrasast.model.ladder import Rung
class _Backend:
def available(self) -> bool:
return True
def reproduce(self, candidate: object) -> bool:
return True
assert confirm(_finding(), backend=_Backend()).rung is Rung.EXECUTION_CONFIRMED
def test_a_candidate_that_does_not_reproduce_stays_where_it_was() -> None:
"""Not reproducing is not a refutation: the sandbox failing to trigger a bug does not prove its absence."""
from openultrasast.model.execution import confirm
class _Backend:
def available(self) -> bool:
return True
def reproduce(self, candidate: object) -> bool:
return False
outcome = confirm(_finding(), backend=_Backend())
assert outcome.rung is None
assert "not_reproduced" in outcome.reason and "refut" not in outcome.reason.lower()
def test_the_seam_reimplements_no_sandbox_machinery() -> None:
"""Req 10.2, asserted structurally. The one thing this module must not grow is a sandbox."""
import ast
from pathlib import Path
source = Path("src/openultrasast/model/execution.py").read_text()
tree = ast.parse(source)
imported = {n.module.split(".")[0] for n in ast.walk(tree) if isinstance(n, ast.ImportFrom) and n.module}
imported |= {a.name.split(".")[0] for n in ast.walk(tree) if isinstance(n, ast.Import) for a in n.names}
for banned in ("docker", "podman", "subprocess", "container", "sandbox"):
assert banned not in imported, f"the execution tier must adopt, not build: {banned}"
names = {n.name for n in ast.walk(tree) if isinstance(n, ast.FunctionDef)}
for banned in ("build_image", "run_container", "compile_target", "apply_patch"):
assert banned not in names, f"{banned} belongs to the adopted tool, not here"