feat(valid-detection-benchmark): 9.1 route catalog, verification, and assembly through new authorities

This commit is contained in:
Marius Ciepluch
2026-11-21 12:41:42 +01:00
parent 3a9f1d12ab
commit a7adc99d31
5 changed files with 674 additions and 2 deletions
+45 -1
View File
@@ -1,4 +1,8 @@
"""Freeze verified positives and deterministic ordinary draws with a held-out guard."""
"""Development-only legacy assembly of verified positives and deterministic ordinary draws.
Replacement admission freezes delegate to the population authority through
:func:`replacement_freeze`; this facade never emits an admission-class manifest
of its own, and its freeze records carry a development-only admission class."""
from __future__ import annotations
@@ -15,8 +19,11 @@ from benchmarks.unseen.eligibility import normalize
from benchmarks.unseen.journal import digest
from .catalog import local_git
from .population_freeze import PopulationFreezeV3, freeze_population
from .verify import verdict
LEGACY_FREEZE_ADMISSION_CLASS = "legacy_development_only"
def negatives(
rows: list[dict], fixes: set[str], functions: set[tuple[str, str]], *, count: int, seed: int, floor: int = extract.ORDINARY_FLOOR
@@ -163,6 +170,7 @@ def freeze(
ordinary_floor=floor,
history_limit=history_limit,
label_check_counts={"confirmed": sum(len(v) for v in retained.values()), "unchecked": 0, "unclear": 0, "refactor": 0},
admission_class=LEGACY_FREEZE_ADMISSION_CLASS,
)
payloads = [
(directory / "pool-valid.toml", text.encode()),
@@ -178,6 +186,42 @@ def freeze(
return record
def replacement_freeze(
positives,
*,
ordinary_selection,
reservation_census,
reservation_authority,
scope_minimums=(),
exclusion_counts=(),
source_provenance_digest,
freeze_policy_digest,
expected_ecosystem_policy_digest,
expected_ground_truth_policy_digest,
forbidden_historical_identities=(),
) -> PopulationFreezeV3:
"""Delegate replacement freezing to the population authority.
The legacy facade holds no freezing logic of its own: reviewed positives, the
ordinary selection, the reservation census, and the artifact contract stay with
their authorities, so an admission-class artifact can never be produced from
legacy assembly output.
"""
return freeze_population(
positives,
ordinary_selection=ordinary_selection,
reservation_census=reservation_census,
reservation_authority=reservation_authority,
scope_minimums=scope_minimums,
exclusion_counts=exclusion_counts,
source_provenance_digest=source_provenance_digest,
freeze_policy_digest=freeze_policy_digest,
expected_ecosystem_policy_digest=expected_ecosystem_policy_digest,
expected_ground_truth_policy_digest=expected_ground_truth_policy_digest,
forbidden_historical_identities=forbidden_historical_identities,
)
def main(argv=None):
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("catalog", type=Path)
+34
View File
@@ -30,6 +30,8 @@ from benchmarks.valid.fix_site_catalog import (
build_fix_site_candidate,
fix_site_candidate_bytes,
)
from benchmarks.valid.reservation import RepositoryIdentityResolver
from openultrasast.core.canonical import bytes_digest, content_digest
LANGUAGES = {
".py": "python",
@@ -150,6 +152,37 @@ def write_catalog(path: Path, cases: list[dict[str, Any]]) -> None:
path.write_text(text, encoding="utf-8")
def candidate_request(
case: Mapping[str, Any],
*,
resolver: RepositoryIdentityResolver,
package_evidence: PackageEcosystemEvidence,
license_evidence: LicenseEvidence,
) -> FixSiteRequest:
"""Route one legacy fix-site case into the review authority's candidate request.
Repository identity comes from the reservation authority's reviewed network
registry, the advisory remains the source evidence with its own content digest,
and package plus license evidence must be supplied from reviewed repository
material because the legacy catalog never recorded them.
"""
advisory_text = str(case.get("advisory_text", ""))
if not advisory_text.strip():
raise ValueError("advisory text is required for source evidence")
return FixSiteRequest(
repository=resolver.resolve(str(case["url"])),
vulnerable_parent=str(case["parent"]),
fixed_revision=str(case["commit"]),
path=str(case["path"]),
function=str(case["function"]),
observed_language=str(case["language"]),
package_evidence=package_evidence,
license_evidence=license_evidence,
source_evidence=SourceEvidence("security_advisory", str(case["advisory"]), bytes_digest(advisory_text.encode("utf-8"))),
change_inputs_digest=content_digest({"parent": case["parent"], "fixed": case["commit"]}),
)
def main(argv: Sequence[str] | None = None) -> int:
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("sources", type=Path, help="JSON array of resolved Candidate dictionaries with CWE and advisory_text")
@@ -182,6 +215,7 @@ __all__ = [
"SourceEvidence",
"build_cases",
"build_fix_site_candidate",
"candidate_request",
"fix_site_candidate_bytes",
"local_git",
"main",
+73
View File
@@ -6,15 +6,30 @@ import argparse
import json
import math
import tomllib
from collections.abc import Mapping
from datetime import date
from pathlib import Path
from openultrasast.core.canonical import content_digest
from openultrasast.model.endpoint import DEFAULT_DETECTOR_MODEL, DeepSeekChatClient, resolve_chat_endpoint
from openultrasast.ruleset.frameworks import load_frameworks
from .catalog import local_git, read_functions
from .ground_truth_review import GroundTruthAttestationV1
CHECKS = ("vulnerable_pre_fix", "fix_addresses_it", "reachable_in_repo")
MODEL_ASSISTANCE_SCHEMA = "openultrasast.valid-detection-benchmark.model-assistance.v1"
_HUMAN_ATTESTATION_FIELDS = (
"producer_identity",
"reviewer_identity",
"conflict_disclosed",
"policy_digest",
"policy_satisfied",
"defect_present",
"fix_addresses",
"in_repository_reachable",
"verified_scopes",
)
def verdict(record: dict) -> str:
@@ -95,6 +110,64 @@ def spot_check(record: dict, decision: str, reviewer: str, checked_date: str) ->
return updated
def model_assistance(record: Mapping[str, object]) -> dict[str, object]:
"""Record the model's checks as separately identified non-authoritative assistance."""
return {
"schema_version": MODEL_ASSISTANCE_SCHEMA,
"case_id": record.get("id"),
"assistance_kind": "model_review_assistance",
"authoritative": False,
"model": record.get("model"),
"checks": {key: record.get(key) for key in (*CHECKS, "advisory_cited")},
"entry_point": record.get("entry_point"),
"confidence": record.get("confidence"),
}
def model_assistance_digest(record: Mapping[str, object]) -> str:
"""Bind model assistance to its own content identity, never to a label."""
return content_digest(model_assistance(record))
def review_attestation(
record: Mapping[str, object],
*,
candidate_digest: str,
ecosystem_review_digest: str,
human_judgment: Mapping[str, object],
) -> GroundTruthAttestationV1:
"""Adapt one legacy verification record to the review authority.
The record's model checks, confidence, and any legacy ``human_spot_check`` fields are
routed only as separately identified non-authoritative assistance; they can never
satisfy the required human judgment. Every authoritative judgment, reviewer identity,
disclosure, and policy value must arrive through the externally governed
``human_judgment`` mapping, which must carry exactly the review-authority
attestation fields; the review authority itself then validates their semantics.
"""
if not isinstance(human_judgment, Mapping):
raise ValueError("human judgment is required; a legacy verification record cannot supply it")
fields = set(human_judgment)
if fields != set(_HUMAN_ATTESTATION_FIELDS):
missing = sorted(set(_HUMAN_ATTESTATION_FIELDS) - fields)
unknown = sorted(fields - set(_HUMAN_ATTESTATION_FIELDS))
raise ValueError(f"human judgment must carry exactly the attestation fields: missing={missing}, unknown={unknown}")
return GroundTruthAttestationV1(
candidate_digest=candidate_digest,
ecosystem_review_digest=ecosystem_review_digest,
producer_identity=str(human_judgment["producer_identity"]),
reviewer_identity=str(human_judgment["reviewer_identity"]),
conflict_disclosed=human_judgment["conflict_disclosed"],
policy_digest=str(human_judgment["policy_digest"]),
policy_satisfied=human_judgment["policy_satisfied"],
defect_present=human_judgment["defect_present"],
fix_addresses=human_judgment["fix_addresses"],
in_repository_reachable=human_judgment["in_repository_reachable"],
verified_scopes=tuple(human_judgment["verified_scopes"]),
model_assistance_digest=model_assistance_digest(record),
)
def write_records(path: Path, records: list[dict]) -> None:
if len({row["id"] for row in records}) != len(records):
raise ValueError("duplicate verification id")