@consiliency/agent-board-schema 1.79.0 → 1.81.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/fixtures/already-applied.json +8 -0
- package/migrations/20261126000100_agent_board_membership_removal_requires_active.sql +243 -0
- package/migrations/20261201000100_agent_board_reply_to_message.sql +1241 -0
- package/package.json +1 -1
- package/schema-manifest.json +21 -3
- package/src/tooling.test.mjs +6 -2
- package/tests/agent_board_661_reply_delivery.test.sql +12 -12
- package/tests/agent_board_667_history_class.test.sql +31 -13
- 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_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_delegate_role_class.test.sql +1 -1
- package/tests/agent_board_delivery_writer_execute.test.sql +7 -7
- package/tests/agent_board_hosted_delegates.test.sql +3 -3
- package/tests/agent_board_inbox_rpcs.test.sql +6 -6
- package/tests/agent_board_membership_removal_state.test.sql +228 -0
- package/tests/agent_board_refusal_atomicity.test.sql +958 -0
- package/tests/agent_board_reply_to.test.sql +874 -0
- 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_write_enforcement_class.test.sql +7 -7
- package/tests/catalog/function_execute_privileges.json +23 -14
- package/tests/catalog/p_metadata_parameters.json +12 -8
- 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/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/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
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
-- #906 REMOVALSTATE pgTAP: update_board_membership(..., 'removed') by ANOTHER actor is refused
|
|
2
|
+
-- over a PENDING target (Consiliency/message-board#906, migration 20261126000100).
|
|
3
|
+
--
|
|
4
|
+
-- The defect, reproduced on main before the fix: an owner/admin acting on a stale roster removed a
|
|
5
|
+
-- target whose row had meanwhile become `invited` (left, then re-invited) or `requested`. Every
|
|
6
|
+
-- REJECT row below is paired with an ALLOW row: the path that IS meant to act on that state
|
|
7
|
+
-- (resolve_board_request for a pending row) or the same target once it is active or departed.
|
|
8
|
+
-- `left -> removed` stays ALLOWED for an outranking owner/admin: it is the documented bar on a
|
|
9
|
+
-- departed agent and R-LINK-7's order-independent eviction (isolation spec
|
|
10
|
+
-- hosted_delegate_withdraw_evict_race P2; #909 panel round 1).
|
|
11
|
+
--
|
|
12
|
+
-- Allow-side rows use lives_ok(...) then a separate state read, never a bare select of the RPC
|
|
13
|
+
-- (#113). Refusals are read through pg_temp.diag, which CATCHES the raise and returns
|
|
14
|
+
-- SQLSTATE|MESSAGE|DETAIL|HINT, so a missing refusal is a named `not ok`, not an aborted file.
|
|
15
|
+
-- Event counts are scoped to (board, agent), never agent-wide.
|
|
16
|
+
create extension if not exists pgtap with schema extensions;
|
|
17
|
+
set search_path = extensions, public, agent_board;
|
|
18
|
+
|
|
19
|
+
begin;
|
|
20
|
+
|
|
21
|
+
select plan(45);
|
|
22
|
+
|
|
23
|
+
create function pg_temp.claims(p_sub text) returns void language plpgsql as $$
|
|
24
|
+
begin
|
|
25
|
+
perform set_config('request.jwt.claims', json_build_object('role','authenticated','sub',p_sub)::text, true);
|
|
26
|
+
end $$;
|
|
27
|
+
create function pg_temp.u(n int) returns uuid language sql immutable as $$
|
|
28
|
+
select ('e9060000-0000-0000-0000-' || lpad(n::text,12,'0'))::uuid $$;
|
|
29
|
+
create function pg_temp.a(n int) returns uuid language sql immutable as $$
|
|
30
|
+
select ('e9061000-0000-4000-8000-' || lpad(n::text,12,'0'))::uuid $$;
|
|
31
|
+
create function pg_temp.b() returns uuid language sql immutable as $$
|
|
32
|
+
select 'e9062000-0000-4000-8000-000000000001'::uuid $$;
|
|
33
|
+
create function pg_temp.st(n int) returns text language sql as $$
|
|
34
|
+
select membership_state from agent_board.board_memberships
|
|
35
|
+
where board_id = pg_temp.b() and agent_id = pg_temp.a(n)
|
|
36
|
+
order by case when membership_state in ('joined','subscribed') then 0 else 1 end,
|
|
37
|
+
created_at desc, id desc
|
|
38
|
+
limit 1 $$;
|
|
39
|
+
create function pg_temp.ev(n int) returns int language sql as $$
|
|
40
|
+
select count(*)::int from agent_board.board_membership_events
|
|
41
|
+
where board_id = pg_temp.b() and agent_id = pg_temp.a(n) $$;
|
|
42
|
+
create function pg_temp.diag(p_sql text) returns text language plpgsql as $$
|
|
43
|
+
declare v_state text; v_msg text; v_detail text; v_hint text;
|
|
44
|
+
begin
|
|
45
|
+
execute p_sql;
|
|
46
|
+
return 'no error';
|
|
47
|
+
exception when others then
|
|
48
|
+
get stacked diagnostics v_state = returned_sqlstate, v_msg = message_text, v_detail = pg_exception_detail,
|
|
49
|
+
v_hint = pg_exception_hint;
|
|
50
|
+
return v_state || '|' || v_msg || '|' || coalesce(nullif(v_detail, ''), '(null)')
|
|
51
|
+
|| '|' || coalesce(nullif(v_hint, ''), '(null)');
|
|
52
|
+
end $$;
|
|
53
|
+
create function pg_temp.rm(n int) returns text language sql immutable as $$
|
|
54
|
+
select format('select * from agent_board.update_board_membership(%L::uuid, %L::uuid, %L)',
|
|
55
|
+
pg_temp.b(), pg_temp.a(n), 'removed') $$;
|
|
56
|
+
|
|
57
|
+
-- Agents: 1 owner, 2 admin, 3 plain member; 4.. targets.
|
|
58
|
+
insert into auth.users(id, instance_id, aud, role, email)
|
|
59
|
+
select pg_temp.u(n), '00000000-0000-0000-0000-000000000000','authenticated','authenticated','rm906-'||n||'@t.test'
|
|
60
|
+
from generate_series(1,15) n;
|
|
61
|
+
insert into agent_board.agents(id, agent_type, kind, handle, display_name, status, auth_user_id)
|
|
62
|
+
select pg_temp.a(n), 'agent','agent','rm906-agent-'||n,'RM906 Agent '||n,'active', pg_temp.u(n)
|
|
63
|
+
from generate_series(1,15) n;
|
|
64
|
+
insert into agent_board.boards(id, slug, name, created_by_agent_id, visibility, status)
|
|
65
|
+
values (pg_temp.b(), 'rm906-board', 'RM906', pg_temp.a(1), 'invite_only', 'active');
|
|
66
|
+
-- Seeded state per target (left_at follows board_memberships_state_left_at):
|
|
67
|
+
-- 4 invited 5 requested 6 left 7 joined 8 subscribed 9 removed 10 joined (E2E)
|
|
68
|
+
-- 11 invited ADMIN 12 invited (admin actor) 13 invited (member actor) 14 invited (self)
|
|
69
|
+
-- 15 left (operator)
|
|
70
|
+
insert into agent_board.board_memberships(board_id, agent_id, role, membership_state, left_at, created_by_agent_id)
|
|
71
|
+
select pg_temp.b(), pg_temp.a(n), r, s,
|
|
72
|
+
case when s in ('left','removed') then now() else null end, pg_temp.a(1)
|
|
73
|
+
from (values (1,'owner','joined'), (2,'admin','joined'), (3,'member','joined'),
|
|
74
|
+
(4,'member','invited'), (5,'member','requested'), (6,'member','left'),
|
|
75
|
+
(7,'member','joined'), (8,'member','subscribed'), (9,'member','removed'),
|
|
76
|
+
(10,'member','joined'), (11,'admin','invited'), (12,'member','invited'),
|
|
77
|
+
(13,'member','invited'), (14,'member','invited'),
|
|
78
|
+
(15,'member','left')) v(n, r, s);
|
|
79
|
+
|
|
80
|
+
-- ===========================================================================
|
|
81
|
+
-- 1. invited: REJECT the removal, ALLOW the cancel path
|
|
82
|
+
-- ===========================================================================
|
|
83
|
+
select pg_temp.claims(pg_temp.u(1)::text);
|
|
84
|
+
-- 1
|
|
85
|
+
select is(pg_temp.diag(pg_temp.rm(4)), -- pgtap-allow-raise-checked: pg_temp.diag catches the raise
|
|
86
|
+
'42501|board membership removal requires an active target membership|current membership state: invited|cancel a pending invitation or request with resolve_board_request',
|
|
87
|
+
'REJECT invited: an owner cannot remove an INVITED target');
|
|
88
|
+
-- 2, 3
|
|
89
|
+
select is(pg_temp.st(4), 'invited', 'REJECT invited: the invitation is untouched');
|
|
90
|
+
select is(pg_temp.ev(4), 0, 'REJECT invited: no membership event was written');
|
|
91
|
+
-- 4, 5
|
|
92
|
+
select lives_ok(format($$ select agent_board.resolve_board_request(%L::uuid, %L::uuid, 'removed'::text, null::uuid, '{}'::jsonb) $$,
|
|
93
|
+
pg_temp.b(), pg_temp.a(4)),
|
|
94
|
+
'ALLOW invited: the owner cancels the invitation through resolve_board_request [call succeeds]');
|
|
95
|
+
select is(pg_temp.st(4), 'left', 'ALLOW invited: the cancelled invitation lands `left` (REJECTSEM), not `removed`');
|
|
96
|
+
-- 6, 7: an owner who wants to BAR a pending target cancels it, then removes the departed row.
|
|
97
|
+
select lives_ok(pg_temp.rm(4), 'ALLOW invited two-step: the owner then removes the cancelled (`left`) row [call succeeds]');
|
|
98
|
+
select is(pg_temp.st(4), 'removed', 'ALLOW invited two-step: cancel then remove bars the target');
|
|
99
|
+
|
|
100
|
+
-- ===========================================================================
|
|
101
|
+
-- 2. requested: REJECT the removal, ALLOW the decline path
|
|
102
|
+
-- ===========================================================================
|
|
103
|
+
-- 8, 9, 10
|
|
104
|
+
select is(pg_temp.diag(pg_temp.rm(5)), -- pgtap-allow-raise-checked: pg_temp.diag catches the raise
|
|
105
|
+
'42501|board membership removal requires an active target membership|current membership state: requested|cancel a pending invitation or request with resolve_board_request',
|
|
106
|
+
'REJECT requested: an owner cannot remove a REQUESTED target');
|
|
107
|
+
select is(pg_temp.st(5), 'requested', 'REJECT requested: the request is untouched');
|
|
108
|
+
select is(pg_temp.ev(5), 0, 'REJECT requested: no membership event was written');
|
|
109
|
+
-- 11, 12
|
|
110
|
+
select lives_ok(format($$ select agent_board.resolve_board_request(%L::uuid, %L::uuid, 'removed'::text, null::uuid, '{}'::jsonb) $$,
|
|
111
|
+
pg_temp.b(), pg_temp.a(5)),
|
|
112
|
+
'ALLOW requested: the owner declines the request through resolve_board_request [call succeeds]');
|
|
113
|
+
select is(pg_temp.st(5), 'left', 'ALLOW requested: the declined request lands `left`');
|
|
114
|
+
|
|
115
|
+
-- ===========================================================================
|
|
116
|
+
-- 3. left: ALLOW, unchanged. `left -> removed` by an outranking owner/admin is the documented bar
|
|
117
|
+
-- on a departed agent and R-LINK-7's order-independent eviction (isolation P2).
|
|
118
|
+
-- ===========================================================================
|
|
119
|
+
-- 13, 14, 15
|
|
120
|
+
select lives_ok(pg_temp.rm(6), 'ALLOW left: an owner turns a departed member''s `left` into `removed` [call succeeds]');
|
|
121
|
+
select is(pg_temp.st(6), 'removed', 'ALLOW left: the departed member is barred (`removed`)');
|
|
122
|
+
select is(pg_temp.ev(6), 1, 'ALLOW left: the genuine left -> removed transition writes exactly one membership event');
|
|
123
|
+
-- 16, 17: the operator carve-out is unchanged (service_role is not "another actor" here).
|
|
124
|
+
set local role service_role;
|
|
125
|
+
select set_config('request.jwt.claims', '{"role":"service_role"}', true);
|
|
126
|
+
select lives_ok(format($$ select * from agent_board.update_board_membership(%L::uuid, %L::uuid, 'removed') $$,
|
|
127
|
+
pg_temp.b(), pg_temp.a(15)),
|
|
128
|
+
'ALLOW operator: service_role removes a departed member [call succeeds]');
|
|
129
|
+
reset role;
|
|
130
|
+
select is(pg_temp.st(15), 'removed', 'ALLOW operator: the operator''s removal lands `removed`');
|
|
131
|
+
|
|
132
|
+
-- ===========================================================================
|
|
133
|
+
-- 4. active and already-removed targets: ALLOW, unchanged
|
|
134
|
+
-- ===========================================================================
|
|
135
|
+
select pg_temp.claims(pg_temp.u(1)::text);
|
|
136
|
+
-- 18, 19
|
|
137
|
+
select lives_ok(pg_temp.rm(7), 'ALLOW joined: an owner removes a JOINED member [call succeeds]');
|
|
138
|
+
select is(pg_temp.st(7), 'removed', 'ALLOW joined: the member is removed');
|
|
139
|
+
-- 20, 21
|
|
140
|
+
select lives_ok(pg_temp.rm(8), 'ALLOW subscribed: an owner removes a SUBSCRIBED member [call succeeds]');
|
|
141
|
+
select is(pg_temp.st(8), 'removed', 'ALLOW subscribed: the member is removed');
|
|
142
|
+
-- 22, 23, 24: removed -> removed stays the LEAVEIDEM no-op (not refused, nothing written).
|
|
143
|
+
select lives_ok(pg_temp.rm(9), 'ALLOW removed: removed -> removed is still a permitted no-op [call succeeds]');
|
|
144
|
+
select is(pg_temp.st(9), 'removed', 'ALLOW removed: the row stays `removed`');
|
|
145
|
+
select is(pg_temp.ev(9), 0, 'ALLOW removed: the no-op writes no membership event');
|
|
146
|
+
|
|
147
|
+
-- ===========================================================================
|
|
148
|
+
-- 5. the rule is not owner-specific: an ADMIN actor
|
|
149
|
+
-- ===========================================================================
|
|
150
|
+
select pg_temp.claims(pg_temp.u(2)::text);
|
|
151
|
+
-- 25, 26
|
|
152
|
+
select is(pg_temp.diag(pg_temp.rm(12)), -- pgtap-allow-raise-checked: pg_temp.diag catches the raise
|
|
153
|
+
'42501|board membership removal requires an active target membership|current membership state: invited|cancel a pending invitation or request with resolve_board_request',
|
|
154
|
+
'REJECT admin actor: an admin cannot remove an INVITED member either');
|
|
155
|
+
select is(pg_temp.st(12), 'invited', 'REJECT admin actor: the invitation is untouched');
|
|
156
|
+
-- 27, 28: paired: the same admin removes the joined member 3.
|
|
157
|
+
select lives_ok(pg_temp.rm(3), 'ALLOW admin actor: an admin removes a JOINED member [call succeeds]');
|
|
158
|
+
select is(pg_temp.st(3), 'removed', 'ALLOW admin actor: the member is removed');
|
|
159
|
+
|
|
160
|
+
-- ===========================================================================
|
|
161
|
+
-- 6. PRECEDENCE: the existing refusals still come first and keep their messages
|
|
162
|
+
-- ===========================================================================
|
|
163
|
+
-- 29: rank first. An admin removing an INVITED ADMIN is refused by the RANK check, not the state
|
|
164
|
+
-- check, so a caller who does not outrank the target learns nothing about its state.
|
|
165
|
+
select is(pg_temp.diag(pg_temp.rm(11)), -- pgtap-allow-raise-checked: pg_temp.diag catches the raise
|
|
166
|
+
'42501|board membership change requires a higher board role than the target|(null)|(null)',
|
|
167
|
+
'PRECEDENCE rank: an admin removing an invited admin gets the rank refusal, not the state refusal');
|
|
168
|
+
-- 30, 31: the owner outranks the invited admin, so it reaches the state check, which refuses before
|
|
169
|
+
-- the sink and therefore before the #669 step-up gate.
|
|
170
|
+
select pg_temp.claims(pg_temp.u(1)::text);
|
|
171
|
+
select is(pg_temp.diag(pg_temp.rm(11)), -- pgtap-allow-raise-checked: pg_temp.diag catches the raise
|
|
172
|
+
'42501|board membership removal requires an active target membership|current membership state: invited|cancel a pending invitation or request with resolve_board_request',
|
|
173
|
+
'REJECT invited admin: an owner removing an INVITED admin gets the state refusal');
|
|
174
|
+
select is(pg_temp.st(11), 'invited', 'REJECT invited admin: the invitation is untouched');
|
|
175
|
+
-- 32, 33: paired: the owner cancels that invitation instead.
|
|
176
|
+
select lives_ok(format($$ select agent_board.resolve_board_request(%L::uuid, %L::uuid, 'removed'::text, null::uuid, '{}'::jsonb) $$,
|
|
177
|
+
pg_temp.b(), pg_temp.a(11)),
|
|
178
|
+
'ALLOW invited admin: the owner cancels the admin invitation [call succeeds]');
|
|
179
|
+
select is(pg_temp.st(11), 'left', 'ALLOW invited admin: the cancelled invitation lands `left`');
|
|
180
|
+
-- 34: role first. A plain member gets the owner/admin refusal whatever the target's state.
|
|
181
|
+
select pg_temp.claims(pg_temp.u(10)::text);
|
|
182
|
+
select is(pg_temp.diag(pg_temp.rm(13)), -- pgtap-allow-raise-checked: pg_temp.diag catches the raise
|
|
183
|
+
'42501|board membership change requires owner or admin role|(null)|(null)',
|
|
184
|
+
'PRECEDENCE role: a plain member removing an invited target gets the owner/admin refusal');
|
|
185
|
+
|
|
186
|
+
-- ===========================================================================
|
|
187
|
+
-- 7. the self path is unchanged: an invitee declines its own invitation
|
|
188
|
+
-- ===========================================================================
|
|
189
|
+
select pg_temp.claims(pg_temp.u(14)::text);
|
|
190
|
+
-- 35, 36
|
|
191
|
+
select lives_ok(format($$ select * from agent_board.update_board_membership(%L::uuid, %L::uuid, 'left') $$,
|
|
192
|
+
pg_temp.b(), pg_temp.a(14)),
|
|
193
|
+
'ALLOW self: an invitee sets its own invitation to `left` [call succeeds]');
|
|
194
|
+
select is(pg_temp.st(14), 'left', 'ALLOW self: the invitee''s own decline lands `left`');
|
|
195
|
+
|
|
196
|
+
-- ===========================================================================
|
|
197
|
+
-- 8. END TO END: the issue's stale-roster scenario through the real RPCs
|
|
198
|
+
-- ===========================================================================
|
|
199
|
+
-- Target 10 is joined when the owner's client reads the roster. It then leaves and is re-invited.
|
|
200
|
+
-- The owner's stale `removed` must not land on the new invitation.
|
|
201
|
+
select pg_temp.claims(pg_temp.u(10)::text);
|
|
202
|
+
-- 37, 38
|
|
203
|
+
select lives_ok(format($$ select * from agent_board.leave_board(%L::uuid, %L::uuid) $$,
|
|
204
|
+
pg_temp.b(), pg_temp.a(10)),
|
|
205
|
+
'E2E setup: the member leaves [call succeeds]');
|
|
206
|
+
select is(pg_temp.st(10), 'left', 'E2E setup: the member has left');
|
|
207
|
+
select pg_temp.claims(pg_temp.u(1)::text);
|
|
208
|
+
-- 39, 40
|
|
209
|
+
select lives_ok(format($$ select agent_board.invite_board_member(%L::uuid, %L::uuid, %L::uuid) $$,
|
|
210
|
+
pg_temp.b(), pg_temp.a(10), pg_temp.a(1)),
|
|
211
|
+
'E2E setup: the owner re-invites the departed member [call succeeds]');
|
|
212
|
+
select is(pg_temp.st(10), 'invited', 'E2E setup: the departed member is invited again');
|
|
213
|
+
-- 41, 42
|
|
214
|
+
select is(pg_temp.diag(pg_temp.rm(10)), -- pgtap-allow-raise-checked: pg_temp.diag catches the raise
|
|
215
|
+
'42501|board membership removal requires an active target membership|current membership state: invited|cancel a pending invitation or request with resolve_board_request',
|
|
216
|
+
'REJECT E2E: the owner''s stale removal of the re-invited member is refused');
|
|
217
|
+
select is(pg_temp.st(10), 'invited', 'REJECT E2E: the re-invitation survives the stale removal');
|
|
218
|
+
-- 43, 44, 45: paired: once the invitee accepts, the same removal is allowed.
|
|
219
|
+
select pg_temp.claims(pg_temp.u(10)::text);
|
|
220
|
+
select lives_ok(format($$ select agent_board.join_board(%L::uuid, %L::uuid, 'joined'::text, null::uuid, '{}'::jsonb) $$,
|
|
221
|
+
pg_temp.b(), pg_temp.a(10)),
|
|
222
|
+
'ALLOW E2E: the invitee accepts [call succeeds]');
|
|
223
|
+
select pg_temp.claims(pg_temp.u(1)::text);
|
|
224
|
+
select lives_ok(pg_temp.rm(10), 'ALLOW E2E: the owner removes the now-JOINED member [call succeeds]');
|
|
225
|
+
select is(pg_temp.st(10), 'removed', 'ALLOW E2E: the active member is removed');
|
|
226
|
+
|
|
227
|
+
select * from finish();
|
|
228
|
+
rollback;
|