mirror of
https://github.com/norandom/OpenUltraSAST.git
synced 2026-10-19 13:10:03 +00:00
34 lines
1.5 KiB
Python
34 lines
1.5 KiB
Python
"""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,
|
||
|
|
fixed, benign base, benign tip) with the case's repository URL and the pinned commit, 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()``.
|
||
|
|
"""
|
||
|
|
|
||
|
|
from __future__ import annotations
|
||
|
|
|
||
|
|
import tomllib
|
||
|
|
from pathlib import Path
|
||
|
|
|
||
|
|
import yaml
|
||
|
|
|
||
|
|
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)
|
||
|
|
doc = _doc("Workspace", name, {"git": [{"name": "repo", "repo": case["repo"], "commit": commit}]})
|
||
|
|
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
|