@consiliency/agent-board-schema 1.76.0 → 1.79.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 +12 -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/package.json +1 -1
- package/schema-manifest.json +30 -3
- package/src/deployment-drift-main.test.mjs +89 -6
- package/src/deployment-drift.test.mjs +20 -1
- package/src/tooling.test.mjs +9 -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_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
|
@@ -29,7 +29,7 @@ set search_path = extensions, public, agent_board;
|
|
|
29
29
|
|
|
30
30
|
begin;
|
|
31
31
|
|
|
32
|
-
select plan(
|
|
32
|
+
select plan(113);
|
|
33
33
|
|
|
34
34
|
do $$
|
|
35
35
|
begin
|
|
@@ -227,16 +227,27 @@ insert into _su_fns values
|
|
|
227
227
|
-- §10.1 catalog class: EC-SU-0, EC-SU-4 (ledger clause, E-2 closure form), EC-SU-5
|
|
228
228
|
-- ===========================================================================
|
|
229
229
|
|
|
230
|
-
-- EC-SU-0
|
|
231
|
-
--
|
|
232
|
-
--
|
|
230
|
+
-- EC-SU-0, as REPLACED by PR-B (plan §10.1: "PR-B replaces it with EC-SU-2"). PR-A asserted that
|
|
231
|
+
-- nothing called the helper. From 20261124000100 the functions whose OWN body calls it are
|
|
232
|
+
-- exactly the six GATED chokepoints (EC-SU-2 in agent_board_step_up.test.sql pins placement and
|
|
233
|
+
-- the reverse closure). Both sides are still keyed by OID: an overload such as
|
|
234
|
+
-- _require_human_step_up(uuid) that calls the helper is an extra caller and names itself.
|
|
233
235
|
select is(
|
|
234
|
-
(select coalesce(string_agg(
|
|
235
|
-
from
|
|
236
|
-
where
|
|
237
|
-
and
|
|
238
|
-
|
|
239
|
-
|
|
236
|
+
(select coalesce(string_agg(p.oid::regprocedure::text, ' ' order by p.oid::regprocedure::text), '(none)')
|
|
237
|
+
from pg_proc p
|
|
238
|
+
where p.pronamespace = 'agent_board'::regnamespace and p.prokind in ('f', 'p')
|
|
239
|
+
and p.oid <> 'agent_board._require_human_step_up(text)'::regprocedure
|
|
240
|
+
and exists (select 1 from _cl c where c.root_oid = p.oid and c.reached_oid = 'agent_board._require_human_step_up(text)'::regprocedure)
|
|
241
|
+
and agent_board_test.stripped_body(p.oid) ~ agent_board_test.call_re('_require_human_step_up')),
|
|
242
|
+
-- pgtap-allow-raise-checked: the names below are regprocedure literals in a catalog comparison, never a call.
|
|
243
|
+
(select string_agg(x::regprocedure::text, ' ' order by x::regprocedure::text) from unnest(array[
|
|
244
|
+
'agent_board.create_invite_link(uuid,text,text,integer,timestamp with time zone,uuid,jsonb)',
|
|
245
|
+
'agent_board.grant_board_role(uuid,uuid,text,uuid)',
|
|
246
|
+
'agent_board.readmit_session_identity(uuid,text,text,jsonb,jsonb,interval)',
|
|
247
|
+
'agent_board.set_board_authority_ceiling(uuid,text,uuid)',
|
|
248
|
+
'agent_board.set_board_role_gate(uuid,boolean)',
|
|
249
|
+
'agent_board.update_board_membership(uuid,uuid,text,jsonb)']) x),
|
|
250
|
+
'EC-SU-0 (replaced by PR-B): the direct callers of _require_human_step_up are exactly the six GATED chokepoints');
|
|
240
251
|
|
|
241
252
|
-- EC-SU-0 control: the same closure DOES see the helper's own calls, so (1) is not vacuous.
|
|
242
253
|
select is(
|
|
@@ -357,14 +368,14 @@ select is(
|
|
|
357
368
|
'300/30',
|
|
358
369
|
'D9: the window is 300 s with 30 s future skew');
|
|
359
370
|
|
|
360
|
-
-- §11.1: the allowlist
|
|
361
|
-
select is(agent_board._step_up_amr_methods(), '{}'::text[], 'E-0-AL: _step_up_amr_methods() is
|
|
371
|
+
-- §11.1 / §11.2: PR-A shipped the allowlist EMPTY; PR-B (20261124000100) freezes it to {otp,totp}.
|
|
372
|
+
select is(agent_board._step_up_amr_methods(), '{otp,totp}'::text[], 'E-0-AL: _step_up_amr_methods() is the PR-B freeze {otp,totp}');
|
|
362
373
|
|
|
363
|
-
-- E-0-AL consequence: under the shipped (
|
|
374
|
+
-- E-0-AL consequence: under the shipped (frozen) allowlist a fresh passkey (unmeasured) proves nothing.
|
|
364
375
|
select throws_ok(
|
|
365
|
-
format('select pg_temp.step(%L)', pg_temp.c('L', jsonb_build_object('amr', jsonb_build_array(jsonb_build_object('method', '
|
|
376
|
+
format('select pg_temp.step(%L)', pg_temp.c('L', jsonb_build_object('amr', jsonb_build_array(jsonb_build_object('method', 'passkey', 'timestamp', pg_temp.now_s() - 10))))),
|
|
366
377
|
'MBS01', 'step_up_required',
|
|
367
|
-
'E-0-AL: a local human with a fresh
|
|
378
|
+
'E-0-AL: a local human with a fresh passkey gets MBS01 under the shipped allowlist (passkey is not yet measured)');
|
|
368
379
|
|
|
369
380
|
-- ===========================================================================
|
|
370
381
|
-- §10.3 predicate rows (D9), p_now = 1000000
|
|
@@ -635,23 +646,55 @@ select ok(
|
|
|
635
646
|
and agent_board_test.stripped_body(p.oid, true) ~ '''fedsession'''),
|
|
636
647
|
'EC-SU-4i: some audit writer still inserts the literal mode ''fedsession'' the class binding matches');
|
|
637
648
|
|
|
638
|
-
--
|
|
639
|
-
--
|
|
640
|
-
--
|
|
641
|
-
--
|
|
649
|
+
-- Every persistent routine body outside pg_catalog/information_schema, read once for EC-SU-4h and 4q:
|
|
650
|
+
-- body comments AND literals stripped (a call is code, never a literal);
|
|
651
|
+
-- body_lit comments stripped, literals KEPT (a dynamic call carries its target inside a literal).
|
|
652
|
+
-- Session temp schemas (pg_temp_N) are excluded: they hold this file's own fixtures and cannot
|
|
653
|
+
-- persist a route. pg_catalog and information_schema are the server's own.
|
|
654
|
+
create temp table _xbody as
|
|
655
|
+
select p.oid, n.nspname::text as nspname,
|
|
656
|
+
agent_board_test.stripped_body(p.oid) as body, agent_board_test.stripped_body(p.oid, true) as body_lit
|
|
657
|
+
from pg_proc p join pg_namespace n on n.oid = p.pronamespace join pg_language l on l.oid = p.prolang
|
|
658
|
+
where n.nspname not in ('pg_catalog', 'information_schema') and n.nspname !~ '^pg_(toast_)?temp_'
|
|
659
|
+
and l.lanname not in ('internal', 'c');
|
|
660
|
+
|
|
661
|
+
-- EC-SU-4h (S1-2 floor b; #802 P-3): fn_call_closure scans agent_board only, and EC-SU-0 does too,
|
|
662
|
+
-- so no routine in ANY other persistent schema may NAME a step-up route. The route set is
|
|
663
|
+
-- derived from the closure, never listed: every agent_board routine whose reflexive call
|
|
664
|
+
-- closure reaches _require_human_step_up (the helper, the six GATED, their wrappers) or a
|
|
665
|
+
-- writer of portal_step_up_proofs (record_portal_step_up and its wrappers). Matched as a
|
|
666
|
+
-- whole identifier, case-insensitively, over body_lit: literals KEPT, because a dynamic
|
|
667
|
+
-- call carries the target's name inside a string; comments stripped (a comment cannot call).
|
|
668
|
+
create temp table _su_routes as
|
|
669
|
+
select distinct c.root_oid as oid, c.root_name as name
|
|
670
|
+
from _cl c
|
|
671
|
+
where c.reached_oid = 'agent_board._require_human_step_up(text)'::regprocedure
|
|
672
|
+
or c.reached_oid in (
|
|
673
|
+
select p.oid from pg_proc p
|
|
674
|
+
where p.pronamespace = 'agent_board'::regnamespace and p.prokind in ('f', 'p')
|
|
675
|
+
and p.prolang <> (select oid from pg_language where lanname = 'internal')
|
|
676
|
+
and agent_board_test.stripped_body(p.oid) ~ agent_board_test.writes_any_re(array['portal_step_up_proofs']));
|
|
642
677
|
select is(
|
|
643
|
-
(select coalesce(string_agg(
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
and agent_board_test.stripped_body(p.oid, true) ~* 'record_portal_step_up'),
|
|
678
|
+
(select coalesce(string_agg(distinct b.oid::regprocedure::text || '->' || r.name, ' '
|
|
679
|
+
order by b.oid::regprocedure::text || '->' || r.name), '(none)')
|
|
680
|
+
from _xbody as b cross join _su_routes as r
|
|
681
|
+
where b.nspname <> 'agent_board'
|
|
682
|
+
and b.body_lit ~ agent_board_test.qname_re(r.name)),
|
|
649
683
|
'(none)',
|
|
650
|
-
'EC-SU-4h: no routine outside agent_board names record_portal_step_up');
|
|
684
|
+
'EC-SU-4h: no routine outside agent_board names a step-up route (record_portal_step_up, _require_human_step_up, a GATED function or any caller of one)');
|
|
651
685
|
select ok(
|
|
652
|
-
(select count(*) > 100 from
|
|
653
|
-
where n.nspname not in ('agent_board', 'pg_catalog', 'information_schema') and coalesce(p.prosrc, '') <> ''),
|
|
686
|
+
(select count(*) > 100 from _xbody where nspname <> 'agent_board'),
|
|
654
687
|
'EC-SU-4h control: the cross-schema scan inspected more than 100 non-agent_board routines');
|
|
688
|
+
-- EC-SU-4h control (#802 P-3): the derived route set is not vacuous. It holds the helper, the
|
|
689
|
+
-- ledger writer and the six GATED chokepoints by name (a positive floor, not the class:
|
|
690
|
+
-- the class is whatever the closure returns, and the assertion above scans all of it).
|
|
691
|
+
select is(
|
|
692
|
+
(select string_agg(x, ' ' order by x) from unnest(array[
|
|
693
|
+
'_require_human_step_up', 'create_invite_link', 'grant_board_role', 'readmit_session_identity',
|
|
694
|
+
'record_portal_step_up', 'set_board_authority_ceiling', 'set_board_role_gate', 'update_board_membership']) x
|
|
695
|
+
where x in (select name from _su_routes)),
|
|
696
|
+
'_require_human_step_up create_invite_link grant_board_role readmit_session_identity record_portal_step_up set_board_authority_ceiling set_board_role_gate update_board_membership',
|
|
697
|
+
'EC-SU-4h control: the closure-derived route set contains the helper, the ledger writer and the six GATED chokepoints');
|
|
655
698
|
|
|
656
699
|
-- EC-SU-4d (S1-2 floor a): the closure cannot see dynamic EXECUTE. The API-executable
|
|
657
700
|
-- SECURITY DEFINER routines in EVERY schema whose bodies can run dynamic SQL (plpgsql with an
|
|
@@ -707,5 +750,66 @@ select is(
|
|
|
707
750
|
'agent_board.mark_retention_metadata(text,timestamp with time zone,uuid,text)'::regprocedure::text,
|
|
708
751
|
'EC-SU-4d control: the dynamic-EXECUTE detector finds exactly the one SECURITY DEFINER routine that has it (service_role only)');
|
|
709
752
|
|
|
753
|
+
-- EC-SU-4q (#802 P-1): SQL builtins that RUN A QUERY STRING are dynamic SQL in any language,
|
|
754
|
+
-- including `language sql`, which EC-SU-4d's detector does not treat as dynamic. A SECURITY
|
|
755
|
+
-- DEFINER routine calling one with 'select agent_board.record_portal_step_up(...)' (or a GATED
|
|
756
|
+
-- function) is a route no call closure can see. The class is derived from pg_catalog: every
|
|
757
|
+
-- builtin with a text argument named query or sqlquery (query_to_xml, query_to_xmlschema,
|
|
758
|
+
-- query_to_xml_and_xmlschema, ts_stat, ts_rewrite's query form). Floor, stated: a builtin
|
|
759
|
+
-- whose query-string argument has another name is not in the class, and cursor_to_xml takes a
|
|
760
|
+
-- cursor that only dynamic SQL (EC-SU-4d) or a static query (the closure) can open.
|
|
761
|
+
create temp table _qx as
|
|
762
|
+
select distinct p.proname::text as name
|
|
763
|
+
from pg_proc p
|
|
764
|
+
where p.pronamespace = 'pg_catalog'::regnamespace and p.prokind = 'f'
|
|
765
|
+
and exists (select 1 from unnest(coalesce(p.proallargtypes, p.proargtypes::oid[]), p.proargnames) a(t, n)
|
|
766
|
+
where n in ('query', 'sqlquery') and t = 'text'::regtype::oid);
|
|
767
|
+
-- The routines (any persistent schema, comments and literals stripped) that call a class member.
|
|
768
|
+
create temp table _qx_callers as
|
|
769
|
+
select b.oid, q.name
|
|
770
|
+
from _xbody as b cross join _qx as q
|
|
771
|
+
where b.body ~ agent_board_test.call_re('pg_catalog.' || q.name);
|
|
772
|
+
select is(
|
|
773
|
+
(select string_agg(x, ' ' order by x) from unnest(array['query_to_xml', 'ts_stat']) x where x in (select name from _qx)),
|
|
774
|
+
'query_to_xml ts_stat',
|
|
775
|
+
'EC-SU-4q control: the catalog-derived query-string builtin class contains query_to_xml and ts_stat');
|
|
776
|
+
-- (a) no SECURITY DEFINER routine in any persistent schema calls one (comments and literals
|
|
777
|
+
-- stripped, so a mention in prose or inside a string is not a call).
|
|
778
|
+
select is(
|
|
779
|
+
(select coalesce(string_agg(distinct b.oid::regprocedure::text || '->' || b.name, ' '
|
|
780
|
+
order by b.oid::regprocedure::text || '->' || b.name), '(none)')
|
|
781
|
+
from _qx_callers as b join pg_proc as p on p.oid = b.oid
|
|
782
|
+
where p.prosecdef),
|
|
783
|
+
'(none)',
|
|
784
|
+
'EC-SU-4q: no SECURITY DEFINER routine in any schema calls a builtin that runs a query string');
|
|
785
|
+
-- (b) no API-executable agent_board root reaches, through its call closure, an agent_board routine
|
|
786
|
+
-- that calls one (an invoker routine reached from a definer runs as the definer's owner).
|
|
787
|
+
select is(
|
|
788
|
+
(select coalesce(string_agg(distinct c.root_oid::regprocedure::text || '->' || q.name, ' '
|
|
789
|
+
order by c.root_oid::regprocedure::text || '->' || q.name), '(none)')
|
|
790
|
+
from _cl as c join _qx_callers as q on q.oid = c.reached_oid
|
|
791
|
+
where exists (select 1 from unnest(array['anon', 'authenticated', 'agent_board_delegate']) r where has_function_privilege(r, c.root_oid, 'EXECUTE'))),
|
|
792
|
+
'(none)',
|
|
793
|
+
'EC-SU-4q: no API-executable agent_board routine reaches a query-string builtin through its call closure');
|
|
794
|
+
-- EC-SU-4q control: the matcher the two rows use finds a qualified call and an upper-case bare
|
|
795
|
+
-- call, and does NOT find a mention in a comment or inside a literal.
|
|
796
|
+
create function pg_temp.su669_qx_hit() returns xml language sql security definer set search_path = '' as $f$
|
|
797
|
+
select pg_catalog.query_to_xml('select 1', true, false, '')
|
|
798
|
+
$f$;
|
|
799
|
+
create function pg_temp.su669_qx_bare() returns bigint language sql security definer set search_path = pg_catalog as $f$
|
|
800
|
+
select count(*) from TS_STAT('select 1')
|
|
801
|
+
$f$;
|
|
802
|
+
create function pg_temp.su669_qx_decoy() returns text language sql security definer set search_path = '' as $f$
|
|
803
|
+
-- query_to_xml(
|
|
804
|
+
select 'ts_stat(select 1) query_to_xml('::text
|
|
805
|
+
$f$;
|
|
806
|
+
select is(
|
|
807
|
+
(select string_agg(v.f || ':' || v.q || '=' || (agent_board_test.stripped_body(p.oid) ~ agent_board_test.call_re('pg_catalog.' || v.q))::text, ' ' order by v.f, v.q)
|
|
808
|
+
from (values ('su669_qx_hit', 'query_to_xml'), ('su669_qx_bare', 'ts_stat'),
|
|
809
|
+
('su669_qx_decoy', 'query_to_xml'), ('su669_qx_decoy', 'ts_stat')) v(f, q)
|
|
810
|
+
join pg_proc p on p.proname = v.f and p.pronamespace = pg_my_temp_schema()),
|
|
811
|
+
'su669_qx_bare:ts_stat=true su669_qx_decoy:query_to_xml=false su669_qx_decoy:ts_stat=false su669_qx_hit:query_to_xml=true',
|
|
812
|
+
'EC-SU-4q control: the query-string call matcher sees qualified and bare upper-case calls and ignores comments and literals');
|
|
813
|
+
|
|
710
814
|
select * from finish();
|
|
711
815
|
rollback;
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
-- THREADKEYGUARDS (S-12 follow-ups, migration 20261121000100).
|
|
2
|
+
--
|
|
3
|
+
-- WHAT THIS FILE PINS: `create_thread` refuses object metadata carrying a top-level
|
|
4
|
+
-- `addressingThreadKey` with 22023 (Consiliency/message-board#816). That key is the idempotency
|
|
5
|
+
-- key `create_or_find_thread` stores and looks up under its (actor, key) lock; `create_thread`
|
|
6
|
+
-- takes no lock, so a caller who could write the key there could plant a second thread under a
|
|
7
|
+
-- pair that function serialises.
|
|
8
|
+
--
|
|
9
|
+
-- WHAT IT DOES NOT PIN: the other half of the migration, `create_or_find_thread` refusing a
|
|
10
|
+
-- transaction that is not READ COMMITTED (#815). A level is chosen by a transaction's first
|
|
11
|
+
-- statement and this file is already inside one, so that half lives in
|
|
12
|
+
-- tests/isolation/specs/create_or_find_thread_same_key_race.spec, permutations 8-12.
|
|
13
|
+
--
|
|
14
|
+
-- The rows, by what each one would catch:
|
|
15
|
+
-- TKG-1..4 REJECT: the key is refused whatever its value and whatever else the object holds,
|
|
16
|
+
-- and the refused calls create nothing (a "strip the key and insert" body fails 4).
|
|
17
|
+
-- TKG-5..8 ALLOW: ordinary object metadata and SQL NULL still work and are stored unchanged.
|
|
18
|
+
-- TKG-9..12 SCOPE: only the spelling the lookup reads, at the top level of an object, is
|
|
19
|
+
-- reserved. A differently cased key, a nested key and an ARRAY holding the string
|
|
20
|
+
-- are stored as before (`?` is true for such an array, hence the object guard).
|
|
21
|
+
-- TKG-13 nothing `create_thread` wrote is readable by the lookup under any key.
|
|
22
|
+
-- TKG-14..15 END TO END: after the refused plant, `create_or_find_thread` with that key creates
|
|
23
|
+
-- its own thread (reused=false) and it is the only one under the pair.
|
|
24
|
+
-- TKG-16..18 KEPT: the blank-subject refusal, SECURITY DEFINER, the pinned search_path.
|
|
25
|
+
-- TKG-19..21 THE CLASS, from pg_catalog (AGENTS.md rule 1), for the statement forms the matchers
|
|
26
|
+
-- see: which functions' bodies contain `INSERT INTO agent_board.threads` (TKG-19),
|
|
27
|
+
-- whether any function assigns `threads.metadata` by UPDATE SET (scalar or row
|
|
28
|
+
-- form), MERGE update or ON CONFLICT DO UPDATE (TKG-20), and whether anon,
|
|
29
|
+
-- authenticated or agent_board_delegate can INSERT/UPDATE the table directly
|
|
30
|
+
-- (TKG-21). A new writer of one of those forms fails these and names itself.
|
|
31
|
+
-- UNSEEN by these rows: a MERGE ... WHEN NOT MATCHED THEN INSERT, a subscripted
|
|
32
|
+
-- metadata assignment (`SET metadata[...] = ...`), and dynamic SQL. Dynamic SQL is
|
|
33
|
+
-- bounded by CPR-9, triggers and rules on threads by CPR-13b
|
|
34
|
+
-- (agent_board_claimpolicy_race.test.sql). The two exempt inserters are each
|
|
35
|
+
-- asserted positively:
|
|
36
|
+
-- `create_thread` refuses the key (TKG-1) and `create_or_find_thread` writes exactly
|
|
37
|
+
-- its own normalized key (TKS-20 in agent_board_thread_key_serialize.test.sql).
|
|
38
|
+
--
|
|
39
|
+
-- Every allow-side call runs under lives_ok and is captured, then asserted separately (#113).
|
|
40
|
+
create extension if not exists pgtap with schema extensions;
|
|
41
|
+
set search_path = extensions, public, agent_board;
|
|
42
|
+
|
|
43
|
+
begin;
|
|
44
|
+
|
|
45
|
+
select plan(21);
|
|
46
|
+
|
|
47
|
+
create temp table _tkg (actor uuid) on commit drop;
|
|
48
|
+
-- Capture tables exist BEFORE the calls they capture, so a call that raises under a mutation
|
|
49
|
+
-- leaves an EMPTY capture and its state assertion fails by name (AGENTS.md rule 3).
|
|
50
|
+
create temp table _tkg_plain (thread_id uuid) on commit drop;
|
|
51
|
+
create temp table _tkg_null (thread_id uuid) on commit drop;
|
|
52
|
+
create temp table _tkg_scope (label text, thread_id uuid) on commit drop;
|
|
53
|
+
create temp table _tkg_cof (thread_id uuid, reused boolean) on commit drop;
|
|
54
|
+
|
|
55
|
+
do $$
|
|
56
|
+
declare
|
|
57
|
+
v_suffix text := replace(substr(gen_random_uuid()::text, 1, 8), '-', '');
|
|
58
|
+
v_actor uuid := gen_random_uuid();
|
|
59
|
+
begin
|
|
60
|
+
insert into agent_board.agents(id, agent_type, kind, handle, display_name, status)
|
|
61
|
+
values (v_actor, 'agent', 'agent', 'tkg-actor-' || v_suffix, 'TKG Actor', 'active');
|
|
62
|
+
insert into _tkg(actor) values (v_actor);
|
|
63
|
+
-- The same caller identity the S-12 isolation spec uses.
|
|
64
|
+
perform set_config('request.jwt.claim.role', 'service_role', true);
|
|
65
|
+
end
|
|
66
|
+
$$;
|
|
67
|
+
|
|
68
|
+
-- TKG-1..4. REJECT rows.
|
|
69
|
+
select throws_ok(
|
|
70
|
+
$$ select * from agent_board.create_thread((select actor from _tkg), 'TKG planted', 'coordination', '{"addressingThreadKey":"tkg-key"}'::jsonb) $$,
|
|
71
|
+
'22023', 'metadata key addressingThreadKey is reserved for create_or_find_thread',
|
|
72
|
+
'TKG-1: create_thread refuses metadata carrying addressingThreadKey with 22023');
|
|
73
|
+
select throws_ok(
|
|
74
|
+
$$ select * from agent_board.create_thread((select actor from _tkg), 'TKG planted', 'coordination', '{"addressingThreadKey":null}'::jsonb) $$,
|
|
75
|
+
'22023', 'metadata key addressingThreadKey is reserved for create_or_find_thread',
|
|
76
|
+
'TKG-2: the key is reserved by NAME: a JSON null value is refused too');
|
|
77
|
+
select throws_ok(
|
|
78
|
+
$$ select * from agent_board.create_thread((select actor from _tkg), 'TKG planted', 'coordination', '{"topic":"tkg","addressingThreadKey":"tkg-key-2","z":1}'::jsonb) $$,
|
|
79
|
+
'22023', 'metadata key addressingThreadKey is reserved for create_or_find_thread',
|
|
80
|
+
'TKG-3: the key is refused among other keys');
|
|
81
|
+
select is(
|
|
82
|
+
(select count(*)::int from agent_board.threads t where t.created_by_agent_id = (select actor from _tkg)),
|
|
83
|
+
0, 'TKG-4: the refused calls created no thread at all (refused, not stripped and inserted)');
|
|
84
|
+
|
|
85
|
+
-- TKG-5..8. ALLOW rows.
|
|
86
|
+
select lives_ok(
|
|
87
|
+
$$ insert into _tkg_plain(thread_id)
|
|
88
|
+
select thread_id from agent_board.create_thread((select actor from _tkg), 'TKG plain', 'coordination', '{"topic":"tkg"}'::jsonb) $$,
|
|
89
|
+
'TKG-5: ordinary object metadata is still accepted');
|
|
90
|
+
select is(
|
|
91
|
+
(select t.metadata::text from _tkg_plain c join agent_board.threads t on t.id = c.thread_id),
|
|
92
|
+
'{"topic": "tkg"}', 'TKG-6: and is stored unchanged');
|
|
93
|
+
select lives_ok(
|
|
94
|
+
$$ insert into _tkg_null(thread_id)
|
|
95
|
+
select thread_id from agent_board.create_thread((select actor from _tkg), 'TKG null', 'coordination', null) $$,
|
|
96
|
+
'TKG-7: SQL NULL metadata is still accepted');
|
|
97
|
+
select is(
|
|
98
|
+
(select t.metadata::text from _tkg_null c join agent_board.threads t on t.id = c.thread_id),
|
|
99
|
+
'{}', 'TKG-8: and still means "no metadata"');
|
|
100
|
+
|
|
101
|
+
-- TKG-9..12. SCOPE rows: what the reservation does NOT reach.
|
|
102
|
+
select lives_ok(
|
|
103
|
+
$$ insert into _tkg_scope(label, thread_id)
|
|
104
|
+
select 'a-case', thread_id from agent_board.create_thread((select actor from _tkg), 'TKG case', 'coordination', '{"addressingthreadkey":"tkg-key"}'::jsonb) $$,
|
|
105
|
+
'TKG-9: a differently cased key is not the reserved key (the lookup is case-sensitive)');
|
|
106
|
+
select lives_ok(
|
|
107
|
+
$$ insert into _tkg_scope(label, thread_id)
|
|
108
|
+
select 'b-nested', thread_id from agent_board.create_thread((select actor from _tkg), 'TKG nested', 'coordination', '{"outer":{"addressingThreadKey":"tkg-key"}}'::jsonb) $$,
|
|
109
|
+
'TKG-10: a nested key is not refused (the lookup reads the top level only)');
|
|
110
|
+
select lives_ok(
|
|
111
|
+
$$ insert into _tkg_scope(label, thread_id)
|
|
112
|
+
select 'c-array', thread_id from agent_board.create_thread((select actor from _tkg), 'TKG array', 'coordination', '["addressingThreadKey"]'::jsonb) $$,
|
|
113
|
+
'TKG-11: non-object metadata is left as it was, even an array holding the string');
|
|
114
|
+
select is(
|
|
115
|
+
(select string_agg(c.label || '=' || t.metadata::text, ' ' order by c.label)
|
|
116
|
+
from _tkg_scope c join agent_board.threads t on t.id = c.thread_id),
|
|
117
|
+
'a-case={"addressingthreadkey": "tkg-key"} b-nested={"outer": {"addressingThreadKey": "tkg-key"}} c-array=["addressingThreadKey"]',
|
|
118
|
+
'TKG-12: all three are stored unchanged');
|
|
119
|
+
|
|
120
|
+
-- TKG-13. Whatever create_thread stored, the lookup cannot read a key out of it.
|
|
121
|
+
select is(
|
|
122
|
+
(select count(*)::int from agent_board.threads t
|
|
123
|
+
where t.created_by_agent_id = (select actor from _tkg)
|
|
124
|
+
and t.metadata ->> 'addressingThreadKey' is not null),
|
|
125
|
+
0, 'TKG-13: no thread create_thread wrote is readable by the addressingThreadKey lookup');
|
|
126
|
+
|
|
127
|
+
-- TKG-14/15. END TO END: the plant attempted in TKG-1 did not pre-empt the real call.
|
|
128
|
+
select lives_ok(
|
|
129
|
+
$$ insert into _tkg_cof(thread_id, reused)
|
|
130
|
+
select thread_id, reused from agent_board.create_or_find_thread((select actor from _tkg), 'TKG real', 'tkg-key') $$,
|
|
131
|
+
'TKG-14: create_or_find_thread with the key TKG-1 tried to plant succeeds');
|
|
132
|
+
select is(
|
|
133
|
+
(select c.reused::text || ' threads=' ||
|
|
134
|
+
(select count(*) from agent_board.threads t
|
|
135
|
+
where t.created_by_agent_id = (select actor from _tkg)
|
|
136
|
+
and t.metadata ->> 'addressingThreadKey' = 'tkg-key')
|
|
137
|
+
from _tkg_cof c),
|
|
138
|
+
'false threads=1',
|
|
139
|
+
'TKG-15: it creates its own thread (reused=false) and that is the only one under the pair');
|
|
140
|
+
|
|
141
|
+
-- TKG-16..18. KEPT.
|
|
142
|
+
select throws_ok(
|
|
143
|
+
$$ select * from agent_board.create_thread((select actor from _tkg), ' ', 'coordination', '{}'::jsonb) $$,
|
|
144
|
+
'22023', 'subject is required',
|
|
145
|
+
'TKG-16: a blank subject is still refused with 22023');
|
|
146
|
+
-- Both only READ pg_proc (the function is named in a string, never called), so they cannot raise:
|
|
147
|
+
-- hence the #113 opt-out. to_regprocedure, not a cast, so a missing signature fails by name.
|
|
148
|
+
select is( -- pgtap-allow-raise-checked
|
|
149
|
+
(select p.prosecdef from pg_proc p
|
|
150
|
+
where p.oid = to_regprocedure('agent_board.create_thread(uuid,text,text,jsonb)')),
|
|
151
|
+
true, 'TKG-17: create_thread is still SECURITY DEFINER');
|
|
152
|
+
select is( -- pgtap-allow-raise-checked
|
|
153
|
+
(select p.proconfig from pg_proc p
|
|
154
|
+
where p.oid = to_regprocedure('agent_board.create_thread(uuid,text,text,jsonb)')),
|
|
155
|
+
array['search_path=agent_board, public']::text[],
|
|
156
|
+
'TKG-18: create_thread still pins search_path = agent_board, public');
|
|
157
|
+
|
|
158
|
+
-- TKG-19..21. THE CLASS, derived from the catalog.
|
|
159
|
+
select is(
|
|
160
|
+
(select string_agg(p.oid::regprocedure::text, ', ' order by p.oid::regprocedure::text)
|
|
161
|
+
from pg_proc p
|
|
162
|
+
where p.pronamespace = 'agent_board'::regnamespace
|
|
163
|
+
and p.prokind in ('f', 'p')
|
|
164
|
+
and agent_board_test.stripped_body(p.oid) ~ agent_board_test.stmt_re('insert into', 'threads')),
|
|
165
|
+
'create_or_find_thread(uuid,text,text,text,jsonb), create_thread(uuid,text,text,jsonb)',
|
|
166
|
+
'TKG-19: the functions whose bodies contain INSERT INTO agent_board.threads are exactly create_or_find_thread and create_thread; a new INSERT INTO threads names itself here; a MERGE ... THEN INSERT or a dynamic-SQL insert does not');
|
|
167
|
+
select is(
|
|
168
|
+
(select string_agg(p.oid::regprocedure::text, ', ' order by p.oid::regprocedure::text)
|
|
169
|
+
from pg_proc p
|
|
170
|
+
where p.pronamespace = 'agent_board'::regnamespace
|
|
171
|
+
and p.prokind in ('f', 'p')
|
|
172
|
+
and agent_board_test.stripped_body(p.oid)
|
|
173
|
+
~ agent_board_test.re(agent_board_test.col_assign_frag('threads', 'metadata', true))),
|
|
174
|
+
null::text,
|
|
175
|
+
'TKG-20: no function assigns threads.metadata (UPDATE SET, MERGE update, or ON CONFLICT DO UPDATE); one that does names itself here; a subscripted target (metadata[...] =) is not an arm of col_assign_frag and is not seen');
|
|
176
|
+
select is(
|
|
177
|
+
(select string_agg(r || ':' || priv, ', ' order by r, priv)
|
|
178
|
+
from unnest(array['anon', 'authenticated', 'agent_board_delegate']) r
|
|
179
|
+
cross join unnest(array['INSERT', 'UPDATE']) priv
|
|
180
|
+
where has_table_privilege(r, 'agent_board.threads', priv)
|
|
181
|
+
or has_column_privilege(r, 'agent_board.threads', 'metadata', priv)),
|
|
182
|
+
null::text,
|
|
183
|
+
'TKG-21: no API role can INSERT into or UPDATE agent_board.threads directly, so the two functions are the only route');
|
|
184
|
+
|
|
185
|
+
select * from finish();
|
|
186
|
+
rollback;
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
-- THREADKEYSERIALIZE (S-12, migration 20261120000200): create_or_find_thread serialises its
|
|
2
|
+
-- lookup-then-insert on a transaction-scoped advisory lock keyed by (actor, normalized key).
|
|
3
|
+
--
|
|
4
|
+
-- THE CONCURRENCY PROPERTY ITSELF IS PINNED BY THE ISOLATION SPEC, NOT HERE.
|
|
5
|
+
-- tests/isolation/specs/create_or_find_thread_same_key_race.spec runs two real sessions:
|
|
6
|
+
-- permutations 1 and 2 show the second same-(actor, key) caller WAIT and then reuse the first
|
|
7
|
+
-- caller's thread, and permutation 5 shows a different actor with the same key NOT wait. A
|
|
8
|
+
-- pgTAP file is one transaction and cannot observe a wait.
|
|
9
|
+
--
|
|
10
|
+
-- WHAT THIS FILE ADDS is the LOCK'S IDENTITY, by behaviour rather than by reading the body. It
|
|
11
|
+
-- counts the advisory locks THIS backend gains from each call (pg_locks, never prosrc), so it
|
|
12
|
+
-- does not depend on how the lock is spelled -- a helper, a direct pg_advisory_xact_lock, or any
|
|
13
|
+
-- other key text all count the same. Each count is a claim about which calls SHARE a lock:
|
|
14
|
+
-- * the first call takes exactly one new lock (no lock at all is the S-12 defect);
|
|
15
|
+
-- * the same actor with the same key, spelled with the padding trim() removes, takes none
|
|
16
|
+
-- (it re-enters the same lock: the key is locked AFTER normalization);
|
|
17
|
+
-- * a different actor with the same key takes a new one (a key-only lock would serialise
|
|
18
|
+
-- different actors -- #808's mutation M1b);
|
|
19
|
+
-- * the same actor with a different key takes a new one (an actor-only lock would serialise
|
|
20
|
+
-- every key of one actor).
|
|
21
|
+
-- It does NOT pin WHERE the lock is taken relative to the lookup: a lock taken after the
|
|
22
|
+
-- `select ... for update` passes every count here and still races. Only the spec sees that, and
|
|
23
|
+
-- tests/mutations/s12-fix/run.sh records that it does (mutation M3_lock_after_lookup).
|
|
24
|
+
--
|
|
25
|
+
-- Then the metadata refusal 20261120000200 adds (TKS-15..20): a JSON array, scalar or JSON null as
|
|
26
|
+
-- p_metadata is refused with 22023 and creates nothing, because `metadata || {addressingThreadKey}`
|
|
27
|
+
-- on a non-object stores the key where the lookup cannot read it (an array: `[{...}]`) and every
|
|
28
|
+
-- retry inserted again. SQL NULL still means "no metadata". That the refusal comes BEFORE the lock
|
|
29
|
+
-- is pinned by the spec's permutation 7, not here (a subtransaction's locks vanish on rollback).
|
|
30
|
+
--
|
|
31
|
+
-- Plus the behaviour the redefinition promises to KEEP: a blank key is still refused with 22023,
|
|
32
|
+
-- and the function is still SECURITY DEFINER with the same pinned search_path (its EXECUTE ACL
|
|
33
|
+
-- is pinned by tests/catalog/function_execute_privileges.json).
|
|
34
|
+
--
|
|
35
|
+
-- Every call runs under lives_ok and is captured, then asserted separately (#113): a bare
|
|
36
|
+
-- `is((select ... from create_or_find_thread(...)))` aborts the file on a raise instead of
|
|
37
|
+
-- failing it.
|
|
38
|
+
create extension if not exists pgtap with schema extensions;
|
|
39
|
+
set search_path = extensions, public, agent_board;
|
|
40
|
+
|
|
41
|
+
begin;
|
|
42
|
+
|
|
43
|
+
select plan(20);
|
|
44
|
+
|
|
45
|
+
create temp table _tks (actor uuid, other uuid) on commit drop;
|
|
46
|
+
-- The advisory locks this backend already held before the call being measured.
|
|
47
|
+
create temp table _tks_seen (classid oid, objid oid, objsubid smallint) on commit drop;
|
|
48
|
+
-- Capture tables exist BEFORE the calls they capture, so a call that raises under a mutation leaves
|
|
49
|
+
-- an EMPTY capture and its state assertion fails by name, instead of a missing relation aborting
|
|
50
|
+
-- the rest of the file (AGENTS.md rule 3).
|
|
51
|
+
create temp table _tks_first (thread_id uuid, reused boolean) on commit drop;
|
|
52
|
+
create temp table _tks_same (like _tks_first) on commit drop;
|
|
53
|
+
create temp table _tks_other (like _tks_first) on commit drop;
|
|
54
|
+
create temp table _tks_key2 (like _tks_first) on commit drop;
|
|
55
|
+
create temp table _tks_nullmeta (like _tks_first) on commit drop;
|
|
56
|
+
|
|
57
|
+
do $$
|
|
58
|
+
declare
|
|
59
|
+
v_suffix text := replace(substr(gen_random_uuid()::text, 1, 8), '-', '');
|
|
60
|
+
v_actor uuid := gen_random_uuid();
|
|
61
|
+
v_other uuid := gen_random_uuid();
|
|
62
|
+
begin
|
|
63
|
+
insert into agent_board.agents(id, agent_type, kind, handle, display_name, status)
|
|
64
|
+
values (v_actor, 'agent', 'agent', 'tks-actor-' || v_suffix, 'TKS Actor', 'active'),
|
|
65
|
+
(v_other, 'agent', 'agent', 'tks-other-' || v_suffix, 'TKS Other', 'active');
|
|
66
|
+
insert into _tks(actor, other) values (v_actor, v_other);
|
|
67
|
+
end
|
|
68
|
+
$$;
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
-- How many advisory locks this backend holds that it did not hold at the previous call, and
|
|
72
|
+
-- remember them all. Called once after each measured call.
|
|
73
|
+
create function pg_temp.tks_new_advisory_locks() returns integer
|
|
74
|
+
language plpgsql as $f$
|
|
75
|
+
declare v_new integer;
|
|
76
|
+
begin
|
|
77
|
+
select count(*)::integer into v_new
|
|
78
|
+
from pg_locks l
|
|
79
|
+
where l.pid = pg_backend_pid() and l.locktype = 'advisory' and l.granted
|
|
80
|
+
and not exists (select 1 from _tks_seen s
|
|
81
|
+
where s.classid = l.classid and s.objid = l.objid and s.objsubid = l.objsubid);
|
|
82
|
+
insert into _tks_seen
|
|
83
|
+
select l.classid, l.objid, l.objsubid from pg_locks l
|
|
84
|
+
where l.pid = pg_backend_pid() and l.locktype = 'advisory' and l.granted
|
|
85
|
+
except select * from _tks_seen;
|
|
86
|
+
return v_new;
|
|
87
|
+
end
|
|
88
|
+
$f$;
|
|
89
|
+
-- The same caller identity the isolation spec uses, and the baseline: whatever the fixture took.
|
|
90
|
+
do $$ begin
|
|
91
|
+
perform set_config('request.jwt.claim.role', 'service_role', true);
|
|
92
|
+
perform pg_temp.tks_new_advisory_locks();
|
|
93
|
+
end $$;
|
|
94
|
+
|
|
95
|
+
-- TKS-1. A blank key is still refused, as before the redefinition.
|
|
96
|
+
select throws_ok(
|
|
97
|
+
$$ select * from agent_board.create_or_find_thread((select actor from _tks), 'TKS subject', ' ') $$,
|
|
98
|
+
'22023', 'subject and idempotency key are required',
|
|
99
|
+
'TKS-1: a key that trims to empty is still refused with 22023 (no null-key insert path)');
|
|
100
|
+
|
|
101
|
+
-- TKS-2/3/4. The first call, with a padded key.
|
|
102
|
+
select lives_ok(
|
|
103
|
+
$$ insert into _tks_first(thread_id, reused)
|
|
104
|
+
select thread_id, reused from agent_board.create_or_find_thread((select actor from _tks), 'TKS subject', ' tks-key ') $$,
|
|
105
|
+
'TKS-2: first call (actor A, key '' tks-key '') succeeds');
|
|
106
|
+
select is((select reused from _tks_first), false, 'TKS-3: the first call creates the thread');
|
|
107
|
+
select is(pg_temp.tks_new_advisory_locks(), 1,
|
|
108
|
+
'TKS-4: the first call takes exactly one new advisory lock (none at all is the S-12 race)');
|
|
109
|
+
|
|
110
|
+
-- TKS-5/6/7. Same actor, the trim-equivalent key: re-enters the SAME lock and reuses the row.
|
|
111
|
+
select lives_ok(
|
|
112
|
+
$$ insert into _tks_same(thread_id, reused)
|
|
113
|
+
select thread_id, reused from agent_board.create_or_find_thread((select actor from _tks), 'TKS subject', 'tks-key') $$,
|
|
114
|
+
'TKS-5: second call (actor A, key ''tks-key'') succeeds');
|
|
115
|
+
select is((select reused::text || ':' || (thread_id = (select thread_id from _tks_first))::text from _tks_same),
|
|
116
|
+
'true:true', 'TKS-6: the second call reuses the first call''s thread');
|
|
117
|
+
select is(pg_temp.tks_new_advisory_locks(), 0,
|
|
118
|
+
'TKS-7: the same actor with the trim-equivalent key takes NO new lock: it is the same lock, so the key is locked after normalization');
|
|
119
|
+
|
|
120
|
+
-- TKS-8/9/10. A different actor, the same key: a DIFFERENT lock.
|
|
121
|
+
select lives_ok(
|
|
122
|
+
$$ insert into _tks_other(thread_id, reused)
|
|
123
|
+
select thread_id, reused from agent_board.create_or_find_thread((select other from _tks), 'TKS subject', 'tks-key') $$,
|
|
124
|
+
'TKS-8: a different actor with the same key succeeds');
|
|
125
|
+
select is((select reused from _tks_other), false, 'TKS-9: the different actor gets its own thread');
|
|
126
|
+
select is(pg_temp.tks_new_advisory_locks(), 1,
|
|
127
|
+
'TKS-10: the different actor takes a NEW lock: actors with the same key do not share one, so they never serialise each other');
|
|
128
|
+
|
|
129
|
+
-- TKS-11/12. The same actor, a different key: a DIFFERENT lock.
|
|
130
|
+
select lives_ok(
|
|
131
|
+
$$ insert into _tks_key2(thread_id, reused)
|
|
132
|
+
select thread_id, reused from agent_board.create_or_find_thread((select actor from _tks), 'TKS subject', 'tks-key-2') $$,
|
|
133
|
+
'TKS-11: the same actor with a different key succeeds');
|
|
134
|
+
select is(pg_temp.tks_new_advisory_locks(), 1,
|
|
135
|
+
'TKS-12: a different key of the same actor takes a NEW lock: the lock is not per actor alone');
|
|
136
|
+
|
|
137
|
+
-- TKS-13/14. Kept: SECURITY DEFINER and the pinned search_path. to_regprocedure, not a cast, so a
|
|
138
|
+
-- missing signature fails these by name instead of aborting the file. Both only READ pg_proc (the
|
|
139
|
+
-- function is named in a string, never called), so they cannot raise: hence the #113 opt-out.
|
|
140
|
+
select is( -- pgtap-allow-raise-checked
|
|
141
|
+
(select p.prosecdef from pg_proc p
|
|
142
|
+
where p.oid = to_regprocedure('agent_board.create_or_find_thread(uuid,text,text,text,jsonb)')),
|
|
143
|
+
true, 'TKS-13: create_or_find_thread is still SECURITY DEFINER');
|
|
144
|
+
select is( -- pgtap-allow-raise-checked
|
|
145
|
+
(select p.proconfig from pg_proc p
|
|
146
|
+
where p.oid = to_regprocedure('agent_board.create_or_find_thread(uuid,text,text,text,jsonb)')),
|
|
147
|
+
array['search_path=agent_board, public']::text[],
|
|
148
|
+
'TKS-14: create_or_find_thread still pins search_path = agent_board, public');
|
|
149
|
+
|
|
150
|
+
-- TKS-15..18. Non-object metadata is REFUSED, and the refused calls create nothing.
|
|
151
|
+
select throws_ok(
|
|
152
|
+
$$ select * from agent_board.create_or_find_thread((select actor from _tks), 'TKS subject', 'tks-meta', 'coordination', '[]'::jsonb) $$,
|
|
153
|
+
'22023', 'metadata must be a JSON object',
|
|
154
|
+
'TKS-15: a JSON array as metadata is refused with 22023');
|
|
155
|
+
select throws_ok(
|
|
156
|
+
$$ select * from agent_board.create_or_find_thread((select actor from _tks), 'TKS subject', 'tks-meta', 'coordination', '"x"'::jsonb) $$,
|
|
157
|
+
'22023', 'metadata must be a JSON object',
|
|
158
|
+
'TKS-16: a JSON scalar as metadata is refused with 22023');
|
|
159
|
+
select throws_ok(
|
|
160
|
+
$$ select * from agent_board.create_or_find_thread((select actor from _tks), 'TKS subject', 'tks-meta', 'coordination', 'null'::jsonb) $$,
|
|
161
|
+
'22023', 'metadata must be a JSON object',
|
|
162
|
+
'TKS-17: a JSON null (not SQL NULL) as metadata is refused with 22023');
|
|
163
|
+
select is(
|
|
164
|
+
(select count(*)::int from agent_board.threads t
|
|
165
|
+
where t.created_by_agent_id = (select actor from _tks)
|
|
166
|
+
and (t.metadata ->> 'addressingThreadKey' = 'tks-meta'
|
|
167
|
+
or (jsonb_typeof(t.metadata) = 'array' and t.metadata @> '[{"addressingThreadKey":"tks-meta"}]'))),
|
|
168
|
+
0, 'TKS-18: the refused calls created no thread under that key, in either storage shape');
|
|
169
|
+
|
|
170
|
+
-- TKS-19/20. SQL NULL metadata is still accepted and means "none"; a second call reuses it.
|
|
171
|
+
select lives_ok(
|
|
172
|
+
$$ insert into _tks_nullmeta(thread_id, reused)
|
|
173
|
+
select thread_id, reused from agent_board.create_or_find_thread((select actor from _tks), 'TKS subject', 'tks-meta', 'coordination', null) $$,
|
|
174
|
+
'TKS-19: SQL NULL metadata is still accepted');
|
|
175
|
+
select is(
|
|
176
|
+
(select n.reused::text || ' ' || t.metadata::text
|
|
177
|
+
from _tks_nullmeta n join agent_board.threads t on t.id = n.thread_id),
|
|
178
|
+
'false {"addressingThreadKey": "tks-meta"}',
|
|
179
|
+
'TKS-20: and the thread it creates stores exactly the key as its metadata');
|
|
180
|
+
|
|
181
|
+
select * from finish();
|
|
182
|
+
rollback;
|
|
@@ -692,7 +692,8 @@ select is( -- pgtap-allow-raise-checked
|
|
|
692
692
|
'agent_board.delete_callback_endpoint(uuid,uuid) -> _resolved_actor_agent_id',
|
|
693
693
|
'agent_board.disable_callback_endpoint(uuid,uuid,text,jsonb) -> _resolved_actor_agent_id',
|
|
694
694
|
'agent_board.issue_signing_key_challenge(uuid,text,interval) -> _resolved_actor_agent_id',
|
|
695
|
-
|
|
695
|
+
-- provision_agent left this set in #669 PR-B (20261124000100): E-3 gave it its own 42501
|
|
696
|
+
-- (kind_change_requires_operator / auth_binding_change_requires_operator).
|
|
696
697
|
'agent_board.register_callback_endpoint(uuid,text,jsonb) -> _resolved_actor_agent_id',
|
|
697
698
|
'agent_board.rotate_callback_signing_key(uuid,uuid,jsonb) -> _resolved_actor_agent_id',
|
|
698
699
|
'agent_board.subscribe_callback_endpoint(uuid,uuid,text,text,uuid,jsonb) -> _resolved_actor_agent_id',
|
|
@@ -702,7 +703,7 @@ select is( -- pgtap-allow-raise-checked
|
|
|
702
703
|
'agent_board.upsert_delegation_policy(uuid,text,jsonb,integer,interval,boolean) -> _resolved_actor_agent_id',
|
|
703
704
|
'agent_board.verify_callback_endpoint(uuid,uuid,jsonb) -> _resolved_actor_agent_id'
|
|
704
705
|
]::text[],
|
|
705
|
-
'#325 HALF B, part 1: exactly these
|
|
706
|
+
'#325 HALF B, part 1: exactly these 14 writers reach NO shared authz predicate and raise no 42501 of their own, and each NAMES the raising resolver it relies on — all 14 the session resolver (provision_agent raises its own 42501 since #669 PR-B); revoke_agent now refuses an unresolved actor in its own body; a new ungated writer joins this set, and a member that loses or switches its resolver reds here');
|
|
706
707
|
|
|
707
708
|
-- WEC-9. The union, and the only assertion here that is a claim about the WHOLE class rather than
|
|
708
709
|
-- about a category. Not spelled over the CLOSURE for 42501: that form is satisfied by 59 of 59
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$comment": "GENERATED by scripts/build-step-up-closure-snapshot.mjs from pg_catalog -- do not hand-edit. #669 plan §14 E-1: `gated` is every agent_board function whose own stripped body calls _require_human_step_up; `forbidden` is the reflexive reverse call closure of that set over agent_board_test.fn_call_closure(), by bare name. scripts/check-step-up-tree.mjs (E-11) forbids supabase/functions/** from naming any `forbidden` name outside its positively-asserted exemptions.",
|
|
3
|
+
"gated": [
|
|
4
|
+
"agent_board.create_invite_link(uuid,text,text,integer,timestamp with time zone,uuid,jsonb)",
|
|
5
|
+
"agent_board.grant_board_role(uuid,uuid,text,uuid)",
|
|
6
|
+
"agent_board.readmit_session_identity(uuid,text,text,jsonb,jsonb,interval)",
|
|
7
|
+
"agent_board.set_board_authority_ceiling(uuid,text,uuid)",
|
|
8
|
+
"agent_board.set_board_role_gate(uuid,boolean)",
|
|
9
|
+
"agent_board.update_board_membership(uuid,uuid,text,jsonb)"
|
|
10
|
+
],
|
|
11
|
+
"forbidden": [
|
|
12
|
+
"create_fleet_onboarding_invite",
|
|
13
|
+
"create_invite_link",
|
|
14
|
+
"grant_board_role",
|
|
15
|
+
"leave_board",
|
|
16
|
+
"readmit_session_identity",
|
|
17
|
+
"set_board_authority_ceiling",
|
|
18
|
+
"set_board_role_gate",
|
|
19
|
+
"signed_grant_board_role",
|
|
20
|
+
"signed_set_board_authority_ceiling",
|
|
21
|
+
"tombstone_delegate_instance",
|
|
22
|
+
"update_board_membership"
|
|
23
|
+
]
|
|
24
|
+
}
|