2026-09-29 18:10:09 +02:00
|
|
|
"""Workspace manifests for the cases of an independent population file (ai-service-plane task 4).
|
|
|
|
|
|
|
|
|
|
``ousast plane workspaces <population.toml> [--out DIR]`` writes one ax ``Workspace`` per case pin (vulnerable,
|
2026-09-29 18:36:29 +02:00
|
|
|
fixed, benign base, benign tip) with the case's repository URL (checked out at ``<path>/repo``, depth 1) and the
|
|
|
|
|
pinned commit in the ``openultrasast.io/git-commits`` annotation (ax's ``GitRepo`` has no commit field), so a Run
|
|
|
|
|
binds a case at a pin by name. The layout of a case is that of ``benchmarks/independent/evaluate.py``'s ``pins()``.
|
2026-09-29 18:10:09 +02:00
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
from __future__ import annotations
|
|
|
|
|
|
|
|
|
|
import tomllib
|
|
|
|
|
from pathlib import Path
|
|
|
|
|
|
|
|
|
|
import yaml
|
|
|
|
|
|
2026-09-29 18:36:29 +02:00
|
|
|
from .manifests import GIT_COMMITS_ANNOTATION
|
2026-09-29 18:10:09 +02:00
|
|
|
from .reconciler import _ax_name, _doc
|
|
|
|
|
|
|
|
|
|
__all__ = ["workspaces"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def workspaces(population: Path, out: Path) -> list[Path]:
|
|
|
|
|
"""One Workspace manifest per case pin of a population file; returns the paths written."""
|
|
|
|
|
out.mkdir(parents=True, exist_ok=True)
|
|
|
|
|
written: list[Path] = []
|
|
|
|
|
for case in tomllib.loads(population.read_text(encoding="utf-8"))["case"]:
|
|
|
|
|
benign = case["benign"]
|
|
|
|
|
pins = {"vulnerable": case["vulnerable"], "fixed": case["fixed"], "benign-base": benign["base"], "benign-tip": benign["tip"]}
|
|
|
|
|
for label, commit in pins.items():
|
|
|
|
|
name = _ax_name(case["id"], label)
|
2026-09-29 18:36:29 +02:00
|
|
|
doc = _doc("Workspace", name, {"git": [{"name": "repo", "repo": case["repo"], "dir": "repo", "depth": 1}]})
|
|
|
|
|
doc["metadata"]["annotations"] = {GIT_COMMITS_ANNOTATION: f"repo={commit}"}
|
2026-09-29 18:10:09 +02:00
|
|
|
text = f"# generated by `ousast plane workspaces` from {population.name}\n" + yaml.safe_dump(doc, sort_keys=False)
|
|
|
|
|
(out / f"{name}.yaml").write_text(text, encoding="utf-8")
|
|
|
|
|
written.append(out / f"{name}.yaml")
|
|
|
|
|
return written
|