mirror of
https://github.com/norandom/OpenUltraSAST.git
synced 2026-11-13 09:48:18 +00:00
feat(detection-core): migrate benchmark readiness and admission consumers
This commit is contained in:
@@ -12,9 +12,9 @@ import statistics
|
||||
from datetime import date
|
||||
from pathlib import Path
|
||||
|
||||
from benchmarks.ax.batch import write_json
|
||||
from benchmarks.unseen.replay import canonical, load_slice, run_replays, sample_changes
|
||||
from benchmarks.unseen.score import coverage, load_records
|
||||
from benchmarks.valid.artifact_contract import write_benchmark_artifact
|
||||
|
||||
|
||||
def stage_times(record):
|
||||
@@ -120,7 +120,7 @@ def main():
|
||||
result.update(
|
||||
image=args.image, deadline_seconds=args.deadline, sample_digest=hashlib.sha256(canonical([c["id"] for c in changes])).hexdigest()
|
||||
)
|
||||
write_json(args.record, result)
|
||||
write_benchmark_artifact(args.record, "deadline-calibration", result, replace=True)
|
||||
return 0 if result["status"] == "ok" else 2
|
||||
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@ from pathlib import Path
|
||||
|
||||
from benchmarks.ax.batch import AXLane, DockerLane, Item, Workload, dispatch, write_json
|
||||
from benchmarks.unseen.score import coverage
|
||||
from benchmarks.valid.artifact_contract import read_benchmark_artifact, write_benchmark_sequence
|
||||
|
||||
|
||||
def make_item(change, arm, image, *, deadline_scale=1.0, lane="ax", deadline=None):
|
||||
@@ -180,7 +181,7 @@ def main():
|
||||
changes = load_slice(args.manifest, args.slice, args.private_manifest)
|
||||
factor = args.deadline_scale
|
||||
if args.calibration:
|
||||
calibration = json.loads(args.calibration.read_text())
|
||||
calibration = read_benchmark_artifact(args.calibration, "deadline-calibration")
|
||||
if calibration.get("status") != "ok" or calibration.get("image") != args.image:
|
||||
parser.error("calibration must be successful and match the replay image")
|
||||
factor = calibration["quick_total"]["factor"]
|
||||
@@ -213,9 +214,11 @@ def run_replays(changes, args, out, lane, *, deadline_scale=1.0, deadline=None):
|
||||
if out.resolve().is_relative_to(Path(__file__).resolve().parents[2]):
|
||||
raise ValueError("raw replay output must be outside the repository")
|
||||
items = [make_item(c, args.arm, args.image, deadline_scale=deadline_scale, lane=lane, deadline=deadline) for c in changes]
|
||||
write_json(
|
||||
write_benchmark_sequence(
|
||||
out / "inputs.json",
|
||||
"benchmark-arm-inputs",
|
||||
[{"item_id": item.id, "change": change, "input_digest": item.input_digest} for item, change in zip(items, changes, strict=True)],
|
||||
replace=True,
|
||||
)
|
||||
maximum = max(
|
||||
max(json.loads(i.inputs["SPEC_URL"])["deadline_seconds"], json.loads(i.inputs["SPEC_URL"])["base_deadline_seconds"]) for i in items
|
||||
@@ -240,7 +243,7 @@ def run_replays(changes, args, out, lane, *, deadline_scale=1.0, deadline=None):
|
||||
return record
|
||||
|
||||
executors[name] = execute
|
||||
return dispatch(items, workload, out, executors, lanes=lanes)
|
||||
return dispatch(items, workload, out, executors, lanes=lanes, record_kind="benchmark-arm-record")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
@@ -9,7 +9,13 @@ import math
|
||||
import random
|
||||
from collections import Counter, defaultdict
|
||||
from pathlib import Path
|
||||
from typing import Any, cast
|
||||
|
||||
from benchmarks.valid.artifact_contract import (
|
||||
read_benchmark_artifact,
|
||||
read_benchmark_sequence,
|
||||
write_benchmark_artifact,
|
||||
)
|
||||
from openultrasast.model.taxonomy import load_families
|
||||
from openultrasast.push.report import CAPABILITY_VETOES
|
||||
|
||||
@@ -324,13 +330,17 @@ def gate(a, b, *, slice_id=None, informed=False, binary=True, threshold=None, th
|
||||
}
|
||||
|
||||
|
||||
def load_records(path):
|
||||
def load_records(path: Path) -> list[dict[str, Any]]:
|
||||
"""Load only canonical benchmark v2 records; producer handoffs are explicit adapters."""
|
||||
path = Path(path)
|
||||
if path.is_file():
|
||||
return json.loads(path.read_text())
|
||||
rows = []
|
||||
for entry in json.loads((path / "inputs.json").read_text()):
|
||||
return [cast(dict[str, Any], row) for row in read_benchmark_sequence(path, "benchmark-arm-records")]
|
||||
rows: list[dict[str, Any]] = []
|
||||
entries = read_benchmark_sequence(path / "inputs.json", "benchmark-arm-inputs")
|
||||
for raw_entry in entries:
|
||||
entry = cast(dict[str, Any], raw_entry)
|
||||
result = path / (hashlib.sha256(entry["item_id"].encode()).hexdigest() + ".json")
|
||||
record = json.loads(result.read_text()) if result.exists() else {}
|
||||
record: dict[str, Any] = cast(dict[str, Any], read_benchmark_artifact(result, "benchmark-arm-record")) if result.exists() else {}
|
||||
if record.get("input_digest") != entry["input_digest"]:
|
||||
record = {}
|
||||
rows.append({**entry["change"], **record, "id": entry["change"]["id"]})
|
||||
@@ -356,7 +366,7 @@ def main():
|
||||
result["unseen"] = gate(load_records(args.against) if args.against else [], current, slice_id=args.slice_id, informed=args.informed)
|
||||
if native and result["flagged"]:
|
||||
result["unseen"] = {"gate": "not_run", "reason": "native_agreement"}
|
||||
args.out.write_text(json.dumps(result, sort_keys=True, indent=2) + "\n")
|
||||
write_benchmark_artifact(args.out, "unseen-score", result, replace=True)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in New Issue
Block a user