@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,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,
|
|
@@ -1614,6 +1614,42 @@
|
|
|
1614
1614
|
"sourceRef": "message-board",
|
|
1615
1615
|
"bytes": 16604,
|
|
1616
1616
|
"sha256": "ce1a878aa752f2f7047958984019030ac7d4c2244c114113e52c8a2abc6dd9d9"
|
|
1617
|
+
},
|
|
1618
|
+
{
|
|
1619
|
+
"order": 174,
|
|
1620
|
+
"id": "20261120000200_agent_board_thread_key_serialize",
|
|
1621
|
+
"filename": "20261120000200_agent_board_thread_key_serialize.sql",
|
|
1622
|
+
"origin": "message-board-forward",
|
|
1623
|
+
"sourceRef": "message-board",
|
|
1624
|
+
"bytes": 7075,
|
|
1625
|
+
"sha256": "5eaf5e3af345d4c0913a99491f5fb4d2b1109152f669a752e401b6027d484639"
|
|
1626
|
+
},
|
|
1627
|
+
{
|
|
1628
|
+
"order": 175,
|
|
1629
|
+
"id": "20261121000100_agent_board_thread_key_guards",
|
|
1630
|
+
"filename": "20261121000100_agent_board_thread_key_guards.sql",
|
|
1631
|
+
"origin": "message-board-forward",
|
|
1632
|
+
"sourceRef": "message-board",
|
|
1633
|
+
"bytes": 11249,
|
|
1634
|
+
"sha256": "0921646160fd23878162d6d053c2ac2631ccb8d80d96c98dfffe58a8a627dd8f"
|
|
1635
|
+
},
|
|
1636
|
+
{
|
|
1637
|
+
"order": 176,
|
|
1638
|
+
"id": "20261124000100_agent_board_step_up_enforcement",
|
|
1639
|
+
"filename": "20261124000100_agent_board_step_up_enforcement.sql",
|
|
1640
|
+
"origin": "message-board-forward",
|
|
1641
|
+
"sourceRef": "message-board",
|
|
1642
|
+
"bytes": 78249,
|
|
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"
|
|
1617
1653
|
}
|
|
1618
1654
|
],
|
|
1619
1655
|
"excludedBridge": {
|
|
@@ -39,23 +39,25 @@ function installChecker(dir) {
|
|
|
39
39
|
copyFileSync(join(ROOT, "scripts", file), join(dir, "scripts", file));
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
|
-
|
|
42
|
+
// `mainFiles` land in main's tip commit, `proposalFiles` in the unmerged proposal: { path: text }.
|
|
43
|
+
function fixture({ mainFiles = {}, proposalFiles = {} } = {}) {
|
|
43
44
|
const root = mkdtempSync(join(tmpdir(), "drift-main-")); roots.push(root);
|
|
44
45
|
const dir = join(root, "checkout"); mkdirSync(join(dir, PKG), { recursive: true });
|
|
45
46
|
git(dir, ["init", "-q", "-b", "main"]);
|
|
46
|
-
const commit = (version, date, description = "original") => {
|
|
47
|
+
const commit = (version, date, description = "original", extra = {}) => {
|
|
47
48
|
writeFileSync(join(dir, PKG, "package.json"), JSON.stringify({ name: "@consiliency/agent-board-schema", version, description }, null, 2));
|
|
48
49
|
writeFileSync(join(dir, PKG, "schema-manifest.json"), JSON.stringify({ schemaVersion: 8, aggregateSha256: `digest-${version}` }));
|
|
49
|
-
|
|
50
|
+
for (const [path, text] of Object.entries(extra)) writeFileSync(join(dir, path), text);
|
|
51
|
+
git(dir, ["add", PKG, ...Object.keys(extra)]);
|
|
50
52
|
git(dir, ["-c", "user.name=fixture", "-c", "user.email=fixture@example.invalid", "commit", "-qm", version + description],
|
|
51
53
|
{ GIT_AUTHOR_DATE: date, GIT_COMMITTER_DATE: date });
|
|
52
54
|
return git(dir, ["rev-parse", "HEAD"]);
|
|
53
55
|
};
|
|
54
56
|
commit("1.63.0", "2026-01-01T00:00:00Z");
|
|
55
57
|
commit("1.64.0", stamp);
|
|
56
|
-
const main = commit("1.64.0", "2026-01-04T00:00:00Z", "adjacent edit");
|
|
58
|
+
const main = commit("1.64.0", "2026-01-04T00:00:00Z", "adjacent edit", mainFiles);
|
|
57
59
|
git(dir, ["switch", "-qc", "proposal"]);
|
|
58
|
-
const proposal = commit("1.65.0", "2026-01-05T00:00:00Z", "unmerged proposal");
|
|
60
|
+
const proposal = commit("1.65.0", "2026-01-05T00:00:00Z", "unmerged proposal", proposalFiles);
|
|
59
61
|
// A cached tracking branch deliberately lies. CI must use the event's base SHA.
|
|
60
62
|
git(dir, ["update-ref", "refs/remotes/origin/main", proposal]);
|
|
61
63
|
// A real local remote supplies operator truth without any network/service access.
|
|
@@ -63,7 +65,9 @@ function fixture() {
|
|
|
63
65
|
git(dir, ["remote", "add", "origin", remote]);
|
|
64
66
|
installChecker(dir);
|
|
65
67
|
const shims = join(root, "bin"); mkdirSync(shims);
|
|
66
|
-
|
|
68
|
+
// `npm view <pkg> dist-tags|time --json` answer from DIST_TAGS / TIMES and fail when unset, so a
|
|
69
|
+
// test that sets neither sees exactly the old shim (#799).
|
|
70
|
+
writeFileSync(join(shims, "npm"), '#!/bin/sh\ncase " $* " in\n *" dist-tags "*) [ -n "${DIST_TAGS:-}" ] || exit 1; printf "%s\\n" "$DIST_TAGS"; exit 0 ;;\n *" time "*) [ -n "${TIMES:-}" ] || exit 1; printf "%s\\n" "$TIMES"; exit 0 ;;\nesac\nprintf "%s\\n" "$PUBLISHED"\n'); chmodSync(join(shims, "npm"), 0o755);
|
|
67
71
|
const preload = join(root, "no-network.mjs");
|
|
68
72
|
writeFileSync(preload, 'globalThis.fetch = async () => ({ ok: true, json: async () => [JSON.parse(process.env.BOARD_ROW)] });');
|
|
69
73
|
const eventPath = join(root, "event.json");
|
|
@@ -171,3 +175,82 @@ describe("authoritative main, independent of the checked-out proposal", () => {
|
|
|
171
175
|
expectUnknown(f.run({ env: { GITHUB_ACTIONS: "false" } }));
|
|
172
176
|
});
|
|
173
177
|
});
|
|
178
|
+
|
|
179
|
+
// #799. The channel grace must read MAIN's release-dist-tags.json. Switching that read to `HEAD:`
|
|
180
|
+
// left 108/108 green, because every other test serves the file through a shim that ignores the
|
|
181
|
+
// revision; only a real-git probe sees it. Here main is 1.64.0, `latest` is 1.63.0 with main's bump
|
|
182
|
+
// months old (the ordinary rule says DRIFT), and the registry has 1.64.0 on `next`, published
|
|
183
|
+
// yesterday. The only variable is WHICH commit declares `next`.
|
|
184
|
+
describe("the channel grace reads main's release-dist-tags.json, never the checkout's (#799)", () => {
|
|
185
|
+
const DECLARED = {
|
|
186
|
+
"release-dist-tags.json": JSON.stringify({ releases: { "v9.9.9": { distTag: "next", reason: "fixture: held back on next for the #799 probe" } } }),
|
|
187
|
+
"CHANGELOG.md": "# Changelog\n\n## v9.9.9 — fixture\n\nnpm dist-tag: `next`\n",
|
|
188
|
+
};
|
|
189
|
+
const registry = (publishedMs) => ({
|
|
190
|
+
PUBLISHED: "1.63.0",
|
|
191
|
+
DIST_TAGS: JSON.stringify({ latest: "1.63.0", next: "1.64.0" }),
|
|
192
|
+
TIMES: JSON.stringify({ "1.63.0": "2026-01-01T00:00:00.000Z", "1.64.0": new Date(publishedMs).toISOString() }),
|
|
193
|
+
});
|
|
194
|
+
const yesterday = () => Date.now() - 86_400_000;
|
|
195
|
+
const checkoutAt = (f, checkout) => {
|
|
196
|
+
if (checkout === "merge") {
|
|
197
|
+
git(f.dir, ["switch", "-qc", "merge", f.main]);
|
|
198
|
+
git(f.dir, ["-c", "user.name=fixture", "-c", "user.email=fixture@example.invalid", "merge", "--no-ff", "-qm", "PR merge", "proposal"]);
|
|
199
|
+
}
|
|
200
|
+
return git(f.dir, ["rev-parse", "HEAD"]);
|
|
201
|
+
};
|
|
202
|
+
|
|
203
|
+
// The declaration is TWO files, validated together, so each must be read at main on its own.
|
|
204
|
+
// With only the dist-tags read moved to HEAD, a PR adding both files stayed green — main's
|
|
205
|
+
// missing CHANGELOG line failed validation anyway. Hence three splits: each one catches a
|
|
206
|
+
// mutation the others miss (measured; see the #799 commit).
|
|
207
|
+
const SPLITS = {
|
|
208
|
+
"both files in the PR": { mainFiles: {}, proposalFiles: DECLARED },
|
|
209
|
+
"only the dist-tags entry in the PR (main already carries the CHANGELOG line)": {
|
|
210
|
+
mainFiles: { "CHANGELOG.md": DECLARED["CHANGELOG.md"] },
|
|
211
|
+
proposalFiles: { "release-dist-tags.json": DECLARED["release-dist-tags.json"] },
|
|
212
|
+
},
|
|
213
|
+
"only the CHANGELOG line in the PR (main already carries the dist-tags entry)": {
|
|
214
|
+
mainFiles: { "release-dist-tags.json": DECLARED["release-dist-tags.json"] },
|
|
215
|
+
proposalFiles: { "CHANGELOG.md": DECLARED["CHANGELOG.md"] },
|
|
216
|
+
},
|
|
217
|
+
};
|
|
218
|
+
const arms = Object.keys(SPLITS).flatMap((split) => ["proposal", "merge"].map((checkout) => [split, checkout]));
|
|
219
|
+
|
|
220
|
+
it.each(arms)("a PR that declares its own channel still drifts: %s (%s checkout)", (split, checkout) => {
|
|
221
|
+
const f = fixture(SPLITS[split]);
|
|
222
|
+
const head = checkoutAt(f, checkout);
|
|
223
|
+
// The checkout really carries the full declaration; main really lacks the PR's half of it.
|
|
224
|
+
for (const path of Object.keys(DECLARED)) expect(readFileSync(join(f.dir, path), "utf8")).toBe(DECLARED[path]);
|
|
225
|
+
for (const path of Object.keys(SPLITS[split].proposalFiles)) {
|
|
226
|
+
expect(spawnSync("git", ["cat-file", "-e", `${f.main}:${path}`], { cwd: f.dir }).status).not.toBe(0);
|
|
227
|
+
}
|
|
228
|
+
const r = f.run({ env: { GITHUB_SHA: head, ...registry(yesterday()) } });
|
|
229
|
+
expect(r.status).toBe(1);
|
|
230
|
+
expect(r.doc.status).toBe("drift");
|
|
231
|
+
expect(r.doc.facts.mergedCommit).toBe(f.main);
|
|
232
|
+
expect(r.doc.facts.channels ?? null).toBeNull();
|
|
233
|
+
expect(r.out).toMatch(/1 schema version\(s\) merged but NOT published/);
|
|
234
|
+
expect(r.out).not.toMatch(/declared dist-tag/);
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
it.each(["proposal", "merge"])("control: the same declaration on MAIN reaches the grace (%s checkout)", (checkout) => {
|
|
238
|
+
const f = fixture({ mainFiles: DECLARED });
|
|
239
|
+
const head = checkoutAt(f, checkout);
|
|
240
|
+
const r = f.run({ env: { GITHUB_SHA: head, ...registry(yesterday()) } });
|
|
241
|
+
expect(r.status).toBe(0);
|
|
242
|
+
expect(r.doc.status).toBe("ok");
|
|
243
|
+
expect(r.doc.facts.channels?.next?.version).toBe("1.64.0");
|
|
244
|
+
expect(r.out).toMatch(/published under the declared dist-tag `next` \(latest is 1\.63\.0\)/);
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
it("a future-dated publish time on main's declared channel gets no grace", () => {
|
|
248
|
+
const f = fixture({ mainFiles: DECLARED });
|
|
249
|
+
const r = f.run({ env: registry(Date.now() + 30 * 86_400_000) });
|
|
250
|
+
expect(r.status).toBe(1);
|
|
251
|
+
expect(r.doc.status).toBe("drift");
|
|
252
|
+
expect(r.doc.facts.channels?.next?.version).toBe("1.64.0");
|
|
253
|
+
expect(r.out).toMatch(/1 schema version\(s\) merged but NOT published/);
|
|
254
|
+
expect(r.out).not.toMatch(/published under the declared dist-tag/);
|
|
255
|
+
});
|
|
256
|
+
});
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
// whole PR exists for — is NOT exercised here. It is exercised as a subprocess in
|
|
28
28
|
// deployment-drift-script.test.mjs, because none of it is reachable through `evaluate()`.
|
|
29
29
|
import { describe, it, expect } from "vitest";
|
|
30
|
-
import { evaluate, minorGap, pgTimestampToIso, OK, DRIFT, UNKNOWN } from "../../../scripts/lib/drift-evaluate.mjs";
|
|
30
|
+
import { evaluate, minorGap, onDeclaredChannel, pgTimestampToIso, OK, DRIFT, UNKNOWN } from "../../../scripts/lib/drift-evaluate.mjs";
|
|
31
31
|
|
|
32
32
|
const NOW = new Date("2026-08-16T18:00:00Z").getTime();
|
|
33
33
|
const BUMP = "2026-08-16T17:00:00Z";
|
|
@@ -341,6 +341,25 @@ describe("dist-tag-aware published leg (#796)", () => {
|
|
|
341
341
|
expect(run(held({ channels: onNext("1.36.0", "not-a-date") })).status).toBe(DRIFT);
|
|
342
342
|
});
|
|
343
343
|
|
|
344
|
+
// #799. A registry time later than now is not evidence of a publish. Floored, it was a
|
|
345
|
+
// negative age that never exceeded --max-days, so the grace ran to that date plus --max-days.
|
|
346
|
+
it("#799-future: a future-dated channel publish time grants no grace (1 minute, 1 day, a year ahead)", () => {
|
|
347
|
+
for (const ahead of [60_000, 86_400_000, 365 * 86_400_000]) {
|
|
348
|
+
const iso = new Date(NOW + ahead).toISOString();
|
|
349
|
+
expect(onDeclaredChannel(onNext("1.36.0", iso), "1.36.0", NOW)).toEqual({ tag: "next", version: "1.36.0", ageDays: null });
|
|
350
|
+
const r = run(held({ channels: onNext("1.36.0", iso) }));
|
|
351
|
+
expect(r.status).toBe(DRIFT);
|
|
352
|
+
expect(r.findings.some((f) => /declared dist-tag/.test(f.msg))).toBe(false);
|
|
353
|
+
}
|
|
354
|
+
});
|
|
355
|
+
|
|
356
|
+
it("#799-future: the control — a publish time exactly at now, and one just before, still reach the grace", () => {
|
|
357
|
+
for (const iso of [new Date(NOW).toISOString(), new Date(NOW - 60_000).toISOString()]) {
|
|
358
|
+
expect(onDeclaredChannel(onNext("1.36.0", iso), "1.36.0", NOW)).toEqual({ tag: "next", version: "1.36.0", ageDays: 0 });
|
|
359
|
+
expect(run(held({ channels: onNext("1.36.0", iso) })).status).toBe(OK);
|
|
360
|
+
}
|
|
361
|
+
});
|
|
362
|
+
|
|
344
363
|
it("#796-strict: a channel naming an OLDER version than merged is still DRIFT (main moved past the held release)", () => {
|
|
345
364
|
expect(run(held({ channels: onNext("1.35.5", daysAgo(1)) })).status).toBe(DRIFT);
|
|
346
365
|
});
|
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) 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 =
|
|
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,
|
|
@@ -376,6 +376,15 @@ describe('manifest integrity', () => {
|
|
|
376
376
|
'20261104190000_agent_board_message_replay_scope.sql',
|
|
377
377
|
'20261108000100_agent_board_send_outcome.sql',
|
|
378
378
|
'20261109000100_agent_board_step_up_groundwork.sql',
|
|
379
|
+
'20261120000200_agent_board_thread_key_serialize.sql',
|
|
380
|
+
// S-12 follow-ups: create_or_find_thread refuses a non-READ-COMMITTED transaction (#815) and
|
|
381
|
+
// create_thread refuses the reserved addressingThreadKey (#816).
|
|
382
|
+
'20261121000100_agent_board_thread_key_guards.sql',
|
|
383
|
+
// #669 PR-B: step-up enforcement on the gated conferral routes (renamed from 20261120000100
|
|
384
|
+
// when refreshed onto main, so it sorts after the S-12 migrations).
|
|
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',
|
|
379
388
|
]) {
|
|
380
389
|
expect(names.has(f)).toBe(true);
|
|
381
390
|
}
|
|
@@ -29,7 +29,7 @@ set search_path = extensions, public, agent_board;
|
|
|
29
29
|
|
|
30
30
|
begin;
|
|
31
31
|
|
|
32
|
-
select plan(
|
|
32
|
+
select plan(69);
|
|
33
33
|
|
|
34
34
|
create temp table _h(k text primary key, v text);
|
|
35
35
|
create function pg_temp.v(p_k text) returns text language sql as $$ select v from _h where k = p_k $$;
|
|
@@ -631,6 +631,10 @@ select ok(
|
|
|
631
631
|
-- no-replay post_message: 43 (two identical calls, two messages)
|
|
632
632
|
-- recipient-state update_inbox_item_state: UPDATEs the caller's OWN inbox item only (63)
|
|
633
633
|
-- tasking-f2 create_tasking_delivery family: #717 F2's ceiling (separate PR); NOT claimed here
|
|
634
|
+
-- thread-only create_or_find_thread: a member only because it serializes through
|
|
635
|
+
-- _lock_idempotency_key (S-12, 20261120000200). It writes a THREAD and nothing
|
|
636
|
+
-- else: its body writes no message/task/delivery/inbox row and reaches no writer
|
|
637
|
+
-- of one (68), and two same-key calls create one thread and no other row (69)
|
|
634
638
|
create temp table _class(signature text primary key, disposition text not null);
|
|
635
639
|
insert into _class values
|
|
636
640
|
('send_direct_message(uuid,uuid,uuid,text,text,text,text,text,jsonb)', 'ceiling'),
|
|
@@ -649,7 +653,8 @@ insert into _class values
|
|
|
649
653
|
('update_inbox_item_state(uuid,uuid,text,jsonb)', 'recipient-state'),
|
|
650
654
|
('create_tasking_delivery(uuid,uuid,text,text,uuid[],uuid,text,text,text,jsonb)', 'tasking-f2'),
|
|
651
655
|
('create_tasking_delivery(uuid,uuid,text,text,jsonb,text,text,text,text,text,jsonb)', 'tasking-f2'),
|
|
652
|
-
('signed_create_tasking_delivery(jsonb,jsonb)', 'tasking-f2')
|
|
656
|
+
('signed_create_tasking_delivery(jsonb,jsonb)', 'tasking-f2'),
|
|
657
|
+
('create_or_find_thread(uuid,text,text,text,jsonb)', 'thread-only');
|
|
653
658
|
|
|
654
659
|
create function pg_temp.derived() returns table(signature text, body text) language sql as $d$
|
|
655
660
|
with fns as (
|
|
@@ -824,5 +829,37 @@ select is(pg_temp.refuse('A', pg_temp.mc('A','T',pg_temp.ids('X'),'mk')),
|
|
|
824
829
|
select is(pg_temp.sees('X','MC'), '0/0/0/0/0/0 -',
|
|
825
830
|
'multicast source proof: the original body and C-authored artifact remain invisible after unrelated-delivery replay');
|
|
826
831
|
|
|
832
|
+
|
|
833
|
+
-- 68 -- thread-only disposition, by the catalog: each member writes threads, writes no message,
|
|
834
|
+
-- task, task event, delivery or inbox row, and reaches no routine that writes one.
|
|
835
|
+
select is(
|
|
836
|
+
(select coalesce(string_agg(c.signature, ' ' order by c.signature), '(none)')
|
|
837
|
+
from _class c join _derived d on d.signature = c.signature
|
|
838
|
+
where c.disposition = 'thread-only'
|
|
839
|
+
and (d.body !~ agent_board_test.writes_any_re(array['threads'])
|
|
840
|
+
or d.body ~ agent_board_test.writes_any_re(array['messages', 'tasks', 'task_events', 'delivery_recipients', 'inbox_items'])
|
|
841
|
+
or exists (select 1 from agent_board_test.fn_call_closure() cl
|
|
842
|
+
where cl.root_oid = to_regprocedure('agent_board.' || c.signature)
|
|
843
|
+
and agent_board_test.stripped_body(cl.reached_oid)
|
|
844
|
+
~ agent_board_test.writes_any_re(array['messages', 'tasks', 'task_events', 'delivery_recipients', 'inbox_items'])))),
|
|
845
|
+
'(none)',
|
|
846
|
+
'thread-only disposition: create_or_find_thread writes threads, and neither it nor anything it calls writes a message, task, event, delivery or inbox row');
|
|
847
|
+
|
|
848
|
+
-- 69 -- thread-only disposition, by behaviour: as agent A, two calls with one fresh key create
|
|
849
|
+
-- exactly one thread (reused false, then true) and change no other row count.
|
|
850
|
+
create function pg_temp.thread_only_rows() returns text language sql as $$
|
|
851
|
+
select pg_temp.fp_rows() || ' tasks=' || (select count(*) from agent_board.tasks)
|
|
852
|
+
|| ' events=' || (select count(*) from agent_board.task_events) $$;
|
|
853
|
+
select pg_temp.put('to.before', pg_temp.thread_only_rows());
|
|
854
|
+
select pg_temp.put('to.first', pg_temp.val('A', $$ select reused::text from agent_board.create_or_find_thread(null, 'F2b thread-only', 'f2b717-thread-only') $$));
|
|
855
|
+
select pg_temp.put('to.second', pg_temp.val('A', $$ select reused::text from agent_board.create_or_find_thread(null, 'F2b thread-only', 'f2b717-thread-only') $$));
|
|
856
|
+
select is(
|
|
857
|
+
pg_temp.v('to.first') || '/' || pg_temp.v('to.second')
|
|
858
|
+
|| ' threads=' || (select count(*) from agent_board.threads where metadata ->> 'addressingThreadKey' = 'f2b717-thread-only')
|
|
859
|
+
|| ' ' || case when pg_temp.thread_only_rows() = pg_temp.v('to.before') then 'rows-unchanged'
|
|
860
|
+
else pg_temp.v('to.before') || ' -> ' || pg_temp.thread_only_rows() end,
|
|
861
|
+
'false/true threads=1 rows-unchanged',
|
|
862
|
+
'thread-only disposition: two same-key calls create one thread and write no message, task, delivery, inbox, callback or evidence row');
|
|
863
|
+
|
|
827
864
|
select * from finish();
|
|
828
865
|
rollback;
|
|
@@ -29,7 +29,7 @@ set search_path = extensions, public, agent_board;
|
|
|
29
29
|
|
|
30
30
|
begin;
|
|
31
31
|
|
|
32
|
-
select plan(
|
|
32
|
+
select plan(57);
|
|
33
33
|
|
|
34
34
|
do $$
|
|
35
35
|
begin
|
|
@@ -625,12 +625,17 @@ select ok(obj_description('agent_board.create_tasking_delivery(uuid,uuid,text,te
|
|
|
625
625
|
-- delivery of the source in the core's own mode;
|
|
626
626
|
-- pinned behaviourally and by mutation in
|
|
627
627
|
-- agent_board_717_message_replay_scope.test.sql
|
|
628
|
+
-- create_or_find_thread thread-only -- S-12 (20261120000200): serializes thread
|
|
629
|
+
-- creation, writes no task or message; pinned
|
|
630
|
+
-- behaviourally at 57 here and at 68/69 in
|
|
631
|
+
-- agent_board_717_message_replay_scope.test.sql
|
|
628
632
|
create temp table _replay_class(signature text primary key, disposition text not null);
|
|
629
633
|
insert into _replay_class values
|
|
630
634
|
('create_tasking_delivery(uuid,uuid,text,text,uuid[],uuid,text,text,text,jsonb)', 'ceiling'),
|
|
631
635
|
('post_board_message(uuid,uuid,uuid,text,text,text,text,text,jsonb)', 'one-board'),
|
|
632
636
|
('send_direct_message(uuid,uuid,uuid,text,text,text,text,text,jsonb)', 'fixed-717-F2b-740'),
|
|
633
|
-
('send_multicast_message(uuid,uuid,uuid[],text,text,text,text,text,jsonb)', 'fixed-717-F2b-740')
|
|
637
|
+
('send_multicast_message(uuid,uuid,uuid[],text,text,text,text,text,jsonb)', 'fixed-717-F2b-740'),
|
|
638
|
+
('create_or_find_thread(uuid,text,text,text,jsonb)', 'thread-only');
|
|
634
639
|
-- 54
|
|
635
640
|
select is(
|
|
636
641
|
(select coalesce(string_agg(s, ' ' order by s), '(none)') from (
|
|
@@ -657,5 +662,19 @@ select is(pg_temp.refuse('A', format($$ select * from agent_board.post_board_mes
|
|
|
657
662
|
pg_temp.v('T'), pg_temp.v('A'), pg_temp.v('B2'))),
|
|
658
663
|
'42501:thread belongs to a different board | side-effects=none',
|
|
659
664
|
'one-board disposition: a board post on T cannot target another board');
|
|
665
|
+
-- 57 -- the thread-only disposition, behaviourally: as agent A, two calls with one fresh key
|
|
666
|
+
-- create exactly one thread (reused false, then true) and no task, event, delivery or message.
|
|
667
|
+
create function pg_temp.thread_only_rows() returns text language sql as $$
|
|
668
|
+
select pg_temp.fp_rows() || ' messages=' || (select count(*) from agent_board.messages) $$;
|
|
669
|
+
select pg_temp.put('to.before', pg_temp.thread_only_rows());
|
|
670
|
+
select pg_temp.put('to.first', pg_temp.val('A', $$ select reused::text from agent_board.create_or_find_thread(null, 'F2 thread-only', 'f2717-thread-only') $$));
|
|
671
|
+
select pg_temp.put('to.second', pg_temp.val('A', $$ select reused::text from agent_board.create_or_find_thread(null, 'F2 thread-only', 'f2717-thread-only') $$));
|
|
672
|
+
select is(
|
|
673
|
+
pg_temp.v('to.first') || '/' || pg_temp.v('to.second')
|
|
674
|
+
|| ' threads=' || (select count(*) from agent_board.threads where metadata ->> 'addressingThreadKey' = 'f2717-thread-only')
|
|
675
|
+
|| ' ' || case when pg_temp.thread_only_rows() = pg_temp.v('to.before') then 'rows-unchanged'
|
|
676
|
+
else pg_temp.v('to.before') || ' -> ' || pg_temp.thread_only_rows() end,
|
|
677
|
+
'false/true threads=1 rows-unchanged',
|
|
678
|
+
'thread-only disposition: two same-key create_or_find_thread calls create one thread and write no task, event, delivery or message');
|
|
660
679
|
select * from finish();
|
|
661
680
|
rollback;
|