diff --git a/tests/test_valid_benchmark_admission_execution.py b/tests/test_valid_benchmark_admission_execution.py index 4b91ef16..a6ed5d12 100644 --- a/tests/test_valid_benchmark_admission_execution.py +++ b/tests/test_valid_benchmark_admission_execution.py @@ -163,9 +163,7 @@ def _selection(freeze) -> OrdinarySelectionV1: positives = freeze.positive_change_digests assignments = tuple( sorted( - OrdinaryDrawAssignmentV1(positive, network, pushes[0].ecosystem, push.push_digest) - for positive in positives - for push in pushes + OrdinaryDrawAssignmentV1(positive, network, pushes[0].ecosystem, push.push_digest) for positive in positives for push in pushes ) ) fix_exclusions = tuple( @@ -329,9 +327,7 @@ def _case_ref(bundle, slot): def _observations(plan, bundle, slots=None): rows = ( - tuple(slot for slot in plan.declaration.expected_observation_slots if slot.arm_id == bundle.arm.arm_id) - if slots is None - else slots + tuple(slot for slot in plan.declaration.expected_observation_slots if slot.arm_id == bundle.arm.arm_id) if slots is None else slots ) reads, stages = _read_rows(bundle), _stage_rows() return tuple( @@ -419,9 +415,7 @@ def _union_rule(): return NeutralOutcome.INDETERMINATE return NeutralOutcome.SATISFIED - rows = tuple( - CombinationDecisionRowV3(outcomes, union(outcomes), "") for outcomes in product(tuple(NeutralOutcome), repeat=2) - ) + rows = tuple(CombinationDecisionRowV3(outcomes, union(outcomes), "") for outcomes in product(tuple(NeutralOutcome), repeat=2)) return CombinationRuleV3( "arm-combined", ("arm-experimental", "arm-shipped"), @@ -437,9 +431,7 @@ class _ExecCase: self.freeze = _freeze() self.selection = _selection(self.freeze) self.material = _material_manifest(self.freeze) - self.manifest, self.manifest_review, self.disclosure, self.resolver = _reviewed_manifest( - self.freeze, self.selection, self.material - ) + self.manifest, self.manifest_review, self.disclosure, self.resolver = _reviewed_manifest(self.freeze, self.selection, self.material) self.ordinary_census = (EcosystemOrdinaryCensusV3("python", ORDINARY_PUSHES),) self.plan = registry.register_evaluation_plan( registrations=( @@ -514,11 +506,7 @@ class _ExecCase: self.plan, self.census, (self.report.report_digest,), self.custody_log_digest, self.plan_review ) self.attempt_status_ref = stored_artifact(b'{"status":"sealed"}', artifact_id="attempt-status")[0] - combined_configuration = next( - row.configuration - for row in self.plan.registrations - if row.configuration.kind is ArmKindV3.COMBINED - ) + combined_configuration = next(row.configuration for row in self.plan.registrations if row.configuration.kind is ArmKindV3.COMBINED) assert combined_configuration.combination_rule is not None self.combination_registrations = ( CombinationRuleRegistrationV1( @@ -592,9 +580,7 @@ class _Env: self.transient = _Client() durable_settings = _settings(StorePurpose.DURABLE) self.repository = S3ArtifactRepository(durable_settings, self.durable) - self.custody_policy = PopulationCustodyPolicy( - (CUSTODIAN,), derive_population_custody_policy_digest((CUSTODIAN,)) - ) + self.custody_policy = PopulationCustodyPolicy((CUSTODIAN,), derive_population_custody_policy_digest((CUSTODIAN,))) self.custody = S3DurableCustodyStore( durable_settings, self.durable, @@ -631,9 +617,7 @@ class _Env: self.custody, self.journal, ACCESS_POLICY, - self.case.execution_request( - resolved, adapter=self.adapter, review=review, selectors=selectors, run_request=run_request - ), + self.case.execution_request(resolved, adapter=self.adapter, review=review, selectors=selectors, run_request=run_request), ) @@ -645,9 +629,7 @@ def _admission_review(case: _ExecCase) -> object: def _selectors(product): - return tuple( - None if row.reference is None else _selector(row.reference, row.checkpoint_digest) for row in product.component_results - ) + return tuple(None if row.reference is None else _selector(row.reference, row.checkpoint_digest) for row in product.component_results) def _selector(reference, digest): @@ -827,9 +809,7 @@ def test_mismatched_authority_binding_is_rejected_before_any_adapter_call() -> N case = _case() environment = _Env(case) authorized = environment.preflight() - changed = tuple( - replace(row, budget_digest=_digest("changed-budget")) if row.arm_id == "arm-shipped" else row for row in case.bindings - ) + changed = tuple(replace(row, budget_digest=_digest("changed-budget")) if row.arm_id == "arm-shipped" else row for row in case.bindings) product = environment.execute(preflight=authorized, run_request=case.run_request(execution_bindings=changed)) @@ -958,9 +938,7 @@ def test_reviewed_admission_manifest_binds_exact_sealed_references_and_authorize assert tuple(ref.slot_digest for ref in manifest.observations) == tuple( slot.slot_digest for slot in case.plan.declaration.expected_observation_slots ) - assert tuple(ref.ref_digest for ref in manifest.observations) == tuple( - ref.ref_digest for ref in product.sealed_observations - ) + assert tuple(ref.ref_digest for ref in manifest.observations) == tuple(ref.ref_digest for ref in product.sealed_observations) assert manifest.custody_log_digest == case.custody_log_digest assert manifest.attempt_history.head_event_digest authorization = product.spend_authorization @@ -1012,9 +990,7 @@ def test_changed_or_unsealed_observation_bytes_prevent_spend(mode: str) -> None: first.sealed_observations, first.admission_manifest, ) - reason = ( - AdmissionExecutionReason.OBSERVATION_CHANGED if mode == "changed" else AdmissionExecutionReason.OBSERVATION_UNSEALED - ) + reason = AdmissionExecutionReason.OBSERVATION_CHANGED if mode == "changed" else AdmissionExecutionReason.OBSERVATION_UNSEALED assert authorization.may_spend is False assert reason in authorization.refusal_reasons assert environment.custody.current_log(case.freeze.population_digest).status is PopulationStatus.AVAILABLE diff --git a/tests/test_valid_benchmark_admission_projection.py b/tests/test_valid_benchmark_admission_projection.py index 005c25f6..15a8ccdf 100644 --- a/tests/test_valid_benchmark_admission_projection.py +++ b/tests/test_valid_benchmark_admission_projection.py @@ -227,9 +227,7 @@ class _RunEnv(_Env): self.case.freeze.positive_change_digests, _scope_census(self.case.freeze), ) - subject = spend.release_review_subject( - manifest.manifest_digest, self.planned_receipt_digest(), cases, self.loader.payload - ) + subject = spend.release_review_subject(manifest.manifest_digest, self.planned_receipt_digest(), cases, self.loader.payload) except spend.AdmissionSpendError: subject = _digest("underivable-release-subject") return _attestation(subject, _digest("release-producer"), self.disclosure) @@ -433,9 +431,7 @@ def _projection(environment: _RunEnv): def _proof_material(flagged: str, control: str, *, outcome: ProofOutcome = ProofOutcome.DEMONSTRATED, safe_observed: bool = False): - producer = ProofProducerIdentity( - "proof-producer", "verifier-7", _digest("sandbox"), _digest("oracle"), _digest("proof-review") - ) + producer = ProofProducerIdentity("proof-producer", "verifier-7", _digest("sandbox"), _digest("oracle"), _digest("proof-review")) producer_digest = derive_producer_identity_digest(producer) affected = ProofSideResult(flagged, True, _digest("affected-observation"), 1, "") safe = ProofSideResult(control, safe_observed, _digest("safe-observation"), 1, "") @@ -649,9 +645,7 @@ def _forged_release(environment: _RunEnv, original, *, marker: str) -> Admission def test_duplicated_ordinary_row_with_fresh_case_digest_is_refused() -> None: environment = _located_env() push = environment.case.selection.pushes[0].push_digest - original = next( - row for row in environment.release.released_cases if row.arm_id == "arm-shipped" and row.case_input_digest == push - ) + original = next(row for row in environment.release.released_cases if row.arm_id == "arm-shipped" and row.case_input_digest == push) forged = _forged_release(environment, original, marker="forged-ordinary-result") assert forged.released_cases[-1].case_digest != original.case_digest assert forged.release_digest == environment.release.release_digest diff --git a/tests/test_valid_benchmark_admission_replay.py b/tests/test_valid_benchmark_admission_replay.py index 4b3544ad..11327b1e 100644 --- a/tests/test_valid_benchmark_admission_replay.py +++ b/tests/test_valid_benchmark_admission_replay.py @@ -115,18 +115,14 @@ def _operator_policy() -> str: def _operator_authority(): - return artifact_read_authority( - ArtifactActorRole.OPERATOR, (), _operator_policy(), expected_access_policy_digest=_operator_policy() - ) + return artifact_read_authority(ArtifactActorRole.OPERATOR, (), _operator_policy(), expected_access_policy_digest=_operator_policy()) @lru_cache(maxsize=1) def _core_context(): context_case = _core_context_case() old = context_case.context.evidence - custody_policy = PopulationCustodyPolicy( - (CUSTODIAN,), derive_population_custody_policy_digest((CUSTODIAN,)) - ) + custody_policy = PopulationCustodyPolicy((CUSTODIAN,), derive_population_custody_policy_digest((CUSTODIAN,))) evidence = make_evidence_validation_context( family_catalog=old.family_catalog, fact_packs=old.fact_packs, @@ -286,9 +282,7 @@ def _bound_bridge_request( ) bound = replace( request, - admission_review=_attestation( - bridged_admission_subject(request), _digest("bridge-admission-producer"), case.disclosure - ), + admission_review=_attestation(bridged_admission_subject(request), _digest("bridge-admission-producer"), case.disclosure), ) return environment, preflight, execution, readiness, bound @@ -327,9 +321,7 @@ def _publication_request(replay, *, planned_arms: tuple[str, ...] = PLANNED_ARMS repository=repository, replay=replay, planned_arm_ids=planned_arms, - planned_input_count=len( - {slot.input_identity_digest for slot in replay.plan_manifest.declaration.expected_observation_slots} - ), + planned_input_count=len({slot.input_identity_digest for slot in replay.plan_manifest.declaration.expected_observation_slots}), population_digest=replay.plan_manifest.declaration.population_digest, freeze_digest=replay.plan_manifest.declaration.freeze_digest, plan_digest=replay.plan_manifest.manifest_digest, @@ -380,11 +372,7 @@ def test_optional_aggregate_is_explicit_non_authorizing_and_whole_coverage_is_de assert "decision" not in {field.name for field in fields(replay.aggregate)} assert "gate" not in {field.name for field in fields(replay.aggregate)} whole = replay.whole_population_coverage - unique_pushes = { - case.underlying_push_digest - for group in replay.cases_by_arm - for case in group.cases - } + unique_pushes = {case.underlying_push_digest for group in replay.cases_by_arm for case in group.cases} assert whole.underlying_push_count == len(replay.report_source.whole_projection.underlying_push_digests) assert whole.underlying_push_count == len(unique_pushes) @@ -480,22 +468,19 @@ def test_bridge_core_authorization_over_raw_documents_and_real_readiness() -> No digests = tuple(sorted(item.result_digest for item in readiness)) assert bridged.plan_manifest.readiness_digests == digests assert bridged.admission_manifest.readiness_digests == digests - assert bridged.preparation.authority.readiness_set_digest == canonical.content_digest( - {"readiness_digests": digests} - ) or bridged.preparation.authority.readiness_set_digest + assert ( + bridged.preparation.authority.readiness_set_digest == canonical.content_digest({"readiness_digests": digests}) + or bridged.preparation.authority.readiness_set_digest + ) assert bridged.preparation.authority.observation_set_digest != derive_evaluation_observation_set_digest_zero() for sealed in bridged.admission_manifest.observations: resolved = bridged.resolver.resolve(sealed.observation) assert canonical.bytes_digest(resolved.content) == sealed.observation.content_digest assert decode_arm_observation_set(resolved.content).observation_digest == sealed.observation_digest - assert bridged.preparation.label_release_request.influenced_artifact_digest == ( - bridged.preparation.authority.authority_digest - ) + assert bridged.preparation.label_release_request.influenced_artifact_digest == (bridged.preparation.authority.authority_digest) assert bridged.preparation.label_release_request.arm_id == bridged.plan_manifest.manifest_digest receipt = _commit_shared_spend(environment, bridged) - binding = validate_shared_spend( - bridged.admission_manifest, bridged.preparation, receipt, environment.context, environment.custody - ) + binding = validate_shared_spend(bridged.admission_manifest, bridged.preparation, receipt, environment.context, environment.custody) assert binding.receipt_digest == receipt.receipt_digest @@ -506,9 +491,7 @@ def derive_evaluation_observation_set_digest_zero() -> str: def _commit_shared_spend(environment: _BridgeEnv, bridged) -> PopulationUseReceipt: preparation = bridged.preparation prior = environment.custody.current_log(preparation.label_release_request.population_digest) - receipt = record_population_use( - preparation.label_release_request, prior, CUSTODIAN, environment.context.evidence.custody_policy - ) + receipt = record_population_use(preparation.label_release_request, prior, CUSTODIAN, environment.context.evidence.custody_policy) successor = append_population_use(prior, receipt, environment.context.evidence.custody_policy) assert environment.custody.compare_and_swap(prior.log_digest, successor) return receipt @@ -523,9 +506,7 @@ def test_unbridged_envelope_references_and_capability_readiness_are_refused_by_c _digest("gap-plan-producer"), case.disclosure, ) - gap_plan = compose_plan_manifest( - case.plan, preflight.plan_manifest.census, digests, preflight.custody_log_digest, plan_review - ) + gap_plan = compose_plan_manifest(case.plan, preflight.plan_manifest.census, digests, preflight.custody_log_digest, plan_review) feasibility = preflight_evaluation(gap_plan, environment.context, case.resolver) envelope_draft = EvaluationAdmissionManifestV3( gap_plan, @@ -540,16 +521,10 @@ def test_unbridged_envelope_references_and_capability_readiness_are_refused_by_c ) envelope_payload = derive_evaluation_admission_manifest_payload_digest(envelope_draft) envelope_review = _attestation(envelope_payload, _digest("gap-admission-producer"), case.disclosure) - envelope_manifest = replace( - envelope_draft, payload_digest=envelope_payload, review=envelope_review - ) - envelope_manifest = replace( - envelope_manifest, manifest_digest=derive_evaluation_admission_manifest_digest(envelope_manifest) - ) + envelope_manifest = replace(envelope_draft, payload_digest=envelope_payload, review=envelope_review) + envelope_manifest = replace(envelope_manifest, manifest_digest=derive_evaluation_admission_manifest_digest(envelope_manifest)) with pytest.raises((EvaluationAdmissionV3Error, ArtifactResolutionError, ArtifactValidationError)): - authorize_evaluation( - envelope_manifest, feasibility, readiness, environment.context, environment.custody, case.resolver - ) + authorize_evaluation(envelope_manifest, feasibility, readiness, environment.context, environment.custody, case.resolver) bridged = bridge_core_authorization(request) original = preflight.plan_manifest capability_draft = EvaluationAdmissionManifestV3( @@ -566,9 +541,7 @@ def test_unbridged_envelope_references_and_capability_readiness_are_refused_by_c capability_payload = derive_evaluation_admission_manifest_payload_digest(capability_draft) capability_review = _attestation(capability_payload, _digest("gap-capability-producer"), case.disclosure) capability_manifest = replace(capability_draft, payload_digest=capability_payload, review=capability_review) - capability_manifest = replace( - capability_manifest, manifest_digest=derive_evaluation_admission_manifest_digest(capability_manifest) - ) + capability_manifest = replace(capability_manifest, manifest_digest=derive_evaluation_admission_manifest_digest(capability_manifest)) assert original.readiness_digests != digests with pytest.raises((EvaluationAdmissionV3Error, EvaluationAuthorityError)): authorize_evaluation( diff --git a/tests/test_valid_benchmark_admission_spend.py b/tests/test_valid_benchmark_admission_spend.py index 32e58403..1286fcb2 100644 --- a/tests/test_valid_benchmark_admission_spend.py +++ b/tests/test_valid_benchmark_admission_spend.py @@ -87,9 +87,7 @@ class _RacedCustody: if not self._raced: self._raced = True prior = self._inner.current_log(self._population) - rival = PopulationUseRequest( - self._population, "rival-arm", LineagePurpose.ADMISSION_LABEL_OPEN, True, None, prior.log_digest - ) + rival = PopulationUseRequest(self._population, "rival-arm", LineagePurpose.ADMISSION_LABEL_OPEN, True, None, prior.log_digest) receipt = record_population_use(rival, prior, self._custodian, self._policy) assert self._inner.compare_and_swap(prior.log_digest, append_population_use(prior, receipt, self._policy)) return self._inner.compare_and_swap(expected_log_digest, replacement) @@ -259,9 +257,7 @@ class _SpendEnv(_Env): self.case.freeze.positive_change_digests, _scope_census(self.case.freeze), ) - subject = release_review_subject( - manifest.manifest_digest, self.planned_receipt_digest(), cases, self.loader.payload - ) + subject = release_review_subject(manifest.manifest_digest, self.planned_receipt_digest(), cases, self.loader.payload) except spend.AdmissionSpendError: subject = _digest("underivable-release-subject") return _attestation(subject, _digest("release-producer"), self.disclosure) @@ -374,13 +370,9 @@ def test_moved_custody_head_refuses_before_any_label_read() -> None: case = _case() environment = _SpendEnv(case) prior = environment.custody.current_log(environment.population) - rival = PopulationUseRequest( - environment.population, "rival-arm", LineagePurpose.ADMISSION_LABEL_OPEN, True, None, prior.log_digest - ) + rival = PopulationUseRequest(environment.population, "rival-arm", LineagePurpose.ADMISSION_LABEL_OPEN, True, None, prior.log_digest) receipt = record_population_use(rival, prior, CUSTODIAN, environment.custody_policy) - assert environment.custody.compare_and_swap( - prior.log_digest, append_population_use(prior, receipt, environment.custody_policy) - ) + assert environment.custody.compare_and_swap(prior.log_digest, append_population_use(prior, receipt, environment.custody_policy)) product = commit_spend_and_release(environment.spend_request()) @@ -531,9 +523,7 @@ def test_reviewed_release_is_sealed_and_carries_no_label_bytes() -> None: product = commit_spend_and_release(environment.spend_request()) - release_rows = [ - row for row in environment.sealed_workflow_payloads() if row[1] == spend.CASE_RELEASE_DOCUMENT_SCHEMA - ] + release_rows = [row for row in environment.sealed_workflow_payloads() if row[1] == spend.CASE_RELEASE_DOCUMENT_SCHEMA] assert len(release_rows) == 1 release_key = release_rows[0][0] release_bytes = environment.durable.body(release_key) @@ -560,9 +550,7 @@ def test_only_release_bound_to_committed_receipt_reaches_scoring() -> None: assert first.refusal_reason is None assert second.refusal_reason is AdmissionSpendReason.CUSTODY_HEAD_UNAVAILABLE assert environment.loader.reads == 1 - release_rows = [ - row for row in environment.sealed_workflow_payloads() if row[1] == spend.CASE_RELEASE_DOCUMENT_SCHEMA - ] + release_rows = [row for row in environment.sealed_workflow_payloads() if row[1] == spend.CASE_RELEASE_DOCUMENT_SCHEMA] assert len(release_rows) == 1 diff --git a/tests/test_valid_benchmark_operator_report.py b/tests/test_valid_benchmark_operator_report.py index ed30628c..6ed48384 100644 --- a/tests/test_valid_benchmark_operator_report.py +++ b/tests/test_valid_benchmark_operator_report.py @@ -159,16 +159,12 @@ def _no_go_variant(resolved: operator_report.ResolvedOperatorReplay) -> operator def _demonstrated_attachment(case: object) -> ProofAttachment: - producer = ProofProducerIdentity( - "prover-arm", "verifier-v1", _digest("sandbox"), _digest("oracle"), _digest("producer-review") - ) + producer = ProofProducerIdentity("prover-arm", "verifier-v1", _digest("sandbox"), _digest("oracle"), _digest("producer-review")) affected = ProofSideResult(_digest("affected-input"), True, _digest("affected-obs"), 2, "") safe = ProofSideResult(_digest("safe-input"), False, _digest("safe-obs"), 2, "") witness = ContentRef("witness", _digest("witness"), "application/json", 64, _digest("retention"), _digest("receipt")) control = ControlBinding(_digest("affected-input"), _digest("safe-input"), witness, _digest("prover-reviewer"), "") - proof = DifferentialProofRecord( - DIFFERENTIAL_PROOF_SCHEMA, producer, affected, safe, control, witness, ProofOutcome.DEMONSTRATED, "" - ) + proof = DifferentialProofRecord(DIFFERENTIAL_PROOF_SCHEMA, producer, affected, safe, control, witness, ProofOutcome.DEMONSTRATED, "") verification = ProofVerificationReceipt( _digest("producer"), _digest("record"), _digest("aff"), _digest("safe"), _digest("witness"), witness, "" ) @@ -239,9 +235,7 @@ def test_completion_shows_multi_arm_scopes_metrics_intervals_and_separate_whole_ assert value["input_read_evidence_digest"] and value["stage_execution_evidence_digest"] -def test_completion_names_failed_gates_for_no_go_scopes( - monkeypatch: pytest.MonkeyPatch, completed: tuple[object, object] -) -> None: +def test_completion_names_failed_gates_for_no_go_scopes(monkeypatch: pytest.MonkeyPatch, completed: tuple[object, object]) -> None: _, replay = completed resolved = _no_go_variant(_resolved(monkeypatch, replay)) value = operator_report.operator_report_json(_completed_outcome(resolved.reference), resolved) @@ -364,9 +358,7 @@ def test_completed_outcome_fails_closed_without_a_matching_valid_replay( assert unexpected.value.reason is operator_report.OperatorReportErrorReason.INCONSISTENT_STATE -def test_invalid_replay_material_fails_closed_at_resolution( - monkeypatch: pytest.MonkeyPatch, completed: tuple[object, object] -) -> None: +def test_invalid_replay_material_fails_closed_at_resolution(monkeypatch: pytest.MonkeyPatch, completed: tuple[object, object]) -> None: _, replay = completed content, reference = _envelope(replay.replay_digest) # type: ignore[attr-defined] @@ -405,9 +397,7 @@ def test_invalid_replay_material_fails_closed_at_resolution( assert wrong_kind.value.reason is operator_report.OperatorReportErrorReason.INVALID_REQUEST -def test_projections_are_deterministic_and_byte_identical( - monkeypatch: pytest.MonkeyPatch, completed: tuple[object, object] -) -> None: +def test_projections_are_deterministic_and_byte_identical(monkeypatch: pytest.MonkeyPatch, completed: tuple[object, object]) -> None: _, replay = completed resolved = _resolved(monkeypatch, replay) outcome = _completed_outcome(resolved.reference) @@ -422,9 +412,7 @@ def test_projections_are_deterministic_and_byte_identical( assert impaired_text == operator_report.operator_report_text(_impaired(), None) -def test_text_and_json_are_equivalent_ascii_projections( - monkeypatch: pytest.MonkeyPatch, completed: tuple[object, object] -) -> None: +def test_text_and_json_are_equivalent_ascii_projections(monkeypatch: pytest.MonkeyPatch, completed: tuple[object, object]) -> None: _, replay = completed resolved = _no_go_variant(_demonstrated_variant(_resolved(monkeypatch, replay))) outcome = _completed_outcome(resolved.reference) @@ -459,9 +447,7 @@ def test_text_and_json_are_equivalent_ascii_projections( ) -def test_rendered_bytes_stay_redacted( - monkeypatch: pytest.MonkeyPatch, completed: tuple[object, object] -) -> None: +def test_rendered_bytes_stay_redacted(monkeypatch: pytest.MonkeyPatch, completed: tuple[object, object]) -> None: _, replay = completed resolved = _resolved(monkeypatch, replay) rendered = operator_report.operator_report_bytes(_completed_outcome(resolved.reference), resolved) @@ -507,9 +493,7 @@ def test_optional_aggregate_declares_constituents_and_weighting_without_decision metrics = replay.report_source.metrics # type: ignore[attr-defined] keys = tuple(sorted({metric.key for metric in metrics})) - samples = tuple( - next(m.sample_count for m in metrics if m.key == key and m.metric_id is MetricId.PRECISION) for key in keys - ) + samples = tuple(next(m.sample_count for m in metrics if m.key == key and m.metric_id is MetricId.PRECISION) for key in keys) weights = tuple(AggregateWeightV3(key, 1, len(keys), "") for key in keys) aggregate = derive_evaluation_aggregate_v3(metrics, samples, weights) aggregated = replace(resolved, aggregate=aggregate) diff --git a/tests/test_valid_benchmark_orchestrator.py b/tests/test_valid_benchmark_orchestrator.py index eb283187..1eeba733 100644 --- a/tests/test_valid_benchmark_orchestrator.py +++ b/tests/test_valid_benchmark_orchestrator.py @@ -269,14 +269,10 @@ def _freeze(*, pilot: bool = False) -> PopulationFreezeV3: selection = canonical.content_digest( { "accepted_changes": positives, - "scope_census": tuple( - (row.vulnerability_family, row.ecosystem.value, row.count) for row in scope_census - ), + "scope_census": tuple((row.vulnerability_family, row.ecosystem.value, row.count) for row in scope_census), } ) - reviews = canonical.content_digest( - {"ecosystem_reviews": ecosystem_reviews, "ground_truth_reviews": ground_truth_reviews} - ) + reviews = canonical.content_digest({"ecosystem_reviews": ecosystem_reviews, "ground_truth_reviews": ground_truth_reviews}) draft = PopulationFreezeV3( PopulationClass.DEVELOPMENT_PILOT if pilot else PopulationClass.ADMISSION, (PopulationClassificationReason.BELOW_MINIMUM_POSITIVES,) if pilot else (), @@ -361,8 +357,9 @@ def _thresholds_and_rules(arm_id: str, scopes: tuple[tuple[str, str], ...], mini return tuple(thresholds), tuple(policies), tuple(sufficiency) -def _configuration(arm_id: str, scopes: tuple[tuple[str, str], ...], *, combined: bool = False, - minimum_ordinary: int = 8, label: str = "configuration") -> ArmConfigurationV3: +def _configuration( + arm_id: str, scopes: tuple[tuple[str, str], ...], *, combined: bool = False, minimum_ordinary: int = 8, label: str = "configuration" +) -> ArmConfigurationV3: thresholds, policies, sufficiency = _thresholds_and_rules(arm_id, scopes, minimum_ordinary) rule = None if combined: @@ -375,8 +372,9 @@ def _configuration(arm_id: str, scopes: tuple[tuple[str, str], ...], *, combined ) for outcomes in product(tuple(NeutralOutcome), repeat=len(arm_ids)) ) - rule = CombinationRuleV3(arm_id, arm_ids, CombinationOperatorV3.DECLARATIVE_TABLE, rows, - ProofCandidatePolicyV3.IDENTICAL_COMPONENT_ONLY, "") + rule = CombinationRuleV3( + arm_id, arm_ids, CombinationOperatorV3.DECLARATIVE_TABLE, rows, ProofCandidatePolicyV3.IDENTICAL_COMPONENT_ONLY, "" + ) return ArmConfigurationV3( arm_id, ArmKindV3.COMBINED if combined else ArmKindV3.COMPONENT, @@ -464,22 +462,29 @@ def _capability_report(durable_identity: str, transient_identity: str, *, failed 1765000000, "", ) - state = replace(state, state_digest=canonical.bytes_digest(canonical.canonical_bytes({ - "schema_version": RETENTION_PROBE_STATE_SCHEMA, - "input_digest": state.input_digest, - "input_bytes_read": state.input_bytes_read, - "started_at_epoch": state.started_at_epoch, - "durable_store_identity": state.durable_store_identity, - "transient_store_identity": state.transient_store_identity, - "transient_bucket": state.transient_bucket, - "current_key": state.current_key, - "current_version_id": state.current_version_id, - "current_deadline_epoch": state.current_deadline_epoch, - "noncurrent_key": state.noncurrent_key, - "noncurrent_version_id": state.noncurrent_version_id, - "successor_version_id": state.successor_version_id, - "noncurrent_deadline_epoch": state.noncurrent_deadline_epoch, - }))) + state = replace( + state, + state_digest=canonical.bytes_digest( + canonical.canonical_bytes( + { + "schema_version": RETENTION_PROBE_STATE_SCHEMA, + "input_digest": state.input_digest, + "input_bytes_read": state.input_bytes_read, + "started_at_epoch": state.started_at_epoch, + "durable_store_identity": state.durable_store_identity, + "transient_store_identity": state.transient_store_identity, + "transient_bucket": state.transient_bucket, + "current_key": state.current_key, + "current_version_id": state.current_version_id, + "current_deadline_epoch": state.current_deadline_epoch, + "noncurrent_key": state.noncurrent_key, + "noncurrent_version_id": state.noncurrent_version_id, + "successor_version_id": state.successor_version_id, + "noncurrent_deadline_epoch": state.noncurrent_deadline_epoch, + } + ) + ), + ) results = tuple( failed_result(ProbeResultName.CONDITIONAL_CREATE, ProbeResultReason.CONDITIONAL_CREATE_UNSUPPORTED) if failed and name is ProbeResultName.CONDITIONAL_CREATE @@ -497,9 +502,7 @@ class _Environment: durable_settings = _settings(StorePurpose.DURABLE) self.repository = S3ArtifactRepository(durable_settings, self.durable) report = case.report - custody_policy = PopulationCustodyPolicy( - (CUSTODIAN,), derive_population_custody_policy_digest((CUSTODIAN,)) - ) + custody_policy = PopulationCustodyPolicy((CUSTODIAN,), derive_population_custody_policy_digest((CUSTODIAN,))) self.custody = S3DurableCustodyStore( durable_settings, self.durable, @@ -528,11 +531,7 @@ def _case(*, ordinary: int = 12, pilot: bool = False, small_scope_claimed: bool freeze = _freeze(pilot=pilot) manifest, manifest_review, disclosure, resolver = _label_blind_manifest(freeze, ordinary) ordinary_census = (EcosystemOrdinaryCensusV3("python", ordinary),) - shipped_scopes = ( - (("injection", "python"), ("output_encoding", "python")) - if small_scope_claimed - else (("injection", "python"),) - ) + shipped_scopes = (("injection", "python"), ("output_encoding", "python")) if small_scope_claimed else (("injection", "python"),) registrations = ( ArmRegistrationV1( ArmRole.COMBINED, @@ -556,9 +555,7 @@ def _case(*, ordinary: int = 12, pilot: bool = False, small_scope_claimed: bool durable_identity = store_namespace_identity(_settings(StorePurpose.DURABLE)) transient_identity = store_namespace_identity(_settings(StorePurpose.TRANSIENT)) report, transient_profile = _capability_report(durable_identity, transient_identity) - census_payload = admission_orchestrator.admission_census_payload_digest( - plan, manifest, ordinary_census, manifest_review - ) + census_payload = admission_orchestrator.admission_census_payload_digest(plan, manifest, ordinary_census, manifest_review) census_review = _attestation(census_payload, _digest("census-producer"), disclosure) census = admission_orchestrator.compose_population_census(plan, manifest, ordinary_census, census_review) custody_log = empty_population_custody_log(freeze.population_digest, CUSTODIAN) @@ -733,8 +730,7 @@ def test_whole_population_never_substitutes_for_an_insufficient_scope() -> None: feasible_rows = [ row for row in preflight.feasibility.rows - if (row.key.arm_id, row.key.scope.family_id, row.key.scope.ecosystem) - == ("arm-shipped", "injection", "python") + if (row.key.arm_id, row.key.scope.family_id, row.key.scope.ecosystem) == ("arm-shipped", "injection", "python") ] assert feasible_rows assert all(row.status is FeasibilityStatusV3.FEASIBLE for row in feasible_rows) @@ -806,9 +802,7 @@ def test_retry_authority_binds_every_ordered_identity() -> None: _digest("destination-arm-experimental"), _digest("destination-arm-shipped"), ) - assert authority.ordered_checkpoint_slot_digests == tuple( - slot.slot_digest for slot in case.plan.declaration.expected_observation_slots - ) + assert authority.ordered_checkpoint_slot_digests == tuple(slot.slot_digest for slot in case.plan.declaration.expected_observation_slots) assert authority.ordered_input_set_digests == (case.manifest.input_set_digest, case.manifest.input_set_digest) assert len(authority.admission_identity_digest) == 64 diff --git a/tests/test_valid_benchmark_run.py b/tests/test_valid_benchmark_run.py index 41418eac..e69fa9c7 100644 --- a/tests/test_valid_benchmark_run.py +++ b/tests/test_valid_benchmark_run.py @@ -441,9 +441,7 @@ def test_command_entry_refuses_invalid_settings_and_capabilities_before_any_oper environment = _CommandEnv() before = (list(environment.durable.operations), list(environment.transient.operations)) with pytest.raises(run.OperatorCommandError) as collision: - run.validated_operator_configuration( - _environ() | {"VALID_BENCHMARK_TRANSIENT_S3_BUCKET": "valid-durable"}, unsupported - ) + run.validated_operator_configuration(_environ() | {"VALID_BENCHMARK_TRANSIENT_S3_BUCKET": "valid-durable"}, unsupported) assert collision.value.reason in { run.OperatorCommandReason.SETTINGS_INVALID, run.OperatorCommandReason.CAPABILITIES_UNSUPPORTED, @@ -558,9 +556,7 @@ def test_run_command_surfaces_the_seam_impaired_product_without_spend() -> None: def test_interrupted_pre_spend_run_resumes_from_the_durable_store_without_rerun_or_release() -> None: environment = _CommandEnv() - interrupted = run.benchmark_run_command( - environment.context(), environment.run_request(environment.stages(crash_before_spend=True)) - ) + interrupted = run.benchmark_run_command(environment.context(), environment.run_request(environment.stages(crash_before_spend=True))) assert interrupted.outcome.status is WorkflowStatus.IMPAIRED assert interrupted.outcome.reason_codes == (WorkflowReasonCode.INTERRUPTED,) @@ -585,9 +581,7 @@ def test_interrupted_pre_spend_run_resumes_from_the_durable_store_without_rerun_ def test_interrupted_post_spend_run_resumes_without_duplicate_release() -> None: environment = _CommandEnv() loader = _CrashingLoader(_label_bytes(environment.case.freeze)) - interrupted = run.benchmark_run_command( - environment.context(), environment.run_request(environment.stages(spend_loader=loader)) - ) + interrupted = run.benchmark_run_command(environment.context(), environment.run_request(environment.stages(spend_loader=loader))) assert interrupted.outcome.status is WorkflowStatus.IMPAIRED assert interrupted.outcome.reason_codes == (WorkflowReasonCode.INSTRUMENT_FAILURE,) @@ -654,20 +648,14 @@ def test_commands_never_mutate_detector_or_infrastructure_state(monkeypatch) -> for env in (environment, crashed): methods = {operation.split(":", 1)[0] for operation in env.durable.operations + env.transient.operations} assert methods <= {"put", "get"} - assert all( - operation.split(":", 1)[1].startswith(DURABLE_PREFIXES) for operation in env.durable.operations - ) - assert all( - operation.split(":", 1)[1].startswith(f"workflow/{WORKFLOW}/") for operation in env.transient.operations - ) + assert all(operation.split(":", 1)[1].startswith(DURABLE_PREFIXES) for operation in env.durable.operations) + assert all(operation.split(":", 1)[1].startswith(f"workflow/{WORKFLOW}/") for operation in env.transient.operations) assert not any("detector" in operation or "lifecycle-policy" in operation for operation in env.durable.operations) def test_status_refuses_hostile_outcome_bytes_without_a_traceback() -> None: environment = _CommandEnv() - result = run.benchmark_run_command( - environment.context(), environment.run_request(environment.stages(crash_before_spend=True)) - ) + result = run.benchmark_run_command(environment.context(), environment.run_request(environment.stages(crash_before_spend=True))) reference = result.outcome_reference assert reference is not None location = artifact_object_location(_settings(StorePurpose.DURABLE), reference) @@ -716,9 +704,7 @@ def test_resume_command_reports_blocked_when_the_seam_terminally_blocks() -> Non ineligible = _lifecycle(environment.population, environment.case.freeze.freeze_digest, active=False) with pytest.raises(run.OperatorCommandError) as blocked: - run.benchmark_resume_command( - environment.context(), environment.resume_request(lifecycle_authority=ineligible) - ) + run.benchmark_resume_command(environment.context(), environment.resume_request(lifecycle_authority=ineligible)) assert blocked.value.reason is run.OperatorCommandReason.RESUME_BLOCKED assert str(blocked.value) == "operator_command_resume_blocked" @@ -736,8 +722,6 @@ def test_command_refusals_stay_closed_without_caller_content() -> None: crashed = _CommandEnv() run.benchmark_run_command(crashed.context(), crashed.run_request(crashed.stages(crash_before_spend=True))) with pytest.raises(run.OperatorCommandError) as unknown: - run.benchmark_resume_command( - crashed.context(), crashed.resume_request(workflow_digest=_digest("missing-workflow")) - ) + run.benchmark_resume_command(crashed.context(), crashed.resume_request(workflow_digest=_digest("missing-workflow"))) assert unknown.value.reason is run.OperatorCommandReason.WORKFLOW_UNKNOWN assert str(unknown.value) == "operator_command_workflow_unknown" diff --git a/tests/test_valid_benchmark_sealed_retry.py b/tests/test_valid_benchmark_sealed_retry.py index 9ce589c5..c61b97f5 100644 --- a/tests/test_valid_benchmark_sealed_retry.py +++ b/tests/test_valid_benchmark_sealed_retry.py @@ -78,9 +78,7 @@ def _frozen_plan(): bundles = _bundles() client = _Client() results = tuple(_run(bundle, _CheckpointAdapter(), client) for bundle in bundles) - selectors = tuple( - observation_checkpoint.CheckpointSelectorV1(result.reference, result.checkpoint_digest) for result in results - ) + selectors = tuple(observation_checkpoint.CheckpointSelectorV1(result.reference, result.checkpoint_digest) for result in results) return bundles, client, selectors @@ -124,9 +122,7 @@ def _review() -> dict[str, object]: def _matching_authority(bundles, selectors, plan, admission: str) -> AutomaticRetryAuthorityV1: candidate = _identity(bundles, selectors, admission) - components = tuple( - sorted(row.arm_id for row in plan.registrations if row.configuration.kind is ArmKindV3.COMPONENT) - ) + components = tuple(sorted(row.arm_id for row in plan.registrations if row.configuration.kind is ArmKindV3.COMPONENT)) return AutomaticRetryAuthorityV1( candidate.population_digest, candidate.freeze_digest, @@ -259,9 +255,7 @@ def _foreign_plan(case, *, changed_inputs: bool = False): input_digests = (_digest("foreign-plan-input"), *input_digests[1:]) return registry.register_evaluation_plan( registrations=current.registrations, - population_digest=( - current.declaration.population_digest if changed_inputs else _digest("foreign-plan-population") - ), + population_digest=(current.declaration.population_digest if changed_inputs else _digest("foreign-plan-population")), freeze_digest=current.declaration.freeze_digest, input_set_digest=derive_evaluation_input_set_digest(input_digests), input_identity_digests=input_digests, @@ -309,17 +303,13 @@ def test_caller_supplied_original_identity_cannot_authorize_changed_current_bund case = _execution_case() env = _RetryEnv(case) lifecycle_authority = env.lifecycle() - changed_budget = replace( - case.bundles[0].budget, deadline_seconds=case.bundles[0].budget.deadline_seconds + 1, budget_digest="" - ) + changed_budget = replace(case.bundles[0].budget, deadline_seconds=case.bundles[0].budget.deadline_seconds + 1, budget_digest="") bundles = (replace(case.bundles[0], budget=changed_budget, bundle_digest=""), *case.bundles[1:]) candidate = _identity(bundles, env.selectors, env.authorized.retry_authority.admission_identity_digest) mismatch = _review_authority(env, candidate, bundles=bundles, lifecycle_authority=lifecycle_authority) adapter = _Adapter(_boom) - result = _pre_spend_resume( - env, bundles=bundles, adapter=adapter, mismatch_authority=mismatch, lifecycle_authority=lifecycle_authority - ) + result = _pre_spend_resume(env, bundles=bundles, adapter=adapter, mismatch_authority=mismatch, lifecycle_authority=lifecycle_authority) assert result.status is sealed_retry.AutomaticRetryStatus.BLOCKED assert result.reason is sealed_retry.AutomaticRetryReason.IDENTITY_CHANGED @@ -345,14 +335,10 @@ def test_changed_identity_dimension_terminally_blocks_admission_without_executio elif mutation == "plan-inputs": plan = _foreign_plan(case, changed_inputs=True) else: - changed = replace( - case.bundles[0].budget, deadline_seconds=case.bundles[0].budget.deadline_seconds + 1, budget_digest="" - ) + changed = replace(case.bundles[0].budget, deadline_seconds=case.bundles[0].budget.deadline_seconds + 1, budget_digest="") bundles = (replace(case.bundles[0], budget=changed, bundle_digest=""), *case.bundles[1:]) candidate = _identity(bundles, env.selectors, admission) - mismatch = _review_authority( - env, candidate, plan=plan, bundles=bundles, lifecycle_authority=lifecycle_authority - ) + mismatch = _review_authority(env, candidate, plan=plan, bundles=bundles, lifecycle_authority=lifecycle_authority) adapter = _Adapter(_boom) result = _pre_spend_resume( @@ -457,9 +443,7 @@ def test_deeply_nested_mismatch_evidence_fails_closed_without_mutation() -> None forged = object.__new__(sealed_retry.RetryMismatchAuthorityV1) for name, value in vars(valid).items(): object.__setattr__(forged, name, value) - object.__setattr__( - forged, "retirement_event_content", b'{"a":' * 100_000 + b"1" + b"}" * 100_000 - ) + object.__setattr__(forged, "retirement_event_content", b'{"a":' * 100_000 + b"1" + b"}" * 100_000) adapter = _Adapter(_boom) with pytest.raises(sealed_retry.AutomaticRetryError) as captured: @@ -656,9 +640,10 @@ def test_post_spend_resume_keeps_labels_spent_and_the_same_immutable_run() -> No assert resumed.labels_spent is True assert resumed.authority_digest == env.authorized.retry_authority.authority_digest - assert resumed.retry_digest == _identity( - env.case.bundles, env.selectors, env.authorized.retry_authority.admission_identity_digest - ).retry_digest + assert ( + resumed.retry_digest + == _identity(env.case.bundles, env.selectors, env.authorized.retry_authority.admission_identity_digest).retry_digest + ) assert resumed.custody_receipt_digest == spent_log.head_receipt_digest assert env.custody.current_log(env.population) == spent_log assert env.custody.current_log(env.population).status is PopulationStatus.SPENT diff --git a/tests/test_valid_benchmark_workflow_journal.py b/tests/test_valid_benchmark_workflow_journal.py index 10d89db7..b8b6c937 100644 --- a/tests/test_valid_benchmark_workflow_journal.py +++ b/tests/test_valid_benchmark_workflow_journal.py @@ -88,11 +88,7 @@ class _Client: raise _ProviderError("InternalError") key = str(kwargs["Key"]) requested = kwargs.get("VersionId") - matching = [ - item - for item in self.versions.get(key, []) - if requested is None or item.version_id == requested - ] + matching = [item for item in self.versions.get(key, []) if requested is None or item.version_id == requested] if not matching: raise _ProviderError("NoSuchKey") version = matching[-1] @@ -112,9 +108,7 @@ class _Client: with self.lock: version_id = f"version-{self.next_version}" self.next_version += 1 - self.versions.setdefault(key, []).append( - _Version(version_id, body, sha256(body + version_id.encode()).hexdigest()) - ) + self.versions.setdefault(key, []).append(_Version(version_id, body, sha256(body + version_id.encode()).hexdigest())) def _digest(seed: str) -> str: @@ -240,9 +234,7 @@ def test_entry_binds_exact_causal_fields_with_byte_identical_digest() -> None: assert _HEX64.fullmatch(first.entry_digest) changed = _entry(counts=WorkflowCounts(2, 2, 12, 6, 0)) assert changed.entry_digest != first.entry_digest - decoded = workflow_journal.decode_workflow_journal_entry( - workflow_journal.journal_entry_bytes(first) - ) + decoded = workflow_journal.decode_workflow_journal_entry(workflow_journal.journal_entry_bytes(first)) assert decoded == first @@ -373,9 +365,7 @@ def test_substituted_authority_cannot_replace_the_selection() -> None: with pytest.raises(workflow_journal.WorkflowJournalError) as guard: workflow_journal.require_selected_authority(head, _authority("substituted"), _digest("s")) assert guard.value.reason is workflow_journal.WorkflowJournalReason.AUTHORITY_SUBSTITUTED - assert workflow_journal.require_selected_authority( - head, head.retry_authority_ref, head.retry_authority_digest - ) + assert workflow_journal.require_selected_authority(head, head.retry_authority_ref, head.retry_authority_digest) def test_missing_predecessor_or_forked_entries_fail() -> None: @@ -387,9 +377,7 @@ def test_missing_predecessor_or_forked_entries_fail() -> None: assert report.value.reason is workflow_journal.WorkflowJournalReason.INVALID_SUCCESSOR collision = _entry(sequence=0, previous_entry_digest=None) with pytest.raises(workflow_journal.WorkflowJournalError): - journal.append_and_swap( - head.head_digest, collision, workflow_journal.successor_head(head, collision) - ) + journal.append_and_swap(head.head_digest, collision, workflow_journal.successor_head(head, collision)) skip = _entry(sequence=2, previous_entry_digest=head.entry_digest) with pytest.raises(workflow_journal.WorkflowJournalError): journal.append_and_swap(head.head_digest, skip, workflow_journal.successor_head(head, skip)) @@ -521,8 +509,13 @@ def test_concurrent_resume_has_exactly_one_winner() -> None: ) assert live.value.reason is workflow_journal.WorkflowJournalReason.LEASE_NOT_EXPIRED current = _appended( - journal, resumed, 2, attempt_id="attempt-2", lease_owner_id="owner-b", - heartbeat_at=_at(45), lease_expires_at=_at(75), + journal, + resumed, + 2, + attempt_id="attempt-2", + lease_owner_id="owner-b", + heartbeat_at=_at(45), + lease_expires_at=_at(75), ) stale = _entry( sequence=3, diff --git a/tests/test_valid_benchmark_workflow_outcome.py b/tests/test_valid_benchmark_workflow_outcome.py index 1f2870ae..33d77956 100644 --- a/tests/test_valid_benchmark_workflow_outcome.py +++ b/tests/test_valid_benchmark_workflow_outcome.py @@ -88,9 +88,7 @@ def _insufficient(**overrides: object) -> workflow_outcome.BenchmarkWorkflowOutc "plan_digest": _digest("plan"), "workflow_digest": _digest("workflow"), "labels_spent": False, - "counts": _counts( - planned_arms=2, completed_arms=0, planned_inputs=12, completed_inputs=0, deferred_inputs=12 - ), + "counts": _counts(planned_arms=2, completed_arms=0, planned_inputs=12, completed_inputs=0, deferred_inputs=12), "failed_gate_names": (workflow_outcome.WorkflowGate.PREFLIGHT_FEASIBILITY,), "degradation_codes": (), "runtime_ms": 90,