mirror of
https://github.com/norandom/OpenUltraSAST.git
synced 2026-12-04 10:48:19 +00:00
feat(detection-core): assemble complete evaluation replay
This commit is contained in:
@@ -652,7 +652,7 @@ contract work and use synthetic/in-memory workflow boundaries only.
|
|||||||
- _Boundary: Evaluation Aggregate_
|
- _Boundary: Evaluation Aggregate_
|
||||||
|
|
||||||
- [ ] 17. Close complete replay and replay-only consumer authorization
|
- [ ] 17. Close complete replay and replay-only consumer authorization
|
||||||
- [ ] 17.1 Assemble one complete replay over the shared evaluation graph
|
- [x] 17.1 Assemble one complete replay over the shared evaluation graph
|
||||||
- Bind the reviewed plan, exact feasibility, reviewed admission authority, preparation, receipt, all-arm spend binding, attempt-history head, V3 release, cases, per-arm reports, combination lineages, shared whole coverage, and optional aggregate.
|
- Bind the reviewed plan, exact feasibility, reviewed admission authority, preparation, receipt, all-arm spend binding, attempt-history head, V3 release, cases, per-arm reports, combination lineages, shared whole coverage, and optional aggregate.
|
||||||
- Require exact equality between planned arms/scopes and case/report identities, including every component required by a combined arm.
|
- Require exact equality between planned arms/scopes and case/report identities, including every component required by a combined arm.
|
||||||
- Prevent replay construction when any arm, scope, mandatory gate, custody binding, release, case, component, or lineage is missing or invalid.
|
- Prevent replay construction when any arm, scope, mandatory gate, custody binding, release, case, component, or lineage is missing or invalid.
|
||||||
@@ -751,6 +751,7 @@ contract work and use synthetic/in-memory workflow boundaries only.
|
|||||||
- Task 16.3 derives the complete seven-metric bundle with fixed algebra and Wilson intervals only after exact census and released-lineage reconciliation, treating zero denominators, missing metrics, or inconsistent projections as invalid evidence.
|
- Task 16.3 derives the complete seven-metric bundle with fixed algebra and Wilson intervals only after exact census and released-lineage reconciliation, treating zero denominators, missing metrics, or inconsistent projections as invalid evidence.
|
||||||
- Task 16.4 emits non-authorizing completed scope reports only after canonical gate, operational, observation, release, and combination-lineage replay; incomplete or impaired measurement remains outside GO/NO-GO.
|
- Task 16.4 emits non-authorizing completed scope reports only after canonical gate, operational, observation, release, and combination-lineage replay; incomplete or impaired measurement remains outside GO/NO-GO.
|
||||||
- Task 16.5 derives optional aggregates only from complete canonical scoped metrics using exact rational weights and reproducible constituent identities, while exposing no gate, decision, proof, or authorization capability.
|
- Task 16.5 derives optional aggregates only from complete canonical scoped metrics using exact rational weights and reproducible constituent identities, while exposing no gate, decision, proof, or authorization capability.
|
||||||
|
- Task 17.1 assembles one deterministic non-authorizing replay from the complete source-rooted plan-to-report graph, rederiving reports, whole coverage, release bindings, and combination lineage while rejecting partial, forged, or noncanonical inputs.
|
||||||
- The frozen migration inventory is a reviewed worklist with stable identities, not a semantic-use census. It may only close entries as `v2_migrated` or `retired`; it never grows, deletes entries, or proves absence by interpreting Python flow.
|
- The frozen migration inventory is a reviewed worklist with stable identities, not a semantic-use census. It may only close entries as `v2_migrated` or `retired`; it never grows, deletes entries, or proves absence by interpreting Python flow.
|
||||||
- Cutover is proved by explicit syntax checks plus deletion of the compatibility and v1 write capability. No task extends the discarded alias/data-flow interpreter.
|
- Cutover is proved by explicit syntax checks plus deletion of the compatibility and v1 write capability. No task extends the discarded alias/data-flow interpreter.
|
||||||
- Task 10.5 debug established that executable owner probes cannot compensate for blanket source-closure acceptance; resumed hunt attempts also require collision-resistant attempt identity and create-only persistence before handoff validation is authoritative.
|
- Task 10.5 debug established that executable owner probes cannot compensate for blanket source-closure acceptance; resumed hunt attempts also require collision-resistant attempt identity and create-only persistence before handoff validation is authoritative.
|
||||||
|
|||||||
@@ -0,0 +1,120 @@
|
|||||||
|
"""Replay-carried sources and deterministic report reproduction."""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import re
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
|
from openultrasast.core import canonical
|
||||||
|
from openultrasast.core.evaluation_aggregate import validate_evaluation_aggregate_v3
|
||||||
|
from openultrasast.core.evaluation_measurement import ScopedMetricResultV3
|
||||||
|
from openultrasast.core.evaluation_observation import ArmObservationSetV3
|
||||||
|
from openultrasast.core.evaluation_ordinary_projection import WholePopulationProjectionV3
|
||||||
|
from openultrasast.core.evaluation_report import _metric_digest, derive_completed_evaluation_reports_v3
|
||||||
|
from openultrasast.core.evaluation_version import require_exact_v3_contract
|
||||||
|
from openultrasast.core.readiness import ReadinessResult, validate_readiness_result
|
||||||
|
|
||||||
|
_SCHEMA = "openultrasast.detection-core.evaluation-replay-report-source.v3"
|
||||||
|
_DIGEST = re.compile(r"[0-9a-f]{64}")
|
||||||
|
|
||||||
|
|
||||||
|
class EvaluationReplayReportError(ValueError):
|
||||||
|
"""Replay reports do not reproduce from their carried canonical sources."""
|
||||||
|
|
||||||
|
|
||||||
|
def _bind(value: object, field: str, expected: str) -> None:
|
||||||
|
actual = getattr(value, field)
|
||||||
|
if actual == "":
|
||||||
|
object.__setattr__(value, field, expected)
|
||||||
|
elif type(actual) is not str or _DIGEST.fullmatch(actual) is None or actual != expected:
|
||||||
|
raise EvaluationReplayReportError(f"{field} does not match canonical report-source content")
|
||||||
|
|
||||||
|
|
||||||
|
def _source_payload(value: Any) -> canonical.JsonValue:
|
||||||
|
return {
|
||||||
|
"metric_digests": tuple(_metric_digest(metric) for metric in value.metrics),
|
||||||
|
"readiness_digests": tuple(item.result_digest for item in value.readiness),
|
||||||
|
"observation_digests": tuple(item.observation_digest for item in value.observations),
|
||||||
|
"whole_projection_digest": value.whole_projection.projection_digest,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def validate_report_source(value: Any) -> None:
|
||||||
|
from openultrasast.core.evaluation_replay import EvaluationReplayReportSourceV3
|
||||||
|
|
||||||
|
require_exact_v3_contract(value, EvaluationReplayReportSourceV3, field="evaluation replay report source")
|
||||||
|
if type(value.metrics) is not tuple or not value.metrics or any(type(item) is not ScopedMetricResultV3 for item in value.metrics):
|
||||||
|
raise EvaluationReplayReportError("report-source metrics must be a nonempty exact tuple")
|
||||||
|
if type(value.readiness) is not tuple or any(type(item) is not ReadinessResult for item in value.readiness):
|
||||||
|
raise EvaluationReplayReportError("report-source readiness must use an exact tuple")
|
||||||
|
if type(value.observations) is not tuple or any(type(item) is not ArmObservationSetV3 for item in value.observations):
|
||||||
|
raise EvaluationReplayReportError("report-source observations must use an exact tuple")
|
||||||
|
if type(value.whole_projection) is not WholePopulationProjectionV3:
|
||||||
|
raise EvaluationReplayReportError("report-source whole projection must use the exact V3 contract")
|
||||||
|
for metric in value.metrics:
|
||||||
|
metric.__post_init__()
|
||||||
|
for readiness in value.readiness:
|
||||||
|
validate_readiness_result(readiness)
|
||||||
|
for observation in value.observations:
|
||||||
|
observation.__post_init__()
|
||||||
|
value.whole_projection.__post_init__()
|
||||||
|
payload = _source_payload(value)
|
||||||
|
_bind(value, "source_digest", canonical.content_digest({"schema_version": _SCHEMA, "payload": payload}))
|
||||||
|
|
||||||
|
|
||||||
|
def validate_replayed_reports(value: Any) -> None:
|
||||||
|
"""Reproduce reports and coverage from replay-carried sources, then bind an optional aggregate."""
|
||||||
|
from openultrasast.core.evaluation_replay import EvaluationReplayReportSourceV3
|
||||||
|
|
||||||
|
source = value.report_source
|
||||||
|
if type(source) is not EvaluationReplayReportSourceV3:
|
||||||
|
raise EvaluationReplayReportError("replay report source must use exact EvaluationReplayReportSourceV3")
|
||||||
|
source.__post_init__()
|
||||||
|
if tuple(item.result_digest for item in source.readiness) != value.plan_manifest.readiness_digests:
|
||||||
|
raise EvaluationReplayReportError("report-source readiness order must exactly equal the reviewed plan")
|
||||||
|
try:
|
||||||
|
reports, whole = derive_completed_evaluation_reports_v3(
|
||||||
|
value.plan_manifest,
|
||||||
|
value.cases_by_arm,
|
||||||
|
source.metrics,
|
||||||
|
source.readiness,
|
||||||
|
source.observations,
|
||||||
|
value.combination_lineages,
|
||||||
|
source.whole_projection,
|
||||||
|
)
|
||||||
|
if value.reports != reports or value.whole_population_coverage != whole:
|
||||||
|
raise EvaluationReplayReportError("reports or whole coverage do not rederive from replay-carried sources")
|
||||||
|
metrics = tuple(metric for report in reports for result in report.scoped_results for metric in result.metrics)
|
||||||
|
if value.aggregate is not None:
|
||||||
|
validate_evaluation_aggregate_v3(value.aggregate, metrics)
|
||||||
|
except EvaluationReplayReportError:
|
||||||
|
raise
|
||||||
|
except (AttributeError, KeyError, LookupError, TypeError, ValueError) as exc:
|
||||||
|
raise EvaluationReplayReportError(f"report source replay refused invalid evidence: {exc}") from exc
|
||||||
|
|
||||||
|
|
||||||
|
def validate_replay_collections(value: Any) -> None:
|
||||||
|
from openultrasast.core.evaluation_aggregate import EvaluationAggregateV3
|
||||||
|
from openultrasast.core.evaluation_combination import CombinationLineageV3
|
||||||
|
from openultrasast.core.evaluation_release import ArmAdmissionCasesV3
|
||||||
|
from openultrasast.core.evaluation_replay import EvaluationReplayReportSourceV3
|
||||||
|
from openultrasast.core.evaluation_report import ArmEvaluationReportV3
|
||||||
|
|
||||||
|
collections = (
|
||||||
|
(value.cases_by_arm, ArmAdmissionCasesV3, "case groups"),
|
||||||
|
(value.reports, ArmEvaluationReportV3, "reports"),
|
||||||
|
(value.combination_lineages, CombinationLineageV3, "combination lineages"),
|
||||||
|
)
|
||||||
|
for items, item_type, field in collections:
|
||||||
|
if type(items) is not tuple or any(type(item) is not item_type for item in items):
|
||||||
|
raise EvaluationReplayReportError(f"{field} must use an exact tuple of {item_type.__name__}")
|
||||||
|
for item in items:
|
||||||
|
item.__post_init__()
|
||||||
|
if type(value.report_source) is not EvaluationReplayReportSourceV3:
|
||||||
|
raise EvaluationReplayReportError("report source must use exact EvaluationReplayReportSourceV3")
|
||||||
|
value.report_source.__post_init__()
|
||||||
|
if value.aggregate is not None and type(value.aggregate) is not EvaluationAggregateV3:
|
||||||
|
raise EvaluationReplayReportError("aggregate must use exact EvaluationAggregateV3 when present")
|
||||||
|
|
||||||
|
|
||||||
|
__all__ = ["EvaluationReplayReportError", "validate_replay_collections", "validate_report_source", "validate_replayed_reports"]
|
||||||
@@ -0,0 +1,385 @@
|
|||||||
|
"""Complete non-authorizing evaluation replay construction for admission V3."""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import re
|
||||||
|
from dataclasses import dataclass
|
||||||
|
from typing import ClassVar
|
||||||
|
|
||||||
|
from openultrasast.core import canonical
|
||||||
|
from openultrasast.core._evaluation_replay_report import (
|
||||||
|
EvaluationReplayReportError,
|
||||||
|
validate_replay_collections,
|
||||||
|
validate_replayed_reports,
|
||||||
|
validate_report_source,
|
||||||
|
)
|
||||||
|
from openultrasast.core.custody import (
|
||||||
|
PopulationStatus,
|
||||||
|
PopulationUseReceipt,
|
||||||
|
derive_population_use_receipt_digest,
|
||||||
|
derive_population_use_request_digest,
|
||||||
|
)
|
||||||
|
from openultrasast.core.evaluation_aggregate import EvaluationAggregateV3
|
||||||
|
from openultrasast.core.evaluation_authority import (
|
||||||
|
EvaluationAdmissionAuthorityV3,
|
||||||
|
EvaluationAdmissionManifestV3,
|
||||||
|
derive_evaluation_admission_manifest_digest,
|
||||||
|
derive_evaluation_admission_manifest_payload_digest,
|
||||||
|
derive_evaluation_observation_set_digest,
|
||||||
|
derive_evaluation_readiness_set_digest,
|
||||||
|
)
|
||||||
|
from openultrasast.core.evaluation_combination import CombinationLineageV3, derive_combination_lineages_v3
|
||||||
|
from openultrasast.core.evaluation_feasibility import EvaluationFeasibilityV3
|
||||||
|
from openultrasast.core.evaluation_measurement import ScopedMetricResultV3
|
||||||
|
from openultrasast.core.evaluation_observation import ArmObservationSetV3
|
||||||
|
from openultrasast.core.evaluation_ordinary_projection import WholePopulationProjectionV3
|
||||||
|
from openultrasast.core.evaluation_plan import (
|
||||||
|
EvaluationPlanManifestV3,
|
||||||
|
derive_evaluation_plan_manifest_digest,
|
||||||
|
derive_evaluation_plan_manifest_payload_digest,
|
||||||
|
)
|
||||||
|
from openultrasast.core.evaluation_release import (
|
||||||
|
AdmissionCaseReleaseV3,
|
||||||
|
ArmAdmissionCasesV3,
|
||||||
|
ReleasedArmCaseBindingV3,
|
||||||
|
derive_admission_case_release_digest_v3,
|
||||||
|
derive_admission_case_release_payload_digest_v3,
|
||||||
|
derive_released_arm_case_binding,
|
||||||
|
)
|
||||||
|
from openultrasast.core.evaluation_report import ArmEvaluationReportV3, WholePopulationCoverageV3
|
||||||
|
from openultrasast.core.evaluation_spend import EvaluationPreparationV3, EvaluationSpendBindingV3
|
||||||
|
from openultrasast.core.evaluation_version import (
|
||||||
|
EVALUATION_ADMISSION_V3_SCHEMA,
|
||||||
|
EvaluationV3Contract,
|
||||||
|
NonAuthorizingV3,
|
||||||
|
require_exact_v3_contract,
|
||||||
|
)
|
||||||
|
from openultrasast.core.readiness import ReadinessResult
|
||||||
|
|
||||||
|
_SCHEMA = "openultrasast.detection-core.evaluation-replay.v3"
|
||||||
|
_DIGEST = re.compile(r"[0-9a-f]{64}")
|
||||||
|
|
||||||
|
|
||||||
|
class EvaluationReplayError(ValueError):
|
||||||
|
"""A complete replay could not be assembled from the exact shared graph."""
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(frozen=True)
|
||||||
|
class EvaluationReplayReportSourceV3(EvaluationV3Contract, NonAuthorizingV3):
|
||||||
|
"""Exact source artifacts required to reproduce completed reports inside a replay."""
|
||||||
|
|
||||||
|
__evaluation_v3_contract_schema__: ClassVar[str] = EVALUATION_ADMISSION_V3_SCHEMA
|
||||||
|
metrics: tuple[ScopedMetricResultV3, ...]
|
||||||
|
readiness: tuple[ReadinessResult, ...]
|
||||||
|
observations: tuple[ArmObservationSetV3, ...]
|
||||||
|
whole_projection: WholePopulationProjectionV3
|
||||||
|
source_digest: str
|
||||||
|
|
||||||
|
def __post_init__(self) -> None:
|
||||||
|
try:
|
||||||
|
validate_report_source(self)
|
||||||
|
except EvaluationReplayReportError as exc:
|
||||||
|
raise EvaluationReplayError(f"report source is invalid: {exc}") from exc
|
||||||
|
|
||||||
|
|
||||||
|
def _digest(value: object, field: str) -> str:
|
||||||
|
if type(value) is not str or _DIGEST.fullmatch(value) is None:
|
||||||
|
raise EvaluationReplayError(f"{field} must be a full lowercase SHA-256 digest")
|
||||||
|
return value
|
||||||
|
|
||||||
|
|
||||||
|
def _bind(value: object, field: str, expected: str) -> None:
|
||||||
|
actual = getattr(value, field)
|
||||||
|
if actual == "":
|
||||||
|
object.__setattr__(value, field, expected)
|
||||||
|
elif _digest(actual, field) != expected:
|
||||||
|
raise EvaluationReplayError(f"{field} does not match canonical replay content")
|
||||||
|
|
||||||
|
|
||||||
|
def _payload(value: EvaluationReplayV3) -> canonical.JsonValue:
|
||||||
|
return {
|
||||||
|
"plan_manifest_digest": value.plan_manifest.manifest_digest,
|
||||||
|
"feasibility_digest": value.feasibility.feasibility_digest,
|
||||||
|
"admission_manifest_digest": value.admission_manifest.manifest_digest,
|
||||||
|
"authority_digest": value.authority.authority_digest,
|
||||||
|
"preparation_digest": value.preparation.preparation_digest,
|
||||||
|
"receipt_digest": value.receipt.receipt_digest,
|
||||||
|
"spend_binding_digest": value.spend_binding.binding_digest,
|
||||||
|
"case_release_digest": value.case_release.release_digest,
|
||||||
|
"case_group_digests": tuple(group.cases_digest for group in value.cases_by_arm),
|
||||||
|
"report_source_digest": value.report_source.source_digest,
|
||||||
|
"report_digests": tuple(report.report_digest for report in value.reports),
|
||||||
|
"combination_lineage_digests": tuple(lineage.lineage_digest for lineage in value.combination_lineages),
|
||||||
|
"attempt_history_head_digest": value.attempt_history_head_digest,
|
||||||
|
"whole_population_coverage_digest": value.whole_population_coverage.coverage_digest,
|
||||||
|
"aggregate_digest": None if value.aggregate is None else value.aggregate.aggregate_digest,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(frozen=True)
|
||||||
|
class EvaluationReplayV3(EvaluationV3Contract, NonAuthorizingV3):
|
||||||
|
__evaluation_v3_contract_schema__: ClassVar[str] = EVALUATION_ADMISSION_V3_SCHEMA
|
||||||
|
plan_manifest: EvaluationPlanManifestV3
|
||||||
|
feasibility: EvaluationFeasibilityV3
|
||||||
|
admission_manifest: EvaluationAdmissionManifestV3
|
||||||
|
authority: EvaluationAdmissionAuthorityV3
|
||||||
|
preparation: EvaluationPreparationV3
|
||||||
|
receipt: PopulationUseReceipt
|
||||||
|
spend_binding: EvaluationSpendBindingV3
|
||||||
|
case_release: AdmissionCaseReleaseV3
|
||||||
|
cases_by_arm: tuple[ArmAdmissionCasesV3, ...]
|
||||||
|
report_source: EvaluationReplayReportSourceV3
|
||||||
|
reports: tuple[ArmEvaluationReportV3, ...]
|
||||||
|
combination_lineages: tuple[CombinationLineageV3, ...]
|
||||||
|
attempt_history_head_digest: str
|
||||||
|
whole_population_coverage: WholePopulationCoverageV3
|
||||||
|
aggregate: EvaluationAggregateV3 | None
|
||||||
|
replay_digest: str
|
||||||
|
|
||||||
|
def __post_init__(self) -> None:
|
||||||
|
require_exact_v3_contract(self, EvaluationReplayV3, field="evaluation replay")
|
||||||
|
_validate_complete_replay(self)
|
||||||
|
_bind(
|
||||||
|
self,
|
||||||
|
"replay_digest",
|
||||||
|
canonical.content_digest({"schema_version": _SCHEMA, "kind": "evaluation_replay", "payload": _payload(self)}),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def _validate_roots(value: EvaluationReplayV3) -> None:
|
||||||
|
exact = (
|
||||||
|
(value.plan_manifest, EvaluationPlanManifestV3, "plan"),
|
||||||
|
(value.feasibility, EvaluationFeasibilityV3, "feasibility"),
|
||||||
|
(value.admission_manifest, EvaluationAdmissionManifestV3, "admission manifest"),
|
||||||
|
(value.authority, EvaluationAdmissionAuthorityV3, "authority"),
|
||||||
|
(value.preparation, EvaluationPreparationV3, "preparation"),
|
||||||
|
(value.receipt, PopulationUseReceipt, "receipt"),
|
||||||
|
(value.spend_binding, EvaluationSpendBindingV3, "spend binding"),
|
||||||
|
(value.case_release, AdmissionCaseReleaseV3, "case release"),
|
||||||
|
(value.whole_population_coverage, WholePopulationCoverageV3, "whole population coverage"),
|
||||||
|
)
|
||||||
|
for item, item_type, field in exact:
|
||||||
|
if type(item) is not item_type:
|
||||||
|
raise EvaluationReplayError(f"{field} must use exact {item_type.__name__}")
|
||||||
|
item.__post_init__()
|
||||||
|
try:
|
||||||
|
validate_replay_collections(value)
|
||||||
|
except EvaluationReplayReportError as exc:
|
||||||
|
raise EvaluationReplayError(f"replay collection is invalid: {exc}") from exc
|
||||||
|
|
||||||
|
|
||||||
|
def _validate_pre_spend_graph(value: EvaluationReplayV3) -> None:
|
||||||
|
plan = value.plan_manifest
|
||||||
|
admission = value.admission_manifest
|
||||||
|
if plan.payload_digest != derive_evaluation_plan_manifest_payload_digest(
|
||||||
|
plan
|
||||||
|
) or plan.manifest_digest != derive_evaluation_plan_manifest_digest(plan):
|
||||||
|
raise EvaluationReplayError("reviewed plan identity is not canonical")
|
||||||
|
if plan.review.subject_digest != plan.payload_digest or plan.census.review.subject_digest != plan.census.payload_digest:
|
||||||
|
raise EvaluationReplayError("reviewed plan or census review is not bound to its canonical payload")
|
||||||
|
expected_keys = tuple(
|
||||||
|
policy.key for configuration in plan.declaration.arm_configurations for policy in configuration.denominator_policies
|
||||||
|
)
|
||||||
|
if value.feasibility.plan_manifest_digest != plan.manifest_digest or tuple(row.key for row in value.feasibility.rows) != expected_keys:
|
||||||
|
raise EvaluationReplayError("feasibility does not completely match the reviewed plan")
|
||||||
|
if not value.feasibility.may_spend:
|
||||||
|
raise EvaluationReplayError("complete replay requires feasible shared spend")
|
||||||
|
if admission.plan_manifest != plan or admission.feasibility_digest != value.feasibility.feasibility_digest:
|
||||||
|
raise EvaluationReplayError("admission manifest differs from the exact plan or feasibility")
|
||||||
|
if admission.payload_digest != derive_evaluation_admission_manifest_payload_digest(
|
||||||
|
admission
|
||||||
|
) or admission.manifest_digest != derive_evaluation_admission_manifest_digest(admission):
|
||||||
|
raise EvaluationReplayError("admission manifest identity is not canonical")
|
||||||
|
if admission.review.subject_digest != admission.payload_digest:
|
||||||
|
raise EvaluationReplayError("admission review is not bound to its canonical payload")
|
||||||
|
expected = (
|
||||||
|
admission.manifest_digest,
|
||||||
|
plan.manifest_digest,
|
||||||
|
tuple(baseline.baseline_digest for baseline in plan.baselines),
|
||||||
|
value.feasibility.feasibility_digest,
|
||||||
|
derive_evaluation_observation_set_digest(admission.observations),
|
||||||
|
derive_evaluation_readiness_set_digest(admission.readiness_digests),
|
||||||
|
admission.custody_log_digest,
|
||||||
|
admission.attempt_history.head_event_digest,
|
||||||
|
admission.review.attestation_digest,
|
||||||
|
)
|
||||||
|
actual = (
|
||||||
|
value.authority.admission_manifest_digest,
|
||||||
|
value.authority.plan_manifest_digest,
|
||||||
|
value.authority.baseline_digests,
|
||||||
|
value.authority.feasibility_digest,
|
||||||
|
value.authority.observation_set_digest,
|
||||||
|
value.authority.readiness_set_digest,
|
||||||
|
value.authority.custody_log_digest,
|
||||||
|
value.authority.attempt_history_head_digest,
|
||||||
|
value.authority.admission_review_digest,
|
||||||
|
)
|
||||||
|
if actual != expected:
|
||||||
|
raise EvaluationReplayError("authority does not match the complete reviewed pre-spend graph")
|
||||||
|
|
||||||
|
|
||||||
|
def _validate_spend_graph(value: EvaluationReplayV3) -> None:
|
||||||
|
preparation = value.preparation
|
||||||
|
receipt = value.receipt
|
||||||
|
spend = value.spend_binding
|
||||||
|
baselines = tuple(item.baseline_digest for item in value.plan_manifest.baselines)
|
||||||
|
if preparation.authority != value.authority or preparation.planned_baseline_digests != baselines:
|
||||||
|
raise EvaluationReplayError("preparation does not cover the exact authority and planned arms")
|
||||||
|
population = value.plan_manifest.declaration.population_digest
|
||||||
|
if preparation.label_release_request.population_digest != population or receipt.population_digest != population:
|
||||||
|
raise EvaluationReplayError("custody receipt population differs from the reviewed plan")
|
||||||
|
if receipt.request != preparation.label_release_request:
|
||||||
|
raise EvaluationReplayError("receipt request differs from the exact preparation")
|
||||||
|
if receipt.request_digest != derive_population_use_request_digest(
|
||||||
|
receipt.request
|
||||||
|
) or receipt.receipt_digest != derive_population_use_receipt_digest(receipt):
|
||||||
|
raise EvaluationReplayError("receipt identity is not canonical")
|
||||||
|
if receipt.prior_status is not PopulationStatus.AVAILABLE or receipt.status is not PopulationStatus.SPENT:
|
||||||
|
raise EvaluationReplayError("receipt is not the exact available-to-spent custody transition")
|
||||||
|
if (spend.preparation_digest, spend.receipt_digest, spend.planned_baseline_digests) != (
|
||||||
|
preparation.preparation_digest,
|
||||||
|
receipt.receipt_digest,
|
||||||
|
baselines,
|
||||||
|
):
|
||||||
|
raise EvaluationReplayError("spend binding differs from preparation, receipt, or planned arms")
|
||||||
|
|
||||||
|
|
||||||
|
def _validate_release_and_reports(value: EvaluationReplayV3) -> tuple[ReleasedArmCaseBindingV3, ...]:
|
||||||
|
plan = value.plan_manifest
|
||||||
|
release = value.case_release
|
||||||
|
expected_release = (
|
||||||
|
plan.manifest_digest,
|
||||||
|
value.admission_manifest.manifest_digest,
|
||||||
|
value.authority.authority_digest,
|
||||||
|
value.preparation.preparation_digest,
|
||||||
|
value.spend_binding.binding_digest,
|
||||||
|
)
|
||||||
|
actual_release = (
|
||||||
|
release.plan_manifest_digest,
|
||||||
|
release.admission_manifest_digest,
|
||||||
|
release.authority_digest,
|
||||||
|
release.preparation_digest,
|
||||||
|
release.spend_binding_digest,
|
||||||
|
)
|
||||||
|
if actual_release != expected_release:
|
||||||
|
raise EvaluationReplayError("case release differs from the complete shared graph")
|
||||||
|
if release.payload_digest != derive_admission_case_release_payload_digest_v3(
|
||||||
|
release
|
||||||
|
) or release.release_digest != derive_admission_case_release_digest_v3(release):
|
||||||
|
raise EvaluationReplayError("case release identity is not canonical")
|
||||||
|
if release.review.subject_digest != release.payload_digest:
|
||||||
|
raise EvaluationReplayError("case release review is not bound to its canonical payload")
|
||||||
|
group_roots = tuple((group.arm_id, group.baseline_digest) for group in value.cases_by_arm)
|
||||||
|
planned_roots = tuple((baseline.arm_id, baseline.baseline_digest) for baseline in plan.baselines)
|
||||||
|
if group_roots != planned_roots or tuple(report.baseline for report in value.reports) != plan.baselines:
|
||||||
|
raise EvaluationReplayError("case groups and reports must completely match every planned arm")
|
||||||
|
expected_bindings = tuple(
|
||||||
|
sorted(
|
||||||
|
(derive_released_arm_case_binding(case, plan) for group in value.cases_by_arm for case in group.cases),
|
||||||
|
key=lambda item: (item.key.arm_id, item.key.scope.family_id, item.key.scope.ecosystem, item.case_id_digest),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
if release.bindings != expected_bindings:
|
||||||
|
raise EvaluationReplayError("case release bindings differ from the complete replay cases")
|
||||||
|
return expected_bindings
|
||||||
|
|
||||||
|
|
||||||
|
def _validate_reports_and_lineage(value: EvaluationReplayV3, bindings: tuple[ReleasedArmCaseBindingV3, ...]) -> None:
|
||||||
|
plan = value.plan_manifest
|
||||||
|
configurations = {item.arm_id: item for item in plan.declaration.arm_configurations}
|
||||||
|
report_by_arm = {item.baseline.arm_id: item for item in value.reports}
|
||||||
|
if len(report_by_arm) != len(value.reports):
|
||||||
|
raise EvaluationReplayError("reports must contain every planned arm exactly once")
|
||||||
|
for group in value.cases_by_arm:
|
||||||
|
report = report_by_arm[group.arm_id]
|
||||||
|
expected_keys = tuple(policy.key for policy in configurations[group.arm_id].denominator_policies)
|
||||||
|
if tuple(result.key for result in report.scoped_results) != expected_keys:
|
||||||
|
raise EvaluationReplayError("report scopes do not completely match the planned arm scopes")
|
||||||
|
completed = tuple(sorted(case.case_id_digest for case in group.cases))
|
||||||
|
if report.operational_evidence.completed_case_digests != completed or report.operational_evidence.deferred_case_digests:
|
||||||
|
raise EvaluationReplayError("report operational cases differ from the complete released arm cases")
|
||||||
|
expected_lineages = derive_combination_lineages_v3(plan.declaration, bindings)
|
||||||
|
if value.combination_lineages != expected_lineages:
|
||||||
|
raise EvaluationReplayError("combination lineage does not replay from every required component")
|
||||||
|
by_arm = {item.rule.combined_arm_id: item for item in value.combination_lineages}
|
||||||
|
for report in value.reports:
|
||||||
|
if report.combination_lineage != by_arm.get(report.baseline.arm_id):
|
||||||
|
raise EvaluationReplayError("report combination lineage differs from the complete replay")
|
||||||
|
|
||||||
|
|
||||||
|
def _validate_coverage_and_aggregate(value: EvaluationReplayV3) -> None:
|
||||||
|
pushes = {case.underlying_push_digest for group in value.cases_by_arm for case in group.cases}
|
||||||
|
coverage = value.whole_population_coverage
|
||||||
|
if (
|
||||||
|
coverage.underlying_push_count != len(pushes)
|
||||||
|
or coverage.completed_underlying_push_count != len(pushes)
|
||||||
|
or coverage.deferred_underlying_push_count != 0
|
||||||
|
):
|
||||||
|
raise EvaluationReplayError("whole population coverage does not reconcile to released cases and census")
|
||||||
|
|
||||||
|
|
||||||
|
def _validate_complete_replay(value: EvaluationReplayV3) -> None:
|
||||||
|
_validate_roots(value)
|
||||||
|
_digest(value.attempt_history_head_digest, "attempt history head digest")
|
||||||
|
_validate_pre_spend_graph(value)
|
||||||
|
if value.attempt_history_head_digest != value.admission_manifest.attempt_history.head_event_digest:
|
||||||
|
raise EvaluationReplayError("attempt history head differs from the reviewed admission graph")
|
||||||
|
_validate_spend_graph(value)
|
||||||
|
bindings = _validate_release_and_reports(value)
|
||||||
|
_validate_reports_and_lineage(value, bindings)
|
||||||
|
_validate_coverage_and_aggregate(value)
|
||||||
|
try:
|
||||||
|
validate_replayed_reports(value)
|
||||||
|
except EvaluationReplayReportError as exc:
|
||||||
|
raise EvaluationReplayError(f"report source replay failed: {exc}") from exc
|
||||||
|
|
||||||
|
|
||||||
|
def assemble_evaluation_replay_v3(
|
||||||
|
plan_manifest: EvaluationPlanManifestV3,
|
||||||
|
feasibility: EvaluationFeasibilityV3,
|
||||||
|
admission_manifest: EvaluationAdmissionManifestV3,
|
||||||
|
authority: EvaluationAdmissionAuthorityV3,
|
||||||
|
preparation: EvaluationPreparationV3,
|
||||||
|
receipt: PopulationUseReceipt,
|
||||||
|
spend_binding: EvaluationSpendBindingV3,
|
||||||
|
case_release: AdmissionCaseReleaseV3,
|
||||||
|
cases_by_arm: tuple[ArmAdmissionCasesV3, ...],
|
||||||
|
report_source: EvaluationReplayReportSourceV3,
|
||||||
|
reports: tuple[ArmEvaluationReportV3, ...],
|
||||||
|
combination_lineages: tuple[CombinationLineageV3, ...],
|
||||||
|
attempt_history_head_digest: str,
|
||||||
|
whole_population_coverage: WholePopulationCoverageV3,
|
||||||
|
aggregate: EvaluationAggregateV3 | None,
|
||||||
|
) -> EvaluationReplayV3:
|
||||||
|
"""Assemble one deterministic bundle only from the complete shared evaluation graph."""
|
||||||
|
try:
|
||||||
|
return EvaluationReplayV3(
|
||||||
|
plan_manifest,
|
||||||
|
feasibility,
|
||||||
|
admission_manifest,
|
||||||
|
authority,
|
||||||
|
preparation,
|
||||||
|
receipt,
|
||||||
|
spend_binding,
|
||||||
|
case_release,
|
||||||
|
cases_by_arm,
|
||||||
|
report_source,
|
||||||
|
reports,
|
||||||
|
combination_lineages,
|
||||||
|
attempt_history_head_digest,
|
||||||
|
whole_population_coverage,
|
||||||
|
aggregate,
|
||||||
|
"",
|
||||||
|
)
|
||||||
|
except EvaluationReplayError:
|
||||||
|
raise
|
||||||
|
except (AttributeError, KeyError, LookupError, TypeError, ValueError) as exc:
|
||||||
|
raise EvaluationReplayError(f"complete evaluation replay refused invalid evidence: {exc}") from exc
|
||||||
|
|
||||||
|
|
||||||
|
__all__ = [
|
||||||
|
"EvaluationReplayError",
|
||||||
|
"EvaluationReplayReportSourceV3",
|
||||||
|
"EvaluationReplayV3",
|
||||||
|
"assemble_evaluation_replay_v3",
|
||||||
|
]
|
||||||
@@ -0,0 +1,262 @@
|
|||||||
|
"""Complete non-authorizing evaluation replay construction for V3."""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from dataclasses import replace
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
from test_core_evaluation_case_validation import _bundle, _reference_authority_case
|
||||||
|
from test_core_evaluation_report import _canonical_lineages, _passing_metrics
|
||||||
|
|
||||||
|
from openultrasast.core import canonical
|
||||||
|
from openultrasast.core._admission_gates import GateResult
|
||||||
|
from openultrasast.core.admission_report import AdmissionDecision
|
||||||
|
from openultrasast.core.custody import derive_population_use_receipt_digest
|
||||||
|
from openultrasast.core.evaluation_aggregate import derive_evaluation_aggregate_v3
|
||||||
|
from openultrasast.core.evaluation_measurement import AggregateWeightV3, MetricId
|
||||||
|
from openultrasast.core.evaluation_ordinary_projection import WholePopulationProjectionV3
|
||||||
|
from openultrasast.core.evaluation_report import derive_completed_evaluation_reports_v3
|
||||||
|
|
||||||
|
|
||||||
|
def _inputs(*, aggregate: bool = True):
|
||||||
|
bundle = _bundle(
|
||||||
|
authority_case=_reference_authority_case(),
|
||||||
|
aligned_combination_cases=True,
|
||||||
|
shared_underlying_by_ecosystem=True,
|
||||||
|
)
|
||||||
|
plan = bundle[3].plan_manifest
|
||||||
|
groups = bundle[2]
|
||||||
|
metrics = _passing_metrics(bundle)
|
||||||
|
readiness_by_digest = {item.result_digest: item for item in bundle[5][3]}
|
||||||
|
readiness = tuple(readiness_by_digest[digest] for digest in plan.readiness_digests)
|
||||||
|
observations = bundle[5][4]
|
||||||
|
lineages = _canonical_lineages(bundle)
|
||||||
|
pushes = tuple(sorted({case.underlying_push_digest for group in groups for case in group.cases}))
|
||||||
|
projection = WholePopulationProjectionV3(pushes, len(pushes), "")
|
||||||
|
reports, whole = derive_completed_evaluation_reports_v3(
|
||||||
|
plan,
|
||||||
|
groups,
|
||||||
|
metrics,
|
||||||
|
readiness,
|
||||||
|
observations,
|
||||||
|
lineages,
|
||||||
|
projection,
|
||||||
|
)
|
||||||
|
keys = tuple(sorted({metric.key for metric in metrics}))
|
||||||
|
weights = tuple(AggregateWeightV3(key, 1, len(keys), "") for key in keys)
|
||||||
|
samples = tuple(
|
||||||
|
next(metric.sample_count for metric in metrics if metric.key == key and metric.metric_id is MetricId.PRECISION) for key in keys
|
||||||
|
)
|
||||||
|
summary = derive_evaluation_aggregate_v3(metrics, samples, weights) if aggregate else None
|
||||||
|
from openultrasast.core.evaluation_replay import EvaluationReplayReportSourceV3
|
||||||
|
|
||||||
|
source = EvaluationReplayReportSourceV3(metrics, readiness, observations, projection, "")
|
||||||
|
return (
|
||||||
|
plan,
|
||||||
|
bundle[5][2],
|
||||||
|
bundle[3],
|
||||||
|
bundle[6],
|
||||||
|
bundle[7],
|
||||||
|
bundle[8],
|
||||||
|
bundle[9],
|
||||||
|
bundle[1],
|
||||||
|
groups,
|
||||||
|
source,
|
||||||
|
reports,
|
||||||
|
lineages,
|
||||||
|
bundle[3].attempt_history.head_event_digest,
|
||||||
|
whole,
|
||||||
|
summary,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def _assemble(*args):
|
||||||
|
from openultrasast.core.evaluation_replay import assemble_evaluation_replay_v3
|
||||||
|
|
||||||
|
return assemble_evaluation_replay_v3(*args)
|
||||||
|
|
||||||
|
|
||||||
|
def test_complete_graph_produces_one_deterministic_non_authorizing_replay() -> None:
|
||||||
|
from openultrasast.core.evaluation_replay import EvaluationReplayV3
|
||||||
|
from openultrasast.core.evaluation_version import NonAuthorizingV3
|
||||||
|
|
||||||
|
inputs = _inputs()
|
||||||
|
replay = _assemble(*inputs)
|
||||||
|
|
||||||
|
assert replay == _assemble(*inputs)
|
||||||
|
assert replay.replay_digest == _assemble(*inputs).replay_digest
|
||||||
|
assert tuple(group.arm_id for group in replay.cases_by_arm) == ("arm-a", "arm-b", "arm-combined")
|
||||||
|
assert tuple(report.baseline.arm_id for report in replay.reports) == ("arm-a", "arm-b", "arm-combined")
|
||||||
|
assert replay.combination_lineages == inputs[11]
|
||||||
|
assert replay.aggregate == inputs[-1]
|
||||||
|
assert issubclass(EvaluationReplayV3, NonAuthorizingV3)
|
||||||
|
assert not hasattr(EvaluationReplayV3, "authorize_consumer")
|
||||||
|
|
||||||
|
|
||||||
|
def test_optional_aggregate_is_bound_when_present_and_may_be_absent() -> None:
|
||||||
|
with_aggregate = _assemble(*_inputs())
|
||||||
|
without_aggregate = _assemble(*_inputs(aggregate=False))
|
||||||
|
|
||||||
|
assert with_aggregate.aggregate is not None
|
||||||
|
assert without_aggregate.aggregate is None
|
||||||
|
assert with_aggregate.replay_digest != without_aggregate.replay_digest
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("index", (8, 10, 11))
|
||||||
|
def test_missing_cases_reports_or_combination_lineage_prevents_replay(index: int) -> None:
|
||||||
|
from openultrasast.core.evaluation_replay import EvaluationReplayError
|
||||||
|
|
||||||
|
inputs = list(_inputs())
|
||||||
|
inputs[index] = inputs[index][:-1]
|
||||||
|
with pytest.raises(EvaluationReplayError, match="complete|planned|lineage|report|case"):
|
||||||
|
_assemble(*inputs)
|
||||||
|
|
||||||
|
|
||||||
|
def test_substituted_custody_attempt_coverage_and_aggregate_are_refused() -> None:
|
||||||
|
from openultrasast.core.evaluation_replay import EvaluationReplayError
|
||||||
|
|
||||||
|
inputs = list(_inputs())
|
||||||
|
changed_receipt = replace(inputs[5], reasons=("substituted",))
|
||||||
|
changed_receipt = replace(changed_receipt, receipt_digest=derive_population_use_receipt_digest(changed_receipt))
|
||||||
|
inputs[5] = changed_receipt
|
||||||
|
with pytest.raises(EvaluationReplayError, match="receipt|spend|custody"):
|
||||||
|
_assemble(*inputs)
|
||||||
|
|
||||||
|
inputs = list(_inputs())
|
||||||
|
inputs[12] = canonical.content_digest("other-attempt-head")
|
||||||
|
with pytest.raises(EvaluationReplayError, match="attempt"):
|
||||||
|
_assemble(*inputs)
|
||||||
|
|
||||||
|
inputs = list(_inputs())
|
||||||
|
inputs[13] = replace(
|
||||||
|
inputs[13],
|
||||||
|
completed_underlying_push_count=inputs[13].completed_underlying_push_count - 1,
|
||||||
|
deferred_underlying_push_count=1,
|
||||||
|
coverage_digest="",
|
||||||
|
)
|
||||||
|
with pytest.raises((EvaluationReplayError, ValueError), match="coverage|push|reconcile"):
|
||||||
|
_assemble(*inputs)
|
||||||
|
|
||||||
|
inputs = list(_inputs())
|
||||||
|
aggregate = inputs[14]
|
||||||
|
assert aggregate is not None
|
||||||
|
changed_metric = replace(aggregate.metrics[0], weighted_value=0.25, metric_digest="")
|
||||||
|
inputs[14] = replace(aggregate, metrics=(changed_metric,) + aggregate.metrics[1:], aggregate_digest="")
|
||||||
|
with pytest.raises((EvaluationReplayError, ValueError), match="aggregate|reproduce|canonical"):
|
||||||
|
_assemble(*inputs)
|
||||||
|
|
||||||
|
|
||||||
|
def _forged_reports(reports, mutation: str):
|
||||||
|
report = reports[0]
|
||||||
|
scoped = report.scoped_results[0]
|
||||||
|
if mutation in {"instrument_gate", "budget_gate", "readiness_gate", "quality_gate"}:
|
||||||
|
original_gate = getattr(scoped, mutation)
|
||||||
|
gate = GateResult(original_gate.kind, original_gate.gate_id, False, ("forged",), original_gate.evidence_digests)
|
||||||
|
changed_scope = replace(scoped, **{mutation: gate}, decision=AdmissionDecision.NO_GO, result_digest="")
|
||||||
|
changed_report = replace(report, scoped_results=(changed_scope,) + report.scoped_results[1:], report_digest="")
|
||||||
|
elif mutation == "metrics":
|
||||||
|
original = scoped.metrics[0]
|
||||||
|
metric = type(original).from_counts(original.key, original.metric_id, numerator=0, denominator=original.denominator)
|
||||||
|
changed_scope = replace(scoped, metrics=(metric,) + scoped.metrics[1:], result_digest="")
|
||||||
|
changed_report = replace(report, scoped_results=(changed_scope,) + report.scoped_results[1:], report_digest="")
|
||||||
|
elif mutation == "runtime":
|
||||||
|
operational = replace(report.operational_evidence, runtime_ms=report.operational_evidence.runtime_ms + 1, evidence_digest="")
|
||||||
|
changed_report = replace(report, operational_evidence=operational, report_digest="")
|
||||||
|
else:
|
||||||
|
funnel = replace(report.operational_evidence.stage_funnel, inputs_read=report.operational_evidence.stage_funnel.inputs_read + 1)
|
||||||
|
operational = replace(report.operational_evidence, stage_funnel=funnel, evidence_digest="")
|
||||||
|
changed_report = replace(report, operational_evidence=operational, report_digest="")
|
||||||
|
return (changed_report,) + reports[1:]
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
"mutation",
|
||||||
|
("instrument_gate", "budget_gate", "readiness_gate", "quality_gate", "metrics", "runtime", "funnel"),
|
||||||
|
)
|
||||||
|
def test_reports_must_rederive_from_replay_carried_sources_for_assembly_and_direct_construction(mutation: str) -> None:
|
||||||
|
from openultrasast.core.evaluation_replay import EvaluationReplayError
|
||||||
|
|
||||||
|
inputs = list(_inputs())
|
||||||
|
forged = _forged_reports(inputs[10], mutation)
|
||||||
|
inputs[10] = forged
|
||||||
|
with pytest.raises(EvaluationReplayError, match="report|source|rederive|canonical"):
|
||||||
|
_assemble(*inputs)
|
||||||
|
|
||||||
|
canonical_replay = _assemble(*_inputs())
|
||||||
|
with pytest.raises(EvaluationReplayError, match="report|source|rederive|canonical"):
|
||||||
|
replace(canonical_replay, reports=forged, replay_digest="")
|
||||||
|
|
||||||
|
|
||||||
|
def test_aggregate_derived_from_forged_report_metrics_cannot_replace_source_bound_aggregate() -> None:
|
||||||
|
from openultrasast.core.evaluation_replay import EvaluationReplayError
|
||||||
|
|
||||||
|
inputs = list(_inputs())
|
||||||
|
forged = _forged_reports(inputs[10], "metrics")
|
||||||
|
forged_metrics = tuple(metric for report in forged for result in report.scoped_results for metric in result.metrics)
|
||||||
|
original = inputs[14]
|
||||||
|
assert original is not None
|
||||||
|
inputs[10] = forged
|
||||||
|
inputs[14] = derive_evaluation_aggregate_v3(forged_metrics, original.sample_counts, original.weights)
|
||||||
|
with pytest.raises(EvaluationReplayError, match="report|source|rederive|canonical"):
|
||||||
|
_assemble(*inputs)
|
||||||
|
|
||||||
|
|
||||||
|
def test_reversed_readiness_is_refused_in_assembly_and_direct_replay_construction() -> None:
|
||||||
|
from openultrasast.core.evaluation_replay import EvaluationReplayError
|
||||||
|
|
||||||
|
inputs = list(_inputs())
|
||||||
|
source = inputs[9]
|
||||||
|
assert len(source.readiness) > 1
|
||||||
|
reversed_source = replace(source, readiness=tuple(reversed(source.readiness)), source_digest="")
|
||||||
|
inputs[9] = reversed_source
|
||||||
|
with pytest.raises(EvaluationReplayError, match="readiness|order|source"):
|
||||||
|
_assemble(*inputs)
|
||||||
|
|
||||||
|
canonical_replay = _assemble(*_inputs())
|
||||||
|
with pytest.raises(EvaluationReplayError, match="readiness|order|source"):
|
||||||
|
replace(canonical_replay, report_source=reversed_source, replay_digest="")
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
"mutation",
|
||||||
|
("metrics", "observations", "case_groups", "reports", "readiness_duplicate", "readiness_omitted", "lineage_duplicate"),
|
||||||
|
)
|
||||||
|
def test_replay_collections_are_never_reordered_normalized_or_deduplicated(mutation: str) -> None:
|
||||||
|
from openultrasast.core.evaluation_replay import EvaluationReplayError
|
||||||
|
|
||||||
|
inputs = list(_inputs())
|
||||||
|
source = inputs[9]
|
||||||
|
if mutation == "metrics":
|
||||||
|
inputs[9] = replace(source, metrics=tuple(reversed(source.metrics)), source_digest="")
|
||||||
|
elif mutation == "observations":
|
||||||
|
inputs[9] = replace(source, observations=tuple(reversed(source.observations)), source_digest="")
|
||||||
|
elif mutation == "case_groups":
|
||||||
|
inputs[8] = tuple(reversed(inputs[8]))
|
||||||
|
elif mutation == "reports":
|
||||||
|
inputs[10] = tuple(reversed(inputs[10]))
|
||||||
|
elif mutation == "readiness_duplicate":
|
||||||
|
inputs[9] = replace(source, readiness=source.readiness + (source.readiness[0],), source_digest="")
|
||||||
|
elif mutation == "readiness_omitted":
|
||||||
|
inputs[9] = replace(source, readiness=source.readiness[:-1], source_digest="")
|
||||||
|
else:
|
||||||
|
inputs[11] = inputs[11] + (inputs[11][0],)
|
||||||
|
with pytest.raises(EvaluationReplayError, match="complete|canonical|order|readiness|report|case|lineage|source"):
|
||||||
|
_assemble(*inputs)
|
||||||
|
|
||||||
|
|
||||||
|
def test_replay_refuses_subclasses_and_v2_remains_unchanged() -> None:
|
||||||
|
from openultrasast.core.admission_report import AdmissionReplay
|
||||||
|
from openultrasast.core.evaluation_replay import EvaluationReplayError
|
||||||
|
|
||||||
|
class PlanSubclass(type(_inputs()[0])):
|
||||||
|
"""Exact-type substitution used only by this regression."""
|
||||||
|
|
||||||
|
inputs = list(_inputs())
|
||||||
|
plan = inputs[0]
|
||||||
|
substituted = object.__new__(PlanSubclass)
|
||||||
|
for field, value in plan.__dict__.items():
|
||||||
|
object.__setattr__(substituted, field, value)
|
||||||
|
inputs[0] = substituted
|
||||||
|
with pytest.raises(EvaluationReplayError, match="exact|plan"):
|
||||||
|
_assemble(*inputs)
|
||||||
|
assert "replay_digest" in AdmissionReplay.__dataclass_fields__
|
||||||
Reference in New Issue
Block a user