@consiliency/agent-board-schema 1.79.0 → 1.80.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 +4 -0
- package/migrations/20261126000100_agent_board_membership_removal_requires_active.sql +243 -0
- package/package.json +1 -1
- package/schema-manifest.json +12 -3
- package/src/tooling.test.mjs +4 -2
- package/tests/agent_board_membership_removal_state.test.sql +228 -0
|
@@ -708,6 +708,10 @@
|
|
|
708
708
|
{
|
|
709
709
|
"id": "20261124000100_agent_board_step_up_enforcement",
|
|
710
710
|
"sha256": "26c02cb8797d059b18f5e81d1db0be237126f48a0598b30e36e683763021384a"
|
|
711
|
+
},
|
|
712
|
+
{
|
|
713
|
+
"id": "20261126000100_agent_board_membership_removal_requires_active",
|
|
714
|
+
"sha256": "295eb0cd22598b6ee45dd5ccaae7290834131b9eb98e286fe91856abf90dd1ac"
|
|
711
715
|
}
|
|
712
716
|
]
|
|
713
717
|
}
|
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
-- #906 REMOVALSTATE: update_board_membership(…, 'removed') by ANOTHER actor is refused over a
|
|
2
|
+
-- PENDING target (`invited`/`requested`) (Consiliency/message-board#906).
|
|
3
|
+
--
|
|
4
|
+
-- The gap: for an actor other than the target, the other-actor branch checked the actor's role
|
|
5
|
+
-- (owner/admin) and its rank against the target's role, but not the target's CURRENT STATE. A
|
|
6
|
+
-- `removed` request against an `invited` or `requested` row was accepted, so a client acting on a
|
|
7
|
+
-- stale roster overrode a NEWER decision: it evicted a target that had meanwhile left and been
|
|
8
|
+
-- re-invited, or whose join request was pending, barring the self-service way back in. The UI's
|
|
9
|
+
-- fresh read before the write (message-board-ui#299) narrows that window; only this function
|
|
10
|
+
-- closes it, because the target row is read FOR UPDATE under the board authority lock here.
|
|
11
|
+
--
|
|
12
|
+
-- DESIGN (A), not (B): refuse `removed` over a pending row for another actor, with its own
|
|
13
|
+
-- message. An optional expected-prior-state parameter (B) would protect only callers that opt in,
|
|
14
|
+
-- leaving every existing client exposed. What (A) leaves alone:
|
|
15
|
+
-- * `left -> removed` by an outranking owner/admin is KEPT. It is the documented bar on a
|
|
16
|
+
-- departed agent (specs/rpc-contracts.md, "A genuine `left -> removed` (an owner barring
|
|
17
|
+
-- invite-link re-entry for a departed agent) ... is the kick moment"), and it is how an
|
|
18
|
+
-- eviction wins whichever of a withdrawal or an eviction commits first (R-LINK-7; isolation
|
|
19
|
+
-- spec hosted_delegate_withdraw_evict_race P2: the owner withdraws first, the admin's waiting
|
|
20
|
+
-- eviction then moves `left` to `removed`). Refusing it let a target that departs first dodge
|
|
21
|
+
-- the eviction and be re-seated (#909 panel round 1).
|
|
22
|
+
-- * cancelling an invitation or declining a request is resolve_board_request(…, 'removed'),
|
|
23
|
+
-- which acts on the PENDING row and lands `left` (REJECTSEM #89); it never goes through this
|
|
24
|
+
-- function. An owner who wants to bar a pending target cancels or declines it (`left`) and
|
|
25
|
+
-- then removes it.
|
|
26
|
+
-- * the subject's own withdrawal (self `left`) and the D7 principal withdrawal are separate
|
|
27
|
+
-- branches, untouched;
|
|
28
|
+
-- * removed -> removed stays the idempotent no-op (LEAVEIDEM);
|
|
29
|
+
-- * service_role keeps the operator carve-out, as for every other rule in this function.
|
|
30
|
+
-- The predicate is spelled as the complement of the permitted prior states (joined, subscribed,
|
|
31
|
+
-- left, removed), so a state added later is refused until someone decides otherwise.
|
|
32
|
+
--
|
|
33
|
+
-- ERROR: 42501 with a message unique to this refusal ('board membership removal requires an
|
|
34
|
+
-- active target membership'), DETAIL = the target's current state, HINT = resolve_board_request.
|
|
35
|
+
-- 42501 keeps PostgREST's 403 (55000/P0002 map to HTTP 500, which reads as a server fault) and
|
|
36
|
+
-- matches every other transition refusal in this body (self change, principal withdrawal from
|
|
37
|
+
-- `removed`); clients already pass 42501 for this RPC through unchanged, so no client mapping or
|
|
38
|
+
-- release is needed.
|
|
39
|
+
--
|
|
40
|
+
-- PLACEMENT: inside the other-actor branch, AFTER the owner/admin check and the rank check, so a
|
|
41
|
+
-- caller that does not outrank the target learns nothing about its state (the existing refusals
|
|
42
|
+
-- still come first and keep their messages), and BEFORE the sink, so the #669 step-up gate stays
|
|
43
|
+
-- the LAST statement before return, keyed on the sink's resulting state, exactly as 20261124000100
|
|
44
|
+
-- left it. Its condition requires a prior joined/subscribed state, which this guard never refuses.
|
|
45
|
+
--
|
|
46
|
+
-- The body is a fresh copy of 20261124000100's definition plus only the #906-marked block. ACL and
|
|
47
|
+
-- COMMENT are restated (AGENTS.md "Schema-change mechanics that bite").
|
|
48
|
+
--
|
|
49
|
+
-- Writes no agent_board.schema_version (stays 8).
|
|
50
|
+
|
|
51
|
+
CREATE OR REPLACE FUNCTION agent_board.update_board_membership(p_board_id uuid, p_agent_id uuid, p_membership_state text, p_metadata jsonb DEFAULT '{}'::jsonb)
|
|
52
|
+
RETURNS TABLE(membership_id uuid, board_id uuid, agent_id uuid, membership_state text, left_at timestamp with time zone, updated_at timestamp with time zone)
|
|
53
|
+
LANGUAGE plpgsql
|
|
54
|
+
SECURITY DEFINER
|
|
55
|
+
SET search_path TO 'agent_board', 'public'
|
|
56
|
+
AS $function$
|
|
57
|
+
declare
|
|
58
|
+
v_membership agent_board.board_memberships%rowtype;
|
|
59
|
+
v_board agent_board.boards%rowtype;
|
|
60
|
+
v_actor uuid := agent_board.current_agent_id();
|
|
61
|
+
v_is_service boolean := agent_board._is_service_role();
|
|
62
|
+
v_existing_state text;
|
|
63
|
+
v_target_role text;
|
|
64
|
+
v_actor_role text;
|
|
65
|
+
-- HOSTED (D7): the caller is the target hosted delegate's principal asking for `left`.
|
|
66
|
+
v_principal_withdraw boolean;
|
|
67
|
+
begin
|
|
68
|
+
if v_actor is null and not v_is_service then
|
|
69
|
+
raise exception 'current agent principal not resolved' using errcode = '42501';
|
|
70
|
+
end if;
|
|
71
|
+
|
|
72
|
+
-- Board authority lock first, before the target row and the sink's FK locks.
|
|
73
|
+
perform agent_board._lock_board_authority_ceiling(p_board_id);
|
|
74
|
+
|
|
75
|
+
v_principal_withdraw := not v_is_service
|
|
76
|
+
and v_actor <> p_agent_id
|
|
77
|
+
and p_membership_state = 'left'
|
|
78
|
+
and v_actor = agent_board._delegate_principal_agent_id(p_agent_id);
|
|
79
|
+
|
|
80
|
+
if not v_is_service and v_actor <> p_agent_id and not v_principal_withdraw then
|
|
81
|
+
select * into v_board from agent_board.boards where id = p_board_id and status = 'active';
|
|
82
|
+
if v_board.id is null then
|
|
83
|
+
raise exception 'board not found' using errcode = 'P0002';
|
|
84
|
+
end if;
|
|
85
|
+
select bm.role
|
|
86
|
+
into v_actor_role
|
|
87
|
+
from agent_board.board_memberships bm
|
|
88
|
+
where bm.board_id = p_board_id
|
|
89
|
+
and bm.agent_id = v_actor
|
|
90
|
+
and bm.membership_state in ('joined', 'subscribed')
|
|
91
|
+
limit 1;
|
|
92
|
+
if v_actor_role is null or v_actor_role not in ('owner', 'admin') then
|
|
93
|
+
raise exception 'board membership change requires owner or admin role'
|
|
94
|
+
using errcode = '42501';
|
|
95
|
+
end if;
|
|
96
|
+
end if;
|
|
97
|
+
|
|
98
|
+
-- HOSTED: LOCKED, so every transition rule below is decided on the state the sink will
|
|
99
|
+
-- overwrite. Unlocked, an admin's uncommitted `removed` committed after this read, and the D7
|
|
100
|
+
-- withdrawal (and an ordinary self-leave, the same branch shape) then wrote `left` over it in
|
|
101
|
+
-- the sink, erasing the eviction R-LINK-7 reads (hosted_delegate_withdraw_evict_race). The
|
|
102
|
+
-- sink's own first lock is this same row in the same order, so the lock set is unchanged;
|
|
103
|
+
-- it is only taken earlier, before reads that lock nothing.
|
|
104
|
+
select bm.membership_state, bm.role
|
|
105
|
+
into v_existing_state, v_target_role
|
|
106
|
+
from agent_board.board_memberships bm
|
|
107
|
+
where bm.board_id = p_board_id
|
|
108
|
+
and bm.agent_id = p_agent_id
|
|
109
|
+
order by
|
|
110
|
+
case when bm.membership_state in ('joined', 'subscribed') then 0 else 1 end,
|
|
111
|
+
bm.created_at desc,
|
|
112
|
+
bm.id desc
|
|
113
|
+
limit 1
|
|
114
|
+
for update;
|
|
115
|
+
if v_existing_state is null then
|
|
116
|
+
raise exception 'board membership not found' using errcode = 'P0002';
|
|
117
|
+
end if;
|
|
118
|
+
|
|
119
|
+
if v_principal_withdraw then
|
|
120
|
+
-- HOSTED (D7): the owner withdraws its own delegate whatever its board role, but ONLY from
|
|
121
|
+
-- the states a self-leave may leave. Never from `removed`: turning an eviction into `left`
|
|
122
|
+
-- would erase the standing R-LINK-7 reads and let the owner re-add the evicted delegate.
|
|
123
|
+
if v_existing_state not in ('joined', 'subscribed', 'invited', 'requested') then
|
|
124
|
+
raise exception 'a principal may withdraw its delegate only from an active or pending membership'
|
|
125
|
+
using errcode = '42501';
|
|
126
|
+
end if;
|
|
127
|
+
elsif not v_is_service then
|
|
128
|
+
if v_actor = p_agent_id then
|
|
129
|
+
if not (
|
|
130
|
+
(p_membership_state = 'left'
|
|
131
|
+
and v_existing_state in ('joined', 'subscribed', 'invited', 'requested'))
|
|
132
|
+
or (p_membership_state in ('joined', 'subscribed')
|
|
133
|
+
and v_existing_state in ('joined', 'subscribed'))
|
|
134
|
+
or (p_membership_state = v_existing_state
|
|
135
|
+
and p_membership_state in ('left', 'removed'))
|
|
136
|
+
) then
|
|
137
|
+
raise exception 'self membership change not permitted; use the join/approval path'
|
|
138
|
+
using errcode = '42501';
|
|
139
|
+
end if;
|
|
140
|
+
else
|
|
141
|
+
if agent_board._role_rank(v_actor_role)
|
|
142
|
+
<= agent_board._role_rank(
|
|
143
|
+
case
|
|
144
|
+
when p_membership_state in ('joined', 'subscribed')
|
|
145
|
+
and coalesce(v_existing_state, '') not in ('joined', 'subscribed')
|
|
146
|
+
then 'member'
|
|
147
|
+
else coalesce(v_target_role, '')
|
|
148
|
+
end) then
|
|
149
|
+
raise exception 'board membership change requires a higher board role than the target'
|
|
150
|
+
using errcode = '42501';
|
|
151
|
+
end if;
|
|
152
|
+
|
|
153
|
+
-- #906 REMOVALSTATE: another actor may not remove a PENDING target. Without this, a
|
|
154
|
+
-- client acting on a stale roster evicted a target that had meanwhile left and been
|
|
155
|
+
-- re-invited, or is `requested`, overriding that newer decision. Pending rows are
|
|
156
|
+
-- cancelled/declined through resolve_board_request (it lands `left`, REJECTSEM #89).
|
|
157
|
+
-- NOT refused: `left` (the documented bar on a departed agent, and R-LINK-7's
|
|
158
|
+
-- order-independent eviction, isolation hosted_delegate_withdraw_evict_race P2) and
|
|
159
|
+
-- `removed` (the LEAVEIDEM no-op below). Spelled as the complement of the permitted prior
|
|
160
|
+
-- states, so a state added later is refused until someone decides otherwise. After the
|
|
161
|
+
-- rank check (a caller that does not outrank the target learns nothing about its state)
|
|
162
|
+
-- and before the sink, so the #669 step-up gate below remains the last statement.
|
|
163
|
+
if p_membership_state = 'removed'
|
|
164
|
+
and v_existing_state not in ('joined', 'subscribed', 'left', 'removed') then
|
|
165
|
+
raise exception 'board membership removal requires an active target membership'
|
|
166
|
+
using errcode = '42501',
|
|
167
|
+
detail = format('current membership state: %s', v_existing_state),
|
|
168
|
+
hint = 'cancel a pending invitation or request with resolve_board_request';
|
|
169
|
+
end if;
|
|
170
|
+
|
|
171
|
+
if p_membership_state in ('joined', 'subscribed')
|
|
172
|
+
and coalesce(v_existing_state, '') not in ('joined', 'subscribed')
|
|
173
|
+
and not agent_board._membership_consent_present(p_board_id, p_agent_id) then
|
|
174
|
+
raise exception 'admitting % requires an act by that agent', p_agent_id
|
|
175
|
+
using errcode = '42501';
|
|
176
|
+
end if;
|
|
177
|
+
|
|
178
|
+
-- INVITEPOLICY (#90): seating an inbound-disclosure membership ('invited'/'requested')
|
|
179
|
+
-- for a target that has blocked THIS actor is refused, mirroring invite_board_member.
|
|
180
|
+
-- Without this, an owner/admin re-seats the exact row the block refuses. Active-admission
|
|
181
|
+
-- states are already consent-gated above; service_role/self never reach this branch.
|
|
182
|
+
if p_membership_state in ('invited', 'requested')
|
|
183
|
+
and not agent_board._invite_permitted(p_board_id, p_agent_id, v_actor) then
|
|
184
|
+
raise exception 'target has blocked invitations from this inviter on this board'
|
|
185
|
+
using errcode = '42501';
|
|
186
|
+
end if;
|
|
187
|
+
end if;
|
|
188
|
+
end if;
|
|
189
|
+
|
|
190
|
+
if not v_is_service
|
|
191
|
+
and p_membership_state = v_existing_state
|
|
192
|
+
and p_membership_state in ('left', 'removed') then
|
|
193
|
+
return query
|
|
194
|
+
select bm.id, bm.board_id, bm.agent_id, bm.membership_state, bm.left_at, bm.updated_at
|
|
195
|
+
from agent_board.board_memberships bm
|
|
196
|
+
where bm.board_id = p_board_id
|
|
197
|
+
and bm.agent_id = p_agent_id
|
|
198
|
+
order by
|
|
199
|
+
case when bm.membership_state in ('joined', 'subscribed') then 0 else 1 end,
|
|
200
|
+
bm.created_at desc,
|
|
201
|
+
bm.id desc
|
|
202
|
+
limit 1;
|
|
203
|
+
return;
|
|
204
|
+
end if;
|
|
205
|
+
|
|
206
|
+
select * into v_membership
|
|
207
|
+
from agent_board._upsert_board_membership_state(
|
|
208
|
+
p_board_id,
|
|
209
|
+
p_agent_id,
|
|
210
|
+
p_membership_state,
|
|
211
|
+
null,
|
|
212
|
+
p_metadata
|
|
213
|
+
);
|
|
214
|
+
|
|
215
|
+
-- #669 STEPUP PR-B (D1, plan §6.2): the step-up check is the LAST statement before the
|
|
216
|
+
-- function returns, after every refusal, the write and the fleet-revocation assert, so every
|
|
217
|
+
-- authorization refusal (22023, P0002, 42501 incl. fleet_revoked: and last-owner) comes first
|
|
218
|
+
-- by construction and MBS01 means "otherwise allowed; confirm it is you". The raise rolls the
|
|
219
|
+
-- whole transaction back. The helper takes no actor: it judges the SESSION (D2).
|
|
220
|
+
-- Q1 as amended by E-5: another actor takes an owner/admin target out of active standing.
|
|
221
|
+
-- Keyed on the target's role and prior state read FOR UPDATE above, and on the state the SINK
|
|
222
|
+
-- RESULTED in, never on the requested state: the #317 sink suppresses an offer (`invited`/
|
|
223
|
+
-- `requested`) over an active row, so a re-invite of an active admin keeps it joined and is
|
|
224
|
+
-- ungated (A-11d), while `removed` or `left` set by another member is gated (R-17/R-17b).
|
|
225
|
+
-- IS DISTINCT FROM: a NULL actor (the operator key) reaches the helper, which exempts it.
|
|
226
|
+
-- coalesce: a NULL resulting state must gate, never pass by three-valued logic.
|
|
227
|
+
if v_actor is distinct from p_agent_id
|
|
228
|
+
and v_target_role in ('owner', 'admin')
|
|
229
|
+
and v_existing_state in ('joined', 'subscribed')
|
|
230
|
+
and coalesce(v_membership.membership_state, '') not in ('joined', 'subscribed') then
|
|
231
|
+
perform agent_board._require_human_step_up('update_board_membership');
|
|
232
|
+
end if;
|
|
233
|
+
|
|
234
|
+
return query
|
|
235
|
+
select v_membership.id, v_membership.board_id, v_membership.agent_id, v_membership.membership_state, v_membership.left_at, v_membership.updated_at;
|
|
236
|
+
end;
|
|
237
|
+
$function$;
|
|
238
|
+
|
|
239
|
+
revoke all on function agent_board.update_board_membership(uuid, uuid, text, jsonb)
|
|
240
|
+
from public, anon, authenticated, service_role, agent_board_delegate;
|
|
241
|
+
grant execute on function agent_board.update_board_membership(uuid, uuid, text, jsonb) to authenticated, service_role;
|
|
242
|
+
comment on function agent_board.update_board_membership(uuid, uuid, text, jsonb) is
|
|
243
|
+
'Authorized membership state transitions with existing self, principal-withdrawal, rank, consent and idempotency rules. Consiliency/message-board#675: board advisory lock before target membership/FK locks; the table refuses any transition removing the last active owner. Consiliency/message-board#906: another (non-service) actor may not set `removed` over a PENDING target: from invited/requested it raises 42501 ''board membership removal requires an active target membership'' (DETAIL the current state, HINT resolve_board_request), after the owner/admin and rank checks and before the write. Cancel or decline a pending row with resolve_board_request (lands left). left -> removed by an outranking owner/admin is unchanged (the bar on a departed agent; R-LINK-7 order-independent eviction), and removed -> removed stays the idempotent no-op. #669 STEPUP PR-B (Q1, E-5): after the membership sink and before the final return, when the actor is not the target, the target''s role (read FOR UPDATE before the write) is owner or admin, its prior state was joined/subscribed and the sink''s RESULTING state is not joined/subscribed, it calls _require_human_step_up(''update_board_membership''), so a human removing an owner/admin, or setting one to left, needs a fresh step-up proof (else MBS01 step_up_required, the transition rolled back). Ordinary members, self transitions, idempotent no-ops and a re-invite the sink suppresses are ungated.';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@consiliency/agent-board-schema",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.80.0",
|
|
4
4
|
"description": "Canonical, immutable, exact-pinnable agent_board schema bundle: ordered SQL migrations, digest + compatibility manifest, and deterministic materialize/plan/check tooling for adopters.",
|
|
5
5
|
"repository": "https://github.com/Consiliency/message-board.git",
|
|
6
6
|
"type": "module",
|
package/schema-manifest.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"schema": "agent_board_schema_manifest.v1",
|
|
3
3
|
"interface": "IF-0-MBPLANE-BUNDLE-1",
|
|
4
4
|
"package": "@consiliency/agent-board-schema",
|
|
5
|
-
"packageVersion": "1.
|
|
5
|
+
"packageVersion": "1.80.0",
|
|
6
6
|
"schemaVersion": 8,
|
|
7
7
|
"minClientVersion": "1.1.0",
|
|
8
8
|
"source": {
|
|
@@ -46,8 +46,8 @@
|
|
|
46
46
|
"usage": "upsert (retention/monitoring defaults; on conflict do nothing)"
|
|
47
47
|
}
|
|
48
48
|
],
|
|
49
|
-
"migrationCount":
|
|
50
|
-
"aggregateSha256": "
|
|
49
|
+
"migrationCount": 178,
|
|
50
|
+
"aggregateSha256": "8f0b8e5d46f72ecb6dcb1e69e95c313c55be39fb79f00fadd5a1afb852018547",
|
|
51
51
|
"migrations": [
|
|
52
52
|
{
|
|
53
53
|
"order": 0,
|
|
@@ -1641,6 +1641,15 @@
|
|
|
1641
1641
|
"sourceRef": "message-board",
|
|
1642
1642
|
"bytes": 78249,
|
|
1643
1643
|
"sha256": "26c02cb8797d059b18f5e81d1db0be237126f48a0598b30e36e683763021384a"
|
|
1644
|
+
},
|
|
1645
|
+
{
|
|
1646
|
+
"order": 177,
|
|
1647
|
+
"id": "20261126000100_agent_board_membership_removal_requires_active",
|
|
1648
|
+
"filename": "20261126000100_agent_board_membership_removal_requires_active.sql",
|
|
1649
|
+
"origin": "message-board-forward",
|
|
1650
|
+
"sourceRef": "message-board",
|
|
1651
|
+
"bytes": 14912,
|
|
1652
|
+
"sha256": "295eb0cd22598b6ee45dd5ccaae7290834131b9eb98e286fe91856abf90dd1ac"
|
|
1644
1653
|
}
|
|
1645
1654
|
],
|
|
1646
1655
|
"excludedBridge": {
|
package/src/tooling.test.mjs
CHANGED
|
@@ -41,9 +41,9 @@ describe('manifest integrity', () => {
|
|
|
41
41
|
expect(manifest.schemaVersion).toBe(8);
|
|
42
42
|
expect(manifest.minClientVersion).toMatch(/^\d+\.\d+\.\d+$/);
|
|
43
43
|
});
|
|
44
|
-
it('registers the four MBAUTHZ + four MBSENDAUTHZ + four MBSESSION + four MBDELEG + three MBFED + three MBHARDEN + two MBPORTALGATE + two MBPORTAL-PR32 + two ROOMOWN + two ROOMLINK + one ROOMDELEG + one LOCALAUTH + one ROOMUIAPI + one FEDSESSION + one FEDSESSION-AUTOJOIN + one GATENULL + one MEMBSTATE + one AGENTSDIR + one LEAVEIDEM + one ROLERESET + one MBROWID + one MBHYGIENE + one MBCONSENT-A + one MBCONSENT-B(a) + one MBCONSENT-B(i) + one MBCONSENT-B(ii) + one MBCONSENT-B(iii) + one MBHARDEN-#97 + one MBHARDEN-#118 + one INVITEPOLICY + one OBSGATE + one OBSGATE-2 + one OBSGATE-3 + one OBSGATE-4 + one FLEETMACHINERLS + one RESOLVENOOP + one ROOMDELEG-LANEB + one CLAIMKEY + two MINTHARDEN + one FLEETMACHINEHIJACK + one CLAIMGATE-SHADOW + one CLAIMGATE-ENFORCE + one FLEETMACHINEREACTIVATION + one DELEGCAPCEILING + one FLEETMACHINERECLAIM + one DELEGSOLEWRITER + one FLEETDOMAINRECLAIM + five ATOMICFLEETONBOARDING (onboarding + ceiling-lock + revocation-evidence + fedsession-gate + fedsession-lock-order) + one OUTBOXWAKE + one ENROLLLOCKORDER + one FEDPROVIDERABSENCE + one WAKERECOVERY + one CONSENTRECONCILE + one ENROLLRESUMPTION + one SIGNEDAUTHORITY + one SIGNERLIFECYCLE + one LEDGERAUTHORITY + one CEILINGLOCKCOMMENT + one LEDGERBOARDCREATE + one RECEIPTSUBJECTGATE + one TASKTHREADLOCKORDER + one CLAIMSUBJECTGATE + one FEDSESSIONIDENTITYGATE + one FEDIDENTITYSLUG + one INVITENODOWNGRADE + one SIGNEDWRITEFLAG + one SIGNEDWRITEMODEL + one RTCREDCLAIM + one ORIGINPOSTURE + one BOARDCLAIMPOLICY + one HEARTBEATPRESERVE + one LIVENESSDENOM + one OWNERLESSRENEWTTL + one OWNERLESSQUOTACENSUS + one FLEETDOMAINNODOWNGRADE + one OWNERLESSQUOTACONVERGE + one ADVISORYREVERTRESET + one CLAIMPOLICYRACE + one CLAIMPOLICYLOCKGRANT + one SESSIONCHALLENGESUPERSEDE + one ROOMCONTRACT + one CALLBACKCONSUMER + one ENROLLTOKENSINGLEUSE + one ROOMCONTRACT-ACTIVEFIRST + one ONBOARD + one HOSTED + one HOSTED-FOLLOWUPS + one OWNPOST + one SIDSCHEMA + one SIDOWNER + one GRANTTARGETROLE (#674) + one LASTOWNER (Consiliency/message-board#675) + one SESSIONPROVENANCE (Consiliency/message-board#665) + one REQUESTREMOVED (Consiliency/message-board#680) + one RLSCORRELATION (Consiliency/message-board#589) + one RESOLUTIONAUTHORITY (Consiliency/message-board#668) + one THREADASSOCIATION checkpoint (#667) + one SIDSERVER-MEASUREDMINT (Consiliency/message-board#653) + one REPLYDELIVERY (#661) + one DELIVERYWRITEREXEC (#717 F1) + one REPLAYSCOPE (#717 F2) + one MESSAGEREPLAYSCOPE (#717 F2b) + one SENDOUTCOME (#670) + one STEPUP-PR-A (#669) + one THREADKEYSERIALIZE (S-12) + one THREADKEYGUARDS (S-12 #815/#816) + one STEPUP-PR-B (#669) forward migrations (migrationCount = prior 113 + 5 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 =
|
|
44
|
+
it('registers the four MBAUTHZ + four MBSENDAUTHZ + four MBSESSION + four MBDELEG + three MBFED + three MBHARDEN + two MBPORTALGATE + two MBPORTAL-PR32 + two ROOMOWN + two ROOMLINK + one ROOMDELEG + one LOCALAUTH + one ROOMUIAPI + one FEDSESSION + one FEDSESSION-AUTOJOIN + one GATENULL + one MEMBSTATE + one AGENTSDIR + one LEAVEIDEM + one ROLERESET + one MBROWID + one MBHYGIENE + one MBCONSENT-A + one MBCONSENT-B(a) + one MBCONSENT-B(i) + one MBCONSENT-B(ii) + one MBCONSENT-B(iii) + one MBHARDEN-#97 + one MBHARDEN-#118 + one INVITEPOLICY + one OBSGATE + one OBSGATE-2 + one OBSGATE-3 + one OBSGATE-4 + one FLEETMACHINERLS + one RESOLVENOOP + one ROOMDELEG-LANEB + one CLAIMKEY + two MINTHARDEN + one FLEETMACHINEHIJACK + one CLAIMGATE-SHADOW + one CLAIMGATE-ENFORCE + one FLEETMACHINEREACTIVATION + one DELEGCAPCEILING + one FLEETMACHINERECLAIM + one DELEGSOLEWRITER + one FLEETDOMAINRECLAIM + five ATOMICFLEETONBOARDING (onboarding + ceiling-lock + revocation-evidence + fedsession-gate + fedsession-lock-order) + one OUTBOXWAKE + one ENROLLLOCKORDER + one FEDPROVIDERABSENCE + one WAKERECOVERY + one CONSENTRECONCILE + one ENROLLRESUMPTION + one SIGNEDAUTHORITY + one SIGNERLIFECYCLE + one LEDGERAUTHORITY + one CEILINGLOCKCOMMENT + one LEDGERBOARDCREATE + one RECEIPTSUBJECTGATE + one TASKTHREADLOCKORDER + one CLAIMSUBJECTGATE + one FEDSESSIONIDENTITYGATE + one FEDIDENTITYSLUG + one INVITENODOWNGRADE + one SIGNEDWRITEFLAG + one SIGNEDWRITEMODEL + one RTCREDCLAIM + one ORIGINPOSTURE + one BOARDCLAIMPOLICY + one HEARTBEATPRESERVE + one LIVENESSDENOM + one OWNERLESSRENEWTTL + one OWNERLESSQUOTACENSUS + one FLEETDOMAINNODOWNGRADE + one OWNERLESSQUOTACONVERGE + one ADVISORYREVERTRESET + one CLAIMPOLICYRACE + one CLAIMPOLICYLOCKGRANT + one SESSIONCHALLENGESUPERSEDE + one ROOMCONTRACT + one CALLBACKCONSUMER + one ENROLLTOKENSINGLEUSE + one ROOMCONTRACT-ACTIVEFIRST + one ONBOARD + one HOSTED + one HOSTED-FOLLOWUPS + one OWNPOST + one SIDSCHEMA + one SIDOWNER + one GRANTTARGETROLE (#674) + one LASTOWNER (Consiliency/message-board#675) + one SESSIONPROVENANCE (Consiliency/message-board#665) + one REQUESTREMOVED (Consiliency/message-board#680) + one RLSCORRELATION (Consiliency/message-board#589) + one RESOLUTIONAUTHORITY (Consiliency/message-board#668) + one THREADASSOCIATION checkpoint (#667) + one SIDSERVER-MEASUREDMINT (Consiliency/message-board#653) + one REPLYDELIVERY (#661) + one DELIVERYWRITEREXEC (#717 F1) + one REPLAYSCOPE (#717 F2) + one MESSAGEREPLAYSCOPE (#717 F2b) + one SENDOUTCOME (#670) + one STEPUP-PR-A (#669) + one THREADKEYSERIALIZE (S-12) + one THREADKEYGUARDS (S-12 #815/#816) + one STEPUP-PR-B (#669) + one REMOVALSTATE (#906) forward migrations (migrationCount = prior 113 + 5 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 = 178)', () => {
|
|
45
45
|
expect(manifest.migrationCount).toBe(manifest.migrations.length);
|
|
46
|
-
expect(manifest.migrationCount).toBe(
|
|
46
|
+
expect(manifest.migrationCount).toBe(178);
|
|
47
47
|
// MBSESSION switched enforcement on (scoped-send re-grant): the client-visible
|
|
48
48
|
// schema version bumped to 8. MBDELEG tightens delegation and MBFED adds only
|
|
49
49
|
// enrollment-only additive surface (identity_providers registry, enrollment audit,
|
|
@@ -383,6 +383,8 @@ describe('manifest integrity', () => {
|
|
|
383
383
|
// #669 PR-B: step-up enforcement on the gated conferral routes (renamed from 20261120000100
|
|
384
384
|
// when refreshed onto main, so it sorts after the S-12 migrations).
|
|
385
385
|
'20261124000100_agent_board_step_up_enforcement.sql',
|
|
386
|
+
// #906: update_board_membership(..., 'removed') by another actor requires an active target.
|
|
387
|
+
'20261126000100_agent_board_membership_removal_requires_active.sql',
|
|
386
388
|
]) {
|
|
387
389
|
expect(names.has(f)).toBe(true);
|
|
388
390
|
}
|
|
@@ -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;
|