lib

Core libraries for Radroots
git clone https://radroots.dev/git/lib.git
Log | Files | Refs | README

decision_package.rs (127482B)


      1 //! Prospective shared SDK authority. Validation does not claim implementation.
      2 
      3 use std::{
      4     collections::{BTreeMap, BTreeSet},
      5     path::Path,
      6 };
      7 
      8 use serde::Deserialize;
      9 
     10 const CONTRACT: &str = "contracts/architecture/decisions/shared_sdk_refactor.v1.json";
     11 const MAX_BYTES: usize = 65_536;
     12 
     13 mod currency_registry;
     14 
     15 #[derive(Deserialize)]
     16 #[serde(deny_unknown_fields)]
     17 struct Policy {
     18     schema_version: u16,
     19     contract_id: String,
     20     state: String,
     21     publication_authorized: bool,
     22     toolchain: Toolchain,
     23     ownership: Ownership,
     24     roles: Roles,
     25     deferred_application_migrations: Vec<String>,
     26     retained_capability_families: Vec<String>,
     27     independence: Independence,
     28     local_outbox_authority: LocalOutboxAuthority,
     29     native_seller_stock_authority: NativeSellerStockAuthority,
     30     provenance: Provenance,
     31     targets: Targets,
     32     portability: Portability,
     33     packages: Vec<Package>,
     34     values: Values,
     35     limits: BTreeMap<String, u64>,
     36     stock_accounting: StockAccounting,
     37     execution: Execution,
     38     protocol: Protocol,
     39     cutover: Cutover,
     40     qualification: Qualification,
     41 }
     42 
     43 #[derive(Deserialize)]
     44 #[serde(deny_unknown_fields)]
     45 struct StockAccounting {
     46     replacement_terms_admission: ReplacementTermsAdmission,
     47     native_terms_installation: NativeTermsInstallation,
     48     native_inspection: NativeInspection,
     49     value_owner: String,
     50     scope: String,
     51     obligation_equation: String,
     52     ticks_max: u64,
     53     values_create_store_effects: bool,
     54     deficit_counts_as_physical_stock: bool,
     55     receipt_consumes_again: bool,
     56     released_deficit_adds_available: bool,
     57     loss_deletes_obligation: bool,
     58     native_atomic_allocation_and_identity_required: bool,
     59     native_correction: NativeCorrection,
     60 }
     61 
     62 #[derive(Deserialize)]
     63 #[serde(deny_unknown_fields)]
     64 struct ReplacementTermsAdmission {
     65     owner: String,
     66     scope: String,
     67     complete_local_causal_coverage_required: bool,
     68     conflicting_authorizations_require_reconciliation: bool,
     69     native_canonical_digest_recompute_required: bool,
     70     native_current_head_and_residual_required: bool,
     71     claim_grants_current_authority: bool,
     72     claim_creates_stock_effects: bool,
     73 }
     74 
     75 #[derive(Deserialize)]
     76 #[serde(deny_unknown_fields)]
     77 struct NativeTermsInstallation {
     78     catalog: u8,
     79     facade_method: String,
     80     execution_method: String,
     81     source_owner: String,
     82     allocation_owner: String,
     83     delta_owner: String,
     84     current_installed_base_required: bool,
     85     original_allocations_required: bool,
     86     positive_hold_phase: String,
     87     negative_release_phase: String,
     88     pending_negatives_finance_holds: bool,
     89     old_commitment_retained_while_pending: bool,
     90     changed_residual_requires_new_admission: bool,
     91     release_composition: String,
     92     quantity_storage: String,
     93     index_plaintext_quantities: bool,
     94     automatic_changed_multi_pool_split: String,
     95     same_signing_and_recovery_owner: bool,
     96     unknown_issuance_releases_stock: bool,
     97     retained_catalog_auto_upgrade: bool,
     98 }
     99 
    100 #[derive(Deserialize)]
    101 #[serde(deny_unknown_fields)]
    102 struct NativeCorrection {
    103     catalog: u8,
    104     selection: String,
    105     max_affected_allocations: u8,
    106     protected_original_allocation_required: bool,
    107     deficit_projection_in_final_transaction: bool,
    108     quantity_storage: String,
    109     worker_charge_bytes: u32,
    110     preparatory_loss_implicit: bool,
    111     quarantine_loss_implicit: bool,
    112 }
    113 
    114 #[derive(Deserialize)]
    115 #[serde(deny_unknown_fields)]
    116 struct NativeInspection {
    117     model_owner: String,
    118     facade_method: String,
    119     storage_port: String,
    120     supported_catalogs: Vec<u8>,
    121     worker_charge_bytes: u32,
    122     same_checkpoint_required: bool,
    123     original_allocation_required: bool,
    124     read_pools_and_operations_required: bool,
    125     pending_claims_are_installed: bool,
    126     query_creates_store_effects: bool,
    127     reports_global_business_completeness: bool,
    128 }
    129 
    130 #[derive(Deserialize)]
    131 #[serde(deny_unknown_fields)]
    132 struct Toolchain {
    133     edition: String,
    134     stable: String,
    135     msrv: String,
    136     historical_receipts_immutable: bool,
    137     dedicated_nightly_and_sp1_separate: bool,
    138 }
    139 
    140 #[derive(Deserialize)]
    141 #[serde(deny_unknown_fields)]
    142 struct Ownership {
    143     shared_repository: String,
    144     ordinary_facade: String,
    145     native_bindings: String,
    146     browser_artifact: String,
    147     sdk_repository_role: String,
    148     app_owns_shared_semantics: bool,
    149 }
    150 
    151 #[derive(Deserialize)]
    152 #[serde(deny_unknown_fields)]
    153 struct Roles {
    154     cli: Vec<String>,
    155     tera: Vec<String>,
    156     browser: Vec<String>,
    157     generic_ffi: Vec<String>,
    158 }
    159 
    160 #[derive(Deserialize)]
    161 #[serde(deny_unknown_fields)]
    162 struct Independence {
    163     hosted_account_required: bool,
    164     farm_hierarchy_required: bool,
    165     rhi_required: bool,
    166     payment_implementation_in_scope: bool,
    167     seller_owner_executor_optional_to_single_device: bool,
    168 }
    169 
    170 #[derive(Deserialize)]
    171 #[serde(deny_unknown_fields)]
    172 struct LocalOutboxAuthority {
    173     scopes: Vec<String>,
    174     seller_enrollment_explicit: bool,
    175     scope_retained_in_authenticated_binding_and_preparation: bool,
    176     legacy_preparation_v2_scope: String,
    177     scope_separates_route_genesis_and_credential_commitments: bool,
    178     coverage: String,
    179     stock_authority: bool,
    180     organization_or_delegation_authority: bool,
    181     existing_order_or_history_recovery: bool,
    182 }
    183 
    184 #[derive(Deserialize)]
    185 #[serde(deny_unknown_fields)]
    186 struct StockCapabilityContract {
    187     id: String,
    188     version: String,
    189 }
    190 
    191 #[derive(Deserialize)]
    192 #[serde(deny_unknown_fields)]
    193 struct StockEnvelopeRetention {
    194     journal_family: u32,
    195     payload_version: u32,
    196     payload_prefix_bytes: u32,
    197     supported_catalogs: Vec<u32>,
    198     retained_unsupported_catalogs: Vec<u32>,
    199     raw_max_bytes: u32,
    200     worker_charge_bytes: u32,
    201     capture_port: String,
    202     query_port: String,
    203     recovery_port: String,
    204     original_preparation_plan_claim_seal_installation_required: bool,
    205     temporary_key_derivation_and_exact_decryption_required: bool,
    206     temporary_key_retained: bool,
    207     original_party_as_outer_author_allowed: bool,
    208     body_derived_projection_and_complete_ancestry_required: bool,
    209     original_credential_capture_requires_live_clock_or_grant: bool,
    210     query_requires_current_recovery_access: bool,
    211     observation_nullable: bool,
    212     existing_original_bytes_may_be_replaced: bool,
    213     capture_grants_dispatch: bool,
    214     capture_changes_physical_stock: bool,
    215     provider_io_inside_sql: bool,
    216 }
    217 
    218 #[derive(Deserialize)]
    219 #[serde(deny_unknown_fields)]
    220 struct StockRewrapping {
    221     journal_family: u16,
    222     admission_journal_family: u16,
    223     admission_payload_bytes: u16,
    224     admission_window_seconds_max: u16,
    225     admission_port: String,
    226     admission_recovery_port: String,
    227     admission_query_port: String,
    228     explicit_request_id_required: bool,
    229     newly_confirmed_admission_before_wrapping: bool,
    230     existing_or_uncertain_admission_grants_invocation: bool,
    231     unknown_admissions_count_toward_limit: bool,
    232     descriptor_includes_uncaptured_admissions: bool,
    233     admission_repair_grants_history_or_invocation: bool,
    234     ordinary_owner: String,
    235     ordinary_facade_methods: Vec<String>,
    236     ordinary_resume_generates_key_or_business_signature: bool,
    237     ordinary_status_is_atomic_absence_proof: bool,
    238 
    239     payload_version: u16,
    240     payload_prefix_bytes: u32,
    241     supported_catalogs: Vec<u16>,
    242     retained_unsupported_catalogs: Vec<u16>,
    243     raw_max_bytes: u32,
    244     worker_charge_bytes: u32,
    245     additional_envelopes_per_recipient_max: u16,
    246     descriptor_page_max: u16,
    247     capture_port: String,
    248     recovery_port: String,
    249     query_port: String,
    250     page_port: String,
    251     original_f10_and_same_s_t2_required: bool,
    252     default_selection_is_original: bool,
    253     new_envelope_selection_explicit: bool,
    254     first_policy_source_bound: bool,
    255     transport_counters_cumulative: bool,
    256     outcomes_scoped_to_exact_envelope: bool,
    257     natural_index_transaction_witness_required: bool,
    258     existing_bytes_may_be_replaced: bool,
    259     original_capture_requires_live_clock_or_grant: bool,
    260     capture_or_query_grants_dispatch: bool,
    261     physical_stock_effect: bool,
    262     temporary_key_retained: bool,
    263     provider_io_inside_sql: bool,
    264 }
    265 
    266 #[derive(Deserialize)]
    267 #[serde(deny_unknown_fields)]
    268 struct NativeSellerStockAuthority {
    269     rewrapping: StockRewrapping,
    270     delivery: StockDelivery,
    271     envelope_retention: StockEnvelopeRetention,
    272     qualified_local_recovery: QualifiedLocalRecovery,
    273     source_payload_schemas: Vec<String>,
    274     source_profile_dispositions: Vec<String>,
    275     source_owner_administration_required: bool,
    276     inventory_scope_grants_source_access: bool,
    277     source_checkpoint_independent: bool,
    278     source_profile_implies_actionability: bool,
    279     causal_history_current_administrator_required: bool,
    280     causal_history_complete_local_scope_required: bool,
    281     causal_history_includes_actual_local_signed_records: bool,
    282     causal_history_inventory_minimum_required: bool,
    283     causal_history_logical_record_deduplication_required: bool,
    284     causal_history_implies_installation: bool,
    285     causal_history_uninterpreted_policy: String,
    286     causal_history_transaction_witnesses_required: bool,
    287     causal_history_implies_business_permission: bool,
    288     source_carrier_max_bytes: u32,
    289     source_chunk_max_bytes: u32,
    290     mapping_payload_schema: String,
    291     mapping_owner_administration_required: bool,
    292     mapping_changes_physical_stock: bool,
    293     mapping_changes_pool_version: bool,
    294     mapping_create_expected_version: u16,
    295     capability_contract: StockCapabilityContract,
    296     scope: String,
    297     database: String,
    298     lock: String,
    299     schema_version: u16,
    300     retained_enrollment_versions: Vec<u16>,
    301     retained_inventory_versions: Vec<u16>,
    302     authority_payload_schema: String,
    303     public_source_payload_schemas: Vec<String>,
    304     public_source_owner_administration_required: bool,
    305     inventory_scope_grants_public_source_access: bool,
    306     public_source_checkpoint_independent: bool,
    307     public_source_input_requires_signature_evidence: bool,
    308     public_source_read_reverifies_signature: bool,
    309     public_source_global_completeness_claimed: bool,
    310     public_source_profile_implies_actionability: bool,
    311     public_source_head_policy: String,
    312     public_source_duplicate_encodings: String,
    313     public_source_raw_max_bytes: u32,
    314     public_source_part_max_bytes: u32,
    315     public_source_part_max_count: u16,
    316     public_source_worker_charge_bytes: u32,
    317     inventory_operation_payload_schema: String,
    318     operation_part_payload_schema: String,
    319     operation_body_max_bytes: u32,
    320     operation_part_max_bytes: u32,
    321     operation_part_max_count: u16,
    322     operation_identity_requires_protected_ancestry: bool,
    323     acceptance_preparation: AcceptancePreparation,
    324     signing_plan_binding: SigningPlanBinding,
    325     signing_issuance: SigningIssuance,
    326     initial_agreement_installation: InitialAgreementInstallation,
    327     preparation_abort: PreparationAbort,
    328     business_consent_payload_version: u16,
    329     business_consent_action: String,
    330     business_consent_modes: Vec<String>,
    331     business_consent_admin_issuance_required: bool,
    332     business_consent_binds_exact_command_and_subject_grant: bool,
    333     business_consent_issuance_has_order_or_stock_effects: bool,
    334     business_consent_worker_charge_bytes: u32,
    335     inventory_movement_payload_schema: String,
    336     grant_payload_schema: String,
    337     grant_change_payload_schema: String,
    338     namespace_excludes_caller_grant: bool,
    339     actor_operation_unique_across_grants: bool,
    340     grant_checkpoint_minimum_required: bool,
    341     grant_checkpoint_policy: String,
    342     grant_set_max: u16,
    343     grant_pool_scope_max: u16,
    344     grant_action_max: u16,
    345     grant_scope_actions: Vec<String>,
    346     grant_write_requires_receipt_and_recovery_read: bool,
    347     inventory_scope_grants_administration: bool,
    348     grant_admin_prepared_transaction_required: bool,
    349     retained_grants_automatically_evicted: bool,
    350     old_self_revoke_api_supported: bool,
    351     pool_tick_scale_explicit: bool,
    352     pool_tick_scale_encoding: String,
    353     inventory_checkpoint_minimum_required: bool,
    354     empty_pool_has_physical_movement: bool,
    355     enrollment_prepared_before_durable_creation: bool,
    356     prepared_enrollment_single_use: bool,
    357     same_connection_owner_as_outbox: bool,
    358     protected_authority_and_grants_separate: bool,
    359     automatic_outbox_migration: bool,
    360     historical_obligations_recovered: bool,
    361     business_effects_qualified: bool,
    362 }
    363 
    364 #[derive(Deserialize)]
    365 #[serde(deny_unknown_fields)]
    366 struct StockDelivery {
    367     supported_catalogs: Vec<u16>,
    368     retained_unsupported_catalogs: Vec<u16>,
    369     attempt_journal_family: u16,
    370     observation_journal_family: u16,
    371     attempt_payload_version: u16,
    372     observation_payload_version: u16,
    373     attempt_body_max_bytes: u32,
    374     observation_body_max_bytes: u32,
    375     target_max: u16,
    376     attempts_per_target: u16,
    377     attempts_per_operation_max: u16,
    378     observations_per_operation_max: u16,
    379     observation_page_max: u16,
    380     summary_target_max: u16,
    381     worker_charge_bytes: u32,
    382     storage_ports: Vec<String>,
    383     original_stock_evidence_installation_outer_required: bool,
    384     original_captured_route_and_current_write_policy_required: bool,
    385     fresh_current_scoped_consent_grant_clock_required: bool,
    386     installed_original_recovery_delivery_supported: bool,
    387     fresh_claim_requires_confirmed_commit: bool,
    388     existing_attempt_grants_dispatch: bool,
    389     unknown_commit_grants_dispatch: bool,
    390     query_grants_dispatch: bool,
    391     first_complete_targets_and_criterion_immutable: bool,
    392     ordinary_command_replays_existing_attempt: bool,
    393     ordinary_fresh_claim_binds_observed_attempt_count: bool,
    394     ordinary_repeat_uses_selected_envelope_attempt_count: bool,
    395     ordinary_obtained_material_owner: String,
    396     ordinary_peer_delivery_precedes_self_signing: bool,
    397     installed_original_delivery_requires_signer: bool,
    398     explicit_resume_claims_bounded_new_attempt: bool,
    399     retries_use_original_outer_bytes: bool,
    400     observation_nullable: bool,
    401     original_credential_capture_requires_live_clock_or_grant: bool,
    402     same_owner_obtained_material_reconciliation_required: bool,
    403     first_observation_per_class_immutable: bool,
    404     wrong_event_request_target_ack_rejected: bool,
    405     protected_refs_indexes_complete_ancestry_required: bool,
    406     final_transaction_witnesses_required: bool,
    407     unbounded_attempt_or_observation_collections: bool,
    408     physical_stock_effect: bool,
    409     transport_inside_sql: bool,
    410 }
    411 
    412 #[derive(Deserialize)]
    413 #[serde(deny_unknown_fields)]
    414 struct AcceptancePreparation {
    415     shared_storage_port: String,
    416     shared_model_owner: String,
    417     legacy_native_aliases: bool,
    418     unsupported_hosts_refuse: bool,
    419     model_constructs_runtime: bool,
    420     planner_owner: String,
    421     payload_version: u32,
    422     order_payload_schema: String,
    423     movement_payload_schema: String,
    424     worker_charge_bytes: u32,
    425     max_allocations: u32,
    426     max_pool_observations: u32,
    427     max_first_issue_window_seconds: u32,
    428     original_replay_before_fresh_planning: bool,
    429     complete_allocation_required: bool,
    430     atomic_holds_and_order_fence_required: bool,
    431     current_issued_consent_required: bool,
    432     final_source_counts_and_witnesses_required: bool,
    433     signer_invoked: bool,
    434     agreement_installed: bool,
    435 }
    436 
    437 #[derive(Deserialize)]
    438 #[serde(deny_unknown_fields)]
    439 struct QualifiedLocalRecovery {
    440     scoped_method: String,
    441     scoped_identity_and_capability_rechecked: bool,
    442     scoped_callback_binding_enforced: bool,
    443     scoped_close_waits_for_active_call: bool,
    444     scoped_method_grants_store_authority: bool,
    445     provider_method: String,
    446     adapter: String,
    447     native_authorizer: String,
    448     captured_replay: String,
    449     native_catalog: u16,
    450     worker_charge_bytes: u32,
    451     existing_protected_claim_required: bool,
    452     current_execute_consent_required: bool,
    453     original_window_required: bool,
    454     call_budget_extends_original_window: bool,
    455     recovery_refusal_proves_original_unissued: bool,
    456     creates_claim_or_stock_effect: bool,
    457     provider_work_inside_sql: bool,
    458     unsupported_legacy_fallback: bool,
    459     after_expiry_retrieval_available: bool,
    460     legacy_and_first_dispatch_unchanged: bool,
    461     current_replay_admission_required: bool,
    462     replay_admission_journal_family: u16,
    463     replay_admission_payload_version: u16,
    464     replay_admission_payload_bytes: u16,
    465     replay_admission_unknown_returns_permit: bool,
    466     replay_admission_reauthorizes_current: bool,
    467     replay_admission_clear_on_refusal: bool,
    468     replay_admission_stock_effect: bool,
    469     retained_untracked_catalogs: Vec<u16>,
    470     replay_admission_report_is_release_authority: bool,
    471 }
    472 
    473 #[derive(Deserialize)]
    474 #[serde(deny_unknown_fields)]
    475 struct PreparationAbort {
    476     shared_storage_port: String,
    477     shared_model_owner: String,
    478     native_workspace_type_aliases: bool,
    479     unsupported_hosts_return: String,
    480     payload_version: u32,
    481     journal_family: u32,
    482     worker_charge_bytes: u32,
    483     retained_payload_versions: Vec<u32>,
    484     retained_v1_requires_absent_claims: bool,
    485     claimed_cleanup_catalogs: Vec<u32>,
    486     untracked_claimed_catalogs: Vec<u32>,
    487     per_recipient_proof_count: u32,
    488     original_unissued_required_for_every_claim: bool,
    489     replay_admission_blocks_release: bool,
    490     obtained_evidence_blocks_release: bool,
    491     contradictory_evidence_retained: bool,
    492     contradiction_requires_recovery: bool,
    493     caller_reports_are_release_authority: bool,
    494     caller_nonissuance_assertion_is_proof: bool,
    495     current_exact_recovery_consent_required: bool,
    496     atomic_exact_original_release_required: bool,
    497     original_preparations_retained: bool,
    498     current_order_projection_authenticated: bool,
    499     later_initial_requires_original_abort: bool,
    500     fresh_signing_after_abort: bool,
    501     unknown_commit_fences_owner: bool,
    502     signer_or_transport_invoked: bool,
    503 }
    504 
    505 #[derive(Deserialize)]
    506 #[serde(deny_unknown_fields)]
    507 struct InitialAgreementInstallation {
    508     payload_version: u32,
    509     journal_family: u32,
    510     worker_charge_bytes: u32,
    511     required_peer_evidence: bool,
    512     missing_self_copy_blocks_installation: bool,
    513     original_order_fence_immutable: bool,
    514     exact_original_hold_quantities_required: bool,
    515     current_exact_recovery_consent_required: bool,
    516     fresh_time_not_before_original_bound_plan: bool,
    517     atomic_pool_agreement_and_work_required: bool,
    518     recipient_work_count: u32,
    519     unknown_commit_fences_owner: bool,
    520     signer_or_transport_invoked: bool,
    521     relay_delivery_claimed: bool,
    522 }
    523 
    524 #[derive(Deserialize)]
    525 #[serde(deny_unknown_fields)]
    526 struct SigningIssuance {
    527     shared_reconciliation_port: String,
    528     reconciliation_retains_writer_through_replacement: bool,
    529     reconciliation_authenticates_before_connection_close: bool,
    530     reconciliation_preflight_initializes_or_migrates: bool,
    531     reconciliation_clears_fence_only_after_confirmed_capture: bool,
    532     shared_capture_port: String,
    533     shared_capture_model_owner: String,
    534     shared_capture_descriptors_are_authority: bool,
    535     shared_capture_reauthenticates_original: bool,
    536     native_capture_report_aliases: bool,
    537     coherent_operation_snapshot_required: bool,
    538     final_evidence_selectors_and_page_rows_required: bool,
    539     recovery_view_has_dispatch_or_installation_rights: bool,
    540     fresh_current_backing_projection_required: bool,
    541     evidence_page_max: u32,
    542     claim_family: u32,
    543     evidence_family: u32,
    544     claim_worker_charge_bytes: u32,
    545     capture_worker_charge_bytes: u32,
    546     capture_raw_max_bytes: u32,
    547     first_dispatch_requires_confirmed_commit: bool,
    548     existing_claim_returns_dispatch_permit: bool,
    549     protected_identity_presence_and_absence_required: bool,
    550     capture_requires_original_claim_and_credential: bool,
    551     capture_requires_current_consent: bool,
    552     capture_requires_observation_clock: bool,
    553     capture_preserves_first_optional_time: bool,
    554     capture_retains_distinct_valid_encodings: bool,
    555     agreement_installed: bool,
    556 }
    557 
    558 #[derive(Deserialize)]
    559 #[serde(deny_unknown_fields)]
    560 struct SigningPlanBinding {
    561     ordinary_acceptance_owner: String,
    562     ordinary_acceptance_facade: String,
    563     ordinary_peer_installed_before_self_work: bool,
    564     ordinary_accepted_task_survives_observer_loss: bool,
    565     ordinary_obtained_owned_before_descriptor_conversion: bool,
    566     generic_obtained_owned_before_descriptor_conversion: bool,
    567     retained_drain_preserves_original_error_and_operation: bool,
    568     rejected_signer_error: String,
    569     effectful_command_result: String,
    570     common_error_max_bytes: u16,
    571     execution_failure_max_bytes: u16,
    572     rejected_signer_metadata_owner: String,
    573     rejected_signer_report_is_nonissuance: bool,
    574     generic_peer_installed_before_rejected_self_return: bool,
    575     unknown_installation_blocks_delivery: bool,
    576     native_first_dispatch_owns_issuer_invocation: bool,
    577     shared_first_dispatch_port: String,
    578     shared_unissued_owner: String,
    579     shared_unissued_retained_before_capture: bool,
    580     shared_unissued_drained_before_storage_close: bool,
    581     shared_unissued_failure_blocks_fresh_commands: bool,
    582     public_native_intent_extraction: bool,
    583     coherent_snapshot_preserves_original_unissued: bool,
    584     exact_issuer_port: String,
    585     native_failure_boundary: String,
    586     native_failure_preserves_signer_rejection: bool,
    587     native_failure_fingerprint_bytes: u8,
    588     native_failure_coverage: String,
    589     native_failure_max_bytes: u16,
    590     browser_failure_boundary: String,
    591     browser_failure_preserves_signer_rejection: bool,
    592     browser_failure_max_bytes: u16,
    593     original_unissued_capture_owner: String,
    594     original_unissued_payload_version: u32,
    595     original_unissued_journal_family: u32,
    596     original_unissued_capture_requires_owned_observation: bool,
    597     original_unissued_capture_borrows_observation: bool,
    598     original_unissued_capture_rechecks_original_claim: bool,
    599     original_unissued_capture_requires_fresh_permission: bool,
    600     original_unissued_capture_requires_fresh_clock: bool,
    601     original_unissued_capture_releases_stock: bool,
    602     original_unissued_reconciliation_same_owner: bool,
    603     original_unissued_late_evidence_retained: bool,
    604     original_unissued_worker_charge_bytes: u32,
    605     original_unissued_live_observation_owner: String,
    606     original_unissued_observation_is_durable: bool,
    607     original_unissued_observation_releases_stock: bool,
    608     recovery_refusal_creates_original_unissued_observation: bool,
    609     ordinary_existing_claim_grants_first_dispatch: bool,
    610     ordinary_replay_requires_original_policy_and_current_permit: bool,
    611     ordinary_acceptance_implies_delivery: bool,
    612     crypto_verifier_owner: String,
    613     scoped_crypto_verification: String,
    614     predecessor_nostr_verifier_alias: bool,
    615     crypto_verification_grants_dispatch_authority: bool,
    616     payload_version: u16,
    617     journal_family: u16,
    618     worker_charge_bytes: u32,
    619     complete_recipient_count: u16,
    620     crypto_and_route_verification_required: bool,
    621     original_t0_rumor_required: bool,
    622     exact_intent_digests_retained: bool,
    623     protected_identity_presence_and_absence_required: bool,
    624     current_issued_consent_required: bool,
    625     final_permission_and_clock_witnesses_required: bool,
    626     signer_invoked: bool,
    627     agreement_installed: bool,
    628 }
    629 
    630 #[derive(Deserialize)]
    631 #[serde(deny_unknown_fields)]
    632 struct Provenance {
    633     app_behavior_implementation: String,
    634     retain_source_provenance: bool,
    635     retain_notices: bool,
    636     map_meaningful_removed_tests_before_removal: bool,
    637     relabel_app_source_license: bool,
    638 }
    639 
    640 #[derive(Deserialize)]
    641 #[serde(deny_unknown_fields)]
    642 struct Targets {
    643     native: Vec<String>,
    644     apple_artifacts: Vec<String>,
    645     browsers: Vec<String>,
    646     browser_contexts: Vec<String>,
    647     generic_binding_languages: Vec<String>,
    648     node_ssr_import_required: bool,
    649     full_node_client_in_scope: bool,
    650     actual_beta_iphone_required: bool,
    651 }
    652 
    653 #[derive(Deserialize)]
    654 #[serde(deny_unknown_fields)]
    655 struct Portability {
    656     native_futures: String,
    657     browser_futures: String,
    658     unsafe_send_bridge_allowed: bool,
    659     portable_core_has_native_hosts: bool,
    660     memory_store_firm_stock_allowed: bool,
    661     nostr_forces_media: bool,
    662     global_no_std_promise: bool,
    663 }
    664 
    665 #[derive(Deserialize)]
    666 #[serde(deny_unknown_fields)]
    667 struct Package {
    668     key: String,
    669     package: String,
    670     directory: String,
    671     dependencies: Vec<String>,
    672     dependency_mode: String,
    673 }
    674 
    675 #[derive(Deserialize)]
    676 #[serde(deny_unknown_fields)]
    677 struct Values {
    678     quantity_coefficient_max: u64,
    679     quantity_scale_max: u8,
    680     count_quantities_integral: bool,
    681     money_minor_max: u64,
    682     currency_exponent_max: u8,
    683     currency_registry: String,
    684     rounding: String,
    685     binding_numbers: String,
    686     stock_ticks_max: u64,
    687     stock_scale_max: u8,
    688     stock_units: Vec<String>,
    689     stock_physical_categories: Vec<String>,
    690     generation_max: u64,
    691 }
    692 
    693 #[derive(Deserialize)]
    694 #[serde(deny_unknown_fields)]
    695 struct Execution {
    696     ordinary_inventory_owner: OrdinaryInventoryOwner,
    697     phases: Vec<String>,
    698     selected_executor_required_for_stock: bool,
    699     fresh_same_key_cache_can_allocate: bool,
    700     shared_route_local_fallback_allowed: bool,
    701     effects_inside_stock_transaction: bool,
    702     unknown_is_nonspendable: bool,
    703     expiry_proves_nonissuance: bool,
    704     obtained_evidence_append_only: bool,
    705     observation_time_nullable: bool,
    706     positive_amendment_hold_before_issuance: bool,
    707     negative_amendment_release_at_installation: bool,
    708     handover_consumes_once: bool,
    709     buyer_receipt_moves_stock: bool,
    710     private_causal_heads_use_timestamp_lww: bool,
    711 }
    712 
    713 #[derive(Deserialize)]
    714 #[serde(deny_unknown_fields)]
    715 struct OrdinaryInventoryOwner {
    716     capture_drain_uses_explicit_reconciliation: bool,
    717     owned_capture_method: String,
    718     retained_capture_survives_observer_loss: bool,
    719     failed_capture_blocks_fresh_work: bool,
    720     failed_capture_blocks_disposal: bool,
    721     capture_preserves_actual_error_code: bool,
    722     pending_capture_retry: String,
    723     capture_reports_must_match_original: bool,
    724     capture_scope_metadata_renews_issuance: bool,
    725     owned_acceptance_method: String,
    726     acceptance_is_preparation_only: bool,
    727     lost_accepted_admission_is_unknown: bool,
    728     execution: String,
    729     facade: String,
    730     selected_workspace_views_share_owner: bool,
    731     exact_owned_attachment_required: bool,
    732     bounded_task_host_required: bool,
    733     native_accepted_work_max: usize,
    734     native_pending_work_blocks_queries: bool,
    735     native_controls_drain_prior_work: bool,
    736     observer_loss_cancels_accepted_work: bool,
    737     close_drains_before_workspace_disposal: bool,
    738     stock_signer_or_transport_constructed: bool,
    739 }
    740 
    741 #[derive(Deserialize)]
    742 #[serde(deny_unknown_fields)]
    743 struct Protocol {
    744     listing_kind: u16,
    745     chat_rumor_kind: u16,
    746     seal_kind: u16,
    747     gift_wrap_kind: u16,
    748     commerce_kind: Option<u16>,
    749     capability_kind: Option<u16>,
    750     assignment_contract: String,
    751     structured_authoring: String,
    752     independent_vectors_required: bool,
    753     duplicate_json_fields_rejected: bool,
    754 }
    755 
    756 #[derive(Deserialize)]
    757 #[serde(deny_unknown_fields)]
    758 struct Cutover {
    759     new_persistent_namespace: bool,
    760     protected_export_and_quarantine_required: bool,
    761     restore_starts_nonpublishing: bool,
    762     unknowns_and_obligations_protected: bool,
    763     automatic_legacy_reissue_allowed: bool,
    764     meaningful_state_reset_requires_operator_approval: bool,
    765 }
    766 
    767 #[derive(Deserialize)]
    768 #[serde(deny_unknown_fields)]
    769 struct Qualification {
    770     implementation_claimed: bool,
    771     software_matrix_executed: bool,
    772     device_matrix_executed: bool,
    773     final_gate_acceptance_claimed: bool,
    774 }
    775 
    776 pub(super) fn validate(workspace_root: &Path) -> Result<(), String> {
    777     let raw = crate::safe_artifact_io::read_regular(
    778         workspace_root,
    779         Path::new(CONTRACT),
    780         MAX_BYTES as u64,
    781     )
    782     .map_err(|_| "shared SDK contract: bounded regular source admission failed".to_owned())?;
    783     validate_bytes(&raw)?;
    784     crate::shared_protocol::validate_contract(workspace_root)?;
    785     currency_registry::validate(workspace_root)
    786 }
    787 
    788 fn require(condition: bool, rule: &'static str) -> Result<(), String> {
    789     if condition {
    790         Ok(())
    791     } else {
    792         Err(format!("shared SDK contract: {rule}"))
    793     }
    794 }
    795 
    796 fn exact_set(actual: &[String], expected: &[&str]) -> bool {
    797     actual.len() == expected.len()
    798         && actual.iter().map(String::as_str).collect::<BTreeSet<_>>()
    799             == expected.iter().copied().collect::<BTreeSet<_>>()
    800 }
    801 
    802 fn validate_bytes(raw: &[u8]) -> Result<(), String> {
    803     require(raw.len() <= MAX_BYTES, "source byte limit exceeded")?;
    804     let p: Policy = serde_json::from_slice(raw)
    805         .map_err(|_| "shared SDK contract: invalid closed JSON shape".to_owned())?;
    806     let accounting = &p.stock_accounting;
    807     let replacement = &accounting.replacement_terms_admission;
    808     require(
    809         replacement.owner == "radroots_domain.causal.prepare_replacement_terms"
    810             && replacement.scope
    811                 == "explicit_existing_agreement_proposal_and_counterparty_authorization"
    812             && replacement.complete_local_causal_coverage_required
    813             && replacement.conflicting_authorizations_require_reconciliation
    814             && replacement.native_canonical_digest_recompute_required
    815             && replacement.native_current_head_and_residual_required
    816             && !replacement.claim_grants_current_authority
    817             && !replacement.claim_creates_stock_effects,
    818         "replacement claim/native authority boundary policy drift",
    819     )?;
    820     let terms = &accounting.native_terms_installation;
    821     require(
    822         terms.catalog == 20
    823             && terms.facade_method == "Orders.install_terms"
    824             && terms.execution_method == "ClientSession.install_stock_terms"
    825             && terms.source_owner == "radroots_domain.causal.prepare_replacement_terms"
    826             && terms.allocation_owner == "radroots_domain.stock.resolve_replacement_allocations"
    827             && terms.delta_owner == "radroots_domain.stock.plan_replacement_allocations"
    828             && terms.current_installed_base_required
    829             && terms.original_allocations_required
    830             && terms.positive_hold_phase == "T0"
    831             && terms.negative_release_phase == "T2"
    832             && !terms.pending_negatives_finance_holds
    833             && terms.old_commitment_retained_while_pending
    834             && terms.changed_residual_requires_new_admission
    835             && terms.release_composition == "original_installation_order_deficit_then_backed"
    836             && terms.quantity_storage == "protected_installation_body"
    837             && !terms.index_plaintext_quantities
    838             && terms.automatic_changed_multi_pool_split == "requires_explicit_complete_allocation"
    839             && terms.same_signing_and_recovery_owner
    840             && !terms.unknown_issuance_releases_stock
    841             && !terms.retained_catalog_auto_upgrade,
    842         "native replacement ownership, residual or stock phase policy drift",
    843     )?;
    844     let inspection = &accounting.native_inspection;
    845     require(
    846         inspection.model_owner == "radroots_storage.inventory.StockSnapshot"
    847             && inspection.facade_method == "Stock.inspect"
    848             && inspection.storage_port == "InventoryStore.inspect_stock"
    849             && inspection.supported_catalogs == [19, 20]
    850             && inspection.worker_charge_bytes == 1048576
    851             && inspection.same_checkpoint_required
    852             && inspection.original_allocation_required
    853             && inspection.read_pools_and_operations_required
    854             && !inspection.pending_claims_are_installed
    855             && !inspection.query_creates_store_effects
    856             && !inspection.reports_global_business_completeness,
    857         "current stock inspection scope, permission, checkpoint or effect policy drift",
    858     )?;
    859     let correction = &accounting.native_correction;
    860     require(
    861         correction.catalog == 20
    862             && correction.selection == "available_then_original_installation_and_allocation_order"
    863             && correction.max_affected_allocations == 32
    864             && correction.protected_original_allocation_required
    865             && correction.deficit_projection_in_final_transaction
    866             && correction.quantity_storage == "protected_original_operation_body"
    867             && correction.worker_charge_bytes == 1048576
    868             && !correction.preparatory_loss_implicit
    869             && !correction.quarantine_loss_implicit,
    870         "native correction original allocation, projection or category policy drift",
    871     )?;
    872     require(
    873         accounting.value_owner == "radroots_domain.stock"
    874             && accounting.scope == "one_fixed_pool_unit"
    875             && accounting.obligation_equation == "remaining = backed + deficit"
    876             && accounting.ticks_max == 1_000_000_000_000_000_000
    877             && !accounting.values_create_store_effects
    878             && !accounting.deficit_counts_as_physical_stock
    879             && !accounting.receipt_consumes_again
    880             && !accounting.released_deficit_adds_available
    881             && !accounting.loss_deletes_obligation
    882             && accounting.native_atomic_allocation_and_identity_required,
    883         "stock accounting value or native effect authority drift",
    884     )?;
    885     require(
    886         p.schema_version == 1
    887             && p.contract_id == "radroots.shared_sdk.refactor.v1"
    888             && p.state == "approved_target_implementation_pending"
    889             && !p.publication_authorized,
    890         "prospective identity or publication authority drift",
    891     )?;
    892     validate_ownership(&p)?;
    893     let local = &p.local_outbox_authority;
    894     require(
    895         exact_set(&local.scopes, &["new_buyer_outbox", "new_seller_outbox"])
    896             && local.seller_enrollment_explicit
    897             && local.scope_retained_in_authenticated_binding_and_preparation
    898             && local.legacy_preparation_v2_scope == "new_buyer_outbox"
    899             && local.scope_separates_route_genesis_and_credential_commitments
    900             && local.coverage == "partial"
    901             && !local.stock_authority
    902             && !local.organization_or_delegation_authority
    903             && !local.existing_order_or_history_recovery,
    904         "local outbox authority drift",
    905     )?;
    906     let stock = &p.native_seller_stock_authority;
    907     let envelope = &stock.envelope_retention;
    908     require(
    909         envelope.journal_family == 10
    910             && envelope.payload_version == 1
    911             && envelope.payload_prefix_bytes == 213
    912             && envelope.supported_catalogs == [16, 17, 18, 19, 20]
    913             && envelope.retained_unsupported_catalogs
    914                 == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]
    915             && envelope.raw_max_bytes == 65536
    916             && envelope.worker_charge_bytes == 1048576
    917             && envelope.capture_port == "InventoryStore.capture_stock_envelope"
    918             && envelope.query_port == "InventoryStore.stock_envelope"
    919             && envelope.recovery_port == "InventoryStore.reconcile_stock_envelope"
    920             && envelope.original_preparation_plan_claim_seal_installation_required
    921             && envelope.temporary_key_derivation_and_exact_decryption_required
    922             && !envelope.temporary_key_retained
    923             && !envelope.original_party_as_outer_author_allowed
    924             && envelope.body_derived_projection_and_complete_ancestry_required
    925             && !envelope.original_credential_capture_requires_live_clock_or_grant
    926             && envelope.query_requires_current_recovery_access
    927             && envelope.observation_nullable
    928             && !envelope.existing_original_bytes_may_be_replaced
    929             && !envelope.capture_grants_dispatch
    930             && !envelope.capture_changes_physical_stock
    931             && !envelope.provider_io_inside_sql,
    932         "stock envelope retention drift",
    933     )?;
    934     let rewrap = &stock.rewrapping;
    935     require(
    936         rewrap.journal_family == 14
    937             && rewrap.admission_journal_family == 13
    938             && rewrap.admission_payload_bytes == 248
    939             && rewrap.admission_window_seconds_max == 30
    940             && rewrap.admission_port == "InventoryStore.prepare_stock_rewrap"
    941             && rewrap.admission_recovery_port == "InventoryStore.reconcile_stock_rewrap_admission"
    942             && rewrap.admission_query_port == "InventoryStore.stock_rewrap_attempt"
    943             && rewrap.explicit_request_id_required
    944             && rewrap.newly_confirmed_admission_before_wrapping
    945             && !rewrap.existing_or_uncertain_admission_grants_invocation
    946             && rewrap.unknown_admissions_count_toward_limit
    947             && rewrap.descriptor_includes_uncaptured_admissions
    948             && !rewrap.admission_repair_grants_history_or_invocation
    949             && rewrap.ordinary_owner == "ClientSession.stock_captures"
    950             && rewrap.ordinary_facade_methods
    951                 == [
    952                     "Orders.rewrap_acceptance",
    953                     "Orders.resume_acceptance_rewrap",
    954                     "Orders.acceptance_rewrap_status",
    955                 ]
    956             && !rewrap.ordinary_resume_generates_key_or_business_signature
    957             && !rewrap.ordinary_status_is_atomic_absence_proof
    958             && rewrap.payload_version == 1
    959             && rewrap.payload_prefix_bytes == 117
    960             && rewrap.supported_catalogs == [18, 19, 20]
    961             && rewrap.retained_unsupported_catalogs
    962                 == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17]
    963             && rewrap.raw_max_bytes == 65536
    964             && rewrap.worker_charge_bytes == 1048576
    965             && rewrap.additional_envelopes_per_recipient_max == 192
    966             && rewrap.descriptor_page_max == 16
    967             && rewrap.capture_port == "InventoryStore.capture_stock_rewrap"
    968             && rewrap.recovery_port == "InventoryStore.reconcile_stock_rewrap"
    969             && rewrap.query_port == "InventoryStore.stock_envelope"
    970             && rewrap.page_port == "InventoryStore.stock_rewraps"
    971             && rewrap.original_f10_and_same_s_t2_required
    972             && rewrap.default_selection_is_original
    973             && rewrap.new_envelope_selection_explicit
    974             && rewrap.first_policy_source_bound
    975             && rewrap.transport_counters_cumulative
    976             && rewrap.outcomes_scoped_to_exact_envelope
    977             && rewrap.natural_index_transaction_witness_required
    978             && !rewrap.existing_bytes_may_be_replaced
    979             && !rewrap.original_capture_requires_live_clock_or_grant
    980             && !rewrap.capture_or_query_grants_dispatch
    981             && !rewrap.physical_stock_effect
    982             && !rewrap.temporary_key_retained
    983             && !rewrap.provider_io_inside_sql,
    984         "stock rewrapping authority or retention drift",
    985     )?;
    986     let delivery = &stock.delivery;
    987     require(
    988         delivery.supported_catalogs == [17, 18, 19, 20]
    989             && delivery.retained_unsupported_catalogs
    990                 == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]
    991             && delivery.attempt_journal_family == 11
    992             && delivery.observation_journal_family == 12
    993             && delivery.attempt_payload_version == 1
    994             && delivery.observation_payload_version == 1
    995             && delivery.attempt_body_max_bytes == 65536
    996             && delivery.observation_body_max_bytes == 16384
    997             && delivery.target_max == 16
    998             && delivery.attempts_per_target == 12
    999             && delivery.attempts_per_operation_max == 384
   1000             && delivery.observations_per_operation_max == 2304
   1001             && delivery.observation_page_max == 16
   1002             && delivery.summary_target_max == 16
   1003             && delivery.worker_charge_bytes == 1048576
   1004             && delivery.storage_ports
   1005                 == [
   1006                     "InventoryStore.prepare_stock_delivery_attempt",
   1007                     "InventoryStore.stock_delivery_attempt",
   1008                     "InventoryStore.stock_delivery_summary",
   1009                     "InventoryStore.record_stock_delivery_observation",
   1010                     "InventoryStore.reconcile_stock_delivery_observation",
   1011                     "InventoryStore.stock_delivery_observations",
   1012                 ]
   1013             && delivery.original_stock_evidence_installation_outer_required
   1014             && delivery.original_captured_route_and_current_write_policy_required
   1015             && delivery.fresh_current_scoped_consent_grant_clock_required
   1016             && delivery.installed_original_recovery_delivery_supported
   1017             && delivery.fresh_claim_requires_confirmed_commit
   1018             && !delivery.existing_attempt_grants_dispatch
   1019             && !delivery.unknown_commit_grants_dispatch
   1020             && !delivery.query_grants_dispatch
   1021             && delivery.first_complete_targets_and_criterion_immutable
   1022             && !delivery.ordinary_command_replays_existing_attempt
   1023             && delivery.ordinary_fresh_claim_binds_observed_attempt_count
   1024             && delivery.ordinary_repeat_uses_selected_envelope_attempt_count
   1025             && delivery.ordinary_obtained_material_owner == "ClientSession.stock_captures"
   1026             && delivery.ordinary_peer_delivery_precedes_self_signing
   1027             && !delivery.installed_original_delivery_requires_signer
   1028             && delivery.explicit_resume_claims_bounded_new_attempt
   1029             && delivery.retries_use_original_outer_bytes
   1030             && delivery.observation_nullable
   1031             && !delivery.original_credential_capture_requires_live_clock_or_grant
   1032             && delivery.same_owner_obtained_material_reconciliation_required
   1033             && delivery.first_observation_per_class_immutable
   1034             && delivery.wrong_event_request_target_ack_rejected
   1035             && delivery.protected_refs_indexes_complete_ancestry_required
   1036             && delivery.final_transaction_witnesses_required
   1037             && !delivery.unbounded_attempt_or_observation_collections
   1038             && !delivery.physical_stock_effect
   1039             && !delivery.transport_inside_sql,
   1040         "stock delivery ownership or bounds drift",
   1041     )?;
   1042     require(
   1043         stock.capability_contract.id == "radroots.seller_stock.native_inventory"
   1044             && stock.capability_contract.version == "1"
   1045             && stock.scope == "seller_stock_owner"
   1046             && stock.database == "stock_execution_v1.sqlite"
   1047             && stock.lock == ".stock_execution_v1.lock"
   1048             && stock.schema_version == 20
   1049             && stock.retained_enrollment_versions == [1]
   1050             && stock.retained_inventory_versions
   1051                 == [
   1052                     2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
   1053                 ]
   1054             && stock.authority_payload_schema == "radroots.seller_stock.authority.v20"
   1055             && stock.public_source_payload_schemas
   1056                 == [
   1057                     "radroots.seller_stock.public_source_event.v1",
   1058                     "radroots.seller_stock.public_source_head.v1",
   1059                     "radroots.seller_stock.public_source_part.v1",
   1060                 ]
   1061             && stock.public_source_owner_administration_required
   1062             && !stock.inventory_scope_grants_public_source_access
   1063             && stock.public_source_checkpoint_independent
   1064             && stock.public_source_input_requires_signature_evidence
   1065             && stock.public_source_read_reverifies_signature
   1066             && !stock.public_source_global_completeness_claimed
   1067             && !stock.public_source_profile_implies_actionability
   1068             && stock.public_source_head_policy == "nip01_timestamp_then_lowest_id_before_profile"
   1069             && stock.public_source_duplicate_encodings == "retain_original_authenticated_event_id"
   1070             && stock.public_source_raw_max_bytes == 65536
   1071             && stock.public_source_part_max_bytes == 16384
   1072             && stock.public_source_part_max_count == 4
   1073             && stock.public_source_worker_charge_bytes == 262144
   1074             && stock.inventory_operation_payload_schema == "radroots.seller_stock.operation.v5"
   1075             && stock.operation_part_payload_schema == "radroots.seller_stock.operation_part.v1"
   1076             && stock.operation_body_max_bytes == 262144
   1077             && stock.operation_part_max_bytes == 16384
   1078             && stock.operation_part_max_count == 16
   1079             && stock.operation_identity_requires_protected_ancestry
   1080             && stock.acceptance_preparation.planner_owner == "radroots_domain"
   1081             && stock.acceptance_preparation.shared_storage_port
   1082                 == "radroots_storage.inventory.InventoryStore.prepare_stock_acceptance"
   1083             && stock.acceptance_preparation.shared_model_owner == "radroots_storage.inventory"
   1084             && !stock.acceptance_preparation.legacy_native_aliases
   1085             && stock.acceptance_preparation.unsupported_hosts_refuse
   1086             && !stock.acceptance_preparation.model_constructs_runtime
   1087             && stock.acceptance_preparation.payload_version == 1
   1088             && stock.acceptance_preparation.order_payload_schema
   1089                 == "radroots.seller_stock.order.v1"
   1090             && stock.acceptance_preparation.movement_payload_schema
   1091                 == "radroots.seller_stock.acceptance_movement.v1"
   1092             && stock.acceptance_preparation.worker_charge_bytes == 524288
   1093             && stock.acceptance_preparation.max_allocations == 64
   1094             && stock.acceptance_preparation.max_pool_observations == 96
   1095             && stock.acceptance_preparation.max_first_issue_window_seconds == 120
   1096             && stock
   1097                 .acceptance_preparation
   1098                 .original_replay_before_fresh_planning
   1099             && stock.acceptance_preparation.complete_allocation_required
   1100             && stock
   1101                 .acceptance_preparation
   1102                 .atomic_holds_and_order_fence_required
   1103             && stock.acceptance_preparation.current_issued_consent_required
   1104             && stock
   1105                 .acceptance_preparation
   1106                 .final_source_counts_and_witnesses_required
   1107             && !stock.acceptance_preparation.signer_invoked
   1108             && !stock.acceptance_preparation.agreement_installed
   1109             && stock.signing_plan_binding.ordinary_acceptance_owner
   1110                 == "radroots_execution.CommandRuntime"
   1111             && stock.signing_plan_binding.ordinary_acceptance_facade == "radroots.Orders.accept"
   1112             && stock
   1113                 .signing_plan_binding
   1114                 .ordinary_peer_installed_before_self_work
   1115             && stock
   1116                 .signing_plan_binding
   1117                 .ordinary_accepted_task_survives_observer_loss
   1118             && stock
   1119                 .signing_plan_binding
   1120                 .ordinary_obtained_owned_before_descriptor_conversion
   1121             && stock
   1122                 .signing_plan_binding
   1123                 .generic_obtained_owned_before_descriptor_conversion
   1124             && stock
   1125                 .signing_plan_binding
   1126                 .retained_drain_preserves_original_error_and_operation
   1127             && stock.signing_plan_binding.rejected_signer_error == "SignerTampering"
   1128             && stock.signing_plan_binding.effectful_command_result == "ExecutionResult"
   1129             && stock.signing_plan_binding.common_error_max_bytes == 64
   1130             && stock.signing_plan_binding.execution_failure_max_bytes == 128
   1131             && stock.signing_plan_binding.rejected_signer_metadata_owner
   1132                 == "radroots_signing.issuance.RejectedArtifact"
   1133             && !stock
   1134                 .signing_plan_binding
   1135                 .rejected_signer_report_is_nonissuance
   1136             && stock
   1137                 .signing_plan_binding
   1138                 .generic_peer_installed_before_rejected_self_return
   1139             && stock
   1140                 .signing_plan_binding
   1141                 .unknown_installation_blocks_delivery
   1142             && stock
   1143                 .signing_plan_binding
   1144                 .native_first_dispatch_owns_issuer_invocation
   1145             && stock.signing_plan_binding.shared_first_dispatch_port
   1146                 == "radroots_execution.session.commerce.AcceptanceDispatch.dispatch"
   1147             && stock.signing_plan_binding.shared_unissued_owner == "ClientSession.stock_captures"
   1148             && stock
   1149                 .signing_plan_binding
   1150                 .shared_unissued_retained_before_capture
   1151             && stock
   1152                 .signing_plan_binding
   1153                 .shared_unissued_drained_before_storage_close
   1154             && stock
   1155                 .signing_plan_binding
   1156                 .shared_unissued_failure_blocks_fresh_commands
   1157             && !stock.signing_plan_binding.public_native_intent_extraction
   1158             && stock
   1159                 .signing_plan_binding
   1160                 .coherent_snapshot_preserves_original_unissued
   1161             && stock.signing_plan_binding.exact_issuer_port
   1162                 == "radroots_signing.issuance.ExactIssuer"
   1163             && stock.signing_plan_binding.native_failure_boundary == "radroots_ffi.Error"
   1164             && stock
   1165                 .signing_plan_binding
   1166                 .native_failure_preserves_signer_rejection
   1167             && stock.signing_plan_binding.native_failure_fingerprint_bytes == 32
   1168             && stock.signing_plan_binding.native_failure_coverage == "canonical_decimal_strings"
   1169             && stock.signing_plan_binding.native_failure_max_bytes == 128
   1170             && stock.signing_plan_binding.browser_failure_boundary
   1171                 == "radroots_browser.bindings.Failure"
   1172             && stock
   1173                 .signing_plan_binding
   1174                 .browser_failure_preserves_signer_rejection
   1175             && stock.signing_plan_binding.browser_failure_max_bytes == 128
   1176             && stock
   1177                 .signing_plan_binding
   1178                 .original_unissued_live_observation_owner
   1179                 == "radroots_storage_sqlite.workspace.StockUnissuedInvocation"
   1180             && !stock
   1181                 .signing_plan_binding
   1182                 .original_unissued_observation_is_durable
   1183             && !stock
   1184                 .signing_plan_binding
   1185                 .original_unissued_observation_releases_stock
   1186             && !stock
   1187                 .signing_plan_binding
   1188                 .recovery_refusal_creates_original_unissued_observation
   1189             && stock.signing_plan_binding.original_unissued_capture_owner
   1190                 == "NativeWorkspace.capture_stock_original_unissued"
   1191             && stock.signing_plan_binding.original_unissued_payload_version == 1
   1192             && stock.signing_plan_binding.original_unissued_journal_family == 8
   1193             && stock
   1194                 .signing_plan_binding
   1195                 .original_unissued_capture_requires_owned_observation
   1196             && stock
   1197                 .signing_plan_binding
   1198                 .original_unissued_capture_borrows_observation
   1199             && stock
   1200                 .signing_plan_binding
   1201                 .original_unissued_capture_rechecks_original_claim
   1202             && !stock
   1203                 .signing_plan_binding
   1204                 .original_unissued_capture_requires_fresh_permission
   1205             && !stock
   1206                 .signing_plan_binding
   1207                 .original_unissued_capture_requires_fresh_clock
   1208             && !stock
   1209                 .signing_plan_binding
   1210                 .original_unissued_capture_releases_stock
   1211             && stock
   1212                 .signing_plan_binding
   1213                 .original_unissued_reconciliation_same_owner
   1214             && stock
   1215                 .signing_plan_binding
   1216                 .original_unissued_late_evidence_retained
   1217             && stock
   1218                 .signing_plan_binding
   1219                 .original_unissued_worker_charge_bytes
   1220                 == 262144
   1221             && !stock
   1222                 .signing_plan_binding
   1223                 .ordinary_existing_claim_grants_first_dispatch
   1224             && stock
   1225                 .signing_plan_binding
   1226                 .ordinary_replay_requires_original_policy_and_current_permit
   1227             && !stock
   1228                 .signing_plan_binding
   1229                 .ordinary_acceptance_implies_delivery
   1230             && stock.signing_plan_binding.crypto_verifier_owner == "radroots_signing.commerce"
   1231             && stock.signing_plan_binding.scoped_crypto_verification
   1232                 == "SignerSession.verify_commerce_plan"
   1233             && !stock.signing_plan_binding.predecessor_nostr_verifier_alias
   1234             && !stock
   1235                 .signing_plan_binding
   1236                 .crypto_verification_grants_dispatch_authority
   1237             && stock.signing_plan_binding.payload_version == 1
   1238             && stock.signing_plan_binding.journal_family == 3
   1239             && stock.signing_plan_binding.worker_charge_bytes == 1048576
   1240             && stock.signing_plan_binding.complete_recipient_count == 2
   1241             && stock
   1242                 .signing_plan_binding
   1243                 .crypto_and_route_verification_required
   1244             && stock.signing_plan_binding.original_t0_rumor_required
   1245             && stock.signing_plan_binding.exact_intent_digests_retained
   1246             && stock
   1247                 .signing_plan_binding
   1248                 .protected_identity_presence_and_absence_required
   1249             && stock.signing_plan_binding.current_issued_consent_required
   1250             && stock
   1251                 .signing_plan_binding
   1252                 .final_permission_and_clock_witnesses_required
   1253             && !stock.signing_plan_binding.signer_invoked
   1254             && !stock.signing_plan_binding.agreement_installed
   1255             && stock
   1256                 .signing_issuance
   1257                 .fresh_current_backing_projection_required
   1258             && stock.signing_issuance.coherent_operation_snapshot_required
   1259             && stock.signing_issuance.shared_capture_port
   1260                 == "InventoryStore.capture_stock_evidence"
   1261             && stock.signing_issuance.shared_reconciliation_port
   1262                 == "InventoryStore.reconcile_stock_evidence"
   1263             && stock
   1264                 .signing_issuance
   1265                 .reconciliation_retains_writer_through_replacement
   1266             && stock
   1267                 .signing_issuance
   1268                 .reconciliation_authenticates_before_connection_close
   1269             && !stock
   1270                 .signing_issuance
   1271                 .reconciliation_preflight_initializes_or_migrates
   1272             && stock
   1273                 .signing_issuance
   1274                 .reconciliation_clears_fence_only_after_confirmed_capture
   1275             && stock.signing_issuance.shared_capture_model_owner == "radroots_storage.inventory"
   1276             && !stock
   1277                 .signing_issuance
   1278                 .shared_capture_descriptors_are_authority
   1279             && stock
   1280                 .signing_issuance
   1281                 .shared_capture_reauthenticates_original
   1282             && !stock.signing_issuance.native_capture_report_aliases
   1283             && stock
   1284                 .signing_issuance
   1285                 .final_evidence_selectors_and_page_rows_required
   1286             && !stock
   1287                 .signing_issuance
   1288                 .recovery_view_has_dispatch_or_installation_rights
   1289             && stock.signing_issuance.evidence_page_max == 32
   1290             && stock.signing_issuance.claim_family == 4
   1291             && stock.signing_issuance.evidence_family == 5
   1292             && stock.signing_issuance.claim_worker_charge_bytes == 1048576
   1293             && stock.signing_issuance.capture_worker_charge_bytes == 262144
   1294             && stock.signing_issuance.capture_raw_max_bytes == 65536
   1295             && stock
   1296                 .signing_issuance
   1297                 .first_dispatch_requires_confirmed_commit
   1298             && !stock
   1299                 .signing_issuance
   1300                 .existing_claim_returns_dispatch_permit
   1301             && stock
   1302                 .signing_issuance
   1303                 .protected_identity_presence_and_absence_required
   1304             && stock
   1305                 .signing_issuance
   1306                 .capture_requires_original_claim_and_credential
   1307             && !stock.signing_issuance.capture_requires_current_consent
   1308             && !stock.signing_issuance.capture_requires_observation_clock
   1309             && stock.signing_issuance.capture_preserves_first_optional_time
   1310             && stock
   1311                 .signing_issuance
   1312                 .capture_retains_distinct_valid_encodings
   1313             && !stock.signing_issuance.agreement_installed
   1314             && stock.qualified_local_recovery.provider_method
   1315                 == "radroots_signing.provider.ParticipantProvider.recover_exact"
   1316             && stock.qualified_local_recovery.scoped_method == "SignerSession.recover_exact"
   1317             && stock
   1318                 .qualified_local_recovery
   1319                 .scoped_identity_and_capability_rechecked
   1320             && stock
   1321                 .qualified_local_recovery
   1322                 .scoped_callback_binding_enforced
   1323             && stock
   1324                 .qualified_local_recovery
   1325                 .scoped_close_waits_for_active_call
   1326             && !stock
   1327                 .qualified_local_recovery
   1328                 .scoped_method_grants_store_authority
   1329             && stock.qualified_local_recovery.adapter == "radroots_nostr.signing.LocalSigner"
   1330             && stock.qualified_local_recovery.native_authorizer
   1331                 == "NativeWorkspace.authorize_stock_exact_replay"
   1332             && stock.qualified_local_recovery.captured_replay == "local_replay_safe"
   1333             && stock.qualified_local_recovery.native_catalog == 20
   1334             && stock.qualified_local_recovery.worker_charge_bytes == 1048576
   1335             && stock
   1336                 .qualified_local_recovery
   1337                 .existing_protected_claim_required
   1338             && stock
   1339                 .qualified_local_recovery
   1340                 .current_execute_consent_required
   1341             && stock.qualified_local_recovery.original_window_required
   1342             && !stock
   1343                 .qualified_local_recovery
   1344                 .call_budget_extends_original_window
   1345             && !stock
   1346                 .qualified_local_recovery
   1347                 .recovery_refusal_proves_original_unissued
   1348             && !stock.qualified_local_recovery.creates_claim_or_stock_effect
   1349             && !stock.qualified_local_recovery.provider_work_inside_sql
   1350             && !stock.qualified_local_recovery.unsupported_legacy_fallback
   1351             && !stock
   1352                 .qualified_local_recovery
   1353                 .after_expiry_retrieval_available
   1354             && stock
   1355                 .qualified_local_recovery
   1356                 .legacy_and_first_dispatch_unchanged
   1357             && stock
   1358                 .qualified_local_recovery
   1359                 .current_replay_admission_required
   1360             && stock
   1361                 .qualified_local_recovery
   1362                 .replay_admission_journal_family
   1363                 == 9
   1364             && stock
   1365                 .qualified_local_recovery
   1366                 .replay_admission_payload_version
   1367                 == 1
   1368             && stock
   1369                 .qualified_local_recovery
   1370                 .replay_admission_payload_bytes
   1371                 == 184
   1372             && !stock
   1373                 .qualified_local_recovery
   1374                 .replay_admission_unknown_returns_permit
   1375             && stock
   1376                 .qualified_local_recovery
   1377                 .replay_admission_reauthorizes_current
   1378             && !stock
   1379                 .qualified_local_recovery
   1380                 .replay_admission_clear_on_refusal
   1381             && !stock.qualified_local_recovery.replay_admission_stock_effect
   1382             && stock.qualified_local_recovery.retained_untracked_catalogs == [13, 14]
   1383             && !stock
   1384                 .qualified_local_recovery
   1385                 .replay_admission_report_is_release_authority
   1386             && stock.preparation_abort.payload_version == 2
   1387             && stock.preparation_abort.journal_family == 7
   1388             && stock.preparation_abort.worker_charge_bytes == 1048576
   1389             && stock.preparation_abort.shared_storage_port
   1390                 == "radroots_storage.inventory.InventoryStore"
   1391             && stock.preparation_abort.shared_model_owner == "radroots_storage.inventory"
   1392             && !stock.preparation_abort.native_workspace_type_aliases
   1393             && stock.preparation_abort.unsupported_hosts_return == "capability_unavailable"
   1394             && stock.preparation_abort.retained_payload_versions == [1]
   1395             && stock.preparation_abort.retained_v1_requires_absent_claims
   1396             && stock.preparation_abort.claimed_cleanup_catalogs == [15, 16, 17, 18, 19, 20]
   1397             && stock.preparation_abort.untracked_claimed_catalogs == [13, 14]
   1398             && stock.preparation_abort.per_recipient_proof_count == 2
   1399             && stock
   1400                 .preparation_abort
   1401                 .original_unissued_required_for_every_claim
   1402             && stock.preparation_abort.replay_admission_blocks_release
   1403             && stock.preparation_abort.obtained_evidence_blocks_release
   1404             && stock.preparation_abort.contradictory_evidence_retained
   1405             && stock.preparation_abort.contradiction_requires_recovery
   1406             && !stock.preparation_abort.caller_reports_are_release_authority
   1407             && !stock
   1408                 .preparation_abort
   1409                 .caller_nonissuance_assertion_is_proof
   1410             && stock
   1411                 .preparation_abort
   1412                 .current_exact_recovery_consent_required
   1413             && stock
   1414                 .preparation_abort
   1415                 .atomic_exact_original_release_required
   1416             && stock.preparation_abort.original_preparations_retained
   1417             && stock
   1418                 .preparation_abort
   1419                 .current_order_projection_authenticated
   1420             && stock
   1421                 .preparation_abort
   1422                 .later_initial_requires_original_abort
   1423             && !stock.preparation_abort.fresh_signing_after_abort
   1424             && stock.preparation_abort.unknown_commit_fences_owner
   1425             && !stock.preparation_abort.signer_or_transport_invoked
   1426             && stock.initial_agreement_installation.payload_version == 1
   1427             && stock.initial_agreement_installation.journal_family == 6
   1428             && stock.initial_agreement_installation.worker_charge_bytes == 1048576
   1429             && stock.initial_agreement_installation.required_peer_evidence
   1430             && !stock
   1431                 .initial_agreement_installation
   1432                 .missing_self_copy_blocks_installation
   1433             && stock
   1434                 .initial_agreement_installation
   1435                 .original_order_fence_immutable
   1436             && stock
   1437                 .initial_agreement_installation
   1438                 .exact_original_hold_quantities_required
   1439             && stock
   1440                 .initial_agreement_installation
   1441                 .current_exact_recovery_consent_required
   1442             && stock
   1443                 .initial_agreement_installation
   1444                 .fresh_time_not_before_original_bound_plan
   1445             && stock
   1446                 .initial_agreement_installation
   1447                 .atomic_pool_agreement_and_work_required
   1448             && stock.initial_agreement_installation.recipient_work_count == 2
   1449             && stock
   1450                 .initial_agreement_installation
   1451                 .unknown_commit_fences_owner
   1452             && !stock
   1453                 .initial_agreement_installation
   1454                 .signer_or_transport_invoked
   1455             && !stock.initial_agreement_installation.relay_delivery_claimed
   1456             && stock.business_consent_payload_version == 1
   1457             && stock.business_consent_action == "orders.accept"
   1458             && stock.business_consent_modes == ["execute_and_recover", "recover_only"]
   1459             && stock.business_consent_admin_issuance_required
   1460             && stock.business_consent_binds_exact_command_and_subject_grant
   1461             && !stock.business_consent_issuance_has_order_or_stock_effects
   1462             && stock.business_consent_worker_charge_bytes == 524288
   1463             && stock.mapping_payload_schema == "radroots.seller_stock.mapping.v1"
   1464             && stock.source_payload_schemas
   1465                 == [
   1466                     "radroots.seller_stock.source_record.v1",
   1467                     "radroots.seller_stock.source_evidence.v1",
   1468                     "radroots.seller_stock.source_part.v1",
   1469                 ]
   1470             && stock.source_profile_dispositions == ["known", "unsupported", "rejected"]
   1471             && stock.source_owner_administration_required
   1472             && !stock.inventory_scope_grants_source_access
   1473             && stock.source_checkpoint_independent
   1474             && !stock.source_profile_implies_actionability
   1475             && stock.causal_history_current_administrator_required
   1476             && stock.causal_history_complete_local_scope_required
   1477             && stock.causal_history_includes_actual_local_signed_records
   1478             && stock.causal_history_inventory_minimum_required
   1479             && stock.causal_history_logical_record_deduplication_required
   1480             && !stock.causal_history_implies_installation
   1481             && stock.causal_history_uninterpreted_policy
   1482                 == "conservative_authenticated_participant_pair_barrier"
   1483             && stock.causal_history_transaction_witnesses_required
   1484             && !stock.causal_history_implies_business_permission
   1485             && stock.source_carrier_max_bytes == 65536
   1486             && stock.source_chunk_max_bytes == 16384
   1487             && stock.mapping_owner_administration_required
   1488             && !stock.mapping_changes_physical_stock
   1489             && !stock.mapping_changes_pool_version
   1490             && stock.mapping_create_expected_version == 0
   1491             && stock.inventory_movement_payload_schema == "radroots.seller_stock.movement.v2"
   1492             && stock.grant_payload_schema == "radroots.seller_stock.grant.v2"
   1493             && stock.grant_change_payload_schema == "radroots.seller_stock.grant_change.v1"
   1494             && stock.namespace_excludes_caller_grant
   1495             && stock.actor_operation_unique_across_grants
   1496             && stock.grant_checkpoint_minimum_required
   1497             && stock.grant_checkpoint_policy
   1498                 == "exact_current_for_fresh_work_original_prior_for_exact_admin_recovery"
   1499             && stock.grant_set_max == 64
   1500             && stock.grant_pool_scope_max == 64
   1501             && stock.grant_action_max == 6
   1502             && stock.grant_scope_actions
   1503                 == [
   1504                     "read_pools",
   1505                     "read_operations",
   1506                     "create_pool",
   1507                     "add_stock",
   1508                     "remove_stock",
   1509                     "spoil_stock",
   1510                 ]
   1511             && stock.grant_write_requires_receipt_and_recovery_read
   1512             && !stock.inventory_scope_grants_administration
   1513             && stock.grant_admin_prepared_transaction_required
   1514             && !stock.retained_grants_automatically_evicted
   1515             && !stock.old_self_revoke_api_supported
   1516             && stock.pool_tick_scale_explicit
   1517             && stock.pool_tick_scale_encoding == "canonical_integer_string"
   1518             && stock.inventory_checkpoint_minimum_required
   1519             && !stock.empty_pool_has_physical_movement
   1520             && stock.enrollment_prepared_before_durable_creation
   1521             && stock.prepared_enrollment_single_use
   1522             && stock.same_connection_owner_as_outbox
   1523             && stock.protected_authority_and_grants_separate
   1524             && !stock.automatic_outbox_migration
   1525             && !stock.historical_obligations_recovered
   1526             && !stock.business_effects_qualified,
   1527         "native seller stock enrollment boundary drift",
   1528     )?;
   1529     validate_targets(&p.targets, &p.portability)?;
   1530     validate_packages(&p.packages)?;
   1531     validate_values(&p.values, &p.limits)?;
   1532     validate_execution(&p.execution, &p.protocol, &p.cutover)?;
   1533     require(
   1534         !p.qualification.implementation_claimed
   1535             && !p.qualification.software_matrix_executed
   1536             && !p.qualification.device_matrix_executed
   1537             && !p.qualification.final_gate_acceptance_claimed,
   1538         "target metadata cannot claim qualification",
   1539     )
   1540 }
   1541 
   1542 fn validate_ownership(p: &Policy) -> Result<(), String> {
   1543     require(
   1544         p.toolchain.edition == "2024"
   1545             && p.toolchain.stable == super::STABLE_TOOLCHAIN
   1546             && p.toolchain.msrv == super::STABLE_TOOLCHAIN
   1547             && p.toolchain.historical_receipts_immutable
   1548             && p.toolchain.dedicated_nightly_and_sp1_separate,
   1549         "exact compiler target drift",
   1550     )?;
   1551     let o = &p.ownership;
   1552     require(
   1553         o.shared_repository == "https://github.com/radrootslabs/lib"
   1554             && o.ordinary_facade == "radroots"
   1555             && o.native_bindings == "radroots_ffi"
   1556             && o.browser_artifact == "radroots_browser"
   1557             && o.sdk_repository_role == "generated_artifact_consumer"
   1558             && !o.app_owns_shared_semantics,
   1559         "shared semantic ownership drift",
   1560     )?;
   1561     require(
   1562         exact_set(&p.roles.cli, &["buyer", "seller"])
   1563             && exact_set(&p.roles.browser, &["buyer", "seller"])
   1564             && exact_set(&p.roles.generic_ffi, &["buyer", "seller"])
   1565             && exact_set(&p.roles.tera, &["seller"]),
   1566         "approved actor scope drift",
   1567     )?;
   1568     require(
   1569         exact_set(
   1570             &p.deferred_application_migrations,
   1571             &["harvestcircle", "applesauce", "kotlin_application"],
   1572         ) && exact_set(
   1573             &p.retained_capability_families,
   1574             &[
   1575                 "farm",
   1576                 "social",
   1577                 "calendar",
   1578                 "media",
   1579                 "places",
   1580                 "knowledge",
   1581                 "communication",
   1582                 "optional_attestation",
   1583             ],
   1584         ),
   1585         "retained or deferred capability scope drift",
   1586     )?;
   1587     let i = &p.independence;
   1588     require(
   1589         !i.hosted_account_required
   1590             && !i.farm_hierarchy_required
   1591             && !i.rhi_required
   1592             && !i.payment_implementation_in_scope
   1593             && i.seller_owner_executor_optional_to_single_device,
   1594         "independent participation scope drift",
   1595     )?;
   1596     let s = &p.provenance;
   1597     require(
   1598         s.app_behavior_implementation == "independent_reimplementation"
   1599             && s.retain_source_provenance
   1600             && s.retain_notices
   1601             && s.map_meaningful_removed_tests_before_removal
   1602             && !s.relabel_app_source_license,
   1603         "implementation provenance or retained-test duty drift",
   1604     )
   1605 }
   1606 
   1607 fn validate_targets(t: &Targets, p: &Portability) -> Result<(), String> {
   1608     require(
   1609         exact_set(
   1610             &t.native,
   1611             &["aarch64-apple-darwin", "x86_64-unknown-linux-gnu"],
   1612         ) && exact_set(
   1613             &t.apple_artifacts,
   1614             &["aarch64-apple-ios", "aarch64-apple-ios-sim"],
   1615         ) && exact_set(&t.browsers, &["chromium", "firefox", "webkit"])
   1616             && exact_set(&t.browser_contexts, &["main_thread", "dedicated_worker"])
   1617             && exact_set(&t.generic_binding_languages, &["swift", "kotlin"])
   1618             && t.node_ssr_import_required
   1619             && !t.full_node_client_in_scope
   1620             && t.actual_beta_iphone_required,
   1621         "supported target matrix drift",
   1622     )?;
   1623     require(
   1624         p.native_futures == "send"
   1625             && p.browser_futures == "local"
   1626             && !p.unsafe_send_bridge_allowed
   1627             && !p.portable_core_has_native_hosts
   1628             && !p.memory_store_firm_stock_allowed
   1629             && !p.nostr_forces_media
   1630             && !p.global_no_std_promise,
   1631         "target-local portability or host capability drift",
   1632     )
   1633 }
   1634 
   1635 fn validate_packages(packages: &[Package]) -> Result<(), String> {
   1636     let expected = [
   1637         "identity",
   1638         "domain",
   1639         "protocol",
   1640         "signing",
   1641         "storage",
   1642         "transport",
   1643         "execution",
   1644         "storage_sqlite",
   1645         "storage_indexeddb",
   1646         "transport_nostr",
   1647         "transport_nostr_native",
   1648         "transport_nostr_browser",
   1649         "secrets",
   1650         "nostr_connect",
   1651         "blossom",
   1652         "geonames",
   1653         "nostrdb",
   1654         "sql_core",
   1655         "replica_schema",
   1656         "replica_store",
   1657         "replica_sync",
   1658         "runtime_paths",
   1659         "runtime_distribution",
   1660         "runtime_manager",
   1661         "service_host",
   1662         "service_sqlite",
   1663         "mesh_agent_proto",
   1664         "mesh_agent_client",
   1665         "mesh",
   1666         "transport_reticulum",
   1667         "simplex_agent_proto",
   1668         "simplex_smp_crypto",
   1669         "simplex_smp_proto",
   1670         "simplex_smp_transport",
   1671         "simplex_chat_proto",
   1672         "simplex_app_store",
   1673         "radroots",
   1674         "radroots_browser",
   1675         "radroots_ffi",
   1676         "test_fixtures",
   1677         "xtask",
   1678     ];
   1679     let nodes = packages
   1680         .iter()
   1681         .map(|p| (p.key.as_str(), p))
   1682         .collect::<BTreeMap<_, _>>();
   1683     require(
   1684         packages.len() == expected.len()
   1685             && nodes.len() == expected.len()
   1686             && nodes.keys().copied().collect::<BTreeSet<_>>() == expected.into_iter().collect(),
   1687         "complete target package set drift",
   1688     )?;
   1689     for p in packages {
   1690         let (name, directory) = match p.key.as_str() {
   1691             "xtask" => ("xtask".to_owned(), "tools/xtask".to_owned()),
   1692             "radroots" | "radroots_browser" | "radroots_ffi" => {
   1693                 (p.key.clone(), format!("crates/{}", p.key))
   1694             }
   1695             _ => (format!("radroots_{}", p.key), format!("crates/{}", p.key)),
   1696         };
   1697         let mode = if p.key == "radroots" {
   1698             "target_specific_optional_concrete_hosts"
   1699         } else {
   1700             "selected_target_required"
   1701         };
   1702         require(
   1703             p.package == name && p.directory == directory && p.dependency_mode == mode,
   1704             "package identity, path or host dependency policy drift",
   1705         )?;
   1706         let deps = p
   1707             .dependencies
   1708             .iter()
   1709             .map(String::as_str)
   1710             .collect::<BTreeSet<_>>();
   1711         require(
   1712             deps.len() == p.dependencies.len() && deps.iter().all(|d| nodes.contains_key(d)),
   1713             "duplicate or unknown package dependency",
   1714         )?;
   1715     }
   1716     for (key, deps) in [
   1717         ("identity", &[][..]),
   1718         ("domain", &["identity"][..]),
   1719         ("protocol", &["domain", "identity"][..]),
   1720         ("signing", &["domain", "identity", "protocol"][..]),
   1721         ("storage", &["domain", "protocol"][..]),
   1722         ("transport", &["protocol", "identity"][..]),
   1723         (
   1724             "execution",
   1725             &["domain", "protocol", "signing", "storage", "transport"][..],
   1726         ),
   1727         (
   1728             "radroots_browser",
   1729             &["execution", "storage_indexeddb", "transport_nostr_browser"][..],
   1730         ),
   1731         ("radroots_ffi", &["radroots"][..]),
   1732     ] {
   1733         require(
   1734             exact_set(&nodes[key].dependencies, deps),
   1735             "portable layer or concrete facade boundary drift",
   1736         )?;
   1737     }
   1738     require(
   1739         nodes["radroots"]
   1740             .dependencies
   1741             .iter()
   1742             .any(|d| d == "execution"),
   1743         "ordinary facade must execute shared commands",
   1744     )?;
   1745     let mut active = BTreeSet::new();
   1746     let mut done = BTreeSet::new();
   1747     for key in nodes.keys() {
   1748         visit(key, &nodes, &mut active, &mut done)?;
   1749     }
   1750     Ok(())
   1751 }
   1752 
   1753 fn visit<'a>(
   1754     key: &'a str,
   1755     nodes: &BTreeMap<&'a str, &'a Package>,
   1756     active: &mut BTreeSet<&'a str>,
   1757     done: &mut BTreeSet<&'a str>,
   1758 ) -> Result<(), String> {
   1759     if done.contains(key) {
   1760         return Ok(());
   1761     }
   1762     require(active.insert(key), "target dependency cycle")?;
   1763     for dep in &nodes[key].dependencies {
   1764         visit(dep, nodes, active, done)?;
   1765     }
   1766     active.remove(key);
   1767     done.insert(key);
   1768     Ok(())
   1769 }
   1770 
   1771 fn validate_values(v: &Values, limits: &BTreeMap<String, u64>) -> Result<(), String> {
   1772     require(
   1773         v.quantity_coefficient_max == 999_999_999_999
   1774             && v.quantity_scale_max == 6
   1775             && v.count_quantities_integral
   1776             && v.money_minor_max == 999_999_999_999_999
   1777             && v.currency_exponent_max == 4
   1778             && v.currency_registry == "pinned_supported_registry_with_verified_redistribution"
   1779             && v.rounding == "half_even_once_per_net_line_then_checked_sum"
   1780             && v.binding_numbers == "exact_decimal_or_integer_strings"
   1781             && v.stock_ticks_max == 1_000_000_000_000_000_000
   1782             && v.stock_scale_max == 6
   1783             && v.stock_units == ["g", "kg", "mL", "L", "each"]
   1784             && v.stock_physical_categories
   1785                 == [
   1786                     "available",
   1787                     "preparatory_hold",
   1788                     "committed_hold",
   1789                     "physical_quarantine",
   1790                     "consumed",
   1791                     "waste",
   1792                     "removed",
   1793                 ]
   1794             && v.generation_max == i64::MAX as u64,
   1795         "exact economics, registry or binding value contract drift",
   1796     )?;
   1797     let expected = BTreeMap::from([
   1798         ("public_event_bytes", 65_536),
   1799         ("private_record_bytes", 16_384),
   1800         ("complete_rumor_bytes", 24_576),
   1801         ("chat_bytes", 4_096),
   1802         ("json_depth", 16),
   1803         ("single_profile_tag_bytes", 32_768),
   1804         ("order_lines", 32),
   1805         ("listing_options", 16),
   1806         ("parent_records", 8),
   1807         ("causal_records_per_scope", 1_000),
   1808         ("causal_source_identities_per_collection", 8_000),
   1809         ("read_page_events", 1_000),
   1810         ("unknown_quarantine_events_per_scope", 1_024),
   1811         ("live_queue_events", 256),
   1812         ("live_queue_bytes", 4_194_304),
   1813         ("default_relays", 4),
   1814         ("maximum_session_relays", 16),
   1815         ("concurrent_verifications", 4),
   1816         ("delivery_attempts_per_target", 12),
   1817         ("first_issuance_seconds", 120),
   1818     ]);
   1819     require(
   1820         limits
   1821             .iter()
   1822             .map(|(k, v)| (k.as_str(), *v))
   1823             .collect::<BTreeMap<_, _>>()
   1824             == expected,
   1825         "initial resource contract requires an explicit amendment",
   1826     )
   1827 }
   1828 
   1829 fn validate_execution(e: &Execution, p: &Protocol, c: &Cutover) -> Result<(), String> {
   1830     require(
   1831         e.ordinary_inventory_owner.execution == "radroots_execution.ClientSession"
   1832             && e.ordinary_inventory_owner.owned_capture_method == "capture_stock_evidence"
   1833             && e.ordinary_inventory_owner
   1834                 .capture_drain_uses_explicit_reconciliation
   1835             && e.ordinary_inventory_owner
   1836                 .retained_capture_survives_observer_loss
   1837             && e.ordinary_inventory_owner.failed_capture_blocks_fresh_work
   1838             && e.ordinary_inventory_owner.failed_capture_blocks_disposal
   1839             && e.ordinary_inventory_owner
   1840                 .capture_preserves_actual_error_code
   1841             && e.ordinary_inventory_owner.pending_capture_retry == "manual_reconciliation"
   1842             && e.ordinary_inventory_owner
   1843                 .capture_reports_must_match_original
   1844             && !e
   1845                 .ordinary_inventory_owner
   1846                 .capture_scope_metadata_renews_issuance
   1847             && e.ordinary_inventory_owner.owned_acceptance_method == "prepare_stock_acceptance"
   1848             && e.ordinary_inventory_owner.acceptance_is_preparation_only
   1849             && e.ordinary_inventory_owner
   1850                 .lost_accepted_admission_is_unknown
   1851             && e.ordinary_inventory_owner.facade == "radroots.Client"
   1852             && e.ordinary_inventory_owner
   1853                 .selected_workspace_views_share_owner
   1854             && e.ordinary_inventory_owner.exact_owned_attachment_required
   1855             && e.ordinary_inventory_owner.bounded_task_host_required
   1856             && e.ordinary_inventory_owner.native_accepted_work_max == 32
   1857             && !e
   1858                 .ordinary_inventory_owner
   1859                 .native_pending_work_blocks_queries
   1860             && e.ordinary_inventory_owner.native_controls_drain_prior_work
   1861             && !e
   1862                 .ordinary_inventory_owner
   1863                 .observer_loss_cancels_accepted_work
   1864             && e.ordinary_inventory_owner
   1865                 .close_drains_before_workspace_disposal
   1866             && !e
   1867                 .ordinary_inventory_owner
   1868                 .stock_signer_or_transport_constructed
   1869             && e.phases == ["T0", "T1", "S", "T2", "D"]
   1870             && e.selected_executor_required_for_stock
   1871             && !e.fresh_same_key_cache_can_allocate
   1872             && !e.shared_route_local_fallback_allowed
   1873             && !e.effects_inside_stock_transaction
   1874             && e.unknown_is_nonspendable
   1875             && !e.expiry_proves_nonissuance
   1876             && e.obtained_evidence_append_only
   1877             && e.observation_time_nullable
   1878             && e.positive_amendment_hold_before_issuance
   1879             && e.negative_amendment_release_at_installation
   1880             && e.handover_consumes_once
   1881             && !e.buyer_receipt_moves_stock
   1882             && !e.private_causal_heads_use_timestamp_lww,
   1883         "durable issuance, stock or authority contract drift",
   1884     )?;
   1885     require(
   1886         (
   1887             p.listing_kind,
   1888             p.chat_rumor_kind,
   1889             p.seal_kind,
   1890             p.gift_wrap_kind,
   1891         ) == (30_402, 14, 13, 1_059)
   1892             && p.commerce_kind == Some(radroots_protocol::profile::COMMERCE_KIND)
   1893             && p.capability_kind == Some(radroots_protocol::profile::CAPABILITIES_KIND)
   1894             && p.assignment_contract == "radroots.shared_sdk.protocol.v1"
   1895             && p.structured_authoring == "blocked_until_wire_and_crypto_qualification"
   1896             && p.independent_vectors_required
   1897             && p.duplicate_json_fields_rejected,
   1898         "protocol assignment or authenticated admission prerequisites drift",
   1899     )?;
   1900     require(
   1901         c.new_persistent_namespace
   1902             && c.protected_export_and_quarantine_required
   1903             && c.restore_starts_nonpublishing
   1904             && c.unknowns_and_obligations_protected
   1905             && !c.automatic_legacy_reissue_allowed
   1906             && c.meaningful_state_reset_requires_operator_approval,
   1907         "protected cutover or reset authority drift",
   1908     )
   1909 }
   1910 
   1911 #[cfg(test)]
   1912 mod tests {
   1913     use super::*;
   1914     use serde_json::{Value, json};
   1915 
   1916     const SOURCE: &str =
   1917         include_str!("../../../../contracts/architecture/decisions/shared_sdk_refactor.v1.json");
   1918 
   1919     fn changed(pointer: &str, replacement: Value) -> Vec<u8> {
   1920         let mut value: Value = serde_json::from_str(SOURCE).unwrap();
   1921         *value.pointer_mut(pointer).expect("fixture path") = replacement;
   1922         serde_json::to_vec(&value).unwrap()
   1923     }
   1924 
   1925     #[test]
   1926     fn approved_scope_is_valid_without_claiming_current_implementation() {
   1927         validate_bytes(SOURCE.as_bytes()).unwrap();
   1928     }
   1929 
   1930     #[test]
   1931     fn physical_accounting_cannot_mint_stock_erase_deficits_or_claim_native_effects() {
   1932         for (field, value) in [
   1933             ("value_owner", json!("application")),
   1934             ("scope", json!("mixed_pool_units")),
   1935             ("obligation_equation", json!("remaining = backed")),
   1936             ("ticks_max", json!(1_000_000_000_000_000_001u64)),
   1937             ("values_create_store_effects", json!(true)),
   1938             ("deficit_counts_as_physical_stock", json!(true)),
   1939             ("receipt_consumes_again", json!(true)),
   1940             ("released_deficit_adds_available", json!(true)),
   1941             ("loss_deletes_obligation", json!(true)),
   1942             (
   1943                 "native_atomic_allocation_and_identity_required",
   1944                 json!(false),
   1945             ),
   1946         ] {
   1947             assert!(
   1948                 validate_bytes(&changed(&format!("/stock_accounting/{field}"), value)).is_err()
   1949             );
   1950         }
   1951     }
   1952 
   1953     #[test]
   1954     fn replacement_claims_require_native_digest_head_and_effect_revalidation() {
   1955         for (field, value) in [
   1956             ("owner", json!("application")),
   1957             ("scope", json!("latest_timestamp_wins")),
   1958             ("complete_local_causal_coverage_required", json!(false)),
   1959             (
   1960                 "conflicting_authorizations_require_reconciliation",
   1961                 json!(false),
   1962             ),
   1963             ("native_canonical_digest_recompute_required", json!(false)),
   1964             ("native_current_head_and_residual_required", json!(false)),
   1965             ("claim_grants_current_authority", json!(true)),
   1966             ("claim_creates_stock_effects", json!(true)),
   1967         ] {
   1968             assert!(
   1969                 validate_bytes(&changed(
   1970                     &format!("/stock_accounting/replacement_terms_admission/{field}"),
   1971                     value,
   1972                 ))
   1973                 .is_err(),
   1974                 "{field}"
   1975             );
   1976         }
   1977     }
   1978 
   1979     #[test]
   1980     fn native_terms_require_original_state_and_separate_stock_effect_phases() {
   1981         for (field, value) in [
   1982             ("catalog", json!(19)),
   1983             ("facade_method", json!("another_executor")),
   1984             ("source_owner", json!("captured_metadata")),
   1985             ("current_installed_base_required", json!(false)),
   1986             ("original_allocations_required", json!(false)),
   1987             ("positive_hold_phase", json!("T2")),
   1988             ("negative_release_phase", json!("T0")),
   1989             ("pending_negatives_finance_holds", json!(true)),
   1990             ("old_commitment_retained_while_pending", json!(false)),
   1991             ("changed_residual_requires_new_admission", json!(false)),
   1992             ("quantity_storage", json!("plaintext_index")),
   1993             ("index_plaintext_quantities", json!(true)),
   1994             (
   1995                 "automatic_changed_multi_pool_split",
   1996                 json!("current_mapping"),
   1997             ),
   1998             ("same_signing_and_recovery_owner", json!(false)),
   1999             ("unknown_issuance_releases_stock", json!(true)),
   2000             ("retained_catalog_auto_upgrade", json!(true)),
   2001         ] {
   2002             assert!(
   2003                 validate_bytes(&changed(
   2004                     &format!("/stock_accounting/native_terms_installation/{field}"),
   2005                     value
   2006                 ))
   2007                 .is_err(),
   2008                 "{field}"
   2009             );
   2010         }
   2011     }
   2012     #[test]
   2013     fn native_corrections_require_original_allocations_and_atomic_deficits() {
   2014         for (field, value) in [
   2015             ("catalog", json!(18)),
   2016             ("selection", json!("latest_mapping")),
   2017             ("max_affected_allocations", json!(33)),
   2018             ("protected_original_allocation_required", json!(false)),
   2019             ("deficit_projection_in_final_transaction", json!(false)),
   2020             ("quantity_storage", json!("plaintext_sql_index")),
   2021             ("worker_charge_bytes", json!(65536)),
   2022             ("preparatory_loss_implicit", json!(true)),
   2023             ("quarantine_loss_implicit", json!(true)),
   2024         ] {
   2025             assert!(
   2026                 validate_bytes(&changed(
   2027                     &format!("/stock_accounting/native_correction/{field}"),
   2028                     value
   2029                 ))
   2030                 .is_err()
   2031             );
   2032         }
   2033     }
   2034 
   2035     #[test]
   2036     fn current_inspection_cannot_invent_backing_authority_or_business_completeness() {
   2037         for (field, value) in [
   2038             ("supported_catalogs", json!([18, 19])),
   2039             ("worker_charge_bytes", json!(16384)),
   2040             ("same_checkpoint_required", json!(false)),
   2041             ("original_allocation_required", json!(false)),
   2042             ("read_pools_and_operations_required", json!(false)),
   2043             ("pending_claims_are_installed", json!(true)),
   2044             ("query_creates_store_effects", json!(true)),
   2045             ("reports_global_business_completeness", json!(true)),
   2046         ] {
   2047             assert!(
   2048                 validate_bytes(&changed(
   2049                     &format!("/stock_accounting/native_inspection/{field}"),
   2050                     value
   2051                 ))
   2052                 .is_err()
   2053             );
   2054         }
   2055     }
   2056 
   2057     #[test]
   2058     fn shared_consumers_cannot_silently_lose_buyer_or_seller_roles() {
   2059         for host in ["cli", "browser", "generic_ffi"] {
   2060             assert!(
   2061                 validate_bytes(&changed(&format!("/roles/{host}"), json!(["seller"]))).is_err()
   2062             );
   2063         }
   2064         assert!(validate_bytes(&changed("/roles/tera", json!(["buyer", "seller"]))).is_err());
   2065         assert!(validate_bytes(&changed("/roles/cli", json!(["buyer", "buyer"]))).is_err());
   2066     }
   2067 
   2068     #[test]
   2069     fn active_compiler_targets_do_not_relabel_historical_or_dedicated_toolchains() {
   2070         for field in ["stable", "msrv"] {
   2071             assert!(
   2072                 validate_bytes(&changed(&format!("/toolchain/{field}"), json!("1.97.1"))).is_err()
   2073             );
   2074         }
   2075         assert!(
   2076             validate_bytes(&changed(
   2077                 "/toolchain/historical_receipts_immutable",
   2078                 json!(false)
   2079             ))
   2080             .is_err()
   2081         );
   2082         assert!(
   2083             validate_bytes(&changed(
   2084                 "/toolchain/dedicated_nightly_and_sp1_separate",
   2085                 json!(false)
   2086             ))
   2087             .is_err()
   2088         );
   2089     }
   2090 
   2091     #[test]
   2092     fn browser_local_ports_and_truthful_memory_capabilities_are_required() {
   2093         assert!(validate_bytes(&changed("/portability/browser_futures", json!("send"))).is_err());
   2094         for field in [
   2095             "unsafe_send_bridge_allowed",
   2096             "memory_store_firm_stock_allowed",
   2097             "portable_core_has_native_hosts",
   2098             "nostr_forces_media",
   2099         ] {
   2100             assert!(
   2101                 validate_bytes(&changed(&format!("/portability/{field}"), json!(true))).is_err()
   2102             );
   2103         }
   2104         assert!(
   2105             validate_bytes(&changed(
   2106                 "/targets/browser_contexts",
   2107                 json!(["main_thread"])
   2108             ))
   2109             .is_err()
   2110         );
   2111         assert!(
   2112             validate_bytes(&changed(
   2113                 "/targets/actual_beta_iphone_required",
   2114                 json!(false)
   2115             ))
   2116             .is_err()
   2117         );
   2118     }
   2119 
   2120     #[test]
   2121     fn dependency_graph_rejects_undefined_edges_cycles_private_paths_and_layer_inversion() {
   2122         for deps in [
   2123             json!(["undeclared_private_engine"]),
   2124             json!(["runtime_paths"]),
   2125             json!(["identity", "identity"]),
   2126         ] {
   2127             assert!(validate_bytes(&changed("/packages/0/dependencies", deps)).is_err());
   2128         }
   2129         let mut value: Value = serde_json::from_str(SOURCE).unwrap();
   2130         let index = value["packages"]
   2131             .as_array()
   2132             .unwrap()
   2133             .iter()
   2134             .position(|p| p["key"] == "runtime_paths")
   2135             .unwrap();
   2136         value["packages"][index]["dependencies"] = json!(["runtime_paths"]);
   2137         assert!(
   2138             validate_bytes(&serde_json::to_vec(&value).unwrap())
   2139                 .unwrap_err()
   2140                 .contains("cycle")
   2141         );
   2142         assert!(
   2143             validate_bytes(&changed(
   2144                 "/packages/0/directory",
   2145                 json!("../enterprise/identity")
   2146             ))
   2147             .is_err()
   2148         );
   2149     }
   2150 
   2151     #[test]
   2152     fn retained_capabilities_and_independent_implementation_cannot_be_removed() {
   2153         assert!(
   2154             validate_bytes(&changed("/retained_capability_families", json!(["farm"]))).is_err()
   2155         );
   2156         assert!(
   2157             validate_bytes(&changed(
   2158                 "/provenance/relabel_app_source_license",
   2159                 json!(true)
   2160             ))
   2161             .is_err()
   2162         );
   2163         assert!(
   2164             validate_bytes(&changed(
   2165                 "/provenance/map_meaningful_removed_tests_before_removal",
   2166                 json!(false)
   2167             ))
   2168             .is_err()
   2169         );
   2170         assert!(
   2171             validate_bytes(&changed(
   2172                 "/ownership/app_owns_shared_semantics",
   2173                 json!(true)
   2174             ))
   2175             .is_err()
   2176         );
   2177     }
   2178 
   2179     #[test]
   2180     fn local_outboxes_cannot_upgrade_legacy_buyer_or_claim_stock_and_restored_history() {
   2181         for (field, bad) in [
   2182             ("scopes", json!(["new_buyer_outbox", "seller_stock"])),
   2183             (
   2184                 "scopes",
   2185                 json!(["new_buyer_outbox", "new_buyer_outbox", "new_seller_outbox"]),
   2186             ),
   2187             ("seller_enrollment_explicit", json!(false)),
   2188             (
   2189                 "scope_retained_in_authenticated_binding_and_preparation",
   2190                 json!(false),
   2191             ),
   2192             ("legacy_preparation_v2_scope", json!("new_seller_outbox")),
   2193             (
   2194                 "scope_separates_route_genesis_and_credential_commitments",
   2195                 json!(false),
   2196             ),
   2197             ("coverage", json!("satisfied")),
   2198             ("stock_authority", json!(true)),
   2199             ("organization_or_delegation_authority", json!(true)),
   2200             ("existing_order_or_history_recovery", json!(true)),
   2201         ] {
   2202             assert!(
   2203                 validate_bytes(&changed(&format!("/local_outbox_authority/{field}"), bad)).is_err(),
   2204                 "{field}"
   2205             );
   2206         }
   2207         let mut unknown: Value = serde_json::from_str(SOURCE).unwrap();
   2208         unknown["local_outbox_authority"]["unknown"] = json!(true);
   2209         assert!(validate_bytes(&serde_json::to_vec(&unknown).unwrap()).is_err());
   2210     }
   2211     #[test]
   2212     fn signing_unknown_and_receipt_cannot_become_spend_authority() {
   2213         for (field, bad) in [
   2214             ("fresh_same_key_cache_can_allocate", true),
   2215             ("shared_route_local_fallback_allowed", true),
   2216             ("expiry_proves_nonissuance", true),
   2217             ("unknown_is_nonspendable", false),
   2218             ("obtained_evidence_append_only", false),
   2219             ("observation_time_nullable", false),
   2220             ("buyer_receipt_moves_stock", true),
   2221             ("private_causal_heads_use_timestamp_lww", true),
   2222         ] {
   2223             assert!(validate_bytes(&changed(&format!("/execution/{field}"), json!(bad))).is_err());
   2224         }
   2225     }
   2226 
   2227     #[test]
   2228     fn stock_claims_require_confirmed_dispatch_and_clock_independent_original_capture() {
   2229         for (field, bad) in [
   2230             ("coherent_operation_snapshot_required", json!(false)),
   2231             (
   2232                 "final_evidence_selectors_and_page_rows_required",
   2233                 json!(false),
   2234             ),
   2235             (
   2236                 "recovery_view_has_dispatch_or_installation_rights",
   2237                 json!(true),
   2238             ),
   2239             ("fresh_current_backing_projection_required", json!(false)),
   2240             ("evidence_page_max", json!(33)),
   2241             ("claim_family", json!(3)),
   2242             ("evidence_family", json!(4)),
   2243             ("claim_worker_charge_bytes", json!(16384)),
   2244             ("capture_worker_charge_bytes", json!(16384)),
   2245             ("capture_raw_max_bytes", json!(65537)),
   2246             ("shared_capture_port", json!("arbitrary_transaction")),
   2247             ("shared_reconciliation_port", json!("blind_capture_retry")),
   2248             (
   2249                 "reconciliation_retains_writer_through_replacement",
   2250                 json!(false),
   2251             ),
   2252             (
   2253                 "reconciliation_authenticates_before_connection_close",
   2254                 json!(false),
   2255             ),
   2256             (
   2257                 "reconciliation_preflight_initializes_or_migrates",
   2258                 json!(true),
   2259             ),
   2260             (
   2261                 "reconciliation_clears_fence_only_after_confirmed_capture",
   2262                 json!(false),
   2263             ),
   2264             (
   2265                 "shared_capture_model_owner",
   2266                 json!("radroots_storage_sqlite"),
   2267             ),
   2268             ("shared_capture_descriptors_are_authority", json!(true)),
   2269             ("shared_capture_reauthenticates_original", json!(false)),
   2270             ("native_capture_report_aliases", json!(true)),
   2271             ("first_dispatch_requires_confirmed_commit", json!(false)),
   2272             ("existing_claim_returns_dispatch_permit", json!(true)),
   2273             (
   2274                 "protected_identity_presence_and_absence_required",
   2275                 json!(false),
   2276             ),
   2277             (
   2278                 "capture_requires_original_claim_and_credential",
   2279                 json!(false),
   2280             ),
   2281             ("capture_requires_current_consent", json!(true)),
   2282             ("capture_requires_observation_clock", json!(true)),
   2283             ("capture_preserves_first_optional_time", json!(false)),
   2284             ("capture_retains_distinct_valid_encodings", json!(false)),
   2285             ("agreement_installed", json!(true)),
   2286         ] {
   2287             assert!(
   2288                 validate_bytes(&changed(
   2289                     &format!("/native_seller_stock_authority/signing_issuance/{field}"),
   2290                     bad
   2291                 ))
   2292                 .is_err(),
   2293                 "{field}"
   2294             );
   2295         }
   2296     }
   2297 
   2298     #[test]
   2299     fn initial_installation_requires_peer_evidence_exact_conservation_and_atomic_recipient_work() {
   2300         for (field, bad) in [
   2301             ("payload_version", json!(2)),
   2302             ("journal_family", json!(7)),
   2303             ("worker_charge_bytes", json!(1048577)),
   2304             ("required_peer_evidence", json!(false)),
   2305             ("missing_self_copy_blocks_installation", json!(true)),
   2306             ("original_order_fence_immutable", json!(false)),
   2307             ("exact_original_hold_quantities_required", json!(false)),
   2308             ("current_exact_recovery_consent_required", json!(false)),
   2309             ("fresh_time_not_before_original_bound_plan", json!(false)),
   2310             ("atomic_pool_agreement_and_work_required", json!(false)),
   2311             ("recipient_work_count", json!(3)),
   2312             ("unknown_commit_fences_owner", json!(false)),
   2313             ("signer_or_transport_invoked", json!(true)),
   2314             ("relay_delivery_claimed", json!(true)),
   2315         ] {
   2316             assert!(
   2317                 validate_bytes(&changed(
   2318                     &format!(
   2319                         "/native_seller_stock_authority/initial_agreement_installation/{field}"
   2320                     ),
   2321                     bad
   2322                 ))
   2323                 .is_err(),
   2324                 "{field}"
   2325             );
   2326         }
   2327     }
   2328 
   2329     #[test]
   2330     fn abort_requires_protected_absence_exact_original_release_and_retained_preparations() {
   2331         for (field, bad) in [
   2332             ("shared_storage_port", json!("native_only")),
   2333             ("shared_model_owner", json!("radroots_storage_sqlite")),
   2334             ("native_workspace_type_aliases", json!(true)),
   2335             ("unsupported_hosts_return", json!("aborted")),
   2336             ("payload_version", json!(3)),
   2337             ("journal_family", json!(6)),
   2338             ("worker_charge_bytes", json!(1048577)),
   2339             ("retained_payload_versions", json!([])),
   2340             ("retained_v1_requires_absent_claims", json!(false)),
   2341             ("claimed_cleanup_catalogs", json!([14, 15])),
   2342             ("untracked_claimed_catalogs", json!([13])),
   2343             ("per_recipient_proof_count", json!(1)),
   2344             ("original_unissued_required_for_every_claim", json!(false)),
   2345             ("replay_admission_blocks_release", json!(false)),
   2346             ("obtained_evidence_blocks_release", json!(false)),
   2347             ("contradictory_evidence_retained", json!(false)),
   2348             ("contradiction_requires_recovery", json!(false)),
   2349             ("caller_reports_are_release_authority", json!(true)),
   2350             ("caller_nonissuance_assertion_is_proof", json!(true)),
   2351             ("current_exact_recovery_consent_required", json!(false)),
   2352             ("atomic_exact_original_release_required", json!(false)),
   2353             ("original_preparations_retained", json!(false)),
   2354             ("current_order_projection_authenticated", json!(false)),
   2355             ("later_initial_requires_original_abort", json!(false)),
   2356             ("fresh_signing_after_abort", json!(true)),
   2357             ("unknown_commit_fences_owner", json!(false)),
   2358             ("signer_or_transport_invoked", json!(true)),
   2359         ] {
   2360             assert!(
   2361                 validate_bytes(&changed(
   2362                     &format!("/native_seller_stock_authority/preparation_abort/{field}"),
   2363                     bad
   2364                 ))
   2365                 .is_err(),
   2366                 "{field}"
   2367             );
   2368         }
   2369     }
   2370 
   2371     #[test]
   2372     fn ordinary_inventory_keeps_selected_owner_and_accepted_task_lifetime() {
   2373         for (field, bad) in [
   2374             ("owned_acceptance_method", json!("inline_fallback")),
   2375             ("owned_capture_method", json!("drop_after_refusal")),
   2376             ("capture_drain_uses_explicit_reconciliation", json!(false)),
   2377             ("retained_capture_survives_observer_loss", json!(false)),
   2378             ("failed_capture_blocks_fresh_work", json!(false)),
   2379             ("failed_capture_blocks_disposal", json!(false)),
   2380             ("capture_preserves_actual_error_code", json!(false)),
   2381             ("pending_capture_retry", json!("new_signing_attempt")),
   2382             ("capture_reports_must_match_original", json!(false)),
   2383             ("capture_scope_metadata_renews_issuance", json!(true)),
   2384             ("acceptance_is_preparation_only", json!(false)),
   2385             ("lost_accepted_admission_is_unknown", json!(false)),
   2386             ("execution", json!("application")),
   2387             ("facade", json!("native_backend")),
   2388             ("selected_workspace_views_share_owner", json!(false)),
   2389             ("exact_owned_attachment_required", json!(false)),
   2390             ("bounded_task_host_required", json!(false)),
   2391             ("native_accepted_work_max", json!(33)),
   2392             ("native_pending_work_blocks_queries", json!(true)),
   2393             ("native_controls_drain_prior_work", json!(false)),
   2394             ("observer_loss_cancels_accepted_work", json!(true)),
   2395             ("close_drains_before_workspace_disposal", json!(false)),
   2396             ("stock_signer_or_transport_constructed", json!(true)),
   2397         ] {
   2398             assert!(
   2399                 validate_bytes(&changed(
   2400                     &format!("/execution/ordinary_inventory_owner/{field}"),
   2401                     bad
   2402                 ))
   2403                 .is_err(),
   2404                 "{field}"
   2405             );
   2406         }
   2407     }
   2408 
   2409     #[test]
   2410     fn qualified_local_recovery_keeps_original_policy_window_and_current_rights() {
   2411         for (field, bad) in [
   2412             ("scoped_method", json!("legacy_replay")),
   2413             ("scoped_identity_and_capability_rechecked", json!(false)),
   2414             ("scoped_callback_binding_enforced", json!(false)),
   2415             ("scoped_close_waits_for_active_call", json!(false)),
   2416             ("scoped_method_grants_store_authority", json!(true)),
   2417             ("provider_method", json!("sign_exact")),
   2418             ("adapter", json!("legacy_signer")),
   2419             ("native_authorizer", json!("caller_assertion")),
   2420             ("captured_replay", json!("non_replayable")),
   2421             ("native_catalog", json!(12)),
   2422             ("worker_charge_bytes", json!(1048577)),
   2423             ("existing_protected_claim_required", json!(false)),
   2424             ("current_execute_consent_required", json!(false)),
   2425             ("original_window_required", json!(false)),
   2426             ("call_budget_extends_original_window", json!(true)),
   2427             ("recovery_refusal_proves_original_unissued", json!(true)),
   2428             ("creates_claim_or_stock_effect", json!(true)),
   2429             ("provider_work_inside_sql", json!(true)),
   2430             ("unsupported_legacy_fallback", json!(true)),
   2431             ("after_expiry_retrieval_available", json!(true)),
   2432             ("legacy_and_first_dispatch_unchanged", json!(false)),
   2433             ("current_replay_admission_required", json!(false)),
   2434             ("replay_admission_journal_family", json!(8)),
   2435             ("replay_admission_payload_version", json!(2)),
   2436             ("replay_admission_payload_bytes", json!(185)),
   2437             ("replay_admission_unknown_returns_permit", json!(true)),
   2438             ("replay_admission_reauthorizes_current", json!(false)),
   2439             ("replay_admission_clear_on_refusal", json!(true)),
   2440             ("replay_admission_stock_effect", json!(true)),
   2441             ("retained_untracked_catalogs", json!([15])),
   2442             ("replay_admission_report_is_release_authority", json!(true)),
   2443         ] {
   2444             assert!(
   2445                 validate_bytes(&changed(
   2446                     &format!("/native_seller_stock_authority/qualified_local_recovery/{field}"),
   2447                     bad
   2448                 ))
   2449                 .is_err(),
   2450                 "{field}"
   2451             );
   2452         }
   2453     }
   2454 
   2455     #[test]
   2456     fn public_sources_require_original_signatures_bounded_parts_and_profile_independent_heads() {
   2457         for (field, bad) in [
   2458             ("schema_version", json!(7)),
   2459             ("retained_inventory_versions", json!([2, 3, 4, 5, 6])),
   2460             ("public_source_payload_schemas", json!([])),
   2461             ("public_source_owner_administration_required", json!(false)),
   2462             ("inventory_scope_grants_public_source_access", json!(true)),
   2463             ("public_source_checkpoint_independent", json!(false)),
   2464             (
   2465                 "public_source_input_requires_signature_evidence",
   2466                 json!(false),
   2467             ),
   2468             ("public_source_read_reverifies_signature", json!(false)),
   2469             ("public_source_global_completeness_claimed", json!(true)),
   2470             ("public_source_profile_implies_actionability", json!(true)),
   2471             ("public_source_head_policy", json!("latest_supported")),
   2472             (
   2473                 "public_source_duplicate_encodings",
   2474                 json!("replace_original"),
   2475             ),
   2476             ("public_source_raw_max_bytes", json!(65537)),
   2477             ("public_source_part_max_bytes", json!(16385)),
   2478             ("public_source_part_max_count", json!(5)),
   2479             ("public_source_worker_charge_bytes", json!(16384)),
   2480         ] {
   2481             assert!(
   2482                 validate_bytes(&changed(
   2483                     &format!("/native_seller_stock_authority/{field}"),
   2484                     bad
   2485                 ))
   2486                 .is_err(),
   2487                 "{field}"
   2488             );
   2489         }
   2490     }
   2491 
   2492     #[test]
   2493     fn acceptance_uses_shared_models_without_native_aliases_or_runtime_fallback() {
   2494         for (field, bad) in [
   2495             ("shared_storage_port", json!("native_only")),
   2496             (
   2497                 "shared_model_owner",
   2498                 json!("radroots_storage_sqlite.workspace"),
   2499             ),
   2500             ("legacy_native_aliases", json!(true)),
   2501             ("unsupported_hosts_refuse", json!(false)),
   2502             ("model_constructs_runtime", json!(true)),
   2503         ] {
   2504             assert!(
   2505                 validate_bytes(&changed(
   2506                     &format!("/native_seller_stock_authority/acceptance_preparation/{field}"),
   2507                     bad
   2508                 ))
   2509                 .is_err(),
   2510                 "{field}"
   2511             );
   2512         }
   2513     }
   2514 
   2515     #[test]
   2516     fn signing_plans_require_complete_original_qualified_intents_before_any_signing() {
   2517         for (field, bad) in [
   2518             ("effectful_command_result", json!("unbounded_error")),
   2519             (
   2520                 "generic_obtained_owned_before_descriptor_conversion",
   2521                 json!(false),
   2522             ),
   2523             (
   2524                 "retained_drain_preserves_original_error_and_operation",
   2525                 json!(false),
   2526             ),
   2527             ("common_error_max_bytes", json!(128)),
   2528             ("execution_failure_max_bytes", json!(256)),
   2529             ("rejected_signer_error", json!("success")),
   2530             ("rejected_signer_metadata_owner", json!("raw_payload")),
   2531             ("rejected_signer_report_is_nonissuance", json!(true)),
   2532             (
   2533                 "generic_peer_installed_before_rejected_self_return",
   2534                 json!(false),
   2535             ),
   2536             ("unknown_installation_blocks_delivery", json!(false)),
   2537             ("native_first_dispatch_owns_issuer_invocation", json!(false)),
   2538             ("shared_first_dispatch_port", json!("into_intent")),
   2539             ("shared_unissued_owner", json!("caller_waiter")),
   2540             ("shared_unissued_retained_before_capture", json!(false)),
   2541             ("shared_unissued_drained_before_storage_close", json!(false)),
   2542             (
   2543                 "shared_unissued_failure_blocks_fresh_commands",
   2544                 json!(false),
   2545             ),
   2546             ("public_native_intent_extraction", json!(true)),
   2547             (
   2548                 "coherent_snapshot_preserves_original_unissued",
   2549                 json!(false),
   2550             ),
   2551             ("exact_issuer_port", json!("legacy_signer_fallback")),
   2552             ("native_failure_boundary", json!("discarded_primitive")),
   2553             ("native_failure_preserves_signer_rejection", json!(false)),
   2554             ("native_failure_fingerprint_bytes", json!(64)),
   2555             ("native_failure_coverage", json!("floating_point")),
   2556             ("native_failure_max_bytes", json!(256)),
   2557             ("browser_failure_boundary", json!("discarded_primitive")),
   2558             ("browser_failure_preserves_signer_rejection", json!(false)),
   2559             ("browser_failure_max_bytes", json!(256)),
   2560             (
   2561                 "original_unissued_live_observation_owner",
   2562                 json!("caller_assertion"),
   2563             ),
   2564             (
   2565                 "original_unissued_capture_owner",
   2566                 json!("caller_certificate"),
   2567             ),
   2568             ("original_unissued_payload_version", json!(2)),
   2569             ("original_unissued_journal_family", json!(5)),
   2570             (
   2571                 "original_unissued_capture_requires_owned_observation",
   2572                 json!(false),
   2573             ),
   2574             (
   2575                 "original_unissued_capture_borrows_observation",
   2576                 json!(false),
   2577             ),
   2578             (
   2579                 "original_unissued_capture_rechecks_original_claim",
   2580                 json!(false),
   2581             ),
   2582             (
   2583                 "original_unissued_capture_requires_fresh_permission",
   2584                 json!(true),
   2585             ),
   2586             (
   2587                 "original_unissued_capture_requires_fresh_clock",
   2588                 json!(true),
   2589             ),
   2590             ("original_unissued_capture_releases_stock", json!(true)),
   2591             ("original_unissued_reconciliation_same_owner", json!(false)),
   2592             ("original_unissued_late_evidence_retained", json!(false)),
   2593             ("original_unissued_worker_charge_bytes", json!(1)),
   2594             ("original_unissued_observation_is_durable", json!(true)),
   2595             ("original_unissued_observation_releases_stock", json!(true)),
   2596             (
   2597                 "recovery_refusal_creates_original_unissued_observation",
   2598                 json!(true),
   2599             ),
   2600             (
   2601                 "ordinary_obtained_owned_before_descriptor_conversion",
   2602                 json!(false),
   2603             ),
   2604             ("ordinary_acceptance_owner", json!("application")),
   2605             ("ordinary_acceptance_facade", json!("radroots_sdk")),
   2606             ("ordinary_peer_installed_before_self_work", json!(false)),
   2607             (
   2608                 "ordinary_accepted_task_survives_observer_loss",
   2609                 json!(false),
   2610             ),
   2611             ("ordinary_existing_claim_grants_first_dispatch", json!(true)),
   2612             (
   2613                 "ordinary_replay_requires_original_policy_and_current_permit",
   2614                 json!(false),
   2615             ),
   2616             ("ordinary_acceptance_implies_delivery", json!(true)),
   2617             ("crypto_verifier_owner", json!("radroots_nostr.commerce")),
   2618             (
   2619                 "scoped_crypto_verification",
   2620                 json!("ParticipantProvider.sign_exact"),
   2621             ),
   2622             ("predecessor_nostr_verifier_alias", json!(true)),
   2623             ("crypto_verification_grants_dispatch_authority", json!(true)),
   2624             ("payload_version", json!(2)),
   2625             ("journal_family", json!(2)),
   2626             ("worker_charge_bytes", json!(524288)),
   2627             ("complete_recipient_count", json!(1)),
   2628             ("crypto_and_route_verification_required", json!(false)),
   2629             ("original_t0_rumor_required", json!(false)),
   2630             ("exact_intent_digests_retained", json!(false)),
   2631             (
   2632                 "protected_identity_presence_and_absence_required",
   2633                 json!(false),
   2634             ),
   2635             ("current_issued_consent_required", json!(false)),
   2636             (
   2637                 "final_permission_and_clock_witnesses_required",
   2638                 json!(false),
   2639             ),
   2640             ("signer_invoked", json!(true)),
   2641             ("agreement_installed", json!(true)),
   2642         ] {
   2643             assert!(
   2644                 validate_bytes(&changed(
   2645                     &format!("/native_seller_stock_authority/signing_plan_binding/{field}"),
   2646                     bad
   2647                 ))
   2648                 .is_err(),
   2649                 "{field}"
   2650             );
   2651         }
   2652     }
   2653 
   2654     #[test]
   2655     fn acceptance_requires_complete_atomic_preparation_without_signing_or_installation() {
   2656         for (field, bad) in [
   2657             ("payload_version", json!(2)),
   2658             ("planner_owner", json!("radroots_storage_sqlite")),
   2659             ("order_payload_schema", json!("unsupported")),
   2660             ("movement_payload_schema", json!("unsupported")),
   2661             ("worker_charge_bytes", json!(524289)),
   2662             ("max_allocations", json!(65)),
   2663             ("max_pool_observations", json!(97)),
   2664             ("max_first_issue_window_seconds", json!(121)),
   2665             ("original_replay_before_fresh_planning", json!(false)),
   2666             ("complete_allocation_required", json!(false)),
   2667             ("atomic_holds_and_order_fence_required", json!(false)),
   2668             ("current_issued_consent_required", json!(false)),
   2669             ("final_source_counts_and_witnesses_required", json!(false)),
   2670             ("signer_invoked", json!(true)),
   2671             ("agreement_installed", json!(true)),
   2672         ] {
   2673             assert!(
   2674                 validate_bytes(&changed(
   2675                     &format!("/native_seller_stock_authority/acceptance_preparation/{field}"),
   2676                     bad
   2677                 ))
   2678                 .is_err(),
   2679                 "{field}"
   2680             );
   2681         }
   2682     }
   2683 
   2684     #[test]
   2685     fn consent_ledger_requires_bounded_parts_explicit_scopes_and_protected_identity() {
   2686         for (field, bad) in [
   2687             ("schema_version", json!(6)),
   2688             ("retained_inventory_versions", json!([2, 3, 4, 5])),
   2689             (
   2690                 "operation_part_payload_schema",
   2691                 json!("radroots.seller_stock.operation_part.v2"),
   2692             ),
   2693             ("operation_body_max_bytes", json!(262145)),
   2694             ("operation_part_max_bytes", json!(16385)),
   2695             ("operation_part_max_count", json!(17)),
   2696             (
   2697                 "operation_identity_requires_protected_ancestry",
   2698                 json!(false),
   2699             ),
   2700             ("business_consent_payload_version", json!(2)),
   2701             ("business_consent_action", json!("stock.add")),
   2702             ("business_consent_modes", json!(["execute_and_recover"])),
   2703             ("business_consent_admin_issuance_required", json!(false)),
   2704             (
   2705                 "business_consent_binds_exact_command_and_subject_grant",
   2706                 json!(false),
   2707             ),
   2708             (
   2709                 "business_consent_issuance_has_order_or_stock_effects",
   2710                 json!(true),
   2711             ),
   2712             ("business_consent_worker_charge_bytes", json!(16384)),
   2713         ] {
   2714             assert!(
   2715                 validate_bytes(&changed(
   2716                     &format!("/native_seller_stock_authority/{field}"),
   2717                     bad
   2718                 ))
   2719                 .is_err(),
   2720                 "{field}"
   2721             );
   2722         }
   2723     }
   2724 
   2725     #[test]
   2726     fn causal_history_contract_requires_current_access_full_scope_and_non_actionability() {
   2727         for (field, bad) in [
   2728             (
   2729                 "causal_history_current_administrator_required",
   2730                 json!(false),
   2731             ),
   2732             ("causal_history_complete_local_scope_required", json!(false)),
   2733             (
   2734                 "causal_history_includes_actual_local_signed_records",
   2735                 json!(false),
   2736             ),
   2737             ("causal_history_inventory_minimum_required", json!(false)),
   2738             (
   2739                 "causal_history_logical_record_deduplication_required",
   2740                 json!(false),
   2741             ),
   2742             ("causal_history_implies_installation", json!(true)),
   2743             (
   2744                 "causal_history_uninterpreted_policy",
   2745                 json!("ignore_unknown_scope"),
   2746             ),
   2747             (
   2748                 "causal_history_transaction_witnesses_required",
   2749                 json!(false),
   2750             ),
   2751             ("causal_history_implies_business_permission", json!(true)),
   2752         ] {
   2753             assert!(
   2754                 validate_bytes(&changed(
   2755                     &format!("/native_seller_stock_authority/{field}"),
   2756                     bad
   2757                 ))
   2758                 .is_err(),
   2759                 "{field}"
   2760             );
   2761         }
   2762     }
   2763 
   2764     #[test]
   2765     fn source_retention_contract_requires_provenance_bounds_and_separate_authority() {
   2766         for (field, bad) in [
   2767             ("schema_version", json!(5)),
   2768             ("retained_inventory_versions", json!([2, 3, 4])),
   2769             ("source_payload_schemas", json!([])),
   2770             ("source_profile_dispositions", json!(["known"])),
   2771             ("source_owner_administration_required", json!(false)),
   2772             ("inventory_scope_grants_source_access", json!(true)),
   2773             ("source_checkpoint_independent", json!(false)),
   2774             ("source_profile_implies_actionability", json!(true)),
   2775             ("source_carrier_max_bytes", json!(65537)),
   2776             ("source_chunk_max_bytes", json!(16385)),
   2777         ] {
   2778             assert!(
   2779                 validate_bytes(&changed(
   2780                     &format!("/native_seller_stock_authority/{field}"),
   2781                     bad
   2782                 ))
   2783                 .is_err(),
   2784                 "{field}"
   2785             );
   2786         }
   2787     }
   2788 
   2789     #[test]
   2790     fn native_mapping_contract_preserves_catalogs_owner_access_and_physical_non_effects() {
   2791         for (field, bad) in [
   2792             ("schema_version", json!(4)),
   2793             ("retained_inventory_versions", json!([2, 3])),
   2794             (
   2795                 "mapping_payload_schema",
   2796                 json!("radroots.seller_stock.mapping.v2"),
   2797             ),
   2798             (
   2799                 "inventory_operation_payload_schema",
   2800                 json!("radroots.seller_stock.operation.v3"),
   2801             ),
   2802             (
   2803                 "authority_payload_schema",
   2804                 json!("radroots.seller_stock.authority.v4"),
   2805             ),
   2806             ("mapping_owner_administration_required", json!(false)),
   2807             ("mapping_changes_physical_stock", json!(true)),
   2808             ("mapping_changes_pool_version", json!(true)),
   2809             ("mapping_create_expected_version", json!(1)),
   2810             ("inventory_scope_grants_administration", json!(true)),
   2811         ] {
   2812             assert!(
   2813                 validate_bytes(&changed(
   2814                     &format!("/native_seller_stock_authority/{field}"),
   2815                     bad
   2816                 ))
   2817                 .is_err(),
   2818                 "{field}"
   2819             );
   2820         }
   2821     }
   2822 
   2823     #[test]
   2824     fn assigned_protocol_kinds_and_target_metadata_cannot_authorize_publication() {
   2825         assert!(validate_bytes(&changed("/protocol/commerce_kind", json!(8891))).is_err());
   2826         assert!(validate_bytes(&changed("/protocol/commerce_kind", json!(null))).is_err());
   2827         assert!(validate_bytes(&changed("/protocol/capability_kind", json!(38990))).is_err());
   2828         assert!(validate_bytes(&changed("/protocol/capability_kind", json!(null))).is_err());
   2829         assert!(validate_bytes(&changed("/protocol/assignment_contract", json!("other"))).is_err());
   2830         assert!(
   2831             validate_bytes(&changed(
   2832                 "/protocol/structured_authoring",
   2833                 json!("qualified")
   2834             ))
   2835             .is_err()
   2836         );
   2837         assert!(validate_bytes(&changed("/publication_authorized", json!(true))).is_err());
   2838         assert!(
   2839             validate_bytes(&changed(
   2840                 "/qualification/implementation_claimed",
   2841                 json!(true)
   2842             ))
   2843             .is_err()
   2844         );
   2845         assert!(
   2846             validate_bytes(&changed(
   2847                 "/cutover/automatic_legacy_reissue_allowed",
   2848                 json!(true)
   2849             ))
   2850             .is_err()
   2851         );
   2852     }
   2853 
   2854     #[test]
   2855     fn stock_rewrapping_cannot_replace_originals_reset_policy_or_invent_dispatch() {
   2856         for (field, bad) in [
   2857             ("journal_family", json!(13)),
   2858             ("admission_journal_family", json!(14)),
   2859             ("admission_payload_bytes", json!(247)),
   2860             ("admission_window_seconds_max", json!(31)),
   2861             ("explicit_request_id_required", json!(false)),
   2862             ("newly_confirmed_admission_before_wrapping", json!(false)),
   2863             (
   2864                 "existing_or_uncertain_admission_grants_invocation",
   2865                 json!(true),
   2866             ),
   2867             ("unknown_admissions_count_toward_limit", json!(false)),
   2868             ("descriptor_includes_uncaptured_admissions", json!(false)),
   2869             ("admission_repair_grants_history_or_invocation", json!(true)),
   2870             ("ordinary_owner", json!("application")),
   2871             ("ordinary_facade_methods", json!([])),
   2872             (
   2873                 "ordinary_resume_generates_key_or_business_signature",
   2874                 json!(true),
   2875             ),
   2876             ("ordinary_status_is_atomic_absence_proof", json!(true)),
   2877             ("supported_catalogs", json!([17, 18])),
   2878             ("payload_prefix_bytes", json!(118)),
   2879             ("additional_envelopes_per_recipient_max", json!(193)),
   2880             ("descriptor_page_max", json!(17)),
   2881             ("default_selection_is_original", json!(false)),
   2882             ("new_envelope_selection_explicit", json!(false)),
   2883             ("first_policy_source_bound", json!(false)),
   2884             ("transport_counters_cumulative", json!(false)),
   2885             ("outcomes_scoped_to_exact_envelope", json!(false)),
   2886             ("natural_index_transaction_witness_required", json!(false)),
   2887             ("existing_bytes_may_be_replaced", json!(true)),
   2888             ("capture_or_query_grants_dispatch", json!(true)),
   2889             ("physical_stock_effect", json!(true)),
   2890             ("temporary_key_retained", json!(true)),
   2891             ("provider_io_inside_sql", json!(true)),
   2892         ] {
   2893             assert!(
   2894                 validate_bytes(&changed(
   2895                     &format!("/native_seller_stock_authority/rewrapping/{field}"),
   2896                     bad
   2897                 ))
   2898                 .is_err(),
   2899                 "{field}"
   2900             );
   2901         }
   2902     }
   2903 
   2904     #[test]
   2905     fn stock_envelope_retention_cannot_become_dispatch_permission_or_a_cache_authority() {
   2906         for (field, bad) in [
   2907             ("journal_family", json!(9)),
   2908             ("payload_prefix_bytes", json!(212)),
   2909             ("supported_catalogs", json!([15, 16])),
   2910             ("raw_max_bytes", json!(65537)),
   2911             ("worker_charge_bytes", json!(65536)),
   2912             (
   2913                 "original_preparation_plan_claim_seal_installation_required",
   2914                 json!(false),
   2915             ),
   2916             (
   2917                 "temporary_key_derivation_and_exact_decryption_required",
   2918                 json!(false),
   2919             ),
   2920             ("temporary_key_retained", json!(true)),
   2921             ("original_party_as_outer_author_allowed", json!(true)),
   2922             (
   2923                 "body_derived_projection_and_complete_ancestry_required",
   2924                 json!(false),
   2925             ),
   2926             (
   2927                 "original_credential_capture_requires_live_clock_or_grant",
   2928                 json!(true),
   2929             ),
   2930             ("query_requires_current_recovery_access", json!(false)),
   2931             ("observation_nullable", json!(false)),
   2932             ("existing_original_bytes_may_be_replaced", json!(true)),
   2933             ("capture_grants_dispatch", json!(true)),
   2934             ("capture_changes_physical_stock", json!(true)),
   2935             ("provider_io_inside_sql", json!(true)),
   2936         ] {
   2937             assert!(
   2938                 validate_bytes(&changed(
   2939                     &format!("/native_seller_stock_authority/envelope_retention/{field}"),
   2940                     bad
   2941                 ))
   2942                 .is_err(),
   2943                 "{field}"
   2944             );
   2945         }
   2946     }
   2947 
   2948     #[test]
   2949     fn stock_delivery_requires_fresh_confirmed_claims_and_bounded_original_outcomes() {
   2950         for (field, bad) in [
   2951             ("supported_catalogs", json!([16, 17])),
   2952             ("attempt_journal_family", json!(10)),
   2953             ("observation_journal_family", json!(11)),
   2954             ("attempts_per_target", json!(13)),
   2955             ("observation_page_max", json!(1000)),
   2956             ("worker_charge_bytes", json!(65536)),
   2957             (
   2958                 "original_stock_evidence_installation_outer_required",
   2959                 json!(false),
   2960             ),
   2961             (
   2962                 "original_captured_route_and_current_write_policy_required",
   2963                 json!(false),
   2964             ),
   2965             (
   2966                 "fresh_current_scoped_consent_grant_clock_required",
   2967                 json!(false),
   2968             ),
   2969             ("fresh_claim_requires_confirmed_commit", json!(false)),
   2970             ("existing_attempt_grants_dispatch", json!(true)),
   2971             ("unknown_commit_grants_dispatch", json!(true)),
   2972             ("query_grants_dispatch", json!(true)),
   2973             (
   2974                 "first_complete_targets_and_criterion_immutable",
   2975                 json!(false),
   2976             ),
   2977             ("ordinary_command_replays_existing_attempt", json!(true)),
   2978             (
   2979                 "ordinary_fresh_claim_binds_observed_attempt_count",
   2980                 json!(false),
   2981             ),
   2982             ("ordinary_obtained_material_owner", json!("application")),
   2983             (
   2984                 "ordinary_repeat_uses_selected_envelope_attempt_count",
   2985                 json!(false),
   2986             ),
   2987             ("ordinary_peer_delivery_precedes_self_signing", json!(false)),
   2988             ("installed_original_delivery_requires_signer", json!(true)),
   2989             ("retries_use_original_outer_bytes", json!(false)),
   2990             ("observation_nullable", json!(false)),
   2991             (
   2992                 "original_credential_capture_requires_live_clock_or_grant",
   2993                 json!(true),
   2994             ),
   2995             (
   2996                 "same_owner_obtained_material_reconciliation_required",
   2997                 json!(false),
   2998             ),
   2999             ("first_observation_per_class_immutable", json!(false)),
   3000             ("wrong_event_request_target_ack_rejected", json!(false)),
   3001             ("final_transaction_witnesses_required", json!(false)),
   3002             ("unbounded_attempt_or_observation_collections", json!(true)),
   3003             ("physical_stock_effect", json!(true)),
   3004             ("transport_inside_sql", json!(true)),
   3005         ] {
   3006             assert!(
   3007                 validate_bytes(&changed(
   3008                     &format!("/native_seller_stock_authority/delivery/{field}"),
   3009                     bad
   3010                 ))
   3011                 .is_err(),
   3012                 "{field}"
   3013             );
   3014         }
   3015     }
   3016 
   3017     #[test]
   3018     fn initial_limits_and_exact_binding_economics_require_explicit_amendment() {
   3019         for (pointer, bad) in [
   3020             ("/limits/public_event_bytes", json!(65537)),
   3021             ("/limits/live_queue_bytes", json!(0)),
   3022             ("/limits/order_lines", json!(33)),
   3023             ("/limits/causal_records_per_scope", json!(1001)),
   3024             ("/limits/causal_source_identities_per_collection", json!(0)),
   3025             ("/values/count_quantities_integral", json!(false)),
   3026             ("/values/currency_exponent_max", json!(5)),
   3027             ("/values/rounding", json!("away_from_zero")),
   3028         ] {
   3029             assert!(validate_bytes(&changed(pointer, bad)).is_err());
   3030         }
   3031     }
   3032 
   3033     #[test]
   3034     fn malformed_oversized_duplicate_or_unknown_input_has_bounded_fixed_errors() {
   3035         assert!(
   3036             validate_bytes(&vec![b' '; MAX_BYTES + 1])
   3037                 .unwrap_err()
   3038                 .contains("byte limit")
   3039         );
   3040         for raw in [
   3041             b"{\"schema_version\":1,\"schema_version\":1}".as_slice(),
   3042             b"{\"private_marker\":\"synthetic-private-input\"}",
   3043             b"not json",
   3044         ] {
   3045             let error = validate_bytes(raw).unwrap_err();
   3046             assert_eq!(error, "shared SDK contract: invalid closed JSON shape");
   3047             assert!(!error.contains("synthetic-private-input"));
   3048         }
   3049     }
   3050 }