@consiliency/agent-board-schema 1.76.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 +16 -0
- package/migrations/20261120000200_agent_board_thread_key_serialize.sql +118 -0
- package/migrations/20261121000100_agent_board_thread_key_guards.sql +196 -0
- package/migrations/20261124000100_agent_board_step_up_enforcement.sql +1213 -0
- package/migrations/20261126000100_agent_board_membership_removal_requires_active.sql +243 -0
- package/package.json +1 -1
- package/schema-manifest.json +39 -3
- package/src/deployment-drift-main.test.mjs +89 -6
- package/src/deployment-drift.test.mjs +20 -1
- package/src/tooling.test.mjs +11 -2
- package/tests/agent_board_717_message_replay_scope.test.sql +39 -2
- package/tests/agent_board_717_tasking_replay_scope.test.sql +21 -2
- package/tests/agent_board_membership_removal_state.test.sql +228 -0
- package/tests/agent_board_role_guard.test.sql +3 -1
- package/tests/agent_board_send_outcome.test.sql +39 -1
- package/tests/agent_board_session_identity_approval_revocation.test.sql +5 -0
- package/tests/agent_board_step_up.test.sql +991 -0
- package/tests/agent_board_step_up_helper.test.sql +132 -28
- package/tests/agent_board_thread_key_guards.test.sql +186 -0
- package/tests/agent_board_thread_key_serialize.test.sql +182 -0
- package/tests/agent_board_write_enforcement_class.test.sql +3 -2
- package/tests/catalog/step_up_gated_closure.json +24 -0
- package/tests/fixtures/pgtap-unexposed.sql +9 -4
- package/tests/isolation/expected/create_or_find_thread_same_key_race.out +641 -0
- package/tests/isolation/expected/session_identity_links.out +4 -0
- package/tests/isolation/specs/create_or_find_thread_same_key_race.spec +252 -0
- package/tests/isolation/specs/session_identity_links.spec +5 -0
- package/tests/mutations/669/run.sh +12 -4
- package/tests/mutations/669b/M11_ceil_first.sql +10 -0
- package/tests/mutations/669b/M11_gate_first.sql +10 -0
- package/tests/mutations/669b/M11_grant_first.sql +10 -0
- package/tests/mutations/669b/M11_inv_first.sql +10 -0
- package/tests/mutations/669b/M11_mem_first.sql +10 -0
- package/tests/mutations/669b/M11_readmit_first.sql +10 -0
- package/tests/mutations/669b/M13a_gate_member_preset.sql +12 -0
- package/tests/mutations/669b/M13b_ungate_admin_preset.sql +12 -0
- package/tests/mutations/669b/M16_actor_is_target.sql +14 -0
- package/tests/mutations/669b/M19_drop_readmit.sql +9 -0
- package/tests/mutations/669b/M1_drop_grant.sql +9 -0
- package/tests/mutations/669b/M20_drop_d5_refusal.sql +9 -0
- package/tests/mutations/669b/M21_drop_removal.sql +9 -0
- package/tests/mutations/669b/M21b_only_removed.sql +9 -0
- package/tests/mutations/669b/M21c_gate_members.sql +12 -0
- package/tests/mutations/669b/M21d_requested_state.sql +9 -0
- package/tests/mutations/669b/M23b_api_wrapper_over_audit_writer.sql +6 -0
- package/tests/mutations/669b/M23c_drop_register_type_refusal.sql +9 -0
- package/tests/mutations/669b/M24_drop_kind_refusal.sql +9 -0
- package/tests/mutations/669b/M24b_drop_auth_bind_refusal.sql +9 -0
- package/tests/mutations/669b/M2a_drop_gate.sql +9 -0
- package/tests/mutations/669b/M2b_drop_ceiling.sql +9 -0
- package/tests/mutations/669b/M2c_drop_invite.sql +9 -0
- package/tests/mutations/669b/MAL2_drop_otp.sql +9 -0
- package/tests/mutations/669b/MAL3_admit_passkey.sql +9 -0
- package/tests/mutations/669b/MD7a_no_revocation.sql +2 -0
- package/tests/mutations/669b/MD7b_overwrite_revoked.sql +2 -0
- package/tests/mutations/669b/MD7c_revoke_members.sql +2 -0
- package/tests/mutations/669b/MD7d_revoke_expired.sql +2 -0
- package/tests/mutations/669b/ME1_wrapper_over_gate.sql +7 -0
- package/tests/mutations/669b/MEC2_write_after_helper.sql +10 -0
- package/tests/mutations/669b/MQX_query_to_xml_definer.sql +6 -0
- package/tests/mutations/669b/MQXb_ts_stat_other_schema.sql +4 -0
- package/tests/mutations/669b/MTR_trigger_route.sql +9 -0
- package/tests/mutations/669b/MTRb_new_assign.sql +11 -0
- package/tests/mutations/669b/MTRc_sync_assigns_value.sql +47 -0
- package/tests/mutations/669b/MTX1_tombstone_second_gated_call.sql +15 -0
- package/tests/mutations/669b/MTX2_tombstone_non_delegate_target.sql +10 -0
- package/tests/mutations/669b/MXS_other_schema_names_gated.sql +5 -0
- package/tests/mutations/669b/run.sh +83 -0
- package/tests/mutations/670/M18a_read_operation_default_dropped.sql +11 -0
- package/tests/mutations/670/M18b_read_operation_default_changed.sql +7 -0
- package/tests/mutations/670/M3-DM_helper_on_replay_branch.sql +10 -0
- package/tests/mutations/670/M3-MC_helper_on_replay_branch.sql +10 -0
- package/tests/mutations/s12/M0_identity.sql +56 -0
- package/tests/mutations/s12/M1_serialise_actor_key.sql +57 -0
- package/tests/mutations/s12/M1b_serialise_key_only.sql +57 -0
- package/tests/mutations/s12/M2_unique_index_no_handler.sql +9 -0
- package/tests/mutations/s12/M3_no_trim.sql +56 -0
- package/tests/mutations/s12/M4_casefold.sql +56 -0
- package/tests/mutations/s12/M5_lookup_ignores_actor.sql +56 -0
- package/tests/mutations/s12/M6_reuse_reports_false.sql +56 -0
- package/tests/mutations/s12/run.sh +112 -0
- package/tests/mutations/s12-fix/M0_identity.sql +83 -0
- package/tests/mutations/s12-fix/M10_security_invoker.sql +9 -0
- package/tests/mutations/s12-fix/M11_search_path_changed.sql +9 -0
- package/tests/mutations/s12-fix/M12_reuse_writes_task.sql +84 -0
- package/tests/mutations/s12-fix/M13_dead_inbox_write.sql +84 -0
- package/tests/mutations/s12-fix/M14_metadata_unchecked.sql +78 -0
- package/tests/mutations/s12-fix/M15_metadata_check_after_lock.sql +84 -0
- package/tests/mutations/s12-fix/M16_sql_null_metadata_refused.sql +83 -0
- package/tests/mutations/s12-fix/M17_isolation_unchecked.sql +70 -0
- package/tests/mutations/s12-fix/M18_isolation_check_after_lock.sql +82 -0
- package/tests/mutations/s12-fix/M19_isolation_rr_only.sql +83 -0
- package/tests/mutations/s12-fix/M1_lock_dropped.sql +78 -0
- package/tests/mutations/s12-fix/M1b_lock_key_only.sql +83 -0
- package/tests/mutations/s12-fix/M20_isolation_unsafe_levels_only.sql +83 -0
- package/tests/mutations/s12-fix/M21_isolation_check_miss_path_only.sql +83 -0
- package/tests/mutations/s12-fix/M22_isolation_inverted.sql +83 -0
- package/tests/mutations/s12-fix/M23_isolation_wrong_sqlstate.sql +83 -0
- package/tests/mutations/s12-fix/M24_create_thread_key_unchecked.sql +37 -0
- package/tests/mutations/s12-fix/M25_create_thread_key_nonnull_only.sql +45 -0
- package/tests/mutations/s12-fix/M26_create_thread_key_casefold.sql +45 -0
- package/tests/mutations/s12-fix/M27_create_thread_no_object_guard.sql +45 -0
- package/tests/mutations/s12-fix/M28_create_thread_key_stripped.sql +40 -0
- package/tests/mutations/s12-fix/M29_create_thread_key_nested_refused.sql +45 -0
- package/tests/mutations/s12-fix/M2_lock_actor_only.sql +83 -0
- package/tests/mutations/s12-fix/M30_create_thread_security_invoker.sql +9 -0
- package/tests/mutations/s12-fix/M31_create_thread_search_path_changed.sql +9 -0
- package/tests/mutations/s12-fix/M32_class_new_thread_inserter.sql +14 -0
- package/tests/mutations/s12-fix/M33_class_metadata_update.sql +12 -0
- package/tests/mutations/s12-fix/M33b_class_metadata_update_upper.sql +17 -0
- package/tests/mutations/s12-fix/M33c_class_metadata_update_row_form.sql +16 -0
- package/tests/mutations/s12-fix/M33d_class_metadata_merge_update.sql +16 -0
- package/tests/mutations/s12-fix/M33e_class_metadata_upsert.sql +16 -0
- package/tests/mutations/s12-fix/M34_class_api_role_insert.sql +9 -0
- package/tests/mutations/s12-fix/M3_lock_after_lookup.sql +83 -0
- package/tests/mutations/s12-fix/M4_lock_raw_key.sql +83 -0
- package/tests/mutations/s12-fix/M5_no_trim.sql +83 -0
- package/tests/mutations/s12-fix/M6_casefold.sql +83 -0
- package/tests/mutations/s12-fix/M7_lookup_ignores_actor.sql +82 -0
- package/tests/mutations/s12-fix/M8_reuse_reports_false.sql +83 -0
- package/tests/mutations/s12-fix/M9_blank_key_admitted.sql +83 -0
- package/tests/mutations/s12-fix/run.sh +288 -0
- package/tests/seeds/20261124000100_agent_board_step_up_enforcement.sql.pre.sql +47 -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;
|
|
@@ -291,7 +291,9 @@ select is((select count(*)::int from pg_proc p,aclexplode(coalesce(p.proacl,acld
|
|
|
291
291
|
|
|
292
292
|
select isnt(obj_description(to_regprocedure('agent_board._board_memberships_last_owner_guard()'),'pg_proc'),null,'CLASS-trigger COMMENT exists');
|
|
293
293
|
|
|
294
|
-
|
|
294
|
+
-- Re-pinned by #669 PR-B (20261124000100): the only body change is the step-up helper call before
|
|
295
|
+
-- the final return; agent_board_step_up.test.sql EC-SU-2 pins that edit and its placement.
|
|
296
|
+
select is((select md5(prosrc) from pg_proc where oid=to_regprocedure('agent_board.grant_board_role(uuid,uuid,text,uuid)')),'f0532a5864ed03f5d432c0846fa8acba','CLASS-main grant body unchanged'); -- pgtap-allow-raise-checked: non-raising catalog identity lookup; no RPC is executed.
|
|
295
297
|
|
|
296
298
|
select ok(strpos(agent_board_test.stripped_body('agent_board.update_board_membership(uuid,uuid,text,jsonb)'::regprocedure),'agent_board._lock_board_authority_ceiling(')>0 and strpos(agent_board_test.stripped_body('agent_board.update_board_membership(uuid,uuid,text,jsonb)'::regprocedure),'agent_board._lock_board_authority_ceiling(')<strpos(agent_board_test.stripped_body('agent_board.update_board_membership(uuid,uuid,text,jsonb)'::regprocedure),'for update'),'CLASS-departure advisory before membership row lock');
|
|
297
299
|
|
|
@@ -20,12 +20,14 @@
|
|
|
20
20
|
-- * Mutation labels: SO-M<n> is the assertion the D11 mutant M<n> must turn red (M9 and M10 are
|
|
21
21
|
-- isolation controls, tests/isolation/specs/send_outcome_*.spec). Receipts are in
|
|
22
22
|
-- plans/evidence/670/.
|
|
23
|
+
-- SO-M3-DM, SO-M3-MC and SO-M18 (#780, #778) are the targets of mutants M3-DM, M3-MC and
|
|
24
|
+
-- M18a/M18b.
|
|
23
25
|
create extension if not exists pgtap with schema extensions;
|
|
24
26
|
set search_path = extensions, public, agent_board;
|
|
25
27
|
|
|
26
28
|
begin;
|
|
27
29
|
|
|
28
|
-
select plan(
|
|
30
|
+
select plan(104);
|
|
29
31
|
|
|
30
32
|
grant usage on schema extensions to authenticated, service_role, anon;
|
|
31
33
|
do $$
|
|
@@ -801,5 +803,41 @@ select is((select count(*)::int from agent_board.send_outcomes where author_agen
|
|
|
801
803
|
select is(pg_temp.read('O', 'TY', 'K1'), pg_temp.confirmed('M.O.TY', 'post_board_message', 'Y'),
|
|
802
804
|
'SO-D5-2: the other author reads its own same-key receipt confirmed');
|
|
803
805
|
|
|
806
|
+
-- ===========================================================================
|
|
807
|
+
-- Follow-ups #778 and #780. Appended here so the assertion numbers above do not move.
|
|
808
|
+
-- ===========================================================================
|
|
809
|
+
-- #778: p_operation's SQL default. Every read above passes three arguments, so none of them
|
|
810
|
+
-- reaches the default. This is the named two-argument form a PostgREST caller sends. Without the
|
|
811
|
+
-- default it is 42883 (mutant M18a); with another default it reads K1 under the wrong operation
|
|
812
|
+
-- (mutant M18b).
|
|
813
|
+
select lives_ok(
|
|
814
|
+
format('select pg_temp.raise_as(%L, %L)', 'A',
|
|
815
|
+
format('select * from agent_board.get_send_outcome(p_thread_id => %L::uuid, p_idempotency_key => %L)', pg_temp.v('TX'), 'K1')),
|
|
816
|
+
'SO-DEF-1: a named two-argument read (no p_operation) lives');
|
|
817
|
+
select is(
|
|
818
|
+
pg_temp.val('A', format('select r::text from agent_board.get_send_outcome(p_thread_id => %L::uuid, p_idempotency_key => %L) r', pg_temp.v('TX'), 'K1')),
|
|
819
|
+
pg_temp.confirmed('M.K1', 'post_board_message', 'X'),
|
|
820
|
+
'SO-M18: a named two-argument read defaults p_operation to post_board_message and reads confirmed');
|
|
821
|
+
|
|
822
|
+
-- #780: SO-M3's replay claim for the two private cores (mutants M3-DM, M3-MC). service_role
|
|
823
|
+
-- creates a keyed direct and a keyed multicast message naming A; A's session then replays each
|
|
824
|
+
-- with the same key and the same recipients, which #717 F2b permits because every recipient
|
|
825
|
+
-- already holds the private delivery. The replay must return the original id and mint nothing.
|
|
826
|
+
-- The leading uuid check keeps two identical errors from reading as "the same id".
|
|
827
|
+
select pg_temp.put('M.RPD.svc', pg_temp.val('SVC', pg_temp.dm('A', 'TD', 'R', 'KRPD')));
|
|
828
|
+
select pg_temp.put('M.RPD.session', pg_temp.val('A', pg_temp.dm('A', 'TD', 'R', 'KRPD')));
|
|
829
|
+
select is(
|
|
830
|
+
(pg_temp.u('M.RPD.svc') is not null)::text || ' ' || (pg_temp.v('M.RPD.session') = pg_temp.v('M.RPD.svc'))::text
|
|
831
|
+
|| ' ' || pg_temp.receipts_key('A', 'KRPD') || ' ' || pg_temp.read('A', 'TD', 'KRPD', 'send_direct_message'),
|
|
832
|
+
'true true 0 (unknown,,,,,)',
|
|
833
|
+
'SO-M3-DM: a session replay of a service_role-created direct message returns the original id and still reads unknown');
|
|
834
|
+
select pg_temp.put('M.RPM.svc', pg_temp.val('SVC', pg_temp.mc('A', 'TD', 'KRPM', 'R', 'R2')));
|
|
835
|
+
select pg_temp.put('M.RPM.session', pg_temp.val('A', pg_temp.mc('A', 'TD', 'KRPM', 'R', 'R2')));
|
|
836
|
+
select is(
|
|
837
|
+
(pg_temp.u('M.RPM.svc') is not null)::text || ' ' || (pg_temp.v('M.RPM.session') = pg_temp.v('M.RPM.svc'))::text
|
|
838
|
+
|| ' ' || pg_temp.receipts_key('A', 'KRPM') || ' ' || pg_temp.read('A', 'TD', 'KRPM', 'send_multicast_message'),
|
|
839
|
+
'true true 0 (unknown,,,,,)',
|
|
840
|
+
'SO-M3-MC: a session replay of a service_role-created multicast message returns the original id and still reads unknown');
|
|
841
|
+
|
|
804
842
|
select * from finish();
|
|
805
843
|
rollback;
|
|
@@ -157,6 +157,11 @@ select is((select count(*) from _sid_readmit_result), 0::bigint,
|
|
|
157
157
|
delete from agent_board.fleet_revocation_events where revocation_reason = 'sid-readmit-owner-ledger-control'
|
|
158
158
|
and subject_id = (select id from agent_board.agents where auth_user_id = (select owner_auth from _sid_readmit_root));
|
|
159
159
|
set local role authenticated;
|
|
160
|
+
-- #669 PR-B (D4): readmitting above member is step-up gated. The human owner is a LOCALAUTH
|
|
161
|
+
-- principal, so it presents a fresh allowlisted amr (totp) in request.jwt.claims; auth.uid() still
|
|
162
|
+
-- comes from the legacy sub GUC set above. agent_board_step_up.test.sql pins the gate itself (R-15).
|
|
163
|
+
select set_config('request.jwt.claims', json_build_object('amr', json_build_array(json_build_object(
|
|
164
|
+
'method', 'totp', 'timestamp', floor(extract(epoch from clock_timestamp()))::bigint)))::text, true);
|
|
160
165
|
select lives_ok($q$select pg_temp.sid_readmit('fork', 'allowed', '["read"]', 'admin')$q$,
|
|
161
166
|
'EC-SIDSCHEMA-5-readmit-owner: authenticated human owner mints the selected successor');
|
|
162
167
|
reset role;
|