style(detection-core): format evaluation contracts

This commit is contained in:
Marius Ciepluch
2026-11-11 12:18:33 +01:00
parent 30129bfe5f
commit ccffef5fa3
8 changed files with 15 additions and 46 deletions
+4 -3
View File
@@ -130,9 +130,10 @@ def test_component_projection_refuses_record_subclasses_and_source_changes() ->
derive_component_case_outcome_projection((tampered,))
changed = _case_record("base", NeutralOutcome.SATISFIED, change="change-b")
assert derive_component_case_outcome_projection((record,)).case_input_digest != derive_component_case_outcome_projection(
(changed,)
).case_input_digest
assert (
derive_component_case_outcome_projection((record,)).case_input_digest
!= derive_component_case_outcome_projection((changed,)).case_input_digest
)
def test_case_input_derivation_refuses_self_consistent_invalid_nested_change_identity() -> None:
@@ -209,11 +209,7 @@ def _bundle(*, authority_case=None, projection_mutation: str | None = None):
if projection_mutation == "case_input":
case_input = _digest("coordinated-other-case-input")
elif projection_mutation == "outcome":
outcome = (
NeutralOutcome.VIOLATION
if outcome is not NeutralOutcome.VIOLATION
else NeutralOutcome.SATISFIED
)
outcome = NeutralOutcome.VIOLATION if outcome is not NeutralOutcome.VIOLATION else NeutralOutcome.SATISFIED
elif projection_mutation == "source":
sources = (_digest("coordinated-other-record"),)
else: # pragma: no cover - fixture misuse
@@ -459,9 +455,7 @@ def test_canonical_release_binding_requires_planned_projection_policy(
substituted_policy: CaseOutcomeProjectionPolicyV3,
) -> None:
bundle = _bundle()
configurations = {
item.arm_id: item for item in bundle[3].plan_manifest.declaration.arm_configurations
}
configurations = {item.arm_id: item for item in bundle[3].plan_manifest.declaration.arm_configurations}
configuration = next(item for item in configurations.values() if item.kind is kind)
group = next(item for item in bundle[2] if item.arm_id == configuration.arm_id)
case = group.cases[0]
+2 -6
View File
@@ -27,9 +27,7 @@ def _projection(
) -> CaseOutcomeProjectionV3:
return CaseOutcomeProjectionV3(
case_input,
CaseOutcomeProjectionPolicyV3.DECLARATIVE_COMBINATION_TABLE
if combined
else CaseOutcomeProjectionPolicyV3.UNANIMOUS_EVIDENCE,
CaseOutcomeProjectionPolicyV3.DECLARATIVE_COMBINATION_TABLE if combined else CaseOutcomeProjectionPolicyV3.UNANIMOUS_EVIDENCE,
sources,
outcome,
"",
@@ -99,9 +97,7 @@ def test_combination_replay_joins_exact_cases_in_registered_component_order() ->
rule = next(item.combination_rule for item in declaration.arm_configurations if item.arm_id == "arm-combined")
assert rule is not None
expected_row = next(
item
for item in rule.decision_rows
if item.component_outcomes == (NeutralOutcome.SATISFIED, NeutralOutcome.VIOLATION)
item for item in rule.decision_rows if item.component_outcomes == (NeutralOutcome.SATISFIED, NeutralOutcome.VIOLATION)
)
assert lineage.rule == rule
+1 -3
View File
@@ -146,9 +146,7 @@ def test_observation_case_policy_must_equal_planned_arm_policy(
changed_observation = replace(original, cases=(changed_case,), observation_digest="")
changed_ref, changed_content = _seal(changed_observation, f"wrong-policy-{arm_id}")
changed_sealed = sealed[:index] + (changed_ref,) + sealed[index + 1 :]
changed_resolver = InMemoryContentResolver(
{**resolver.artifacts, changed_ref.observation.artifact_id: changed_content}
)
changed_resolver = InMemoryContentResolver({**resolver.artifacts, changed_ref.observation.artifact_id: changed_content})
with pytest.raises(EvaluationObservationError, match="policy"):
_validate(declaration, changed_sealed, changed_resolver)
+1 -5
View File
@@ -100,11 +100,7 @@ def _configuration(arm_id: str, *, combined: bool = False, configuration: str =
_digest("budget"),
"container@sha256:abc",
_digest("outcomes"),
(
CaseOutcomeProjectionPolicyV3.DECLARATIVE_COMBINATION_TABLE
if combined
else CaseOutcomeProjectionPolicyV3.UNANIMOUS_EVIDENCE
),
(CaseOutcomeProjectionPolicyV3.DECLARATIVE_COMBINATION_TABLE if combined else CaseOutcomeProjectionPolicyV3.UNANIMOUS_EVIDENCE),
_combination_rule() if combined else None,
"",
)