feat(contributor-scan): benchmark runs go beside the scan runs (3.1, follow-up)

`ousast benchmark` and its MCP twin wrote a run to
`<target>/.openultrasast/benchmarks/<id>/`, into the scanned tree, and no user
document said so. By the maintainer decision of 2026-11-24 a benchmark run now
goes to `<runs_dir>/<benchmark-run-id>/`, beside the scan runs, where run
retention removes it like a scan run.

`create_benchmark_run` in src/openultrasast/benchmark.py takes the runs
directory instead of the target. The two `_benchmark` functions, in cli.py and
in mcp.py, load the configuration the way `_run_scan` does and pass
`config.runs_dir`, so a benchmark run follows `OPENULTRASAST_RUNS_DIR` like the
scan it runs.

Both create the run once the scan has returned. Created first, as it was, the
run was under the scan's own retention while the scan ran, and a scan that
outlasted the retention window took it for an old one: the scoreboard could not
be written and the scan outcome was never printed. A failed scan now also
leaves no empty run behind.

README.md and docs/examples.md name where a benchmark run goes.

Tests: the three location assertions failed before the change and pass after
it. A new test pins that retention removes a benchmark run like a scan run, and
another that a benchmark keeps its run when its scan outlasts the retention
window. The nine test files around the change pass (120 passed); ruff, mypy,
the three gates and compileall pass. A run of the real CLI printed `run_dir=`
and `benchmark_run_dir=` as siblings under the runs directory and left only the
calibration ledger in the scanned tree. An independent reviewer approved the
change in two rounds; its first round found the retention window, which this
cut closes.
This commit is contained in:
Marius Ciepluch
2026-11-25 10:40:01 +01:00
parent 78434a6e9f
commit 9e4983f465
7 changed files with 83 additions and 13 deletions
+7 -2
View File
@@ -182,10 +182,15 @@ def resolve_benchmark_source(manifest_path: Path, manifest: BenchmarkManifest) -
return source.resolve()
def create_benchmark_run(target: Path, manifest: BenchmarkManifest) -> BenchmarkRun:
def create_benchmark_run(runs_dir: Path, manifest: BenchmarkManifest) -> BenchmarkRun:
"""A run beside the scan runs, named like one so that run retention removes it.
Create it once its scan has returned: a run that exists while a scan prunes can be taken for an old
one when the scan outlasts the retention window.
"""
timestamp = datetime.now(UTC).strftime("%Y%m%dT%H%M%SZ")
benchmark_run_id = f"{timestamp}-{uuid4().hex[:8]}"
root = target.resolve() / ".openultrasast" / "benchmarks" / benchmark_run_id
root = runs_dir / benchmark_run_id
root.mkdir(parents=True, exist_ok=False)
return BenchmarkRun(benchmark_run_id=benchmark_run_id, root=root, manifest=manifest)
+2 -1
View File
@@ -1100,10 +1100,11 @@ def _benchmark(manifest_path: Path, config_path: Path, mode: str) -> int:
raise SystemExit(f"benchmark manifest is not a file: {manifest_path}")
manifest = load_benchmark_manifest(manifest_path)
target = resolve_benchmark_source(manifest_path, manifest)
run = create_benchmark_run(target, manifest)
config = load_config(config_path if config_path.exists() else None)
started_at = perf_counter()
outcome = _run_scan(target, config_path, mode, "never")
runtime_seconds = perf_counter() - started_at
run = create_benchmark_run(Path(config.runs_dir), manifest)
findings = _load_scan_findings(outcome.run_dir)
baseline_findings = load_baseline_findings(manifest_path, manifest)
result = evaluate_benchmark(
+5 -2
View File
@@ -163,6 +163,7 @@ def _artifacts(args: dict[str, Any]) -> dict[str, Any]:
def _benchmark(args: dict[str, Any]) -> dict[str, Any]:
from .benchmark import create_benchmark_run, evaluate_benchmark, load_benchmark_manifest, load_findings, resolve_benchmark_source
from .cli import _run_scan
from .config import load_config
manifest_path = Path(_require(args, "manifest"))
if not manifest_path.is_file():
@@ -170,8 +171,10 @@ def _benchmark(args: dict[str, Any]) -> dict[str, Any]:
mode = str(args.get("mode", "quick"))
manifest = load_benchmark_manifest(manifest_path)
target = resolve_benchmark_source(manifest_path, manifest)
run = create_benchmark_run(target, manifest)
outcome = _run_scan(target, Path(str(args.get("config", "openultrasast.toml"))), mode, "never")
config_path = Path(str(args.get("config", "openultrasast.toml")))
config = load_config(config_path if config_path.exists() else None)
outcome = _run_scan(target, config_path, mode, "never")
run = create_benchmark_run(Path(config.runs_dir), manifest)
result = evaluate_benchmark(
run=run, mode=mode, findings=load_findings(outcome.run_dir / "findings.json"), scan_id=outcome.scan_id, scan_run_dir=outcome.run_dir
)