@consiliency/agent-board-schema 1.80.0 → 1.83.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -0
- package/fixtures/already-applied.json +12 -0
- package/migrations/20261201000100_agent_board_reply_to_message.sql +1241 -0
- package/migrations/20261202000100_agent_board_archive_board.sql +1238 -0
- package/migrations/20261203000100_agent_board_archive_board_reads.sql +391 -0
- package/package.json +1 -1
- package/schema-manifest.json +30 -3
- package/src/tooling.test.mjs +8 -2
- package/tests/agent_board_661_reply_delivery.test.sql +12 -12
- package/tests/agent_board_667_history_class.test.sql +50 -15
- package/tests/agent_board_717_message_replay_scope.test.sql +29 -16
- package/tests/agent_board_717_tasking_replay_scope.test.sql +3 -3
- package/tests/agent_board_archive_board.test.sql +956 -0
- package/tests/agent_board_archive_board_reads.test.sql +785 -0
- package/tests/agent_board_archive_board_reads_plan.test.sql +56 -0
- package/tests/agent_board_atomic_fleet_onboarding.test.sql +2 -0
- package/tests/agent_board_board_claim_policy.test.sql +5 -3
- package/tests/agent_board_bundle_endpoint_compat.test.sql +2 -2
- package/tests/agent_board_canary_signed_fleet_enforcement.test.sql +3 -3
- package/tests/agent_board_claim_subject_gate.test.sql +3 -1
- package/tests/agent_board_claimpolicy_race.test.sql +8 -6
- package/tests/agent_board_delegate_role_class.test.sql +1 -1
- package/tests/agent_board_delivery_writer_execute.test.sql +7 -7
- package/tests/agent_board_fk_lock_edges.test.sql +27 -3
- package/tests/agent_board_gatenull_membstate.test.sql +3 -1
- package/tests/agent_board_hosted_delegates.test.sql +3 -3
- package/tests/agent_board_inbox_rpcs.test.sql +6 -6
- package/tests/agent_board_invite_no_downgrade.test.sql +2 -2
- package/tests/agent_board_ledger_authority.test.sql +3 -1
- package/tests/agent_board_refusal_atomicity.test.sql +958 -0
- package/tests/agent_board_reply_to.test.sql +874 -0
- package/tests/agent_board_role_guard.test.sql +4 -1
- package/tests/agent_board_rolereset.test.sql +5 -4
- package/tests/agent_board_room_roster.test.sql +2 -2
- package/tests/agent_board_scoped_send_regrant.test.sql +8 -8
- package/tests/agent_board_send_outcome.test.sql +10 -10
- package/tests/agent_board_send_role_gate.test.sql +2 -2
- package/tests/agent_board_step_up.test.sql +12 -7
- package/tests/agent_board_step_up_helper.test.sql +20 -17
- package/tests/agent_board_write_enforcement_class.test.sql +9 -8
- package/tests/catalog/function_execute_privileges.json +59 -14
- package/tests/catalog/p_metadata_parameters.json +28 -8
- package/tests/catalog/step_up_gated_closure.json +2 -0
- package/tests/isolation/expected/archive_vs_content.out +800 -0
- package/tests/isolation/expected/reply_parent_vs_thread_delete.out +55 -0
- package/tests/isolation/expected/reply_vs_parent_author_delete.out +56 -0
- package/tests/isolation/specs/archive_vs_content.spec +128 -0
- package/tests/isolation/specs/reply_parent_vs_thread_delete.spec +42 -0
- package/tests/isolation/specs/reply_vs_parent_author_delete.spec +46 -0
- package/tests/mutations/655/M01_no_writer_check.sql +22 -0
- package/tests/mutations/655/M02_drop_fk.sql +2 -0
- package/tests/mutations/655/M03_existence_only.sql +13 -0
- package/tests/mutations/655/M04_distinct_cross_thread_error.sql +17 -0
- package/tests/mutations/655/M05_view_no_thread_conjunct.sql +46 -0
- package/tests/mutations/655/M06_thread_feed_not_invoker.sql +46 -0
- package/tests/mutations/655/M06b_board_feed_not_invoker.sql +49 -0
- package/tests/mutations/655/M07_excerpt_via_definer.sql +49 -0
- package/tests/mutations/655/M08_excerpt_200.sql +46 -0
- package/tests/mutations/655/M09_fk_restrict.sql +4 -0
- package/tests/mutations/655/M10_post_message_drops_arg.sql +13 -0
- package/tests/mutations/655/M10b_post_message_passes_null.sql +12 -0
- package/tests/mutations/655/M11_slug_drops_arg.sql +15 -0
- package/tests/mutations/655/M11b_dm_descriptor_positional.sql +31 -0
- package/tests/mutations/655/M12_signed_pbm_nine_args.sql +19 -0
- package/tests/mutations/655/M12b_signed_mc_one_branch.sql +15 -0
- package/tests/mutations/655/M13_undriven_entrypoint.sql +8 -0
- package/tests/mutations/655/M14_second_writer.sql +6 -0
- package/tests/mutations/655/M15_insert_primitive_public.sql +2 -0
- package/tests/mutations/655/M16_comment_missing.sql +2 -0
- package/tests/mutations/655/M17_old_allow_set_rows.sql +5 -0
- package/tests/mutations/655/M18_board_excerpt_139.sql +49 -0
- package/tests/mutations/655/M19_column_in_middle.sql +47 -0
- package/tests/mutations/655/M20_projects_parent_id.sql +46 -0
- package/tests/mutations/655/M21_replay_applies_new_parent.sql +22 -0
- package/tests/mutations/655/M22_fk_not_valid.sql +4 -0
- package/tests/mutations/655/MB4a_no_readability.sql +13 -0
- package/tests/mutations/655/MB4b_own_readability_message.sql +20 -0
- package/tests/mutations/655/MB4c_service_role_reads_all.sql +12 -0
- package/tests/mutations/655/MB4d_delegate_uses_authenticated_arm.sql +12 -0
- package/tests/mutations/655/MB4f_no_board_member_branch.sql +14 -0
- package/tests/mutations/655/MB4g_helper_granted_authenticated.sql +2 -0
- package/tests/mutations/655/MB4j_writer_uses_current_agent.sql +12 -0
- package/tests/mutations/655/MB4k_delegate_policy_loses_initplan.sql +5 -0
- package/tests/mutations/655/MB4l_board_memberships_policy_narrowed.sql +3 -0
- package/tests/mutations/655/W1_auth_no_membership_state.sql +13 -0
- package/tests/mutations/655/W2_auth_no_agent_binding.sql +13 -0
- package/tests/mutations/655/W3_delivery_no_recipient_binding.sql +12 -0
- package/tests/mutations/655/W4_delegate_no_board_conjunct.sql +18 -0
- package/tests/mutations/655/W5_boardset_no_membership_state.sql +13 -0
- package/tests/mutations/655/W6_boardset_no_agent_binding.sql +14 -0
- package/tests/mutations/655/run.sh +93 -0
- package/tests/mutations/670/M10_lock_removed.sql +2 -2
- package/tests/mutations/670/M14_post_message_mints_from_metadata.sql +2 -2
- package/tests/mutations/670/M3-DM_helper_on_replay_branch.sql +2 -2
- package/tests/mutations/670/M3-MC_helper_on_replay_branch.sql +2 -2
- package/tests/mutations/670/M3_helper_on_replay_branch.sql +2 -2
- package/tests/mutations/670/M8_delivery_swallows_errors.sql +2 -2
- package/tests/mutations/670/M9_lock_key_includes_board.sql +2 -2
- package/tests/mutations/670/run.sh +1 -1
- package/tests/mutations/717-f1/M10_wrapper_stops_delegating.sql +1 -1
- package/tests/mutations/717-f1/M9_public_route_revoked_from_service_role.sql +1 -1
- package/tests/mutations/717-f2b/L1_dm_lock_split_by_recipient.sql +2 -2
- package/tests/mutations/717-f2b/L2_dm_lock_removed.sql +2 -2
- package/tests/mutations/717-f2b/L3_mc_lock_split_by_recipients.sql +2 -2
- package/tests/mutations/717-f2b/L4_mc_lock_removed.sql +2 -2
- package/tests/mutations/717-f2b/M0_prefix_definitions.sql +1 -1
- package/tests/mutations/717-f2b/M10_mc_lookup_any_author.sql +2 -2
- package/tests/mutations/717-f2b/M11_dm_swallow_refusal.sql +2 -2
- package/tests/mutations/717-f2b/M12_mc_swallow_refusal.sql +2 -2
- package/tests/mutations/717-f2b/M15_mc_any_source.sql +1 -1
- package/tests/mutations/717-f2b/M1_dm_drop_recipient_proof.sql +2 -2
- package/tests/mutations/717-f2b/M2_mc_drop_recipient_proof.sql +2 -2
- package/tests/mutations/717-f2b/M3_dm_metadata_as_proof.sql +2 -2
- package/tests/mutations/717-f2b/M4_mc_metadata_as_proof.sql +2 -2
- package/tests/mutations/717-f2b/M5_dm_any_mode.sql +2 -2
- package/tests/mutations/717-f2b/M6_dm_board_delivery_counts.sql +2 -2
- package/tests/mutations/717-f2b/M7_mc_any_mode.sql +2 -2
- package/tests/mutations/717-f2b/M8_dm_thread_stamp_as_proof.sql +2 -2
- package/tests/mutations/717-f2b/M9_dm_lookup_any_author.sql +2 -2
- package/tests/mutations/717-f2b/run.sh +2 -2
- package/tests/mutations/918/M01_any_role.sql +13 -0
- package/tests/mutations/918/M02_departed_owner.sql +13 -0
- package/tests/mutations/918/M03_no_fleet_recheck.sql +13 -0
- package/tests/mutations/918/M04_no_step_up.sql +13 -0
- package/tests/mutations/918/M04b_step_up_archive_only.sql +14 -0
- package/tests/mutations/918/M04c_step_up_change_only.sql +17 -0
- package/tests/mutations/918/M05_null_flag.sql +12 -0
- package/tests/mutations/918/M05b_null_board.sql +12 -0
- package/tests/mutations/918/M06_not_idempotent.sql +12 -0
- package/tests/mutations/918/M06b_wrong_flag_returned.sql +12 -0
- package/tests/mutations/918/M07_create_board_unarchives.sql +15 -0
- package/tests/mutations/918/M08_no_moderation.sql +12 -0
- package/tests/mutations/918/M08b_any_change.sql +12 -0
- package/tests/mutations/918/M09_bootstrap_archived.sql +12 -0
- package/tests/mutations/918/M10_drop_artifacts.sql +2 -0
- package/tests/mutations/918/M10_drop_board_authority_ceilings.sql +2 -0
- package/tests/mutations/918/M10_drop_board_invite_blocks.sql +2 -0
- package/tests/mutations/918/M10_drop_board_invite_tokens.sql +3 -0
- package/tests/mutations/918/M10_drop_board_memberships.sql +3 -0
- package/tests/mutations/918/M10_drop_boards.sql +2 -0
- package/tests/mutations/918/M10_drop_callback_subscriptions.sql +3 -0
- package/tests/mutations/918/M10_drop_claims.sql +3 -0
- package/tests/mutations/918/M10_drop_conflicts.sql +2 -0
- package/tests/mutations/918/M10_drop_delegations.sql +2 -0
- package/tests/mutations/918/M10_drop_delivery_recipients.sql +2 -0
- package/tests/mutations/918/M10_drop_escalations.sql +2 -0
- package/tests/mutations/918/M10_drop_fleet_receive_policies.sql +2 -0
- package/tests/mutations/918/M10_drop_messages.sql +2 -0
- package/tests/mutations/918/M10_drop_task_events.sql +2 -0
- package/tests/mutations/918/M10_drop_tasks.sql +2 -0
- package/tests/mutations/918/M10_drop_thread_memberships.sql +3 -0
- package/tests/mutations/918/M10_drop_threads.sql +2 -0
- package/tests/mutations/918/M10i_drop_insert_board_invite_tokens.sql +2 -0
- package/tests/mutations/918/M10i_drop_insert_board_memberships.sql +2 -0
- package/tests/mutations/918/M10i_drop_insert_callback_subscriptions.sql +2 -0
- package/tests/mutations/918/M10i_drop_insert_claims.sql +2 -0
- package/tests/mutations/918/M10i_drop_insert_thread_memberships.sql +2 -0
- package/tests/mutations/918/M10u_drop_update_board_invite_tokens.sql +2 -0
- package/tests/mutations/918/M10u_drop_update_board_memberships.sql +2 -0
- package/tests/mutations/918/M10u_drop_update_callback_subscriptions.sql +2 -0
- package/tests/mutations/918/M10u_drop_update_claims.sql +2 -0
- package/tests/mutations/918/M10u_drop_update_thread_memberships.sql +2 -0
- package/tests/mutations/918/M11_artifacts_no_message.sql +10 -0
- package/tests/mutations/918/M11_artifacts_no_task.sql +10 -0
- package/tests/mutations/918/M11_artifacts_no_task_event.sql +10 -0
- package/tests/mutations/918/M11_claims_no_resource_key.sql +10 -0
- package/tests/mutations/918/M11_claims_no_thread.sql +10 -0
- package/tests/mutations/918/M11_delivery_no_source_message.sql +10 -0
- package/tests/mutations/918/M11_delivery_no_source_task.sql +10 -0
- package/tests/mutations/918/M12_claims_all.sql +9 -0
- package/tests/mutations/918/M13_memberships_all.sql +9 -0
- package/tests/mutations/918/M14_tokens_all.sql +9 -0
- package/tests/mutations/918/M15_subscriptions_all.sql +9 -0
- package/tests/mutations/918/M15b_thread_memberships_all.sql +9 -0
- package/tests/mutations/918/M16_messages_update.sql +10 -0
- package/tests/mutations/918/M16b_task_events_update.sql +10 -0
- package/tests/mutations/918/M17_boards_old_only.sql +10 -0
- package/tests/mutations/918/M18_threads_insert_only.sql +10 -0
- package/tests/mutations/918/M18b_guard_disabled.sql +2 -0
- package/tests/mutations/918/M20_no_clamp_exemption.sql +14 -0
- package/tests/mutations/918/M20b_clamp_any_session.sql +14 -0
- package/tests/mutations/918/M20c_clamp_raise.sql +13 -0
- package/tests/mutations/918/M20d_clamp_other_columns.sql +13 -0
- package/tests/mutations/918/M20e_clamp_any_principal.sql +15 -0
- package/tests/mutations/918/M20f_clamp_any_identity_row.sql +13 -0
- package/tests/mutations/918/M21_ignore_old_row.sql +14 -0
- package/tests/mutations/918/M22_never_refuses.sql +12 -0
- package/tests/mutations/918/M22b_wrong_sqlstate.sql +12 -0
- package/tests/mutations/918/M23_delegate_execute.sql +2 -0
- package/tests/mutations/918/M23b_status_oracle.sql +2 -0
- package/tests/mutations/918/M24_new_writer.sql +2 -0
- package/tests/mutations/918/M24b_new_dynamic_writer.sql +2 -0
- package/tests/mutations/918/M24c_second_status_writer.sql +2 -0
- package/tests/mutations/918/M24d_new_relation.sql +2 -0
- package/tests/mutations/918/M24e_direct_grant.sql +2 -0
- package/tests/mutations/918/M25_memberships_dropped_on_archive.sql +10 -0
- package/tests/mutations/918/M27_departure_result_only.sql +10 -0
- package/tests/mutations/918/M27b_departure_any_role.sql +10 -0
- package/tests/mutations/918/M27c_claim_result_only.sql +10 -0
- package/tests/mutations/918/M27d_claim_any_thread.sql +10 -0
- package/tests/mutations/918/M27e_subscription_result_only.sql +10 -0
- package/tests/mutations/918/M28_token_update_not_expiry.sql +8 -0
- package/tests/mutations/918/M28_token_update_not_reanchor.sql +8 -0
- package/tests/mutations/918/M28_token_update_not_role.sql +8 -0
- package/tests/mutations/918/M28_token_update_not_uses.sql +8 -0
- package/tests/mutations/918/M28b_revocation_any_edit.sql +10 -0
- package/tests/mutations/918/M28c_unrevoke.sql +10 -0
- package/tests/mutations/918/M28d_thread_access_agent.sql +10 -0
- package/tests/mutations/918/M28e_thread_access_thread.sql +10 -0
- package/tests/mutations/918/M28f_thread_access_expiry.sql +10 -0
- package/tests/mutations/918/M28g_thread_access_unrevoke.sql +10 -0
- package/tests/mutations/918/M29_grant_no_refusal.sql +13 -0
- package/tests/mutations/918/M29b_grant_refuses_first.sql +18 -0
- package/tests/mutations/918/M30_redeem_no_status.sql +12 -0
- package/tests/mutations/918/M30b_redeem_distinct_text.sql +16 -0
- package/tests/mutations/918/M31_display_any_status.sql +7 -0
- package/tests/mutations/918/M31b_display_not_service.sql +2 -0
- package/tests/mutations/918/M32_status_before_authority.sql +15 -0
- package/tests/mutations/918/M33_retention_refused.sql +14 -0
- package/tests/mutations/918/M33b_retention_any_metadata.sql +14 -0
- package/tests/mutations/918/M34_guard_rewrites_board_id.sql +13 -0
- package/tests/mutations/918/M34_guard_rewrites_claim_policy.sql +13 -0
- package/tests/mutations/918/M34_guard_rewrites_status.sql +13 -0
- package/tests/mutations/918/M34d_guard_returns_null.sql +16 -0
- package/tests/mutations/918/M34e_guard_rewrites_uppercase.sql +13 -0
- package/tests/mutations/918/M34f_guard_select_into_uppercase.sql +13 -0
- package/tests/mutations/918/M35_new_resource_kind.sql +3 -0
- package/tests/mutations/918/M35b_new_fk_anchor.sql +2 -0
- package/tests/mutations/918/M35c_exempt_gains_writer.sql +2 -0
- package/tests/mutations/918/M35d_service_role_gains_update.sql +2 -0
- package/tests/mutations/918/M36_token_created_at.sql +10 -0
- package/tests/mutations/918/M36b_thread_access_created_at.sql +10 -0
- package/tests/mutations/918/M37_non_object_refused.sql +14 -0
- package/tests/mutations/918/M37b_non_object_any_edit.sql +13 -0
- package/tests/mutations/918/M37c_non_object_any_key.sql +13 -0
- package/tests/mutations/918/M37d_non_object_partial_mark.sql +13 -0
- package/tests/mutations/918/M37e_non_object_result_any_type.sql +13 -0
- package/tests/mutations/918/M37f_non_object_any_last_element.sql +13 -0
- package/tests/mutations/918/M38_claim_key_free.sql +10 -0
- package/tests/mutations/918/M38b_claim_key_verbatim.sql +10 -0
- package/tests/mutations/918/M38c_claim_key_canonical_only.sql +10 -0
- package/tests/mutations/918/equivalents/M37ef_grid.sql +42 -0
- package/tests/mutations/918/isolation/I1_guard_no_lock.sql +13 -0
- package/tests/mutations/918/isolation/I2_archive_no_key_update.sql +12 -0
- package/tests/mutations/918/isolation/I3_guard_for_update.sql +12 -0
- package/tests/mutations/918/isolation/I4_archive_any_isolation.sql +12 -0
- package/tests/mutations/918/isolation/I5_redeem_unlocked.sql +12 -0
- package/tests/mutations/918/isolation/I6_thread_membership_unlocked.sql +12 -0
- package/tests/mutations/918/isolation/I7_thread_membership_for_share.sql +12 -0
- package/tests/mutations/918/pr2/R01_inbox_no_filter.sql +9 -0
- package/tests/mutations/918/pr2/R01b_inbox_hides_boardless.sql +9 -0
- package/tests/mutations/918/pr2/R01d_inbox_requires_readable.sql +9 -0
- package/tests/mutations/918/pr2/R01e_inbox_active_too.sql +9 -0
- package/tests/mutations/918/pr2/R02_counts_no_filter.sql +9 -0
- package/tests/mutations/918/pr2/R02b_counts_hide_boardless.sql +9 -0
- package/tests/mutations/918/pr2/R03_dashboard_no_filter.sql +9 -0
- package/tests/mutations/918/pr2/R03b_dashboard_hides_boardless.sql +9 -0
- package/tests/mutations/918/pr2/R03c_dashboard_tasks.sql +9 -0
- package/tests/mutations/918/pr2/R03d_dashboard_calls_helper.sql +9 -0
- package/tests/mutations/918/pr2/R04_open_esc_no_filter.sql +9 -0
- package/tests/mutations/918/pr2/R04b_open_esc_no_task.sql +9 -0
- package/tests/mutations/918/pr2/R04c_open_esc_no_thread.sql +9 -0
- package/tests/mutations/918/pr2/R05_ops_esc_no_filter.sql +9 -0
- package/tests/mutations/918/pr2/R05b_ops_esc_no_task.sql +9 -0
- package/tests/mutations/918/pr2/R05c_ops_esc_no_thread.sql +9 -0
- package/tests/mutations/918/pr2/R06_stale_no_filter.sql +9 -0
- package/tests/mutations/918/pr2/R06b_stale_no_task.sql +9 -0
- package/tests/mutations/918/pr2/R06c_stale_no_thread.sql +9 -0
- package/tests/mutations/918/pr2/R06d_stale_no_key.sql +9 -0
- package/tests/mutations/918/pr2/R06e_stale_unguarded_cast.sql +9 -0
- package/tests/mutations/918/pr2/R07_memberships_filtered.sql +9 -0
- package/tests/mutations/918/pr2/R07b_memberships_constant.sql +9 -0
- package/tests/mutations/918/pr2/R08a_v_active_claims_filtered.sql +9 -0
- package/tests/mutations/918/pr2/R08b_v_board_feed_filtered.sql +9 -0
- package/tests/mutations/918/pr2/R08c_task_tree_filtered.sql +5 -0
- package/tests/mutations/918/pr2/R08d_thread_feed_filtered.sql +5 -0
- package/tests/mutations/918/pr2/R08e_callback_subs_filtered.sql +5 -0
- package/tests/mutations/918/pr2/R09_inbox_definer_view.sql +9 -0
- package/tests/mutations/918/pr2/R09b_view_grant.sql +2 -0
- package/tests/mutations/918/pr2/R09c_view_revoke.sql +2 -0
- package/tests/mutations/918/pr2/R09d_column_renamed.sql +2 -0
- package/tests/mutations/918/pr2/R10_new_view.sql +2 -0
- package/tests/mutations/918/pr2/R10b_new_routine.sql +2 -0
- package/tests/mutations/918/pr2/R10c_new_indirect_routine.sql +2 -0
- package/tests/mutations/918/pr2/R10d_predicate_returns_rows.sql +2 -0
- package/tests/mutations/918/pr2/R10e_overload.sql +3 -0
- package/tests/mutations/918/pr2/R10f_execute_root.sql +2 -0
- package/tests/mutations/918/pr2/R10g_predicate_array.sql +2 -0
- package/tests/mutations/918/pr2/R10h_predicate_domain.sql +2 -0
- package/tests/mutations/918/pr2/R10i_polymorphic.sql +2 -0
- package/tests/mutations/918/pr2/R10j_predicate_json.sql +2 -0
- package/tests/mutations/918/pr2/R10k_foreign_view.sql +2 -0
- package/tests/mutations/918/pr2/R10l_foreign_view_transitive.sql +2 -0
- package/tests/mutations/918/pr2/R10m_foreign_view_function.sql +2 -0
- package/tests/mutations/918/pr2/R10n_foreign_matview.sql +2 -0
- package/tests/mutations/918/pr2/R10o_ambiguous_overload.sql +6 -0
- package/tests/mutations/918/pr2/R10p_resolved_overload.sql +6 -0
- package/tests/mutations/918/pr2/R11_requests_no_filter.sql +9 -0
- package/tests/mutations/918/pr2/R11b_requests_hide_all.sql +9 -0
- package/tests/mutations/918/pr2/R11c_requests_no_creator.sql +11 -0
- package/tests/mutations/918/pr2/R11d_requests_no_pending.sql +9 -0
- package/tests/mutations/918/pr2/R11e_requests_any_state.sql +9 -0
- package/tests/mutations/918/pr2/R11f_requests_active_too.sql +9 -0
- package/tests/mutations/918/pr2/R12_helper_definer.sql +2 -0
- package/tests/mutations/918/pr2/R12b_helper_no_thread.sql +11 -0
- package/tests/mutations/918/pr2/R12c_helper_no_task.sql +11 -0
- package/tests/mutations/918/pr2/R12d_helper_any_board.sql +10 -0
- package/tests/mutations/918/pr2/R12e_helper_task_any_board.sql +10 -0
- package/tests/mutations/918/pr2/R12f_helper_null.sql +11 -0
- package/tests/mutations/918/pr2/R12g_helper_delegate.sql +2 -0
- package/tests/mutations/918/pr2/R12h_helper_public.sql +2 -0
- package/tests/mutations/918/pr2/R12i_no_generic_plan.sql +2 -0
- package/tests/mutations/918/pr2/R13_archive_columns.sql +2 -0
- package/tests/mutations/918/pr2/R13b_second_agents_fk.sql +2 -0
- package/tests/mutations/918/pr2/R13c_archive_column.sql +2 -0
- package/tests/mutations/918/pr2/R15_rls_narrowed.sql +2 -0
- package/tests/mutations/918/pr2/R15b_rls_widened.sql +2 -0
- package/tests/mutations/918/pr2/R15c_threads_rls_narrowed.sql +2 -0
- package/tests/mutations/918/pr2/R16_archive_deletes.sql +10 -0
- package/tests/mutations/918/pr2/R16b_archive_marks_read.sql +10 -0
- package/tests/mutations/918/pr2/R17_wake_bypasses_inbox.sql +8 -0
- package/tests/mutations/918/pr2/R18_directory_archived.sql +7 -0
- package/tests/mutations/918/pr2/R19_delegate_ids_active_only.sql +7 -0
- package/tests/mutations/918/run.sh +95 -0
- package/tests/mutations/919/M10_quoted_net_http_post_scratch.sql +5 -0
- package/tests/mutations/919/M11_pbm_calls_public.sql +11 -0
- package/tests/mutations/919/M1_pbm_refusal_swallowed_after_write.sql +14 -0
- package/tests/mutations/919/M2_cof_refusal_swallowed_after_write.sql +13 -0
- package/tests/mutations/919/M3_pbm_receipt_fault_swallowed.sql +10 -0
- package/tests/mutations/919/M4_pg_notify_scratch.sql +5 -0
- package/tests/mutations/919/M5_dynamic_notify_scratch.sql +5 -0
- package/tests/mutations/919/M6_trigger_outside_schema.sql +3 -0
- package/tests/mutations/919/M7_pbm_step_up_gate.sql +10 -0
- package/tests/mutations/919/M8_pbm_positive_writes_nothing.sql +10 -0
- package/tests/mutations/919/M9_cof_positive_writes_nothing.sql +10 -0
- package/tests/mutations/919/run.sh +81 -0
- package/tests/seeds/20261202000100_agent_board_archive_board.sql.pre.sql +24 -0
- package/tests/seeds/20261203000100_agent_board_archive_board_reads.sql.pre.sql +38 -0
|
@@ -0,0 +1,956 @@
|
|
|
1
|
+
-- #918 ARCHIVEBOARD PR-1 pgTAP (migration 20261202000100_agent_board_archive_board.sql).
|
|
2
|
+
--
|
|
3
|
+
-- THE CONTRACT
|
|
4
|
+
-- * set_board_archived is the only API writer of boards.status. Active owner only, fleet-revocation
|
|
5
|
+
-- re-check, step-up on EVERY call in both directions, idempotent, null argument 22023.
|
|
6
|
+
-- * create_board's slug collision never un-archives.
|
|
7
|
+
-- * An INSERT or UPDATE of one of the 18 guarded relations that adds or changes content or settings
|
|
8
|
+
-- on an archived board is refused MBA01, whatever route reaches it. What stays allowed: reading,
|
|
9
|
+
-- departures, an owner/admin removing another member, revoking an invite, releasing a claim, and
|
|
10
|
+
-- the housekeeping rows each EXEMPT row below names.
|
|
11
|
+
-- * WHAT THE CLASS SCAN SEES: agent_board routines whose own body writes a board-scoped relation with
|
|
12
|
+
-- a static statement, or runs EXECUTE. It does not see a writable view, a rewrite rule, a routine
|
|
13
|
+
-- in another schema, or a trigger that assigns NEW.
|
|
14
|
+
--
|
|
15
|
+
-- METHOD (AGENTS.md rules 1-3)
|
|
16
|
+
-- * The classes (relations, writers) are derived from pg_constraint / pg_attribute / pg_trigger /
|
|
17
|
+
-- pg_proc and compared BY NAME, so a new member names itself.
|
|
18
|
+
-- * Behaviour rows run the SAME call on an ACTIVE twin board (control) and on the archived one,
|
|
19
|
+
-- each in its own rolled-back subtransaction (pg_temp.probe), and compare the pair of outcomes.
|
|
20
|
+
-- A refusal for some other reason shows up in the control. No call runs inside an assertion's
|
|
21
|
+
-- value expression un-caught: probe catches every error and reports its SQLSTATE.
|
|
22
|
+
-- * The fixture looks like production: `set constraints all immediate` fires the deferred lineage
|
|
23
|
+
-- trigger, so every agent holds its `legacy` session_identities row, as every committed agent does.
|
|
24
|
+
-- Without it "has a session_identities row" is vacuously discriminating inside a rolled-back file.
|
|
25
|
+
-- * 'svcrole' rows run with the EFFECTIVE role service_role, not only its claim.
|
|
26
|
+
-- * TAP numbers are counted by the receipts, never written here.
|
|
27
|
+
create extension if not exists pgtap with schema extensions;
|
|
28
|
+
set search_path = extensions, public, agent_board;
|
|
29
|
+
|
|
30
|
+
begin;
|
|
31
|
+
|
|
32
|
+
select plan(273);
|
|
33
|
+
|
|
34
|
+
create temp table _h(k text primary key, v text);
|
|
35
|
+
create function pg_temp.v(p_k text) returns text language sql as $$ select v from _h where k = p_k $$;
|
|
36
|
+
create function pg_temp.u(p_k text) returns uuid language sql as $$ select v::uuid from _h where k = p_k $$;
|
|
37
|
+
create function pg_temp.put(p_k text, p_v text) returns void language sql as $$
|
|
38
|
+
insert into _h values (p_k, p_v) on conflict (k) do update set v = excluded.v $$;
|
|
39
|
+
|
|
40
|
+
-- p_who's session claims; 'svc' is the operator key.
|
|
41
|
+
create function pg_temp.c(p_who text, p_extra jsonb default '{}'::jsonb) returns text language sql as $$
|
|
42
|
+
select case when p_who in ('svc', 'svcrole') then '{"role":"service_role"}'
|
|
43
|
+
else (jsonb_build_object('role', 'authenticated', 'sub', pg_temp.v(p_who || '.auth'), 'aud', 'authenticated') || p_extra)::text end $$;
|
|
44
|
+
-- A local human's fresh / stale step-up claims.
|
|
45
|
+
create function pg_temp.su(p_who text, p_age int) returns text language sql volatile as $$
|
|
46
|
+
select pg_temp.c(p_who, jsonb_build_object('amr', jsonb_build_array(jsonb_build_object(
|
|
47
|
+
'method', 'totp', 'timestamp', floor(extract(epoch from clock_timestamp()))::bigint - p_age)))) $$;
|
|
48
|
+
create function pg_temp.claims(p_claims text) returns void language plpgsql as $$
|
|
49
|
+
begin
|
|
50
|
+
perform set_config('request.jwt.claim.sub', '', true);
|
|
51
|
+
perform set_config('request.jwt.claim.role', '', true);
|
|
52
|
+
perform set_config('request.jwt.claims', coalesce(p_claims, ''), true);
|
|
53
|
+
end $$;
|
|
54
|
+
-- Substitute {KEY} placeholders from _h.
|
|
55
|
+
create function pg_temp.fmt(p_sql text) returns text language plpgsql as $$
|
|
56
|
+
declare r record;
|
|
57
|
+
begin
|
|
58
|
+
for r in select k, v from _h loop
|
|
59
|
+
p_sql := replace(p_sql, '{' || r.k || '}', coalesce(r.v, 'NULL'));
|
|
60
|
+
end loop;
|
|
61
|
+
if p_sql ~ '\{[A-Za-z0-9_.]+\}' then raise exception 'unresolved placeholder in %', p_sql; end if;
|
|
62
|
+
return p_sql;
|
|
63
|
+
end $$;
|
|
64
|
+
-- Run under claims and KEEP the effects ('OK' / 'SQLSTATE message').
|
|
65
|
+
create function pg_temp.run(p_claims text, p_sql text) returns text language plpgsql as $$
|
|
66
|
+
begin
|
|
67
|
+
begin
|
|
68
|
+
perform pg_temp.claims(p_claims);
|
|
69
|
+
execute pg_temp.fmt(p_sql);
|
|
70
|
+
perform pg_temp.claims(null);
|
|
71
|
+
return 'OK';
|
|
72
|
+
exception when others then
|
|
73
|
+
return sqlstate || ' ' || sqlerrm;
|
|
74
|
+
end;
|
|
75
|
+
end $$;
|
|
76
|
+
-- Run under claims and ALWAYS roll back; 'OK' or the SQLSTATE. p_check, if given, is evaluated in
|
|
77
|
+
-- the same subtransaction after the call, and its text is appended: 'OK:<value>'.
|
|
78
|
+
create function pg_temp.probe(p_claims text, p_sql text, p_check text default null, p_role text default null) returns text language plpgsql as $$
|
|
79
|
+
declare v_check text; v_sql text := pg_temp.fmt(p_sql);
|
|
80
|
+
begin
|
|
81
|
+
begin
|
|
82
|
+
perform pg_temp.claims(p_claims);
|
|
83
|
+
if p_role is not null then execute format('set local role %I', p_role); end if;
|
|
84
|
+
execute v_sql;
|
|
85
|
+
reset role;
|
|
86
|
+
perform pg_temp.claims(null);
|
|
87
|
+
if p_check is not null then execute pg_temp.fmt(p_check) into v_check; end if;
|
|
88
|
+
raise exception using errcode = 'ZZ999', message = coalesce(v_check, '');
|
|
89
|
+
exception
|
|
90
|
+
when sqlstate 'ZZ999' then
|
|
91
|
+
return case when p_check is null then 'OK' else 'OK:' || coalesce(nullif(sqlerrm, ''), '<null>') end;
|
|
92
|
+
when others then
|
|
93
|
+
perform pg_temp.put('LASTERR', sqlerrm);
|
|
94
|
+
return sqlstate;
|
|
95
|
+
end;
|
|
96
|
+
end $$;
|
|
97
|
+
-- The same, with the message: 'SQLSTATE message'.
|
|
98
|
+
create function pg_temp.probe_text(p_claims text, p_sql text, p_role text default null) returns text language plpgsql as $$
|
|
99
|
+
declare r text;
|
|
100
|
+
begin
|
|
101
|
+
r := pg_temp.probe(p_claims, p_sql, null, p_role);
|
|
102
|
+
return case when r like 'OK%' then r else r || ' ' || pg_temp.v('LASTERR') end;
|
|
103
|
+
end $$;
|
|
104
|
+
create function pg_temp.role_of(p_who text) returns text language sql as $$
|
|
105
|
+
select case when p_who = 'svcrole' then 'service_role' end $$;
|
|
106
|
+
-- The pair '<active outcome> / <archived outcome>' of one template. {B}, {T}, ... in the template
|
|
107
|
+
-- name the CURRENT board's fixture: AC.* or AR.* is bound before each run.
|
|
108
|
+
create function pg_temp.bind(p_b text) returns void language sql as $$
|
|
109
|
+
select pg_temp.put(substr(h.k, 4), h.v) from _h h where h.k like p_b || '.%' $$;
|
|
110
|
+
create function pg_temp.pair(p_who text, p_sql text, p_check text default null) returns text language plpgsql as $$
|
|
111
|
+
declare a text; b text;
|
|
112
|
+
begin
|
|
113
|
+
perform pg_temp.bind('AC'); a := pg_temp.probe(pg_temp.c(p_who), p_sql, p_check, pg_temp.role_of(p_who));
|
|
114
|
+
perform pg_temp.bind('AR'); b := pg_temp.probe(pg_temp.c(p_who), p_sql, p_check, pg_temp.role_of(p_who));
|
|
115
|
+
return a || ' / ' || b;
|
|
116
|
+
end $$;
|
|
117
|
+
|
|
118
|
+
-- ===========================================================================
|
|
119
|
+
-- A. The classes, from the catalog
|
|
120
|
+
-- ===========================================================================
|
|
121
|
+
-- A relation is board-scoped when a foreign-key path leads from it to boards, or when it carries a
|
|
122
|
+
-- board_id or thread_id column (FK or not).
|
|
123
|
+
create temp table _rel as
|
|
124
|
+
with recursive scoped(oid) as (
|
|
125
|
+
select 'agent_board.boards'::regclass::oid
|
|
126
|
+
union
|
|
127
|
+
select c.conrelid
|
|
128
|
+
from pg_constraint c
|
|
129
|
+
join scoped s on c.confrelid = s.oid
|
|
130
|
+
join pg_class r on r.oid = c.conrelid
|
|
131
|
+
where c.contype = 'f' and r.relnamespace = 'agent_board'::regnamespace and c.conrelid <> c.confrelid)
|
|
132
|
+
select c.oid, c.relname::text as name
|
|
133
|
+
from pg_class c
|
|
134
|
+
where c.oid in (
|
|
135
|
+
select oid from scoped
|
|
136
|
+
union
|
|
137
|
+
select a.attrelid from pg_attribute a join pg_class r on r.oid = a.attrelid
|
|
138
|
+
where r.relnamespace = 'agent_board'::regnamespace and r.relkind in ('r', 'p')
|
|
139
|
+
and a.attname in ('board_id', 'thread_id') and not a.attisdropped);
|
|
140
|
+
create temp table _guard as
|
|
141
|
+
select t.oid, t.tgrelid, r.name, t.tgname,
|
|
142
|
+
string_to_array(rtrim(replace(encode(t.tgargs, 'escape'), '\000', ','), ','), ',') as args,
|
|
143
|
+
t.tgenabled, t.tgfoid,
|
|
144
|
+
-- pg_get_triggerdef qualifies by the session search_path, which this file sets above.
|
|
145
|
+
replace(replace(pg_get_triggerdef(t.oid), 'CREATE TRIGGER ' || t.tgname || ' ', ''),
|
|
146
|
+
' FOR EACH ROW ', ' ') as def
|
|
147
|
+
from pg_trigger t join _rel r on r.oid = t.tgrelid
|
|
148
|
+
where t.tgfoid = to_regprocedure('agent_board._archived_board_guard()') and not t.tgisinternal;
|
|
149
|
+
|
|
150
|
+
create temp table _rel_exempt(name text primary key, why text not null);
|
|
151
|
+
insert into _rel_exempt values
|
|
152
|
+
('board_invite_redemptions', 'derived: its only ROUTINE writer also writes a guarded membership and uses_count in the same transaction. service_role holds direct DML on it (pre-existing grant, follow-up); a ledger row by itself seats nobody'),
|
|
153
|
+
('board_membership_events', 'append-only ledger of membership transitions, including the departures that stay allowed'),
|
|
154
|
+
('callback_delivery_attempts', 'delivery bookkeeping for events queued before the archive'),
|
|
155
|
+
('callback_outbox_events', 'derived on insert (a post or an inbox action queues it); its updates are delivery bookkeeping'),
|
|
156
|
+
('enrollment_federation_audit', 'identity audit, not board content'),
|
|
157
|
+
('fleet_onboarding_invite_bounds', 'derived: its only writer first mints a guarded board_invite_tokens row'),
|
|
158
|
+
('fleet_trust_sets', 'fleet configuration; no routine writes it'),
|
|
159
|
+
('identity_providers', 'operator configuration; no routine writes it'),
|
|
160
|
+
('inbox_items', 'derived on insert (NOT NULL delivery_recipient_id); its updates are the recipient''s own read state'),
|
|
161
|
+
('presence', 'agent liveness, keyed by agent, not board content'),
|
|
162
|
+
('read_receipts', 'reading'),
|
|
163
|
+
('send_authz_telemetry', 'audit'),
|
|
164
|
+
('send_outcomes', 'derived receipt of an inserted message'),
|
|
165
|
+
('signature_evidence', 'audit'),
|
|
166
|
+
('signature_replay_state', 'replay protection');
|
|
167
|
+
|
|
168
|
+
-- AB-C1
|
|
169
|
+
select is(
|
|
170
|
+
(select coalesce(nullif(concat_ws(' ',
|
|
171
|
+
(select 'unclassified: ' || string_agg(name, ', ' order by name) from _rel
|
|
172
|
+
where name not in (select name from _guard) and name not in (select name from _rel_exempt)),
|
|
173
|
+
(select 'both: ' || string_agg(distinct g.name, ', ') from _guard g join _rel_exempt e using (name)),
|
|
174
|
+
(select 'stale exemption: ' || string_agg(name, ', ' order by name) from _rel_exempt where name not in (select name from _rel))), ''), '(none)')),
|
|
175
|
+
'(none)',
|
|
176
|
+
'AB-C1: every board-scoped relation (FK path to boards, or a board_id/thread_id column) is guarded or exempt, by name');
|
|
177
|
+
select is((select count(*)::int from _rel) || '/' || (select count(distinct name)::int from _guard) || '/' || (select count(*)::int from _guard), '33/18/23',
|
|
178
|
+
'AB-C1 control: the derivation saw 33 relations, 18 of them guarded by 23 triggers');
|
|
179
|
+
-- AB-C2: what each guard fires on, which transitions it exempts, which anchors it resolves.
|
|
180
|
+
select is(
|
|
181
|
+
(select string_agg(def, E'\n' order by name collate "C", tgname collate "C") from _guard),
|
|
182
|
+
$want$BEFORE INSERT OR UPDATE ON agent_board.artifacts EXECUTE FUNCTION _archived_board_guard('thread_id', 'task_id', 'message_id', 'task_event_id')
|
|
183
|
+
BEFORE INSERT OR UPDATE ON agent_board.board_authority_ceilings EXECUTE FUNCTION _archived_board_guard('board_id')
|
|
184
|
+
BEFORE INSERT ON agent_board.board_invite_blocks EXECUTE FUNCTION _archived_board_guard('board_id')
|
|
185
|
+
BEFORE INSERT ON agent_board.board_invite_tokens EXECUTE FUNCTION _archived_board_guard('board_id')
|
|
186
|
+
BEFORE UPDATE ON agent_board.board_invite_tokens WHEN ((NOT ((old.revoked_at IS NULL) AND (new.revoked_at IS NOT NULL) AND (((to_jsonb(old.*) - 'revoked_at'::text) - 'revoked_by_agent_id'::text) = ((to_jsonb(new.*) - 'revoked_at'::text) - 'revoked_by_agent_id'::text))))) EXECUTE FUNCTION _archived_board_guard('board_id')
|
|
187
|
+
BEFORE INSERT ON agent_board.board_memberships EXECUTE FUNCTION _archived_board_guard('board_id')
|
|
188
|
+
BEFORE UPDATE ON agent_board.board_memberships WHEN ((NOT ((old.membership_state <> ALL (ARRAY['left'::text, 'removed'::text])) AND (new.membership_state = ANY (ARRAY['left'::text, 'removed'::text])) AND (NOT (((old.board_id IS DISTINCT FROM new.board_id) OR (old.agent_id IS DISTINCT FROM new.agent_id)) OR (old.role IS DISTINCT FROM new.role)))))) EXECUTE FUNCTION _archived_board_guard('board_id')
|
|
189
|
+
BEFORE UPDATE ON agent_board.boards WHEN (((old.status = 'archived'::text) AND (new.status = 'archived'::text))) EXECUTE FUNCTION _archived_board_guard('id')
|
|
190
|
+
BEFORE INSERT ON agent_board.callback_subscriptions EXECUTE FUNCTION _archived_board_guard('board_id')
|
|
191
|
+
BEFORE UPDATE ON agent_board.callback_subscriptions WHEN ((NOT ((old.subscription_status = 'active'::text) AND (new.subscription_status = 'disabled'::text) AND (NOT (old.board_id IS DISTINCT FROM new.board_id))))) EXECUTE FUNCTION _archived_board_guard('board_id')
|
|
192
|
+
BEFORE INSERT ON agent_board.claims EXECUTE FUNCTION _archived_board_guard('thread_id', 'task_id', 'resource_key')
|
|
193
|
+
BEFORE UPDATE ON agent_board.claims WHEN ((NOT ((old.status = 'active'::text) AND (new.status = ANY (ARRAY['released'::text, 'expired'::text])) AND (NOT ((((old.thread_id IS DISTINCT FROM new.thread_id) OR (old.task_id IS DISTINCT FROM new.task_id)) OR (old.agent_id IS DISTINCT FROM new.agent_id)) OR (old.resource_kind IS DISTINCT FROM new.resource_kind))) AND ((new.resource_key = old.resource_key) OR (new.resource_key = _canonical_claim_key(old.resource_kind, old.resource_key)))))) EXECUTE FUNCTION _archived_board_guard('thread_id', 'task_id', 'resource_key')
|
|
194
|
+
BEFORE INSERT OR UPDATE ON agent_board.conflicts EXECUTE FUNCTION _archived_board_guard('thread_id')
|
|
195
|
+
BEFORE INSERT OR UPDATE ON agent_board.delegations EXECUTE FUNCTION _archived_board_guard('parent_task_id', 'child_task_id')
|
|
196
|
+
BEFORE INSERT ON agent_board.delivery_recipients EXECUTE FUNCTION _archived_board_guard('board_id', 'source_message_id', 'source_task_id', 'source_delegation_id')
|
|
197
|
+
BEFORE INSERT OR UPDATE ON agent_board.escalations EXECUTE FUNCTION _archived_board_guard('thread_id')
|
|
198
|
+
BEFORE INSERT OR UPDATE ON agent_board.fleet_receive_policies EXECUTE FUNCTION _archived_board_guard('board_id')
|
|
199
|
+
BEFORE INSERT ON agent_board.messages EXECUTE FUNCTION _archived_board_guard('thread_id')
|
|
200
|
+
BEFORE INSERT ON agent_board.task_events EXECUTE FUNCTION _archived_board_guard('thread_id')
|
|
201
|
+
BEFORE INSERT OR UPDATE ON agent_board.tasks EXECUTE FUNCTION _archived_board_guard('thread_id')
|
|
202
|
+
BEFORE INSERT ON agent_board.thread_memberships EXECUTE FUNCTION _archived_board_guard('thread_id')
|
|
203
|
+
BEFORE UPDATE ON agent_board.thread_memberships WHEN ((NOT ((old.revoked_at IS NULL) AND (new.revoked_at IS NOT NULL) AND ((to_jsonb(old.*) - 'revoked_at'::text) = (to_jsonb(new.*) - 'revoked_at'::text))))) EXECUTE FUNCTION _archived_board_guard('thread_id')
|
|
204
|
+
BEFORE INSERT OR UPDATE OF board_id ON agent_board.threads EXECUTE FUNCTION _archived_board_guard('board_id')$want$,
|
|
205
|
+
'AB-C2: each guard''s events, WHEN clause and anchor arguments are exactly these');
|
|
206
|
+
select is(
|
|
207
|
+
(select coalesce(string_agg(name, ', '), '(none)') from _guard
|
|
208
|
+
where tgenabled <> 'O' or tgname not in ('trg_archived_board_guard', 'trg_archived_board_guard_update')),
|
|
209
|
+
'(none)', 'AB-C2: every guard is enabled and carries one of the two names');
|
|
210
|
+
-- AB-C3: the arguments cover every way a guarded row can name a board. Any FK column to boards or
|
|
211
|
+
-- threads; and, when the row has no NOT NULL board/thread anchor, every FK column to ANY board-scoped
|
|
212
|
+
-- relation (derived from _rel, not listed) unless its FK also carries a column that is an argument.
|
|
213
|
+
create temp table _fkcol as
|
|
214
|
+
select c.conrelid, r.name, a.attname::text as col, c.confrelid, c.oid as con,
|
|
215
|
+
c.confrelid in ('agent_board.boards'::regclass, 'agent_board.threads'::regclass) as direct, a.attnotnull
|
|
216
|
+
from pg_constraint c
|
|
217
|
+
join _rel r on r.oid = c.conrelid
|
|
218
|
+
join _rel f on f.oid = c.confrelid
|
|
219
|
+
join pg_attribute a on a.attrelid = c.conrelid and a.attnum = any(c.conkey)
|
|
220
|
+
where c.contype = 'f' and c.conrelid <> c.confrelid;
|
|
221
|
+
create temp table _gargs as select tgrelid, name, array_agg(distinct x) as args from _guard, unnest(args) x group by 1, 2;
|
|
222
|
+
select is(
|
|
223
|
+
(select coalesce(string_agg(distinct f.name || '.' || f.col, ', ' order by f.name || '.' || f.col), '(none)')
|
|
224
|
+
from _fkcol f join _gargs g on g.tgrelid = f.conrelid
|
|
225
|
+
where not (f.col = any(g.args))
|
|
226
|
+
and (f.direct or not exists (select 1 from _fkcol d where d.conrelid = f.conrelid and d.direct and d.attnotnull))
|
|
227
|
+
and not exists (select 1 from _fkcol s where s.con = f.con and s.col = any(g.args))),
|
|
228
|
+
'(none)',
|
|
229
|
+
'AB-C3: every FK column through which a guarded row can name a board is one of its guard''s arguments');
|
|
230
|
+
select is((select count(*)::int from _fkcol f join _gargs g on g.tgrelid = f.conrelid) || '/' ||
|
|
231
|
+
(select count(*)::int from _fkcol f join _gargs g on g.tgrelid = f.conrelid where f.col = any(g.args)), '35/27',
|
|
232
|
+
'AB-C3 control: the argument check inspected these FK columns, this many of them arguments');
|
|
233
|
+
select is(
|
|
234
|
+
(select count(distinct array_to_string(args, ','))::text from _guard g where g.name = 'board_memberships') || '/' ||
|
|
235
|
+
(select coalesce(string_agg(name, ',' order by name), '(none)') from (select name from _guard group by name having count(distinct array_to_string(args, ',')) > 1) x),
|
|
236
|
+
'1/(none)', 'AB-C3: a relation with two guards resolves the same anchors in both');
|
|
237
|
+
-- AB-C3b: a claim names its resource in text. The vocabulary of resource_kind is bound here: `task` is
|
|
238
|
+
-- the one kind whose key is a board-scoped id, and the guard resolves exactly it. A new kind reds this.
|
|
239
|
+
select is(
|
|
240
|
+
(select pg_get_constraintdef(oid) from pg_constraint where conname = 'claims_resource_kind_check'),
|
|
241
|
+
$$CHECK ((resource_kind = ANY (ARRAY['task'::text, 'file'::text, 'repo_file'::text, 'repository'::text, 'machine'::text, 'tool'::text, 'custom'::text])))$$,
|
|
242
|
+
'AB-C3b: the claims.resource_kind vocabulary the guard''s task branch was decided against');
|
|
243
|
+
-- AB-C4: no API role writes a guarded relation except through a routine; service_role writes exactly
|
|
244
|
+
-- these five directly, and the guard is what stops it ('svcrole' rows below).
|
|
245
|
+
select is(
|
|
246
|
+
(select coalesce(string_agg(r || ':' || g.name || ':' || p, ', '), '(none)')
|
|
247
|
+
from (select distinct tgrelid, name from _guard) g, unnest(array['anon', 'authenticated', 'agent_board_delegate']) r, unnest(array['INSERT', 'UPDATE', 'DELETE', 'TRUNCATE']) p
|
|
248
|
+
where has_table_privilege(r, g.tgrelid, p)
|
|
249
|
+
or (p in ('INSERT', 'UPDATE') and has_any_column_privilege(r, g.tgrelid, p))),
|
|
250
|
+
'(none)', 'AB-C4: no API role holds a direct write privilege on a guarded relation');
|
|
251
|
+
select is(
|
|
252
|
+
(select string_agg(g.name || ':' || (select string_agg(left(p, 1), '' order by p) from unnest(array['INSERT', 'UPDATE', 'DELETE', 'TRUNCATE']) p
|
|
253
|
+
where has_table_privilege('service_role', g.tgrelid, p) or (p in ('INSERT', 'UPDATE') and has_any_column_privilege('service_role', g.tgrelid, p))), ' ' order by g.name collate "C")
|
|
254
|
+
from (select distinct tgrelid, name from _guard) g
|
|
255
|
+
where exists (select 1 from unnest(array['INSERT', 'UPDATE', 'DELETE', 'TRUNCATE']) p where has_table_privilege('service_role', g.tgrelid, p)
|
|
256
|
+
or (p in ('INSERT', 'UPDATE') and has_any_column_privilege('service_role', g.tgrelid, p)))),
|
|
257
|
+
'board_authority_ceilings:IU board_invite_blocks:DI board_invite_tokens:IU fleet_receive_policies:DIU thread_memberships:IU',
|
|
258
|
+
'AB-C4: service_role''s direct write privileges on guarded relations are exactly these');
|
|
259
|
+
|
|
260
|
+
-- AB-C5: THE WRITER CLASS. Every routine whose own stripped body writes a board-scoped relation, or
|
|
261
|
+
-- that runs dynamic SQL (whose writes a body scan cannot read), with its disposition:
|
|
262
|
+
-- REFUSE on an archived board the call is refused MBA01 by the guard
|
|
263
|
+
-- REFUSE-OWN it refused a non-active board before #918, with its own code (pinned below)
|
|
264
|
+
-- MIXED some transitions refused, some allowed (each has a row)
|
|
265
|
+
-- EXEMPT stays allowed (each has a positive row)
|
|
266
|
+
create temp table _w as
|
|
267
|
+
select p.oid, p.proname::text as name, p.oid::regprocedure::text as sig,
|
|
268
|
+
(select coalesce(array_agg(r.name order by r.name), '{}') from _rel r
|
|
269
|
+
where agent_board_test.stripped_body(p.oid) ~ agent_board_test.write_re(r.name)) as rels
|
|
270
|
+
from pg_proc p
|
|
271
|
+
where p.pronamespace = 'agent_board'::regnamespace and p.prokind in ('f', 'p')
|
|
272
|
+
and p.prolang <> (select oid from pg_language where lanname = 'internal')
|
|
273
|
+
and (agent_board_test.stripped_body(p.oid) ~ agent_board_test.writes_any_re((select array_agg(name) from _rel))
|
|
274
|
+
or agent_board_test.stripped_body(p.oid) ~ agent_board_test.re('\m' || agent_board_test.ci_re('execute') || '\M'));
|
|
275
|
+
create temp table _wdecl(name text primary key, cls text not null);
|
|
276
|
+
insert into _wdecl values
|
|
277
|
+
('_append_task_event', 'REFUSE'), ('_associate_empty_thread', 'REFUSE'), ('_insert_thread_message', 'REFUSE'),
|
|
278
|
+
('_next_thread_message_sequence', 'REFUSE'), ('_queue_board_post_callbacks', 'REFUSE'),
|
|
279
|
+
('_redeem_unbounded_invite_for_agent', 'REFUSE'), ('_upsert_delivery_recipient', 'REFUSE'), ('_upsert_inbox_item', 'REFUSE'),
|
|
280
|
+
('_record_send_outcome', 'REFUSE'),
|
|
281
|
+
('acquire_claim', 'REFUSE'), ('add_artifact', 'REFUSE'), ('create_invite_link', 'REFUSE'), ('create_task', 'REFUSE'),
|
|
282
|
+
('delegate_task', 'REFUSE'), ('grant_board_role', 'REFUSE'), ('mint_delegated_child', 'REFUSE'), ('raise_conflict', 'REFUSE'),
|
|
283
|
+
('raise_escalation', 'REFUSE'), ('readmit_session_identity', 'REFUSE'), ('renew_claim', 'REFUSE'),
|
|
284
|
+
('resolve_conflict', 'REFUSE'), ('resolve_escalation', 'REFUSE'), ('set_board_authority_ceiling', 'REFUSE'),
|
|
285
|
+
('set_board_claim_policy', 'REFUSE'), ('set_board_member_label', 'REFUSE'), ('set_board_role_gate', 'REFUSE'),
|
|
286
|
+
('set_fleet_receive_policy', 'REFUSE'), ('subscribe_callback_endpoint', 'REFUSE'),
|
|
287
|
+
('block_board_inviter', 'REFUSE-OWN'), ('create_fleet_onboarding_invite', 'REFUSE-OWN'),
|
|
288
|
+
('_upsert_board_membership_state', 'MIXED'), ('create_board', 'MIXED'), ('link_session_alias', 'MIXED'),
|
|
289
|
+
('_fedsession_autojoin_default_board', 'EXEMPT'), ('bootstrap_board_owner_memberships', 'EXEMPT'),
|
|
290
|
+
('_emit_membership_event', 'EXEMPT'), ('_enroll_federated_human_after_revocation_gate', 'EXEMPT'),
|
|
291
|
+
('_enroll_federated_identity_once', 'EXEMPT'), ('_queue_inbox_callbacks', 'EXEMPT'), ('_record_send_authz_telemetry', 'EXEMPT'),
|
|
292
|
+
('_record_signed_write_evidence', 'EXEMPT'), ('claim_callback_outbox_events', 'EXEMPT'),
|
|
293
|
+
('create_or_find_thread', 'EXEMPT'), ('create_thread', 'EXEMPT'), ('disable_callback_delivery_endpoint', 'EXEMPT'),
|
|
294
|
+
('disable_callback_endpoint', 'EXEMPT'), ('evaluate_signed_write_fleet_policy', 'EXEMPT'), ('heartbeat', 'EXEMPT'),
|
|
295
|
+
('mark_read', 'EXEMPT'), ('mark_retention_metadata', 'EXEMPT'), ('reclaim_fleet_machine', 'EXEMPT'),
|
|
296
|
+
('record_callback_delivery_retry', 'EXEMPT'), ('record_callback_delivery_success', 'EXEMPT'),
|
|
297
|
+
('record_callback_delivery_terminal_failure', 'EXEMPT'), ('release_claim', 'EXEMPT'), ('reserve_signed_write_replay', 'EXEMPT'),
|
|
298
|
+
('revoke_invite_link', 'EXEMPT'), ('set_board_archived', 'EXEMPT'), ('unblock_board_inviter', 'EXEMPT'),
|
|
299
|
+
('unsubscribe_callback_endpoint', 'EXEMPT'), ('update_inbox_item_state', 'EXEMPT');
|
|
300
|
+
select is(
|
|
301
|
+
(select coalesce(nullif(concat_ws(' ',
|
|
302
|
+
(select 'unclassified: ' || string_agg(sig, ', ' order by sig) from _w where name not in (select name from _wdecl)),
|
|
303
|
+
(select 'declared-only: ' || string_agg(name, ', ' order by name) from _wdecl where name not in (select name from _w))), ''), '(none)')),
|
|
304
|
+
'(none)',
|
|
305
|
+
'AB-C5: the catalog-derived class of routines that write a board-scoped relation is classified, by name; a new writer names itself');
|
|
306
|
+
select is((select count(*)::int from _w) || '/' || (select count(*)::int from _wdecl), '61/61',
|
|
307
|
+
'AB-C5 control: 61 writers, one overload each');
|
|
308
|
+
-- AB-C5b: the writer set behind each EXEMPT relation's reason, by name ('-' = no routine writes it).
|
|
309
|
+
select is(
|
|
310
|
+
(select string_agg(e.name || '=' || coalesce((select string_agg(w.name, '+' order by w.name collate "C") from _w w where e.name = any(w.rels)), '-'), ' ' order by e.name collate "C") from _rel_exempt e),
|
|
311
|
+
'board_invite_redemptions=_redeem_unbounded_invite_for_agent board_membership_events=_emit_membership_event callback_delivery_attempts=disable_callback_delivery_endpoint+record_callback_delivery_retry+record_callback_delivery_success+record_callback_delivery_terminal_failure callback_outbox_events=_queue_board_post_callbacks+_queue_inbox_callbacks+claim_callback_outbox_events+disable_callback_delivery_endpoint+record_callback_delivery_retry+record_callback_delivery_success+record_callback_delivery_terminal_failure enrollment_federation_audit=_enroll_federated_human_after_revocation_gate+_enroll_federated_identity_once fleet_onboarding_invite_bounds=create_fleet_onboarding_invite fleet_trust_sets=- identity_providers=- inbox_items=_upsert_inbox_item+update_inbox_item_state presence=heartbeat read_receipts=mark_read send_authz_telemetry=_record_send_authz_telemetry send_outcomes=_record_send_outcome signature_evidence=_record_signed_write_evidence+evaluate_signed_write_fleet_policy signature_replay_state=_record_signed_write_evidence+reserve_signed_write_replay',
|
|
312
|
+
'AB-C5b: each exempt relation''s routine writers are exactly the ones its reason was decided on');
|
|
313
|
+
-- AB-C6: an EXEMPT or MIXED routine whose body writes a GUARDED relation relies on a transition the
|
|
314
|
+
-- guard exempts (or on a board-less row); exactly these do, each with a behaviour row.
|
|
315
|
+
select is(
|
|
316
|
+
(select string_agg(w.name || ':' || (select string_agg(x, '+' order by x) from unnest(w.rels) x where x in (select name from _guard)), ' ' order by w.name collate "C")
|
|
317
|
+
from _w w join _wdecl d using (name)
|
|
318
|
+
where d.cls in ('EXEMPT', 'MIXED') and w.rels && (select array_agg(name) from _guard)),
|
|
319
|
+
'_fedsession_autojoin_default_board:board_memberships _upsert_board_membership_state:board_memberships bootstrap_board_owner_memberships:board_memberships create_board:board_memberships+boards create_or_find_thread:threads create_thread:threads disable_callback_delivery_endpoint:callback_subscriptions disable_callback_endpoint:callback_subscriptions link_session_alias:board_memberships reclaim_fleet_machine:claims release_claim:claims revoke_invite_link:board_invite_tokens set_board_archived:boards unblock_board_inviter:board_invite_blocks unsubscribe_callback_endpoint:callback_subscriptions',
|
|
320
|
+
'AB-C6: the EXEMPT/MIXED writers of a guarded relation are exactly these');
|
|
321
|
+
-- AB-C7: a REFUSE routine that writes NO guarded relation itself is refused because the guarded write
|
|
322
|
+
-- of its own call came first (it is reached only after one); exactly these.
|
|
323
|
+
select is(
|
|
324
|
+
(select string_agg(w.name, ' ' order by w.name collate "C")
|
|
325
|
+
from _w w join _wdecl d using (name)
|
|
326
|
+
where d.cls like 'REFUSE%' and not (w.rels && (select array_agg(name) from _guard))),
|
|
327
|
+
'_queue_board_post_callbacks _record_send_outcome _upsert_inbox_item create_fleet_onboarding_invite',
|
|
328
|
+
'AB-C7: the REFUSE writers that write only derived relations are exactly these');
|
|
329
|
+
select is(
|
|
330
|
+
(select string_agg(distinct q.name || '<-' || p.proname, ' ' order by q.name || '<-' || p.proname)
|
|
331
|
+
from (values ('_queue_board_post_callbacks'), ('_record_send_outcome'), ('_upsert_inbox_item')) q(name)
|
|
332
|
+
join pg_proc p on p.pronamespace = 'agent_board'::regnamespace and p.prokind = 'f'
|
|
333
|
+
and p.proname <> q.name
|
|
334
|
+
and agent_board_test.stripped_body(p.oid) ~ agent_board_test.call_re(q.name)
|
|
335
|
+
and not (agent_board_test.stripped_body(p.oid) ~ agent_board_test.call_re('_insert_thread_message')
|
|
336
|
+
or agent_board_test.stripped_body(p.oid) ~ agent_board_test.call_re('_upsert_delivery_recipient'))),
|
|
337
|
+
null,
|
|
338
|
+
'AB-C7: every caller of a derived-only writer also calls _insert_thread_message or _upsert_delivery_recipient, whose write is guarded');
|
|
339
|
+
-- AB-C8: the sole-writer property.
|
|
340
|
+
select is(
|
|
341
|
+
(select coalesce(string_agg(p.oid::regprocedure::text, ' ' order by p.oid::regprocedure::text), '(none)')
|
|
342
|
+
from pg_proc p where p.pronamespace = 'agent_board'::regnamespace and p.prokind in ('f', 'p')
|
|
343
|
+
and agent_board_test.stripped_body(p.oid) ~ agent_board_test.col_write_re('boards', 'status')),
|
|
344
|
+
'set_board_archived(uuid,boolean)',
|
|
345
|
+
'AB-C8: set_board_archived is the only routine that writes boards.status');
|
|
346
|
+
-- AB-C9: the refusal has one source and one code.
|
|
347
|
+
select is(
|
|
348
|
+
(select string_agg(p.proname, ' ' order by p.proname)
|
|
349
|
+
from pg_proc p where p.pronamespace = 'agent_board'::regnamespace and p.prokind in ('f', 'p')
|
|
350
|
+
-- keep_literals: the marker IS a literal (the SQLSTATE).
|
|
351
|
+
and agent_board_test.stripped_body(p.oid, true) ~ 'MBA01'),
|
|
352
|
+
'_assert_boards_not_archived', 'AB-C9: MBA01 is raised by _assert_boards_not_archived alone');
|
|
353
|
+
-- The guard never assigns NEW and returns nothing else. BCP-20, CPR-8 and CPR-13b (boards.claim_policy,
|
|
354
|
+
-- threads.board_id immutability) rely on it: a BEFORE trigger writes by assigning NEW, which no
|
|
355
|
+
-- statement scan sees. The matcher catches `new.x :=`, `new.x =`, `new :=` and `into new`, in any case.
|
|
356
|
+
select is(
|
|
357
|
+
(select string_agg(p.proname, ' ' order by p.proname) from pg_proc p
|
|
358
|
+
where p.oid in ('agent_board._archived_board_guard()'::regprocedure, 'agent_board._assert_boards_not_archived(uuid[])'::regprocedure)
|
|
359
|
+
and not agent_board_test.stripped_body(p.oid) ~ agent_board_test.re('\m' || agent_board_test.ci_re('new') || '\s*(\.\s*' || agent_board_test.ident_any_frag() || '\s*)?:?=(?!=)|\m' || agent_board_test.ci_re('into') || '\s+(' || agent_board_test.ci_re('strict') || '\s+)?' || agent_board_test.ci_re('new') || '\M')),
|
|
360
|
+
'_archived_board_guard _assert_boards_not_archived', 'AB-C9 (R7): the guard assigns neither NEW nor a NEW column');
|
|
361
|
+
select is(
|
|
362
|
+
(select format('returns=%s return_new=%s', regexp_count(b, agent_board_test.re('\m' || agent_board_test.ci_re('return') || '\M')), regexp_count(b, agent_board_test.re('\m' || agent_board_test.ci_re('return') || '\s+' || agent_board_test.ci_re('new') || '\s*;')))
|
|
363
|
+
from (select agent_board_test.stripped_body('agent_board._archived_board_guard()'::regprocedure) as b) x),
|
|
364
|
+
'returns=3 return_new=3', 'AB-C9 (R7): every return of the guard is the NEW it was given');
|
|
365
|
+
select is( -- pgtap-allow-raise-checked: regprocedure literals in a catalog comparison, never a call
|
|
366
|
+
(select string_agg(p.proname || ':' || p.prosecdef::text || ':' || coalesce(array_to_string(p.proconfig, ','), '-') || ':'
|
|
367
|
+
|| coalesce((select string_agg(r, ',' order by r) from unnest(array['anon', 'authenticated', 'service_role', 'agent_board_delegate', 'public']) r
|
|
368
|
+
where has_function_privilege(r, p.oid, 'EXECUTE')), 'none'), ' ' order by p.proname)
|
|
369
|
+
from pg_proc p where p.oid in ('agent_board._archived_board_guard()'::regprocedure, 'agent_board._assert_boards_not_archived(uuid[])'::regprocedure,
|
|
370
|
+
'agent_board.set_board_archived(uuid,boolean)'::regprocedure)),
|
|
371
|
+
'_archived_board_guard:true:search_path="":none _assert_boards_not_archived:true:search_path="":none set_board_archived:true:search_path=agent_board, public:authenticated,service_role',
|
|
372
|
+
'AB-C9: definer flags, search_path and EXECUTE of the three #918 functions');
|
|
373
|
+
select is( -- pgtap-allow-raise-checked: regprocedure literals in a catalog comparison, never a call
|
|
374
|
+
(select count(*)::int from pg_proc p where p.oid in ('agent_board._archived_board_guard()'::regprocedure, 'agent_board._assert_boards_not_archived(uuid[])'::regprocedure,
|
|
375
|
+
'agent_board.set_board_archived(uuid,boolean)'::regprocedure, 'agent_board.create_board(uuid,text,text,text,jsonb,text)'::regprocedure,
|
|
376
|
+
'agent_board.update_board_membership(uuid,uuid,text,jsonb)'::regprocedure, 'agent_board.bootstrap_board_owner_memberships()'::regprocedure,
|
|
377
|
+
'agent_board.grant_board_role(uuid,uuid,text,uuid)'::regprocedure, 'agent_board._redeem_unbounded_invite_for_agent(text,uuid)'::regprocedure, 'agent_board.invite_board_for_display(text)'::regprocedure)
|
|
378
|
+
and obj_description(p.oid, 'pg_proc') like '%message-board#918%'),
|
|
379
|
+
9, 'AB-C9: every function this migration created or replaced carries its #918 COMMENT');
|
|
380
|
+
|
|
381
|
+
-- ===========================================================================
|
|
382
|
+
-- Fixtures
|
|
383
|
+
-- Agents (step-up exempt): O owner, A admin, M member, N member, Z outsider, RO ledger-revoked
|
|
384
|
+
-- owner, D, DA and DS departed 9 days ago (DA and
|
|
385
|
+
-- DS with array and scalar metadata), FA bound to a fleet machine, S/PX/S2/RX minted SESSION identities of
|
|
386
|
+
-- O. H a local HUMAN owner (and O's human owner), HA a local HUMAN admin.
|
|
387
|
+
-- Boards: AC (active twin) and AR (archived below by O through the RPC). Same rows on both.
|
|
388
|
+
-- ===========================================================================
|
|
389
|
+
do $$
|
|
390
|
+
declare
|
|
391
|
+
v_who text[] := array['H','O','A','M','N','Z','RO','HA','P1','P2','D','FA','DA','DS'];
|
|
392
|
+
i int; b text; v_dr uuid; v_ii uuid;
|
|
393
|
+
v_board uuid; v_t uuid; v_x uuid; v_ep uuid; v_sub uuid;
|
|
394
|
+
begin
|
|
395
|
+
for i in 1 .. array_length(v_who, 1) loop
|
|
396
|
+
perform pg_temp.put(v_who[i], '91800000-0000-4000-8000-' || lpad(i::text, 12, '0'));
|
|
397
|
+
perform pg_temp.put(v_who[i] || '.auth', '91800001-0000-4000-8000-' || lpad(i::text, 12, '0'));
|
|
398
|
+
insert into auth.users(id, instance_id, aud, role, email)
|
|
399
|
+
values (pg_temp.u(v_who[i] || '.auth'), '00000000-0000-0000-0000-000000000000', 'authenticated', 'authenticated', 'ab918-' || lower(v_who[i]) || '@t.test');
|
|
400
|
+
insert into agent_board.agents(id, agent_type, kind, handle, display_name, status, auth_user_id, owner_user_id)
|
|
401
|
+
values (pg_temp.u(v_who[i]), case when v_who[i] in ('H', 'HA') then 'human' else 'agent' end,
|
|
402
|
+
(case when v_who[i] in ('H', 'HA') then 'human' else 'agent' end)::agent_board.agent_kind,
|
|
403
|
+
'ab918-' || lower(v_who[i]), 'AB918 ' || v_who[i], 'active', pg_temp.u(v_who[i] || '.auth'), pg_temp.u(case when v_who[i] = 'O' then 'H.auth' else v_who[i] || '.auth' end));
|
|
404
|
+
end loop;
|
|
405
|
+
insert into agent_board.agent_signing_keys(id, agent_id, key_id, key_version, public_key, public_key_format, fingerprint, status, proof_state)
|
|
406
|
+
values ('91800002-0000-4000-8000-000000000001', pg_temp.u('O'), 'primary', 1, public.test_pubkey('ab918-o'),
|
|
407
|
+
'raw_ed25519_base64url', public.test_key_fingerprint('ab918-o'), 'active', 'proven');
|
|
408
|
+
-- O is a session-identity root with an approved measurement; every other agent gets its `legacy`
|
|
409
|
+
-- row from the deferred lineage trigger, fired here exactly as a commit would.
|
|
410
|
+
insert into agent_board.session_identities(agent_id, root_agent_id, depth, approved_risky_digest, current_risky_digest)
|
|
411
|
+
values (pg_temp.u('O'), pg_temp.u('O'), 0, 'approved', 'approved');
|
|
412
|
+
set constraints all immediate;
|
|
413
|
+
set constraints all deferred;
|
|
414
|
+
insert into agent_board.fleet_trust_domains(id, slug, display_name, domain_kind, owner_agent_id, lifecycle_state, approved_at)
|
|
415
|
+
values ('91800003-0000-4000-8000-000000000001', 'ab918-td', 'AB918', 'tailnet', pg_temp.u('O'), 'active', now());
|
|
416
|
+
insert into agent_board.fleet_machines(id, trust_domain_id, owner_agent_id, machine_label, machine_fingerprint, lifecycle_state, enrollment_source, enrolled_at)
|
|
417
|
+
values ('91800003-0000-4000-8000-000000000002', '91800003-0000-4000-8000-000000000001', pg_temp.u('O'), 'ab918', 'sha256:ab918-machine', 'active', 'portal', now());
|
|
418
|
+
insert into agent_board.fleet_machine_agents(machine_id, agent_id, lifecycle_state) values ('91800003-0000-4000-8000-000000000002', pg_temp.u('FA'), 'active');
|
|
419
|
+
insert into agent_board.boards(id, slug, name, created_by_agent_id, visibility)
|
|
420
|
+
values ('91810000-0000-4000-8000-000000000003', 'ab918-ax', 'AB918 AX', pg_temp.u('O'), 'private');
|
|
421
|
+
insert into agent_board.board_invite_tokens(code, board_id, preset_role, preset_membership_state, expires_at, created_by_agent_id)
|
|
422
|
+
values ('ab918-xcode', '91810000-0000-4000-8000-000000000003', 'member', 'joined', now() + interval '1 day', pg_temp.u('O'));
|
|
423
|
+
perform pg_temp.put('XCODE', 'ab918-xcode');
|
|
424
|
+
foreach b in array array['AC', 'AR'] loop
|
|
425
|
+
v_board := case b when 'AC' then '91810000-0000-4000-8000-000000000001' else '91810000-0000-4000-8000-000000000002' end;
|
|
426
|
+
perform pg_temp.put(b || '.B', v_board::text);
|
|
427
|
+
perform pg_temp.put(b || '.SLUG', 'ab918-' || lower(b));
|
|
428
|
+
insert into agent_board.boards(id, slug, name, created_by_agent_id, visibility)
|
|
429
|
+
values (v_board, 'ab918-' || lower(b), 'AB918 ' || b, pg_temp.u('O'), 'open');
|
|
430
|
+
insert into agent_board.board_memberships(board_id, agent_id, role, membership_state, created_by_agent_id)
|
|
431
|
+
select v_board, pg_temp.u(w), r, 'joined', pg_temp.u('O')
|
|
432
|
+
from (values ('O','owner'), ('RO','owner'), ('H','owner'), ('A','admin'), ('HA','admin'), ('M','member'), ('N','member'), ('FA','member')) m(w, r);
|
|
433
|
+
insert into agent_board.board_memberships(board_id, agent_id, role, membership_state, created_by_agent_id, left_at)
|
|
434
|
+
values (v_board, pg_temp.u('D'), 'member', 'left', pg_temp.u('D'), now() - interval '9 days');
|
|
435
|
+
-- departed members whose metadata is not an object (adopter data; no routine writes one)
|
|
436
|
+
insert into agent_board.board_memberships(board_id, agent_id, role, membership_state, created_by_agent_id, left_at, metadata)
|
|
437
|
+
values (v_board, pg_temp.u('DA'), 'member', 'left', pg_temp.u('DA'), now() - interval '9 days', '["legacy"]'),
|
|
438
|
+
(v_board, pg_temp.u('DS'), 'member', 'left', pg_temp.u('DS'), now() - interval '9 days', '"legacy"');
|
|
439
|
+
-- a pending request and a pending invitation
|
|
440
|
+
insert into agent_board.board_memberships(board_id, agent_id, role, membership_state, created_by_agent_id)
|
|
441
|
+
values (v_board, pg_temp.u('P1'), 'member', 'requested', pg_temp.u('P1')), (v_board, pg_temp.u('P2'), 'member', 'invited', pg_temp.u('O'));
|
|
442
|
+
insert into agent_board.threads(thread_type, created_by_agent_id, subject, board_id)
|
|
443
|
+
values ('coordination', pg_temp.u('O'), 'ab918 thread', v_board) returning id into v_t;
|
|
444
|
+
perform pg_temp.put(b || '.T', v_t::text);
|
|
445
|
+
insert into agent_board.threads(thread_type, created_by_agent_id, subject)
|
|
446
|
+
values ('coordination', pg_temp.u('M'), 'ab918 empty thread') returning id into v_x;
|
|
447
|
+
perform pg_temp.put(b || '.TE', v_x::text);
|
|
448
|
+
insert into agent_board.callback_endpoints(owner_agent_id, endpoint_url, endpoint_status, verified_at)
|
|
449
|
+
values (pg_temp.u('M'), 'https://ab918.test/' || b, 'verified', now()) returning id into v_ep;
|
|
450
|
+
perform pg_temp.put(b || '.EP', v_ep::text);
|
|
451
|
+
insert into agent_board.callback_endpoints(owner_agent_id, endpoint_url, endpoint_status, verified_at)
|
|
452
|
+
values (pg_temp.u('M'), 'https://ab918-2.test/' || b, 'verified', now()) returning id into v_x;
|
|
453
|
+
perform pg_temp.put(b || '.EP2', v_x::text);
|
|
454
|
+
insert into agent_board.callback_subscriptions(endpoint_id, agent_id, subscription_scope, event_category, board_id, board_membership_id)
|
|
455
|
+
select v_ep, pg_temp.u('M'), 'board', 'board.post.delivered', v_board, bm.id
|
|
456
|
+
from agent_board.board_memberships bm where bm.board_id = v_board and bm.agent_id = pg_temp.u('M') returning id into v_sub;
|
|
457
|
+
-- a post by O through the real RPC: a message, deliveries, inbox items and a queued callback
|
|
458
|
+
perform pg_temp.claims(pg_temp.c('O'));
|
|
459
|
+
select message_id into v_x from agent_board.post_board_message(v_t, pg_temp.u('O'), v_board, 's', 'hello', p_idempotency_key => 'ab918-post');
|
|
460
|
+
perform pg_temp.put(b || '.MSG', v_x::text);
|
|
461
|
+
select task_id into v_x from agent_board.create_task(v_t, pg_temp.u('O'), 'task', p_assigned_agent_id => pg_temp.u('M'));
|
|
462
|
+
perform pg_temp.put(b || '.TASK', v_x::text);
|
|
463
|
+
select task_id into v_x from agent_board.create_task(v_t, pg_temp.u('O'), 'task 2');
|
|
464
|
+
perform pg_temp.put(b || '.TASK2', v_x::text);
|
|
465
|
+
select conflict_id into v_x from agent_board.raise_conflict(v_t, pg_temp.u('O'), 'c');
|
|
466
|
+
perform pg_temp.put(b || '.CF', v_x::text);
|
|
467
|
+
select escalation_id into v_x from agent_board.raise_escalation(v_t, pg_temp.u('O'), 'e');
|
|
468
|
+
perform pg_temp.put(b || '.ES', v_x::text);
|
|
469
|
+
select lease_token into v_x from agent_board.acquire_claim(pg_temp.u('O'), 'custom', 'ab918-claim-' || b, now() + interval '30 minutes', p_thread_id => v_t);
|
|
470
|
+
perform pg_temp.put(b || '.LEASE', v_x::text);
|
|
471
|
+
perform pg_temp.put(b || '.CODE', (select code from agent_board.create_invite_link(v_board, 'member')));
|
|
472
|
+
perform * from agent_board.block_board_inviter(v_board, pg_temp.u('A'), pg_temp.u('O'));
|
|
473
|
+
perform * from agent_board.set_fleet_receive_policy(pg_temp.u('O'), 'ab918', 'allow', p_board_id => v_board);
|
|
474
|
+
perform pg_temp.claims(pg_temp.c('svc'));
|
|
475
|
+
perform * from agent_board.set_fleet_receive_policy(null, 'ab918-board', 'allow', p_board_id => v_board);
|
|
476
|
+
perform pg_temp.claims(null);
|
|
477
|
+
-- a revoked invite, a revoked and a board-less thread membership, and an invite on a third board
|
|
478
|
+
insert into agent_board.board_invite_tokens(code, board_id, preset_role, preset_membership_state, expires_at, created_by_agent_id, revoked_at)
|
|
479
|
+
values ('ab918-revoked-' || b, v_board, 'member', 'joined', now() + interval '1 day', pg_temp.u('O'), now());
|
|
480
|
+
perform pg_temp.put(b || '.RCODE', 'ab918-revoked-' || b);
|
|
481
|
+
insert into agent_board.thread_memberships(thread_id, agent_id, role, revoked_at) values (v_t, pg_temp.u('M'), 'member', now()) returning id into v_x;
|
|
482
|
+
perform pg_temp.put(b || '.RTM', v_x::text);
|
|
483
|
+
insert into agent_board.threads(thread_type, created_by_agent_id, subject) values ('coordination', pg_temp.u('O'), 'ab918 other') returning id into v_x;
|
|
484
|
+
insert into agent_board.thread_memberships(thread_id, agent_id, role) values (v_x, pg_temp.u('A'), 'member') returning id into v_x;
|
|
485
|
+
perform pg_temp.put(b || '.XTM', v_x::text);
|
|
486
|
+
select ii.id into v_ii from agent_board.inbox_items ii where ii.board_id = v_board and ii.recipient_agent_id = pg_temp.u('M');
|
|
487
|
+
perform pg_temp.put(b || '.II', v_ii::text);
|
|
488
|
+
select dr.id into v_dr from agent_board.delivery_recipients dr where dr.board_id = v_board and dr.recipient_agent_id = pg_temp.u('M');
|
|
489
|
+
perform pg_temp.put(b || '.DR', v_dr::text);
|
|
490
|
+
select coe.id into v_x from agent_board.callback_outbox_events coe where coe.board_id = v_board and coe.subscription_id = v_sub;
|
|
491
|
+
perform pg_temp.put(b || '.OB', v_x::text);
|
|
492
|
+
select te.id into v_x from agent_board.task_events te where te.task_id = pg_temp.u(b || '.TASK') order by te.event_sequence limit 1;
|
|
493
|
+
perform pg_temp.put(b || '.TEV', v_x::text);
|
|
494
|
+
insert into agent_board.thread_memberships(thread_id, agent_id, role) values (v_t, pg_temp.u('N'), 'member') returning id into v_x;
|
|
495
|
+
perform pg_temp.put(b || '.TM', v_x::text);
|
|
496
|
+
insert into agent_board.claims(thread_id, agent_id, resource_kind, resource_key, lease_expires_at, status, released_at)
|
|
497
|
+
values (v_t, pg_temp.u('N'), 'custom', 'ab918-done-' || b, now() + interval '1 hour', 'released', now()) returning lease_token into v_x;
|
|
498
|
+
perform pg_temp.put(b || '.DONE', v_x::text);
|
|
499
|
+
-- a live task claim, and a live fleet-backed claim of a task still stored under its legacy alias
|
|
500
|
+
insert into agent_board.claims(thread_id, agent_id, resource_kind, resource_key, lease_expires_at)
|
|
501
|
+
values (v_t, pg_temp.u('O'), 'task', pg_temp.v(b || '.TASK2'), now() + interval '1 hour') returning lease_token into v_x;
|
|
502
|
+
perform pg_temp.put(b || '.TLEASE', v_x::text);
|
|
503
|
+
insert into agent_board.claims(thread_id, task_id, agent_id, resource_kind, resource_key, lease_expires_at)
|
|
504
|
+
values (v_t, pg_temp.u(b || '.TASK'), pg_temp.u('O'), 'repository', 'repo:sha256:ab918-' || b, now() + interval '1 hour') returning lease_token into v_x;
|
|
505
|
+
perform pg_temp.put(b || '.FLEASE', v_x::text);
|
|
506
|
+
insert into agent_board.callback_subscriptions(endpoint_id, agent_id, subscription_scope, event_category, board_id, board_membership_id, subscription_status, disabled_at)
|
|
507
|
+
select pg_temp.u(b || '.EP2'), pg_temp.u('M'), 'board', 'board.post.updated', v_board, bm.id, 'disabled', now()
|
|
508
|
+
from agent_board.board_memberships bm where bm.board_id = v_board and bm.agent_id = pg_temp.u('M') returning id into v_x;
|
|
509
|
+
perform pg_temp.put(b || '.DSUB', v_x::text);
|
|
510
|
+
insert into agent_board.claims(thread_id, agent_id, resource_kind, resource_key, lease_expires_at)
|
|
511
|
+
values (v_t, pg_temp.u('N'), 'machine', case b when 'AC' then 'sha256:ab918-other' else 'sha256:ab918-machine' end, now() + interval '1 hour');
|
|
512
|
+
end loop;
|
|
513
|
+
-- RO carries an agent-subject fleet revocation; its agents.status stays active.
|
|
514
|
+
insert into agent_board.fleet_revocation_events(subject_kind, subject_id, agent_id, revoked_by_agent_id, revocation_reason)
|
|
515
|
+
values ('agent', pg_temp.u('RO'), pg_temp.u('RO'), pg_temp.u('RO'), 'ab918');
|
|
516
|
+
end $$;
|
|
517
|
+
-- Session identities, minted through the real RPC with rooms on BOTH boards: S and its fork RX under O; PX under
|
|
518
|
+
-- O and S2 under PX. RX is then revoked by its human owner. PX is demoted AFTER S2 was minted, so
|
|
519
|
+
-- S2's next link must clamp it.
|
|
520
|
+
create function pg_temp.mint(p_label text, p_parent text, p_role text) returns void language plpgsql as $$
|
|
521
|
+
declare r record;
|
|
522
|
+
begin
|
|
523
|
+
select * into r from agent_board.mint_delegated_child(pg_temp.u(p_parent), 'ab918-sid-' || lower(p_label), '["read"]',
|
|
524
|
+
public.test_pubkey('ab918-sid-' || p_label), interval '8 hours', false, 'claude', 'ab918-sid-' || p_label,
|
|
525
|
+
case when p_parent = 'O' then null else '0' end,
|
|
526
|
+
jsonb_build_array(jsonb_build_object('board_id', pg_temp.u('AC.B'), 'role', p_role), jsonb_build_object('board_id', pg_temp.u('AR.B'), 'role', p_role)),
|
|
527
|
+
'{"resolution":"resolved","risky_digest":"approved"}', case when p_label = 'RX' then pg_temp.u('S') end);
|
|
528
|
+
perform pg_temp.put(p_label, r.child_agent_id::text);
|
|
529
|
+
perform pg_temp.put(p_label || '.key', r.signing_key_id::text);
|
|
530
|
+
perform pg_temp.put(p_label || '.auth', (select auth_user_id::text from agent_board.agents where id = r.child_agent_id));
|
|
531
|
+
end $$;
|
|
532
|
+
create function pg_temp.lease(p_label text) returns void language plpgsql as $$
|
|
533
|
+
declare c record; e bigint;
|
|
534
|
+
begin
|
|
535
|
+
select * into c from agent_board.issue_signing_key_challenge(pg_temp.u(p_label), 'delegated-ephemeral');
|
|
536
|
+
select m.identity_lease_epoch into e from agent_board.mint_fleet_agent_session(c.challenge_id, split_part(c.challenge, ':', 3),
|
|
537
|
+
pg_temp.u(p_label || '.key'), pg_temp.u(p_label), 900, null, 'ab918-sid-' || p_label) m;
|
|
538
|
+
perform pg_temp.put(p_label || '.epoch', e::text);
|
|
539
|
+
end $$;
|
|
540
|
+
select is(pg_temp.run(pg_temp.c('svc'), $$select agent_board.upsert_delegation_policy('{O}', 'root_minted', '["read","write"]', 200, interval '7 days', true);
|
|
541
|
+
select pg_temp.mint('S', 'O', 'admin'); select pg_temp.mint('RX', 'O', 'member'); select pg_temp.mint('PX', 'O', 'admin'); select pg_temp.lease('PX');
|
|
542
|
+
select pg_temp.mint('S2', 'PX', 'admin'); select pg_temp.lease('S2')$$), 'OK', 'AB fixture: O mints session identities with rooms on both boards');
|
|
543
|
+
select is(pg_temp.run(pg_temp.c('H'), $$select agent_board.revoke_session_identity('{RX}')$$), 'OK', 'AB fixture: the human owner H revokes RX');
|
|
544
|
+
select is(pg_temp.run(pg_temp.c('O'), $$select agent_board.grant_board_role('{AC.B}', '{PX}', 'observer'); select agent_board.grant_board_role('{AR.B}', '{PX}', 'observer')$$), 'OK', 'AB fixture: PX is demoted below S2'); -- pgtap-allow-raise-checked: the call runs inside pg_temp.run/probe, which catch every error
|
|
545
|
+
set constraints all immediate;
|
|
546
|
+
set constraints all deferred;
|
|
547
|
+
select is(
|
|
548
|
+
(select string_agg(x.w || ':' || si.identity_kind, ' ' order by x.w collate "C")
|
|
549
|
+
from unnest(array['A','HA','M','S']) x(w) join agent_board.session_identities si on si.agent_id = pg_temp.u(x.w)),
|
|
550
|
+
'A:legacy HA:legacy M:legacy S:session',
|
|
551
|
+
'AB fixture control: ordinary principals hold a legacy session_identities row, as every committed agent does; S is a session identity');
|
|
552
|
+
create temp table _before as
|
|
553
|
+
select 'AR'::text as b, (select count(*) from agent_board.board_memberships where board_id = pg_temp.u('AR.B')) as memberships,
|
|
554
|
+
(select string_agg(agent_id::text || role || membership_state, ',' order by agent_id) from agent_board.board_memberships where board_id = pg_temp.u('AR.B')) as rows,
|
|
555
|
+
(select count(*) from agent_board.messages where thread_id = pg_temp.u('AR.T')) as messages;
|
|
556
|
+
|
|
557
|
+
-- ===========================================================================
|
|
558
|
+
-- B. set_board_archived
|
|
559
|
+
-- ===========================================================================
|
|
560
|
+
create function pg_temp.q(p_b text, p_on text) returns text language sql as $$
|
|
561
|
+
select format('select * from agent_board.set_board_archived(%s, %s)', coalesce(quote_literal(pg_temp.v(p_b)) || '::uuid', 'null'), p_on) $$;
|
|
562
|
+
create function pg_temp.status(p_b text) returns text language sql as $$ select status from agent_board.boards where id = pg_temp.u(p_b) $$;
|
|
563
|
+
select is(pg_temp.run(pg_temp.c('O'), 'select * from agent_board.set_board_archived(null, true)'), '22023 p_board_id and p_archived must not be null', 'AB-B1: a null board id is 22023'); -- pgtap-allow-raise-checked: the call runs inside pg_temp.run/probe, which catch every error
|
|
564
|
+
select is(pg_temp.run(pg_temp.c('O'), pg_temp.q('AR.B', 'null')), '22023 p_board_id and p_archived must not be null', 'AB-B1: a null flag is 22023');
|
|
565
|
+
select is(pg_temp.run(pg_temp.c(w), pg_temp.q('AR.B', 'true')), '42501 only a board owner may archive or un-archive a board',
|
|
566
|
+
'AB-B2 REJECT: ' || w || ' may not archive')
|
|
567
|
+
from unnest(array['A', 'M', 'N', 'Z', 'P2', 'S', 'D', 'svc']) w;
|
|
568
|
+
select is(pg_temp.run(pg_temp.c('O'), $$select * from agent_board.set_board_archived('91819999-0000-4000-8000-000000000009', true)$$), -- pgtap-allow-raise-checked: the call runs inside pg_temp.run/probe, which catch every error
|
|
569
|
+
'42501 only a board owner may archive or un-archive a board', 'AB-B2 REJECT: an unknown board answers as a board the caller does not own');
|
|
570
|
+
select is(pg_temp.run(pg_temp.c('RO'), pg_temp.q('AR.B', 'true')), '42501 fleet_revoked: set_board_archived is not permitted for a fleet-revoked agent', 'AB-B3 REJECT: a fleet-revoked owner may not archive');
|
|
571
|
+
select is(pg_temp.status('AR.B'), 'active', 'AB-B3 state: no refusal above changed the status');
|
|
572
|
+
-- A departed owner is not an owner.
|
|
573
|
+
select is(pg_temp.probe(pg_temp.c('H'), $$select agent_board.leave_board('{AC.B}', '{H}'); select * from agent_board.set_board_archived('{AC.B}', true)$$), -- pgtap-allow-raise-checked: the call runs inside pg_temp.run/probe, which catch every error
|
|
574
|
+
'42501', 'AB-B2 REJECT: an owner who left may not archive');
|
|
575
|
+
-- Step-up, both directions, every call.
|
|
576
|
+
select is(pg_temp.run(pg_temp.c('H'), pg_temp.q('AR.B', 'true')), 'MBS01 step_up_required', 'AB-B4 REJECT: a human owner with no proof cannot archive');
|
|
577
|
+
select is(pg_temp.run(pg_temp.su('H', 301), pg_temp.q('AR.B', 'true')), 'MBS01 step_up_required', 'AB-B4 REJECT: a human owner with a stale proof cannot archive');
|
|
578
|
+
select is(pg_temp.status('AR.B'), 'active', 'AB-B4 state: MBS01 rolled the archive back');
|
|
579
|
+
select is(pg_temp.run(pg_temp.su('H', 10), pg_temp.q('AR.B', 'true')), 'OK', 'AB-B4 ALLOW: a human owner with a fresh proof archives');
|
|
580
|
+
select is(pg_temp.status('AR.B'), 'archived', 'AB-B4 state: archived');
|
|
581
|
+
select is(pg_temp.run(pg_temp.su('H', 301), pg_temp.q('AR.B', 'false')), 'MBS01 step_up_required', 'AB-B5 REJECT: a human owner with a stale proof cannot un-archive');
|
|
582
|
+
select is(pg_temp.run(pg_temp.su('H', 301), pg_temp.q('AR.B', 'true')), 'MBS01 step_up_required', 'AB-B5 REJECT: a no-op call is gated too');
|
|
583
|
+
select is(pg_temp.status('AR.B'), 'archived', 'AB-B5 state: still archived');
|
|
584
|
+
select is(pg_temp.run(pg_temp.c(w), pg_temp.q('AR.B', 'false')), '42501 only a board owner may archive or un-archive a board',
|
|
585
|
+
'AB-B2 REJECT: ' || w || ' may not un-archive')
|
|
586
|
+
from unnest(array['A', 'M', 'Z', 'svc']) w;
|
|
587
|
+
select is(pg_temp.run(pg_temp.c('RO'), pg_temp.q('AR.B', 'false')), '42501 fleet_revoked: set_board_archived is not permitted for a fleet-revoked agent', 'AB-B3 REJECT: a fleet-revoked owner may not un-archive');
|
|
588
|
+
select is(pg_temp.run(pg_temp.su('H', 10), pg_temp.q('AR.B', 'false')), 'OK', 'AB-B5 ALLOW: a human owner with a fresh proof un-archives');
|
|
589
|
+
select is(pg_temp.status('AR.B'), 'active', 'AB-B5 state: active again');
|
|
590
|
+
-- The agent owner is exempt from step-up; the returned row; idempotence.
|
|
591
|
+
select is(pg_temp.probe(pg_temp.c('O'), pg_temp.q('AR.B', 'true'), $$select status || '/' || (updated_at = now())::text from agent_board.boards where id = '{AR.B}'$$),
|
|
592
|
+
'OK:archived/true', 'AB-B6 ALLOW: an agent owner archives; updated_at moves');
|
|
593
|
+
select is(pg_temp.run(pg_temp.c('svc'), $$update agent_board.boards set updated_at = '2026-01-01' where id = '{AR.B}'$$), 'OK', 'AB-B6 fixture: an active board''s row is editable');
|
|
594
|
+
select is(pg_temp.probe(pg_temp.c('O'), pg_temp.q('AR.B', 'false'), $$select status || '/' || updated_at::date::text from agent_board.boards where id = '{AR.B}'$$),
|
|
595
|
+
'OK:active/2026-01-01', 'AB-B6 idempotent: un-archiving an active board writes nothing');
|
|
596
|
+
select is(pg_temp.run(pg_temp.c('O'), pg_temp.q('AR.B', 'true')), 'OK', 'AB-B6 ALLOW: O archives AR (kept for the rest of the file)');
|
|
597
|
+
create temp table _ar_at as select updated_at from agent_board.boards where id = pg_temp.u('AR.B');
|
|
598
|
+
create temp table _ret as select null::uuid as board_id, null::boolean as archived, null::timestamptz as updated_at where false;
|
|
599
|
+
select is(pg_temp.run(pg_temp.c('O'), 'insert into _ret select * from agent_board.set_board_archived(''{AR.B}'', true)'), 'OK', 'AB-B6 ALLOW: archiving an archived board succeeds'); -- pgtap-allow-raise-checked: the call runs inside pg_temp.run/probe, which catch every error
|
|
600
|
+
select is((select board_id::text || '/' || archived::text || '/' || (updated_at = (select updated_at from _ar_at))::text from _ret),
|
|
601
|
+
pg_temp.v('AR.B') || '/true/true', 'AB-B6 idempotent: it returns the unchanged row');
|
|
602
|
+
select is(
|
|
603
|
+
(select memberships || '|' || rows || '|' || messages from _before),
|
|
604
|
+
(select (select count(*) from agent_board.board_memberships where board_id = pg_temp.u('AR.B')) || '|'
|
|
605
|
+
|| (select string_agg(agent_id::text || role || membership_state, ',' order by agent_id) from agent_board.board_memberships where board_id = pg_temp.u('AR.B')) || '|'
|
|
606
|
+
|| (select count(*) from agent_board.messages where thread_id = pg_temp.u('AR.T'))),
|
|
607
|
+
'AB-B7: archiving leaves memberships, roles and messages untouched');
|
|
608
|
+
|
|
609
|
+
-- ===========================================================================
|
|
610
|
+
-- C. create_board: the slug collision never un-archives
|
|
611
|
+
-- ===========================================================================
|
|
612
|
+
select is(pg_temp.pair('O', $$select * from agent_board.create_board('{O}', '{SLUG}', 'renamed')$$,
|
|
613
|
+
$$select name || '/' || status from agent_board.boards where id = '{B}'$$),
|
|
614
|
+
'OK:renamed/active / MBA01', 'AB-C10: the owner repeating a slug renames an active board and is refused on an archived one');
|
|
615
|
+
select is(pg_temp.pair('Z', $$select * from agent_board.create_board('{Z}', '{SLUG}', 'renamed')$$), '42501 / 42501',
|
|
616
|
+
'AB-C10: a non-owner gets 42501 on both (no archived oracle)');
|
|
617
|
+
select is(pg_temp.probe(pg_temp.c('O'), $$select * from agent_board.create_board('{O}', 'ab918-fresh', 'fresh')$$,
|
|
618
|
+
$$select status || '/' || (select count(*) from agent_board.board_memberships m where m.board_id = b.id) from agent_board.boards b where slug = 'ab918-fresh'$$),
|
|
619
|
+
'OK:active/1', 'AB-C10 ALLOW: a fresh slug still creates a board with its owner seat');
|
|
620
|
+
select is((select name || '/' || status from agent_board.boards where id = pg_temp.u('AR.B')), 'AB918 AR/archived', 'AB-C10 state: AR is untouched');
|
|
621
|
+
|
|
622
|
+
-- ===========================================================================
|
|
623
|
+
-- D. REFUSE: allowed on the active twin, MBA01 on the archived board
|
|
624
|
+
-- ===========================================================================
|
|
625
|
+
create temp table _d(n int generated always as identity, label text, who text, q text);
|
|
626
|
+
insert into _d(label, who, q) values
|
|
627
|
+
('post_board_message (uuid) [_insert_thread_message, _next_thread_message_sequence, _upsert_delivery_recipient, _upsert_inbox_item, _queue_board_post_callbacks]', 'M', $$select * from agent_board.post_board_message('{T}', '{M}', '{B}', 's', 'x')$$),
|
|
628
|
+
('post_board_message with a key [_record_send_outcome]', 'M', $$select * from agent_board.post_board_message('{T}', '{M}', '{B}', 's', 'x', p_idempotency_key => 'ab918-k')$$),
|
|
629
|
+
('post_board_message replay of a key used before the archive', 'O', $$select * from agent_board.post_board_message('{T}', '{O}', '{B}', 's', 'hello', p_idempotency_key => 'ab918-post')$$),
|
|
630
|
+
('post_board_message into an unassociated thread [_associate_empty_thread]', 'M', $$select * from agent_board.post_board_message('{TE}', '{M}', '{B}', 's', 'x')$$),
|
|
631
|
+
('_associate_empty_thread', 'svc', $$select agent_board._associate_empty_thread('{TE}', '{B}')$$),
|
|
632
|
+
('moving a thread OFF the board', 'svc', $$update agent_board.threads set board_id = null where id = '{T}'$$),
|
|
633
|
+
('a direct service thread insert on the board', 'svc', $$insert into agent_board.threads(thread_type, created_by_agent_id, subject, board_id) values ('coordination', '{M}', 'x', '{B}')$$),
|
|
634
|
+
('post_message', 'M', $$select * from agent_board.post_message('{T}', '{M}', 'x')$$),
|
|
635
|
+
('reply', 'M', $$select * from agent_board.post_message('{T}', '{M}', 'x', p_reply_to_message_id => '{MSG}')$$),
|
|
636
|
+
('send_direct_message in a board thread', 'M', $$select * from agent_board.send_direct_message('{T}', '{M}', '{O}'::uuid, 's', 'x')$$),
|
|
637
|
+
('send_multicast_message in a board thread', 'M', $$select * from agent_board.send_multicast_message('{T}', '{M}', array['{O}', '{N}']::uuid[], 's', 'x')$$),
|
|
638
|
+
('a service_role post', 'svc', $$select * from agent_board.post_board_message('{T}', '{M}', '{B}', 's', 'x')$$),
|
|
639
|
+
('signed_post_board_message', 'svc', $$select * from agent_board.signed_post_board_message('{"p_thread_id":"{T}","p_board_id":"{B}","p_subject":"s","p_body":"x"}', '{GW}')$$),
|
|
640
|
+
('signed_send_direct_message', 'svc', $$select * from agent_board.signed_send_direct_message('{"p_thread_id":"{T}","p_recipient_agent_id":"{M}","p_subject":"s","p_body":"x"}', '{GW}')$$),
|
|
641
|
+
('signed_send_multicast_message', 'svc', $$select * from agent_board.signed_send_multicast_message('{"p_thread_id":"{T}","p_recipient_agent_ids":["{M}","{N}"],"p_subject":"s","p_body":"x"}', '{GW}')$$),
|
|
642
|
+
('signed_append_task_event', 'svc', $$select * from agent_board.signed_append_task_event('{"p_task_id":"{TASK}","p_event_type":"commented"}', '{GW}')$$),
|
|
643
|
+
('signed_create_tasking_delivery', 'svc', $$select * from agent_board.signed_create_tasking_delivery('{"p_thread_id":"{T}","p_title":"t","p_recipient_agent_ids":["{M}"]}', '{GW}')$$),
|
|
644
|
+
('signed_grant_board_role', 'svc', $$select * from agent_board.signed_grant_board_role('{"p_board_id":"{B}","p_agent_id":"{M}","p_grantee_role":"admin"}', '{GWV}')$$),
|
|
645
|
+
('signed_set_board_authority_ceiling', 'svc', $$select * from agent_board.signed_set_board_authority_ceiling('{"p_board_id":"{B}","p_max_grantable_role":"member"}', '{GWV}')$$),
|
|
646
|
+
('a delivery row through its source message alone [_upsert_delivery_recipient]', 'svc', $$select agent_board._upsert_delivery_recipient('direct', '{Z}', 'message', '{MSG}')$$),
|
|
647
|
+
('a delivery row through its source task alone', 'svc', $$select agent_board._upsert_delivery_recipient('direct', '{Z}', 'task', null, '{TASK}')$$),
|
|
648
|
+
-- The row writes behind the RPCs, each alone: a missing guard on one of these tables is otherwise
|
|
649
|
+
-- masked by the guard on the next table the same RPC writes.
|
|
650
|
+
('a direct service message insert', 'svc', $$insert into agent_board.messages(thread_id, author_agent_id, message_sequence, body) values ('{T}', '{M}', 999, 'x')$$),
|
|
651
|
+
('a direct service task insert', 'svc', $$insert into agent_board.tasks(thread_id, created_by_agent_id, title) values ('{T}', '{M}', 'x')$$),
|
|
652
|
+
('a direct service task update', 'svc', $$update agent_board.tasks set status = 'in_progress' where id = '{TASK}'$$),
|
|
653
|
+
('a direct service task event', 'svc', $$insert into agent_board.task_events(task_id, thread_id, actor_agent_id, event_sequence, event_type, origin_posture) values ('{TASK}', '{T}', '{M}', 999, 'commented', 'unattested:direct-rpc')$$),
|
|
654
|
+
('moving a task OFF the board''s thread', 'svc', $$update agent_board.tasks set thread_id = '{TE}' where id = '{TASK}'$$),
|
|
655
|
+
('create_task', 'M', $$select * from agent_board.create_task('{T}', '{M}', 'x')$$),
|
|
656
|
+
('create_tasking_delivery', 'O', $$select * from agent_board.create_tasking_delivery('{T}', '{O}', 'x', p_recipient_agent_ids => array['{M}']::uuid[])$$),
|
|
657
|
+
('append_task_event [_append_task_event]', 'M', $$select * from agent_board.append_task_event('{TASK}', '{M}', 'commented')$$),
|
|
658
|
+
('delegate_task', 'M', $$select * from agent_board.delegate_task('{TASK}', '{M}', 'x')$$),
|
|
659
|
+
('a direct service delegation insert', 'svc', $$insert into agent_board.delegations(parent_task_id, child_task_id, delegated_by_agent_id) values ('{TASK}', '{TASK}', '{M}')$$),
|
|
660
|
+
('add_artifact on the thread', 'M', $$select * from agent_board.add_artifact('{M}', 'https://x', p_thread_id => '{T}')$$),
|
|
661
|
+
('add_artifact on the message', 'M', $$select * from agent_board.add_artifact('{M}', 'https://x', p_message_id => '{MSG}')$$),
|
|
662
|
+
('add_artifact on the task event', 'M', $$select * from agent_board.add_artifact('{M}', 'https://x', p_task_event_id => '{TEV}')$$),
|
|
663
|
+
('a direct service artifact on the task alone', 'svc', $$insert into agent_board.artifacts(task_id, created_by_agent_id, uri) values ('{TASK}', '{M}', 'https://x')$$),
|
|
664
|
+
('raise_conflict', 'M', $$select * from agent_board.raise_conflict('{T}', '{M}', 'x')$$),
|
|
665
|
+
('resolve_conflict', 'M', $$select * from agent_board.resolve_conflict('{CF}', '{M}')$$),
|
|
666
|
+
('raise_escalation', 'M', $$select * from agent_board.raise_escalation('{T}', '{M}', 'x')$$),
|
|
667
|
+
('resolve_escalation', 'M', $$select * from agent_board.resolve_escalation('{ES}', '{M}')$$),
|
|
668
|
+
('acquire_claim on the thread', 'M', $$select * from agent_board.acquire_claim('{M}', 'custom', 'ab918-new', now() + interval '10 minutes', p_thread_id => '{T}')$$),
|
|
669
|
+
('acquire_claim on the task', 'M', $$select * from agent_board.acquire_claim('{M}', 'custom', 'ab918-new', now() + interval '10 minutes', p_task_id => '{TASK}')$$),
|
|
670
|
+
('acquire_claim of the task RESOURCE, with no thread', 'M', $$select * from agent_board.acquire_claim('{M}', 'task', '{TASK}', now() + interval '10 minutes')$$),
|
|
671
|
+
('renew_claim', 'O', $$select * from agent_board.renew_claim('{LEASE}', now() + interval '20 minutes')$$),
|
|
672
|
+
('create_invite_link', 'O', $$select * from agent_board.create_invite_link('{B}', 'member')$$),
|
|
673
|
+
('consuming a use of an invite', 'svcrole', $$update agent_board.board_invite_tokens set uses_count = uses_count + 1 where code = '{CODE}'$$),
|
|
674
|
+
('grant_board_role (raise)', 'O', $$select * from agent_board.grant_board_role('{B}', '{M}', 'admin')$$),
|
|
675
|
+
('grant_board_role (demote)', 'O', $$select * from agent_board.grant_board_role('{B}', '{A}', 'member')$$),
|
|
676
|
+
-- R1: every route a role reduction can take, on every kind of principal.
|
|
677
|
+
('signed_grant_board_role demoting an ordinary admin (legacy identity)', 'svc', $$select * from agent_board.signed_grant_board_role('{"p_board_id":"{B}","p_agent_id":"{A}","p_grantee_role":"member"}', '{GWV}')$$),
|
|
678
|
+
('signed_grant_board_role demoting a HUMAN admin', 'svc', $$select * from agent_board.signed_grant_board_role('{"p_board_id":"{B}","p_agent_id":"{HA}","p_grantee_role":"member"}', '{GWV}')$$),
|
|
679
|
+
('signed_grant_board_role demoting an ordinary member to observer', 'svc', $$select * from agent_board.signed_grant_board_role('{"p_board_id":"{B}","p_agent_id":"{M}","p_grantee_role":"observer"}', '{GWV}')$$),
|
|
680
|
+
('signed_grant_board_role demoting a SESSION identity', 'svc', $$select * from agent_board.signed_grant_board_role('{"p_board_id":"{B}","p_agent_id":"{S}","p_grantee_role":"member"}', '{GWV}')$$),
|
|
681
|
+
('a service_role grant_board_role demoting a SESSION identity', 'svc', $$select * from agent_board.grant_board_role('{B}', '{S}', 'member', '{O}')$$),
|
|
682
|
+
('a service_role grant_board_role demoting an ordinary admin', 'svc', $$select * from agent_board.grant_board_role('{B}', '{A}', 'member', '{O}')$$),
|
|
683
|
+
('grant_board_role (demote a session identity through the API)', 'O', $$select * from agent_board.grant_board_role('{B}', '{S}', 'member')$$),
|
|
684
|
+
('set_board_member_label', 'O', $$select agent_board.set_board_member_label('{B}', '{M}', 'x')$$),
|
|
685
|
+
('set_board_role_gate', 'O', $$select * from agent_board.set_board_role_gate('{B}', true)$$),
|
|
686
|
+
('set_board_claim_policy', 'O', $$select * from agent_board.set_board_claim_policy('{B}', 'advisory')$$),
|
|
687
|
+
('set_board_authority_ceiling', 'O', $$select * from agent_board.set_board_authority_ceiling('{B}', 'member')$$),
|
|
688
|
+
('set_fleet_receive_policy (insert)', 'M', $$select * from agent_board.set_fleet_receive_policy('{M}', 'ab918-m', p_board_id => '{B}')$$),
|
|
689
|
+
('set_fleet_receive_policy (update)', 'O', $$select * from agent_board.set_fleet_receive_policy('{O}', 'ab918', 'allow', p_board_id => '{B}')$$),
|
|
690
|
+
('subscribe_callback_endpoint (insert)', 'M', $$select * from agent_board.subscribe_callback_endpoint('{EP2}', '{M}', 'board', 'board.post.delivered', '{B}')$$),
|
|
691
|
+
('subscribe_callback_endpoint (re-enable)', 'M', $$select * from agent_board.unsubscribe_callback_endpoint('{EP}', '{M}', 'board', 'board.post.delivered', '{B}'); select * from agent_board.subscribe_callback_endpoint('{EP}', '{M}', 'board', 'board.post.delivered', '{B}')$$),
|
|
692
|
+
('update_board_membership: a self joined -> subscribed toggle', 'M', $$select * from agent_board.update_board_membership('{B}', '{M}', 'subscribed')$$),
|
|
693
|
+
('_upsert_board_membership_state: a new seat', 'svc', $$select agent_board._upsert_board_membership_state('{B}', '{Z}', 'joined')$$),
|
|
694
|
+
('_upsert_board_membership_state: an offer', 'svc', $$select agent_board._upsert_board_membership_state('{B}', '{Z}', 'invited')$$),
|
|
695
|
+
('update_board_membership by the operator: re-admission', 'svc', $$select * from agent_board.update_board_membership('{B}', '{P1}', 'joined')$$),
|
|
696
|
+
('a direct service thread_memberships insert', 'svcrole', $$insert into agent_board.thread_memberships(thread_id, agent_id) values ('{T}', '{Z}')$$),
|
|
697
|
+
-- R2: only a TRANSITION into a departed state is a departure.
|
|
698
|
+
('set_board_member_label on a DEPARTED member', 'O', $$select agent_board.set_board_member_label('{B}', '{D}', 'x')$$),
|
|
699
|
+
('_upsert_board_membership_state INSERTing a departed row', 'svc', $$select agent_board._upsert_board_membership_state('{B}', '{Z}', 'removed')$$),
|
|
700
|
+
('update_board_membership: an owner moving a departed member left -> removed', 'O', $$select * from agent_board.update_board_membership('{B}', '{D}', 'removed')$$),
|
|
701
|
+
('a departure that also moves the role', 'svc', $$update agent_board.board_memberships set membership_state = 'left', left_at = now(), role = 'admin' where board_id = '{B}' and agent_id = '{M}'$$),
|
|
702
|
+
('a retention mark that also writes another metadata key', 'svc', $$update agent_board.board_memberships set metadata = '{"ops_retained_at":"x","label":"y"}' where board_id = '{B}' and agent_id = '{D}'$$),
|
|
703
|
+
('a direct insert of a released claim', 'svc', $$insert into agent_board.claims(thread_id, agent_id, resource_kind, resource_key, lease_expires_at, status, released_at) values ('{T}', '{M}', 'custom', 'ab918-z', now(), 'released', now())$$),
|
|
704
|
+
('editing a released claim in place', 'svc', $$update agent_board.claims set metadata = '{"x":1}' where lease_token = '{DONE}'$$),
|
|
705
|
+
('releasing a claim while moving it to another thread', 'svc', $$update agent_board.claims set status = 'released', released_at = now(), thread_id = '{TE}' where lease_token = '{LEASE}'$$),
|
|
706
|
+
('a retention mark on array metadata that also edits it', 'svc', $$update agent_board.board_memberships set metadata = '["edited", {"ops_retained_at":"x","ops_retention_run_id":"y","ops_retention_reason":"z"}]' where board_id = '{B}' and agent_id = '{DA}'$$),
|
|
707
|
+
('appending something else to array metadata', 'svc', $$update agent_board.board_memberships set metadata = metadata || '{"label":"y"}' where board_id = '{B}' and agent_id = '{DA}'$$),
|
|
708
|
+
('appending the retention keys plus another to array metadata', 'svc', $$update agent_board.board_memberships set metadata = metadata || '{"ops_retained_at":"x","ops_retention_run_id":"y","ops_retention_reason":"z","label":"y"}' where board_id = '{B}' and agent_id = '{DA}'$$),
|
|
709
|
+
-- The mark is ALL THREE keys: an appended object holding fewer of them, or none, is not the sweep's.
|
|
710
|
+
('appending a retention mark without ops_retained_at to array metadata', 'svc', $$update agent_board.board_memberships set metadata = metadata || '{"ops_retention_run_id":"x","ops_retention_reason":"x"}' where board_id = '{B}' and agent_id = '{DA}'$$),
|
|
711
|
+
('appending a retention mark without ops_retention_run_id to array metadata', 'svc', $$update agent_board.board_memberships set metadata = metadata || '{"ops_retained_at":"x","ops_retention_reason":"x"}' where board_id = '{B}' and agent_id = '{DA}'$$),
|
|
712
|
+
('appending a retention mark without ops_retention_reason to array metadata', 'svc', $$update agent_board.board_memberships set metadata = metadata || '{"ops_retained_at":"x","ops_retention_run_id":"x"}' where board_id = '{B}' and agent_id = '{DA}'$$),
|
|
713
|
+
('appending an empty object to array metadata', 'svc', $$update agent_board.board_memberships set metadata = metadata || '{}' where board_id = '{B}' and agent_id = '{DA}'$$),
|
|
714
|
+
('appending a retention mark without ops_retained_at to scalar metadata', 'svc', $$update agent_board.board_memberships set metadata = metadata || '{"ops_retention_run_id":"x","ops_retention_reason":"x"}' where board_id = '{B}' and agent_id = '{DS}'$$),
|
|
715
|
+
('appending a retention mark without ops_retention_run_id to scalar metadata', 'svc', $$update agent_board.board_memberships set metadata = metadata || '{"ops_retained_at":"x","ops_retention_reason":"x"}' where board_id = '{B}' and agent_id = '{DS}'$$),
|
|
716
|
+
('appending a retention mark without ops_retention_reason to scalar metadata', 'svc', $$update agent_board.board_memberships set metadata = metadata || '{"ops_retained_at":"x","ops_retention_run_id":"x"}' where board_id = '{B}' and agent_id = '{DS}'$$),
|
|
717
|
+
('appending an empty object to scalar metadata', 'svc', $$update agent_board.board_memberships set metadata = metadata || '{}' where board_id = '{B}' and agent_id = '{DS}'$$),
|
|
718
|
+
('replacing scalar metadata', 'svc', $$update agent_board.board_memberships set metadata = '"edited"' where board_id = '{B}' and agent_id = '{DS}'$$),
|
|
719
|
+
('releasing a task claim while moving its task key', 'svc', $$update agent_board.claims set status = 'released', released_at = now(), resource_key = '{M}' where lease_token = '{TLEASE}'$$),
|
|
720
|
+
('releasing a custom claim while moving its key', 'svc', $$update agent_board.claims set status = 'released', released_at = now(), resource_key = 'ab918-moved' where lease_token = '{LEASE}'$$),
|
|
721
|
+
('a direct insert of a disabled callback subscription', 'svc', $$insert into agent_board.callback_subscriptions(endpoint_id, agent_id, subscription_scope, event_category, board_id, board_membership_id, subscription_status, disabled_at) select '{EP2}', '{M}', 'board', 'board.post.delivered', '{B}', bm.id, 'disabled', now() from agent_board.board_memberships bm where bm.board_id = '{B}' and bm.agent_id = '{M}'$$),
|
|
722
|
+
('editing a disabled callback subscription in place', 'svc', $$update agent_board.callback_subscriptions set metadata = '{"x":1}' where id = '{DSUB}'$$),
|
|
723
|
+
-- R5: service_role's own UPDATE on the relations it can write.
|
|
724
|
+
('service_role re-anchoring an invite onto the board', 'svcrole', $$update agent_board.board_invite_tokens set board_id = '{B}' where code = '{XCODE}'$$),
|
|
725
|
+
('service_role raising an invite''s preset_role', 'svcrole', $$update agent_board.board_invite_tokens set preset_role = 'admin' where code = '{CODE}'$$),
|
|
726
|
+
('service_role raising an invite''s max_uses', 'svcrole', $$update agent_board.board_invite_tokens set max_uses = 99 where code = '{CODE}'$$),
|
|
727
|
+
('service_role extending an invite', 'svcrole', $$update agent_board.board_invite_tokens set expires_at = now() + interval '30 days' where code = '{CODE}'$$),
|
|
728
|
+
('service_role un-revoking an invite', 'svcrole', $$update agent_board.board_invite_tokens set revoked_at = null where code = '{RCODE}'$$),
|
|
729
|
+
('a revocation that also extends the invite', 'svcrole', $$update agent_board.board_invite_tokens set revoked_at = now(), expires_at = now() + interval '30 days' where code = '{CODE}'$$),
|
|
730
|
+
('an invite revocation that also rewrites created_at', 'svcrole', $$update agent_board.board_invite_tokens set revoked_at = now(), revoked_by_agent_id = '{O}', created_at = '2020-01-01' where code = '{CODE}'$$),
|
|
731
|
+
('a thread-access revocation that also rewrites created_at', 'svcrole', $$update agent_board.thread_memberships set revoked_at = now(), created_at = '2020-01-01' where id = '{TM}'$$),
|
|
732
|
+
('service_role re-anchoring thread access', 'svcrole', $$update agent_board.thread_memberships set agent_id = '{Z}' where id = '{TM}'$$),
|
|
733
|
+
('service_role moving thread access onto the board''s thread', 'svcrole', $$update agent_board.thread_memberships set thread_id = '{T}' where id = '{XTM}'$$),
|
|
734
|
+
('service_role extending thread access', 'svcrole', $$update agent_board.thread_memberships set expires_at = now() + interval '1 year' where id = '{TM}'$$),
|
|
735
|
+
('service_role un-revoking thread access', 'svcrole', $$update agent_board.thread_memberships set revoked_at = null where id = '{RTM}'$$),
|
|
736
|
+
('service_role inserting a ceiling', 'svcrole', $$insert into agent_board.board_authority_ceilings(board_id, max_grantable_role) values ('{B}', 'member')$$),
|
|
737
|
+
('service_role editing a receive policy', 'svcrole', $$update agent_board.fleet_receive_policies set default_action = 'deny' where board_id = '{B}' and policy_name = 'ab918'$$),
|
|
738
|
+
('a direct service boards edit', 'svc', $$update agent_board.boards set description = 'x' where id = '{B}'$$),
|
|
739
|
+
('a direct service invite block', 'svcrole', $$insert into agent_board.board_invite_blocks(board_id, target_agent_id, inviter_agent_id) values ('{B}', '{N}', '{A}')$$);
|
|
740
|
+
select pg_temp.put('GW', jsonb_build_object('agent_id', pg_temp.u('O'), 'verification_status', 'warn',
|
|
741
|
+
'payload_digest', 'sha256:' || repeat('7', 64), 'enforcement_mode', 'warn')::text);
|
|
742
|
+
select pg_temp.put('GWF', jsonb_build_object('agent_id', pg_temp.u('FA'), 'verification_status', 'verified',
|
|
743
|
+
'payload_digest', 'sha256:' || repeat('8', 64), 'enforcement_mode', 'warn')::text);
|
|
744
|
+
select pg_temp.put('GWV', jsonb_build_object('agent_id', pg_temp.u('O'), 'signing_key_id', '91800002-0000-4000-8000-000000000001', 'key_id', 'primary',
|
|
745
|
+
'key_version', 1, 'algorithm', 'Ed25519', 'verification_status', 'verified', 'payload_digest', 'sha256:' || repeat('a', 64),
|
|
746
|
+
'signature_digest', 'sha256:' || repeat('b', 64), 'canonicalization_version', 'agent-provenance-jcs.v1',
|
|
747
|
+
'enforcement_mode', 'require_for_agent_writes', 'redacted', true)::text);
|
|
748
|
+
select is(pg_temp.pair(d.who, d.q), 'OK / MBA01', 'AB-D REFUSE ' || d.label) from _d d order by d.n;
|
|
749
|
+
-- Session identities: minting or readmitting into a room on an archived board, through the real RPCs.
|
|
750
|
+
select is(pg_temp.pair('svc', format($f$select * from agent_board.mint_delegated_child('{O}', 'ab918-sid-mint', '["read"]', %L, interval '8 hours', false, 'claude', 'ab918-mint', null,
|
|
751
|
+
jsonb_build_array(jsonb_build_object('board_id', '{B}', 'role', 'member')), '{"resolution":"resolved","risky_digest":"approved"}')$f$, public.test_pubkey('ab918-mint'))),
|
|
752
|
+
'OK / MBA01', 'AB-D REFUSE mint_delegated_child with a room on the board');
|
|
753
|
+
select is(pg_temp.pair('H', format($f$select * from agent_board.readmit_session_identity('{RX}', 'ab918-readmit', %L, '["read"]',
|
|
754
|
+
jsonb_build_array(jsonb_build_object('board_id', '{B}', 'role', 'member')), interval '1 hour')$f$, public.test_pubkey('ab918-readmit'))),
|
|
755
|
+
'OK / MBA01', 'AB-D REFUSE readmit_session_identity with a room on the board (R10)');
|
|
756
|
+
-- The guard passes a row through unchanged: what is written on the active board is what was sent.
|
|
757
|
+
select is(pg_temp.probe(pg_temp.c('svc'), $$insert into agent_board.board_memberships(board_id, agent_id, role, membership_state, created_by_agent_id, metadata) values ('{AC.B}', '{Z}', 'admin', 'subscribed', '{O}', '{"k":1}')$$,
|
|
758
|
+
$$select role || '/' || membership_state || '/' || metadata::text from agent_board.board_memberships where board_id = '{AC.B}' and agent_id = '{Z}'$$),
|
|
759
|
+
'OK:admin/subscribed/{"k": 1}', 'AB-D the guard does not rewrite an inserted row');
|
|
760
|
+
select is(pg_temp.probe(pg_temp.c('svc'), $$update agent_board.threads set board_id = '{AC.B}', subject = 'kept' where id = '{AC.TE}'$$,
|
|
761
|
+
$$select board_id::text || '/' || subject from agent_board.threads where id = '{AC.TE}'$$),
|
|
762
|
+
'OK:91810000-0000-4000-8000-000000000001/kept', 'AB-D the guard does not rewrite an updated row');
|
|
763
|
+
|
|
764
|
+
-- ===========================================================================
|
|
765
|
+
-- D2. REFUSE-OWN: refused a non-active board before #918, unchanged, pinned
|
|
766
|
+
-- ===========================================================================
|
|
767
|
+
create temp table _d2(n int generated always as identity, label text, who text, q text, want text);
|
|
768
|
+
insert into _d2(label, who, q, want) values
|
|
769
|
+
('post_board_message by slug', 'M', $$select * from agent_board.post_board_message('{T}', '{M}', '{SLUG}'::text, 'addressing_v1', 's', 'x', 'comment', 'medium', null, '{}'::jsonb)$$, 'OK / P0002'),
|
|
770
|
+
('join_board', 'Z', $$select * from agent_board.join_board('{B}', '{Z}')$$, 'OK / P0002'),
|
|
771
|
+
('request_join_board', 'Z', $$select * from agent_board.request_join_board('{B}', '{Z}')$$, null),
|
|
772
|
+
('resolve_board_request', 'O', $$select * from agent_board.resolve_board_request('{B}', '{P1}', 'removed', '{O}')$$, 'OK / P0002'),
|
|
773
|
+
('invite_board_member', 'O', $$select * from agent_board.invite_board_member('{B}', '{Z}', '{O}')$$, 'OK / P0002'),
|
|
774
|
+
('block_board_inviter', 'M', $$select * from agent_board.block_board_inviter('{B}', '{A}')$$, 'OK / P0002'),
|
|
775
|
+
-- `left` set by another, non-principal actor is 42501 on ANY board (pre-#918, unchanged).
|
|
776
|
+
('update_board_membership: another member to left', 'O', $$select * from agent_board.update_board_membership('{B}', '{M}', 'left')$$, '42501 / 42501'),
|
|
777
|
+
('update_board_membership: another member to subscribed', 'O', $$select * from agent_board.update_board_membership('{B}', '{M}', 'subscribed')$$, 'OK / P0002');
|
|
778
|
+
select is(pg_temp.pair(d.who, d.q), d.want, 'AB-D2 REFUSE-OWN ' || d.label) from _d2 d where d.want is not null order by d.n;
|
|
779
|
+
select matches(pg_temp.pair('Z', (select q from _d2 where label = 'request_join_board')), '^\S+ / (P0002|22023)$', 'AB-D2 REFUSE-OWN request_join_board');
|
|
780
|
+
select is(pg_temp.pair('O', $$select * from agent_board.create_fleet_onboarding_invite('{B}', '91800003-0000-4000-8000-000000000002', 'codex', 'ab918', 'message-board', 'sha256:ab918-repo', 'worker', 'phase_worker', 'ab918-fleet', 1, now() + interval '1 hour', '{O}')$$),
|
|
781
|
+
'OK / 42501', 'AB-D2 REFUSE-OWN create_fleet_onboarding_invite');
|
|
782
|
+
|
|
783
|
+
-- ===========================================================================
|
|
784
|
+
-- E. EXEMPT: stays allowed on the archived board, positively
|
|
785
|
+
-- ===========================================================================
|
|
786
|
+
-- Reading, as the authenticated role under RLS.
|
|
787
|
+
create function pg_temp.reads(p_who text) returns text language plpgsql as $$
|
|
788
|
+
declare r text;
|
|
789
|
+
begin
|
|
790
|
+
begin
|
|
791
|
+
perform pg_temp.claims(pg_temp.c(p_who));
|
|
792
|
+
set local role authenticated;
|
|
793
|
+
select (select count(*) from agent_board.boards where id = '91810000-0000-4000-8000-000000000002')
|
|
794
|
+
|| '/' || (select count(*) from agent_board.v_board_memberships where board_id = '91810000-0000-4000-8000-000000000002' and membership_state = 'joined')
|
|
795
|
+
|| '/' || (select count(*) from agent_board.v_board_feed where board_id = '91810000-0000-4000-8000-000000000002')
|
|
796
|
+
into r;
|
|
797
|
+
raise exception using errcode = 'ZZ999', message = r;
|
|
798
|
+
exception when sqlstate 'ZZ999' then return sqlerrm; when others then return sqlstate || ' ' || sqlerrm;
|
|
799
|
+
end;
|
|
800
|
+
end $$;
|
|
801
|
+
grant agent_board_delegate, anon, authenticated, service_role to current_user;
|
|
802
|
+
select matches(pg_temp.reads('M'), '^1/[1-9][0-9]*/[1-9][0-9]*$', 'AB-E reading: a member still reads the board row, its roster and its feed under RLS');
|
|
803
|
+
create temp table _e(n int generated always as identity, label text, who text, q text, chk text, want text);
|
|
804
|
+
insert into _e(label, who, q, chk, want) values
|
|
805
|
+
('self-leave [leave_board, _upsert_board_membership_state -> left, _emit_membership_event]', 'M', $$select * from agent_board.leave_board('{B}', '{M}')$$,
|
|
806
|
+
$$select membership_state || '/' || (select count(*) from agent_board.board_membership_events e where e.board_id = '{B}' and e.agent_id = '{M}' and e.result_state = 'left') from agent_board.board_memberships where board_id = '{B}' and agent_id = '{M}'$$, 'left/1'),
|
|
807
|
+
('an invitee withdraws', 'P2', $$select * from agent_board.leave_board('{B}', '{P2}')$$, $$select membership_state from agent_board.board_memberships where board_id = '{B}' and agent_id = '{P2}'$$, 'left'),
|
|
808
|
+
('the OWNER removes a member', 'O', $$select * from agent_board.update_board_membership('{B}', '{M}', 'removed')$$, $$select membership_state from agent_board.board_memberships where board_id = '{B}' and agent_id = '{M}'$$, 'removed'),
|
|
809
|
+
('an ADMIN removes a member', 'A', $$select * from agent_board.update_board_membership('{B}', '{M}', 'removed')$$, $$select membership_state from agent_board.board_memberships where board_id = '{B}' and agent_id = '{M}'$$, 'removed'),
|
|
810
|
+
('the operator removes a member', 'svc', $$select * from agent_board.update_board_membership('{B}', '{M}', 'removed')$$, $$select membership_state from agent_board.board_memberships where board_id = '{B}' and agent_id = '{M}'$$, 'removed'),
|
|
811
|
+
('revoke_invite_link', 'O', $$select * from agent_board.revoke_invite_link('{CODE}')$$, $$select (revoked_at is not null)::text from agent_board.board_invite_tokens where code = '{CODE}'$$, 'true'),
|
|
812
|
+
('release_claim', 'O', $$select * from agent_board.release_claim('{LEASE}')$$, $$select status from agent_board.claims where lease_token = '{LEASE}'$$, 'released'),
|
|
813
|
+
('a claim expires', 'svc', $$update agent_board.claims set status = 'expired' where lease_token = '{LEASE}'$$, $$select status from agent_board.claims where lease_token = '{LEASE}'$$, 'expired'),
|
|
814
|
+
('unblock_board_inviter', 'O', $$select agent_board.unblock_board_inviter('{B}', '{A}')$$, $$select count(*)::text from agent_board.board_invite_blocks where board_id = '{B}'$$, '0'),
|
|
815
|
+
('unsubscribe_callback_endpoint', 'M', $$select * from agent_board.unsubscribe_callback_endpoint('{EP}', '{M}', 'board', 'board.post.delivered', '{B}')$$, $$select subscription_status from agent_board.callback_subscriptions where endpoint_id = '{EP}'$$, 'disabled'),
|
|
816
|
+
('disable_callback_endpoint', 'M', $$select * from agent_board.disable_callback_endpoint('{EP}', '{M}')$$, $$select subscription_status from agent_board.callback_subscriptions where endpoint_id = '{EP}'$$, 'disabled'),
|
|
817
|
+
('disable_callback_delivery_endpoint', 'svc', $$select * from agent_board.disable_callback_delivery_endpoint('{EP}', '{OB}')$$, $$select subscription_status from agent_board.callback_subscriptions where endpoint_id = '{EP}'$$, 'disabled'),
|
|
818
|
+
('claim_callback_outbox_events', 'svc', $$select * from agent_board.claim_callback_outbox_events(100)$$, $$select outbox_status from agent_board.callback_outbox_events where id = '{OB}'$$, 'delivering'),
|
|
819
|
+
('record_callback_delivery_success', 'svc', $$select * from agent_board.record_callback_delivery_success('{OB}', '{EP}')$$, $$select outbox_status from agent_board.callback_outbox_events where id = '{OB}'$$, 'delivered'),
|
|
820
|
+
('record_callback_delivery_retry', 'svc', $$select * from agent_board.record_callback_delivery_retry('{OB}', '{EP}', 503, 'x', now() + interval '1 hour')$$, $$select outbox_status from agent_board.callback_outbox_events where id = '{OB}'$$, 'retryable'),
|
|
821
|
+
('record_callback_delivery_terminal_failure', 'svc', $$select * from agent_board.record_callback_delivery_terminal_failure('{OB}', '{EP}', 410, 'x')$$, $$select outbox_status from agent_board.callback_outbox_events where id = '{OB}'$$, 'failed'),
|
|
822
|
+
('update_inbox_item_state [_queue_inbox_callbacks]', 'M', $$select * from agent_board.update_inbox_item_state('{II}', '{M}', 'read')$$, $$select action_state from agent_board.inbox_items where id = '{II}'$$, 'read'),
|
|
823
|
+
('mark_read', 'M', $$select * from agent_board.mark_read('{T}', '{M}', 1)$$, $$select last_read_message_sequence::text from agent_board.read_receipts where thread_id = '{T}' and agent_id = '{M}'$$, '1'),
|
|
824
|
+
('heartbeat with the thread', 'M', $$select * from agent_board.heartbeat('{M}', '{T}', 'ready')$$, $$select thread_id::text from agent_board.presence where agent_id = '{M}'$$, '{T}'),
|
|
825
|
+
('mark_retention_metadata over messages', 'svc', $$select agent_board.mark_retention_metadata('messages', now() + interval '1 day', gen_random_uuid())$$, $$select (metadata ? 'ops_retained_at')::text from agent_board.messages where id = '{MSG}'$$, 'true'),
|
|
826
|
+
('mark_retention_metadata over task_events', 'svc', $$select agent_board.mark_retention_metadata('task_events', now() + interval '1 day', gen_random_uuid())$$, $$select (payload ? 'ops_retained_at')::text from agent_board.task_events where id = '{TEV}'$$, 'true'),
|
|
827
|
+
('mark_retention_metadata over delivery_recipients', 'svc', $$select agent_board.mark_retention_metadata('delivery_recipients', now() + interval '1 day', gen_random_uuid())$$, $$select (metadata ? 'ops_retained_at')::text from agent_board.delivery_recipients where id = '{DR}'$$, 'true'),
|
|
828
|
+
('mark_retention_metadata over departed memberships', 'svc', $$select agent_board.mark_retention_metadata('board_memberships', now(), gen_random_uuid())$$, $$select (metadata ? 'ops_retained_at')::text from agent_board.board_memberships where board_id = '{B}' and agent_id = '{D}'$$, 'true'),
|
|
829
|
+
('mark_retention_metadata with departed ARRAY metadata present', 'svc', $$select agent_board.mark_retention_metadata('board_memberships', now(), gen_random_uuid())$$, $$select (metadata -> 0)::text || '/' || (metadata -> 1 ? 'ops_retained_at')::text || '/' || jsonb_array_length(metadata) from agent_board.board_memberships where board_id = '{B}' and agent_id = '{DA}'$$, '"legacy"/true/2'),
|
|
830
|
+
('mark_retention_metadata with departed SCALAR metadata present', 'svc', $$select agent_board.mark_retention_metadata('board_memberships', now(), gen_random_uuid())$$, $$select (metadata -> 0)::text || '/' || (metadata -> 1 ? 'ops_retained_at')::text || '/' || jsonb_array_length(metadata) from agent_board.board_memberships where board_id = '{B}' and agent_id = '{DS}'$$, '"legacy"/true/2'),
|
|
831
|
+
('release_claim of a task claim', 'O', $$select * from agent_board.release_claim('{TLEASE}')$$, $$select status || '/' || (resource_key = '{TASK2}')::text from agent_board.claims where lease_token = '{TLEASE}'$$, 'released/true'),
|
|
832
|
+
('release_claim of a fleet-backed task claim stored under its alias', 'O', $$select * from agent_board.release_claim('{FLEASE}')$$, $$select status || '/' || (resource_key like 'sha256:ab918-%')::text from agent_board.claims where lease_token = '{FLEASE}'$$, 'released/true'),
|
|
833
|
+
('expiry of a fleet-backed task claim stored under its alias', 'svc', $$update agent_board.claims set status = 'expired' where lease_token = '{FLEASE}'$$, $$select status || '/' || (resource_key like 'repo:sha256:ab918-%')::text from agent_board.claims where lease_token = '{FLEASE}'$$, 'expired/true'),
|
|
834
|
+
('service_role revoking an invite', 'svcrole', $$update agent_board.board_invite_tokens set revoked_at = now(), revoked_by_agent_id = '{O}' where code = '{CODE}'$$, $$select (revoked_at is not null)::text from agent_board.board_invite_tokens where code = '{CODE}'$$, 'true'),
|
|
835
|
+
('service_role revoking thread access', 'svcrole', $$update agent_board.thread_memberships set revoked_at = now() where id = '{TM}'$$, $$select (revoked_at is not null)::text from agent_board.thread_memberships where id = '{TM}'$$, 'true'),
|
|
836
|
+
('_record_send_authz_telemetry', 'svc', $$select agent_board._record_send_authz_telemetry('service_role_bypass', 'unknown', '{M}', '{B}', 'post_board_message', null, null, '{}'::jsonb)$$, $$select (count(*) > 0)::text from agent_board.send_authz_telemetry where board_id = '{B}'$$, 'true'),
|
|
837
|
+
('_record_signed_write_evidence', 'svc', $$select agent_board._record_signed_write_evidence('message', '{MSG}', 'post_board_message', '{}'::jsonb, '{GW}')$$, $$select (count(*) > 0)::text from agent_board.signature_evidence where source_message_id = '{MSG}'$$, 'true'),
|
|
838
|
+
('reserve_signed_write_replay', 'svc', $$select * from agent_board.reserve_signed_write_replay('{O}', '91800002-0000-4000-8000-000000000001', 'post_board_message', 'sha256:x', 'ab918-nonce')$$, $$select count(*)::text from agent_board.signature_replay_state where nonce = 'ab918-nonce'$$, '1'),
|
|
839
|
+
('evaluate_signed_write_fleet_policy for a fleet-bound sender', 'svc', $$select pg_temp.put('FEV', (select allowed::text || '/' || actionable::text from agent_board.evaluate_signed_write_fleet_policy('post_board_message', '{"p_board_id":"{B}"}', '{GWF}')))$$, $$select pg_temp.v('FEV') || '/' || (select count(*) from agent_board.signature_evidence where agent_id = '{FA}' and operation = 'post_board_message')$$, 'true/true/1'),
|
|
840
|
+
('create_thread (board-less)', 'M', $$select * from agent_board.create_thread('{M}', 'ab918 boardless')$$, $$select (board_id is null)::text from agent_board.threads where subject = 'ab918 boardless'$$, 'true'),
|
|
841
|
+
('create_or_find_thread (board-less)', 'M', $$select * from agent_board.create_or_find_thread('{M}', 'ab918 cof', 'ab918-cof')$$, $$select (board_id is null)::text from agent_board.threads where subject = 'ab918 cof'$$, 'true'),
|
|
842
|
+
('a session identity''s role is clamped DOWN by the service (link_session_alias'' write)', 'svc', $$update agent_board.board_memberships set role = 'member' where board_id = '{B}' and agent_id = '{S}'$$, $$select role from agent_board.board_memberships where board_id = '{B}' and agent_id = '{S}'$$, 'member'),
|
|
843
|
+
('link_session_alias'' removal', 'svc', $$select agent_board._upsert_board_membership_state('{B}', '{S}', 'removed')$$, $$select membership_state from agent_board.board_memberships where board_id = '{B}' and agent_id = '{S}'$$, 'removed');
|
|
844
|
+
select is(pg_temp.pair(e.who, e.q, e.chk),
|
|
845
|
+
'OK:' || replace(e.want, '{T}', pg_temp.v('AC.T')) || ' / OK:' || replace(e.want, '{T}', pg_temp.v('AR.T')),
|
|
846
|
+
'AB-E EXEMPT ' || e.label) from _e e order by e.n;
|
|
847
|
+
-- The clamp exemption is exactly that: a raise, another column, another principal, or an API session is refused.
|
|
848
|
+
create temp table _e2(n int generated always as identity, label text, who text, q text, want text);
|
|
849
|
+
insert into _e2(label, who, q, want) values
|
|
850
|
+
('a role RAISE on a session identity', 'svc', $$update agent_board.board_memberships set role = 'owner' where board_id = '{B}' and agent_id = '{S}'$$, 'OK / MBA01'),
|
|
851
|
+
('a role reduction that also writes metadata', 'svc', $$update agent_board.board_memberships set role = 'member', metadata = '{"x":1}' where board_id = '{B}' and agent_id = '{S}'$$, 'OK / MBA01'),
|
|
852
|
+
('a role reduction on an ordinary member (legacy identity)', 'svc', $$update agent_board.board_memberships set role = 'observer' where board_id = '{B}' and agent_id = '{M}'$$, 'OK / MBA01'),
|
|
853
|
+
('a role reduction on a HUMAN admin', 'svc', $$update agent_board.board_memberships set role = 'member' where board_id = '{B}' and agent_id = '{HA}'$$, 'OK / MBA01'),
|
|
854
|
+
('a role reduction on an ordinary principal', 'svc', $$update agent_board.board_memberships set role = 'member' where board_id = '{B}' and agent_id = '{A}'$$, 'OK / MBA01'),
|
|
855
|
+
('a role reduction on a session identity outside the service', 'O', $$update agent_board.board_memberships set role = 'member' where board_id = '{B}' and agent_id = '{S}'$$, 'OK / MBA01');
|
|
856
|
+
select is(pg_temp.pair(e.who, e.q), e.want, 'AB-E2 the clamp exemption does not cover ' || e.label) from _e2 e order by e.n;
|
|
857
|
+
-- link_session_alias, the real RPC, by S2's holder: it clamps S2 below its demoted parent on BOTH boards.
|
|
858
|
+
select is(pg_temp.probe(jsonb_build_object('role', 'service_role', 'sub', pg_temp.v('S2.auth'), 'identity_lease_epoch', pg_temp.v('S2.epoch'))::text,
|
|
859
|
+
$$select agent_board.link_session_alias('{S2}', '{S2.epoch}', 'ab918-sid-s2-again')$$,
|
|
860
|
+
$$select (select role from agent_board.board_memberships where board_id = '{AC.B}' and agent_id = '{S2}') || '/' || (select role from agent_board.board_memberships where board_id = '{AR.B}' and agent_id = '{S2}')$$),
|
|
861
|
+
'OK:observer/observer', 'AB-E MIXED link_session_alias clamps a session identity on the active AND the archived board (R10)');
|
|
862
|
+
-- bootstrap_board_owner_memberships: the creator O has left. The active twin is repaired; the archived
|
|
863
|
+
-- board is skipped, and the sweep does not abort on it.
|
|
864
|
+
select is(pg_temp.pair('O', $$select * from agent_board.leave_board('{B}', '{O}'); select pg_temp.claims('{"role":"service_role"}'); select * from agent_board.bootstrap_board_owner_memberships()$$, -- pgtap-allow-raise-checked: the call runs inside pg_temp.probe, which catches every error
|
|
865
|
+
$$select count(*)::text from agent_board.board_memberships where board_id = '{B}' and agent_id = '{O}' and membership_state = 'joined'$$),
|
|
866
|
+
'OK:1 / OK:0', 'AB-E EXEMPT bootstrap_board_owner_memberships repairs the active twin, skips the archived board and does not abort');
|
|
867
|
+
-- reclaim_fleet_machine releases a claim held on an archived board's thread.
|
|
868
|
+
select is(pg_temp.probe(pg_temp.c('svc'), $$select * from agent_board.reclaim_fleet_machine('91800003-0000-4000-8000-000000000002', '{Z}', '{O}')$$,
|
|
869
|
+
$$select status from agent_board.claims where resource_kind = 'machine' and thread_id = '{AR.T}'$$),
|
|
870
|
+
'OK:released', 'AB-E EXEMPT reclaim_fleet_machine releases a claim on an archived board''s thread');
|
|
871
|
+
-- A federated principal whose provider's default board is archived: enrolled, audited, not seated.
|
|
872
|
+
insert into agent_board.identity_providers(issuer, audience, supported, policy_approved, allowed_scopes, allowed_board_scopes, allowed_agent_kinds, default_board_id)
|
|
873
|
+
values ('https://ab918.test', 'message-board', true, true, '{board:send}', '{board:x}', '{agent,human}', pg_temp.u('AR.B'));
|
|
874
|
+
select is(pg_temp.probe(pg_temp.c('svc'), $$select * from agent_board.enroll_federated_human('https://ab918.test', 'message-board', 'ab918-h', jsonb_build_object('sub', 'ab918-h', 'email_verified', false), 'AB918 H')$$, -- pgtap-allow-raise-checked: the call runs inside pg_temp.run/probe, which catch every error
|
|
875
|
+
$$select (select count(*) from agent_board.enrollment_federation_audit where subject = 'ab918-h') || '/' ||
|
|
876
|
+
(select count(*) from agent_board.board_memberships m join agent_board.enrollment_federation_audit e on e.agent_id = m.agent_id where e.subject = 'ab918-h')$$),
|
|
877
|
+
'OK:1/0', 'AB-E EXEMPT enroll_federated_human [_enroll_federated_human_after_revocation_gate, _fedsession_autojoin_default_board]: audited, not seated on the archived default board');
|
|
878
|
+
select is(pg_temp.probe(pg_temp.c('svc'), format($$select * from agent_board.enroll_federated_identity('https://ab918.test', 'message-board', 'ab918-i', jsonb_build_object('iss','https://ab918.test','aud','message-board','sub','ab918-i'),
|
|
879
|
+
'ab918-fed', %L, 'raw_ed25519_base64url', %L, true, md5('ab918') || md5('ab918b'), now() + interval '1 hour', null, 'agent', '{board:send}', '{board:x}')$$, public.test_pubkey('ab918-fed'), public.test_key_fingerprint('ab918-fed')),
|
|
880
|
+
$$select (select count(*) from agent_board.enrollment_federation_audit where subject = 'ab918-i')::text$$),
|
|
881
|
+
'OK:1', 'AB-E EXEMPT enroll_federated_identity [_enroll_federated_identity_once]: audited');
|
|
882
|
+
|
|
883
|
+
-- ===========================================================================
|
|
884
|
+
-- E3. An outsider learns nothing: SQLSTATE and text, under the effective role
|
|
885
|
+
-- ===========================================================================
|
|
886
|
+
select is(pg_temp.pair('Z', $$select * from agent_board.redeem_invite_link('{CODE}')$$), 'OK / 42501', 'AB-E3 redeem_invite_link: usable on the active board, refused on the archived one [_redeem_unbounded_invite_for_agent]'); -- pgtap-allow-raise-checked: the call runs inside pg_temp.run/probe, which catch every error
|
|
887
|
+
select is(pg_temp.probe_text(pg_temp.c('Z'), $$select * from agent_board.redeem_invite_link('{AR.CODE}')$$, 'authenticated'), -- pgtap-allow-raise-checked: the call runs inside pg_temp.run/probe, which catch every error
|
|
888
|
+
'42501 invite is not usable', 'AB-E3 redeem_invite_link on an archived board: the uniform answer');
|
|
889
|
+
select is(pg_temp.probe_text(pg_temp.c('Z'), $$select * from agent_board.redeem_invite_link('{AR.CODE}')$$, 'authenticated'), -- pgtap-allow-raise-checked: the call runs inside pg_temp.run/probe, which catch every error
|
|
890
|
+
pg_temp.probe_text(pg_temp.c('Z'), $$select * from agent_board.redeem_invite_link('ab918-no-such-code')$$, 'authenticated'),
|
|
891
|
+
'AB-E3 redeem_invite_link: an archived board''s code answers exactly as an unknown code');
|
|
892
|
+
select is(pg_temp.probe_text(pg_temp.c('Z'), $$select * from agent_board.redeem_invite_link('{AR.CODE}')$$, 'authenticated'), -- pgtap-allow-raise-checked: the call runs inside pg_temp.run/probe, which catch every error
|
|
893
|
+
pg_temp.probe_text(pg_temp.c('Z'), $$select * from agent_board.redeem_invite_link('{AR.RCODE}')$$, 'authenticated'),
|
|
894
|
+
'AB-E3 redeem_invite_link: and as a revoked code');
|
|
895
|
+
-- The call itself runs inside the role-scoped execution; only its count is read afterwards.
|
|
896
|
+
select is(pg_temp.pair('svcrole', $$select set_config('ab918.display', (select count(*)::text from agent_board.invite_board_for_display(encode(sha256(convert_to('{CODE}', 'utf8')), 'hex'))), true)$$, $$select current_setting('ab918.display')$$),
|
|
897
|
+
'OK:1 / OK:0', 'AB-E3 invite_board_for_display resolves an active board''s code and not an archived board''s');
|
|
898
|
+
select is( -- pgtap-allow-raise-checked: the call runs inside pg_temp.run/probe, which catch every error
|
|
899
|
+
(select string_agg(distinct pg_temp.probe_text(pg_temp.c('Z'), format($$select * from agent_board.update_board_membership(%L, '{M}', %L)$$, x.b, s), 'authenticated'), ' | ')
|
|
900
|
+
from unnest(array[pg_temp.v('AC.B'), pg_temp.v('AR.B'), '91819999-0000-4000-8000-000000000009']) x(b), unnest(array['removed', 'subscribed', 'invited']) s),
|
|
901
|
+
'42501 board membership change requires owner or admin role',
|
|
902
|
+
'AB-E3 update_board_membership by an outsider: one answer for an active, an archived and an unknown board, whatever state is asked for');
|
|
903
|
+
select is( -- pgtap-allow-raise-checked: the call runs inside pg_temp.run/probe, which catch every error
|
|
904
|
+
(select string_agg(distinct pg_temp.probe_text(pg_temp.c('M'), format($$select * from agent_board.update_board_membership(%L, '{N}', %L)$$, x.b, s), 'authenticated'), ' | ')
|
|
905
|
+
from unnest(array[pg_temp.v('AC.B'), pg_temp.v('AR.B')]) x(b), unnest(array['removed', 'subscribed']) s),
|
|
906
|
+
'42501 board membership change requires owner or admin role',
|
|
907
|
+
'AB-E3 update_board_membership by a plain member: authority is answered before status');
|
|
908
|
+
select is(pg_temp.probe_text(pg_temp.c('Z'), format($$select * from agent_board.%s$$, f), 'authenticated'), pg_temp.probe_text(pg_temp.c('Z'), format($$select * from agent_board.%s$$, replace(f, '{AR.', '{AC.')), 'authenticated'),
|
|
909
|
+
'AB-E3 an outsider gets the active board''s answer from ' || split_part(f, '(', 1))
|
|
910
|
+
from unnest(array[
|
|
911
|
+
$$post_board_message('{AR.T}', '{Z}', '{AR.B}', 's', 'x')$$, $$create_task('{AR.T}', '{Z}', 'x')$$, $$raise_conflict('{AR.T}', '{Z}', 'x')$$,
|
|
912
|
+
$$create_invite_link('{AR.B}', 'member')$$, $$grant_board_role('{AR.B}', '{M}', 'observer')$$, $$set_board_role_gate('{AR.B}', true)$$,
|
|
913
|
+
$$set_board_claim_policy('{AR.B}', 'advisory')$$, $$set_board_authority_ceiling('{AR.B}', 'member')$$, $$set_board_archived('{AR.B}', true)$$,
|
|
914
|
+
$$set_board_member_label('{AR.B}', '{M}', 'x')$$, $$create_board('{Z}', '{AR.SLUG}', 'x')$$]) f;
|
|
915
|
+
|
|
916
|
+
-- ===========================================================================
|
|
917
|
+
-- F. Moderation keeps its rules; and the board comes back
|
|
918
|
+
-- ===========================================================================
|
|
919
|
+
create temp table _f(n int generated always as identity, label text, claims text, q text, want text);
|
|
920
|
+
insert into _f(label, claims, q, want) values
|
|
921
|
+
('a member cannot remove another member', pg_temp.c('M'), $$select * from agent_board.update_board_membership('{AR.B}', '{N}', 'removed')$$, '42501'),
|
|
922
|
+
('an outsider cannot remove a member', pg_temp.c('Z'), $$select * from agent_board.update_board_membership('{AR.B}', '{N}', 'removed')$$, '42501'),
|
|
923
|
+
('an admin cannot remove an owner (rank)', pg_temp.c('A'), $$select * from agent_board.update_board_membership('{AR.B}', '{O}', 'removed')$$, '42501'),
|
|
924
|
+
('a pending target is still refused (#906)', pg_temp.c('O'), $$select * from agent_board.update_board_membership('{AR.B}', '{P2}', 'removed')$$, '42501'),
|
|
925
|
+
('a human owner removing an admin still needs step-up', pg_temp.su('H', 301), $$select * from agent_board.update_board_membership('{AR.B}', '{A}', 'removed')$$, 'MBS01'),
|
|
926
|
+
('a human owner with a fresh proof removes an admin', pg_temp.su('H', 10), $$select * from agent_board.update_board_membership('{AR.B}', '{A}', 'removed')$$, 'OK');
|
|
927
|
+
select is(pg_temp.probe(f.claims, f.q), f.want, 'AB-F moderation on an archived board: ' || f.label) from _f f order by f.n;
|
|
928
|
+
-- The refusal precedes step-up: a stale human gets MBA01, not a pointless MBS01 prompt.
|
|
929
|
+
select is(pg_temp.probe(pg_temp.su('H', 301), $$select * from agent_board.grant_board_role('{AR.B}', '{M}', 'admin')$$), 'MBA01', 'AB-F order: MBA01 comes before MBS01'); -- pgtap-allow-raise-checked: the call runs inside pg_temp.run/probe, which catch every error
|
|
930
|
+
select is(pg_temp.probe(pg_temp.c('Z'), $$select * from agent_board.post_board_message('{AR.T}', '{Z}', '{AR.B}', 's', 'x')$$), '42501', 'AB-F order: a caller who was not allowed to post learns nothing (42501, not MBA01)');
|
|
931
|
+
select is((select count(*)::int from agent_board.messages where thread_id = pg_temp.u('AR.T')), 1, 'AB-F state: no refused call left a message on AR');
|
|
932
|
+
select is(pg_temp.probe(pg_temp.c('O'), $$select * from agent_board.set_board_archived('{AR.B}', false); select * from agent_board.post_board_message('{AR.T}', '{O}', '{AR.B}', 's', 'back')$$, -- pgtap-allow-raise-checked: the call runs inside pg_temp.run/probe, which catch every error
|
|
933
|
+
$$select count(*)::text from agent_board.messages where thread_id = '{AR.T}'$$), 'OK:2', 'AB-F ALLOW: un-archiving re-opens the board to posts');
|
|
934
|
+
|
|
935
|
+
-- ===========================================================================
|
|
936
|
+
-- G. The upgrade path: a board archived BEFORE this migration (tests/seeds/…_archive_board.sql.pre.sql)
|
|
937
|
+
-- ===========================================================================
|
|
938
|
+
select is((select status || '/' || updated_at::date::text || '/' || name from agent_board.boards where id = '91890000-0000-4000-8000-000000000001'),
|
|
939
|
+
'archived/2026-11-27/AB918 seed', 'AB-G: the migration did not touch a board that was already archived');
|
|
940
|
+
select is((select string_agg(membership_state || ':' || role, ',' order by agent_id) from agent_board.board_memberships where board_id = '91890000-0000-4000-8000-000000000001'),
|
|
941
|
+
'joined:owner,joined:member', 'AB-G: nor its memberships');
|
|
942
|
+
select is((select count(*)::int from agent_board.messages m join agent_board.threads t on t.id = m.thread_id where t.board_id = '91890000-0000-4000-8000-000000000001'), 1, 'AB-G: nor its history');
|
|
943
|
+
select pg_temp.put('SO', '91890000-0000-4000-8000-0000000000a1'); select pg_temp.put('SO.auth', '91890000-0000-4000-8000-0000000000b1');
|
|
944
|
+
select pg_temp.put('SM', '91890000-0000-4000-8000-0000000000a2'); select pg_temp.put('SM.auth', '91890000-0000-4000-8000-0000000000b2');
|
|
945
|
+
select is(pg_temp.probe(pg_temp.c('SM'), $$select * from agent_board.post_board_message('91890000-0000-4000-8000-000000000002', '{SM}', '91890000-0000-4000-8000-000000000001', 's', 'x')$$), 'MBA01', 'AB-G: it is refused like any other archived board');
|
|
946
|
+
select is(pg_temp.probe(pg_temp.c('SM'), $$select * from agent_board.release_claim('91890000-0000-4000-8000-000000000003')$$, $$select status from agent_board.claims where lease_token = '91890000-0000-4000-8000-000000000003'$$), 'OK:released', 'AB-G: a claim taken before the migration can be released');
|
|
947
|
+
select is(pg_temp.probe(pg_temp.c('SM'), $$select * from agent_board.leave_board('91890000-0000-4000-8000-000000000001', '{SM}')$$), 'OK', 'AB-G: a member can leave'); -- pgtap-allow-raise-checked: the call runs inside pg_temp.run/probe, which catch every error
|
|
948
|
+
-- The last-owner rule is untouched on an archived board (R10), through the real leave.
|
|
949
|
+
select is(pg_temp.probe_text(pg_temp.c('SO'), $$select * from agent_board.leave_board('91890000-0000-4000-8000-000000000001', '{SO}')$$), -- pgtap-allow-raise-checked: the call runs inside pg_temp.probe, which catches every error
|
|
950
|
+
'23514 last_active_board_owner: cannot remove the last active owner', 'AB-G: the last owner of an archived board cannot leave it');
|
|
951
|
+
select is(pg_temp.probe_text(pg_temp.c('SO'), $$select * from agent_board.set_board_archived('91890000-0000-4000-8000-000000000001', false); select * from agent_board.leave_board('91890000-0000-4000-8000-000000000001', '{SO}')$$), -- pgtap-allow-raise-checked: the call runs inside pg_temp.probe, which catches every error
|
|
952
|
+
'23514 last_active_board_owner: cannot remove the last active owner', 'AB-G: nor after un-archiving it (the same rule, the same answer)');
|
|
953
|
+
select is(pg_temp.probe(pg_temp.c('SO'), $$select * from agent_board.set_board_archived('91890000-0000-4000-8000-000000000001', false); select * from agent_board.post_board_message('91890000-0000-4000-8000-000000000002', '{SO}', '91890000-0000-4000-8000-000000000001', 's', 'x')$$), 'OK', 'AB-G: its owner can un-archive it, and it takes posts again'); -- pgtap-allow-raise-checked: the call runs inside pg_temp.run/probe, which catch every error
|
|
954
|
+
|
|
955
|
+
select * from finish();
|
|
956
|
+
rollback;
|