@consiliency/agent-board-schema 1.74.0 → 1.76.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/fixtures/already-applied.json +8 -0
- package/migrations/20261108000100_agent_board_send_outcome.sql +708 -0
- package/migrations/20261109000100_agent_board_step_up_groundwork.sql +343 -0
- package/package.json +1 -1
- package/schema-manifest.json +21 -3
- package/src/deployment-drift-main.test.mjs +20 -3
- package/src/deployment-drift-script.test.mjs +77 -2
- package/src/deployment-drift.test.mjs +60 -0
- package/src/tooling.test.mjs +4 -2
- package/tests/agent_board_667_history_class.test.sql +2 -0
- package/tests/agent_board_717_native_surface.test.sql +223 -0
- package/tests/agent_board_delegate_role_class.test.sql +2 -2
- package/tests/agent_board_delivery_writer_execute.test.sql +4 -2
- package/tests/agent_board_enrollment_audit_content.test.sql +6 -1
- package/tests/agent_board_hosted_delegates.test.sql +8 -1
- package/tests/agent_board_send_outcome.test.sql +805 -0
- package/tests/agent_board_step_up_helper.test.sql +711 -0
- package/tests/agent_board_write_enforcement_class.test.sql +12 -5
- package/tests/catalog/function_execute_privileges.json +96 -0
- package/tests/catalog/p_metadata_parameters.json +40 -0
- package/tests/fixtures/isolation-substrate.sql +8 -0
- package/tests/fixtures/pgtap-unexposed.sql +61 -0
- package/tests/isolation/expected/send_outcome_cross_board.out +40 -0
- package/tests/isolation/expected/send_outcome_independence.out +295 -0
- package/tests/isolation/expected/send_outcome_membership.out +140 -0
- package/tests/isolation/expected/send_outcome_overlap.out +89 -0
- package/tests/isolation/expected/send_outcome_reader.out +87 -0
- package/tests/isolation/expected/send_outcome_recovery.out +107 -0
- package/tests/isolation/specs/send_outcome_cross_board.spec +66 -0
- package/tests/isolation/specs/send_outcome_independence.spec +95 -0
- package/tests/isolation/specs/send_outcome_membership.spec +73 -0
- package/tests/isolation/specs/send_outcome_overlap.spec +69 -0
- package/tests/isolation/specs/send_outcome_reader.spec +61 -0
- package/tests/isolation/specs/send_outcome_recovery.spec +68 -0
- package/tests/mutations/669/M10_service_role_blanket.sql +10 -0
- package/tests/mutations/669/M12a_no_parse_wrapper.sql +17 -0
- package/tests/mutations/669/M12b_no_session_wrapper.sql +23 -0
- package/tests/mutations/669/M12c_no_claim_type_guard.sql +13 -0
- package/tests/mutations/669/M12d_no_amr_element_guards.sql +15 -0
- package/tests/mutations/669/M14_now_not_clock.sql +9 -0
- package/tests/mutations/669/M15_classifier_reads_metadata.sql +17 -0
- package/tests/mutations/669/M17_skip_ledger.sql +15 -0
- package/tests/mutations/669/M18_service_role_sub_insensitive.sql +9 -0
- package/tests/mutations/669/M18b_drop_uid_conjunct.sql +9 -0
- package/tests/mutations/669/M23_definer_wrapper_over_writer.sql +5 -0
- package/tests/mutations/669/M3_age_from_iat.sql +9 -0
- package/tests/mutations/669/M4_window_900.sql +9 -0
- package/tests/mutations/669/M4b_lt_to_le.sql +9 -0
- package/tests/mutations/669/M5_no_skew_bound.sql +9 -0
- package/tests/mutations/669/M6a_user_metadata_amr.sql +9 -0
- package/tests/mutations/669/M6b_app_metadata_claim.sql +9 -0
- package/tests/mutations/669/M6c_legacy_guc.sql +9 -0
- package/tests/mutations/669/M7_either_claim_any_human.sql +9 -0
- package/tests/mutations/669/M8_any_amr_method.sql +9 -0
- package/tests/mutations/669/M8b_accept_aal2.sql +9 -0
- package/tests/mutations/669/M9_every_kind.sql +9 -0
- package/tests/mutations/669/MAL_allowlist_nonempty.sql +9 -0
- package/tests/mutations/669/MAR_writer_arg_renamed.sql +14 -0
- package/tests/mutations/669/MAU_audit_mode_retyped.sql +2 -0
- package/tests/mutations/669/MA_helper_always_raises.sql +10 -0
- package/tests/mutations/669/MDX_dynamic_execute_definer.sql +5 -0
- package/tests/mutations/669/MD_detail_carries_value.sql +12 -0
- package/tests/mutations/669/MEC0_caller_of_helper.sql +4 -0
- package/tests/mutations/669/MEC0b_overload_caller.sql +4 -0
- package/tests/mutations/669/MG1_helper_granted_authenticated.sql +2 -0
- package/tests/mutations/669/MG2_ledger_insert_authenticated.sql +2 -0
- package/tests/mutations/669/MG3_ledger_policy.sql +2 -0
- package/tests/mutations/669/MR1_writer_no_class_check.sql +9 -0
- package/tests/mutations/669/MR2_writer_wide_window.sql +9 -0
- package/tests/mutations/669/MR3_writer_prunes_everyone.sql +11 -0
- package/tests/mutations/669/MR4_writer_lower_exclusive.sql +9 -0
- package/tests/mutations/669/MR5_writer_upper_exclusive.sql +9 -0
- package/tests/mutations/669/MR6_writer_upper_61.sql +9 -0
- package/tests/mutations/669/MW2_second_ledger_writer.sql +4 -0
- package/tests/mutations/669/MXS_cross_schema_wrapper.sql +4 -0
- package/tests/mutations/669/run.sh +72 -0
- package/tests/mutations/670/E1_helper_author_from_message.sql +7 -0
- package/tests/mutations/670/E2_helper_no_null_check.sql +13 -0
- package/tests/mutations/670/M10_lock_removed.sql +10 -0
- package/tests/mutations/670/M11_table_granted_to_authenticated.sql +2 -0
- package/tests/mutations/670/M12_helper_granted_to_service_role.sql +2 -0
- package/tests/mutations/670/M13_message_fk_no_cascade.sql +8 -0
- package/tests/mutations/670/M14_post_message_mints_from_metadata.sql +11 -0
- package/tests/mutations/670/M15_second_receipt_writer.sql +9 -0
- package/tests/mutations/670/M16_read_no_btrim.sql +7 -0
- package/tests/mutations/670/M17_read_volatile.sql +2 -0
- package/tests/mutations/670/M1_helper_no_service_role_guard.sql +13 -0
- package/tests/mutations/670/M3_helper_on_replay_branch.sql +10 -0
- package/tests/mutations/670/M4_read_checks_thread_existence.sql +10 -0
- package/tests/mutations/670/M5a_read_requires_thread_access.sql +10 -0
- package/tests/mutations/670/M5b_read_requires_board_membership.sql +11 -0
- package/tests/mutations/670/M6_read_admits_service_role.sql +14 -0
- package/tests/mutations/670/M7_confirmed_adds_message_sequence.sql +12 -0
- package/tests/mutations/670/M8_delivery_swallows_errors.sql +19 -0
- package/tests/mutations/670/M9_lock_key_includes_board.sql +10 -0
- package/tests/mutations/670/run.sh +84 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
-- remove the claims-parse exception wrapper; must fail R-7 not-json (#48) with 22P02
|
|
2
|
+
do $m$
|
|
3
|
+
declare d text := pg_get_functiondef('agent_board._require_human_step_up(text)'::regprocedure); n text;
|
|
4
|
+
begin
|
|
5
|
+
n := d;
|
|
6
|
+
if strpos(n, ' begin
|
|
7
|
+
v_claims := v_raw::jsonb;
|
|
8
|
+
exception when others then
|
|
9
|
+
v_claims := null;
|
|
10
|
+
end;') = 0 then raise exception 'MUTATION ANCHOR MISS (1)'; end if;
|
|
11
|
+
n := replace(n, ' begin
|
|
12
|
+
v_claims := v_raw::jsonb;
|
|
13
|
+
exception when others then
|
|
14
|
+
v_claims := null;
|
|
15
|
+
end;', ' v_claims := v_raw::jsonb;');
|
|
16
|
+
execute n;
|
|
17
|
+
end $m$;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
-- remove the session-reader exception wrapper; must fail R-7 not-json (#48) with 22P02
|
|
2
|
+
do $m$
|
|
3
|
+
declare d text := pg_get_functiondef('agent_board._require_human_step_up(text)'::regprocedure); n text;
|
|
4
|
+
begin
|
|
5
|
+
n := d;
|
|
6
|
+
if strpos(n, ' begin
|
|
7
|
+
v_service := agent_board._is_service_role();
|
|
8
|
+
v_uid := auth.uid();
|
|
9
|
+
v_actor := agent_board.current_agent_id();
|
|
10
|
+
exception when others then
|
|
11
|
+
raise exception ''step_up_required'' using errcode = ''MBS01'', detail = p_operation;
|
|
12
|
+
end;') = 0 then raise exception 'MUTATION ANCHOR MISS (1)'; end if;
|
|
13
|
+
n := replace(n, ' begin
|
|
14
|
+
v_service := agent_board._is_service_role();
|
|
15
|
+
v_uid := auth.uid();
|
|
16
|
+
v_actor := agent_board.current_agent_id();
|
|
17
|
+
exception when others then
|
|
18
|
+
raise exception ''step_up_required'' using errcode = ''MBS01'', detail = p_operation;
|
|
19
|
+
end;', ' v_service := agent_board._is_service_role();
|
|
20
|
+
v_uid := auth.uid();
|
|
21
|
+
v_actor := agent_board.current_agent_id();');
|
|
22
|
+
execute n;
|
|
23
|
+
end $m$;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
-- remove the T JSON-number guard; must fail R-7 malformed-T rows (#49-50) with 22P02
|
|
2
|
+
do $m$
|
|
3
|
+
declare d text := pg_get_functiondef('agent_board._require_human_step_up(text)'::regprocedure); n text;
|
|
4
|
+
begin
|
|
5
|
+
n := d;
|
|
6
|
+
if strpos(n, ' if jsonb_typeof(v_t) is distinct from ''number'' then
|
|
7
|
+
raise exception ''step_up_required'' using errcode = ''MBS01'', detail = p_operation;
|
|
8
|
+
end if;') = 0 then raise exception 'MUTATION ANCHOR MISS (1)'; end if;
|
|
9
|
+
n := replace(n, ' if jsonb_typeof(v_t) is distinct from ''number'' then
|
|
10
|
+
raise exception ''step_up_required'' using errcode = ''MBS01'', detail = p_operation;
|
|
11
|
+
end if;', '');
|
|
12
|
+
execute n;
|
|
13
|
+
end $m$;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
-- remove the amr element object/timestamp guards; must fail R-7b's string-timestamp row (#59)
|
|
2
|
+
do $m$
|
|
3
|
+
declare d text := pg_get_functiondef('agent_board._require_human_step_up(text)'::regprocedure); n text;
|
|
4
|
+
begin
|
|
5
|
+
n := d;
|
|
6
|
+
if strpos(n, ' continue when jsonb_typeof(v_e) is distinct from ''object'';
|
|
7
|
+
') = 0 then raise exception 'MUTATION ANCHOR MISS (1)'; end if;
|
|
8
|
+
n := replace(n, ' continue when jsonb_typeof(v_e) is distinct from ''object'';
|
|
9
|
+
', '');
|
|
10
|
+
if strpos(n, ' continue when jsonb_typeof(v_e -> ''timestamp'') is distinct from ''number'';
|
|
11
|
+
') = 0 then raise exception 'MUTATION ANCHOR MISS (2)'; end if;
|
|
12
|
+
n := replace(n, ' continue when jsonb_typeof(v_e -> ''timestamp'') is distinct from ''number'';
|
|
13
|
+
', '');
|
|
14
|
+
execute n;
|
|
15
|
+
end $m$;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
-- measure freshness on now() instead of clock_timestamp(); must fail the M14 row (#67)
|
|
2
|
+
do $m$
|
|
3
|
+
declare d text := pg_get_functiondef('agent_board._require_human_step_up(text)'::regprocedure); n text;
|
|
4
|
+
begin
|
|
5
|
+
n := d;
|
|
6
|
+
if strpos(n, 'v_now := extract(epoch from clock_timestamp());') = 0 then raise exception 'MUTATION ANCHOR MISS (1)'; end if;
|
|
7
|
+
n := replace(n, 'v_now := extract(epoch from clock_timestamp());', 'v_now := extract(epoch from now());');
|
|
8
|
+
execute n;
|
|
9
|
+
end $m$;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
-- the classifier accepts agents.metadata federation; must fail the M15 row (#66), RP-M15 (#74)
|
|
2
|
+
do $m$
|
|
3
|
+
declare d text := pg_get_functiondef('agent_board._step_up_is_portal_human(uuid)'::regprocedure); n text;
|
|
4
|
+
begin
|
|
5
|
+
n := d;
|
|
6
|
+
if strpos(n, 'and exists (
|
|
7
|
+
select 1
|
|
8
|
+
from agent_board.enrollment_federation_audit f') = 0 then raise exception 'MUTATION ANCHOR MISS (1)'; end if;
|
|
9
|
+
n := replace(n, 'and exists (
|
|
10
|
+
select 1
|
|
11
|
+
from agent_board.enrollment_federation_audit f', 'and (a.metadata ? ''federation'' or exists (
|
|
12
|
+
select 1
|
|
13
|
+
from agent_board.enrollment_federation_audit f');
|
|
14
|
+
if strpos(n, 'and f.mode = ''fedsession''))') = 0 then raise exception 'MUTATION ANCHOR MISS (2)'; end if;
|
|
15
|
+
n := replace(n, 'and f.mode = ''fedsession''))', 'and f.mode = ''fedsession'')))');
|
|
16
|
+
execute n;
|
|
17
|
+
end $m$;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
-- the helper skips the ledger lookup; must fail R-5f (#46)
|
|
2
|
+
do $m$
|
|
3
|
+
declare d text := pg_get_functiondef('agent_board._require_human_step_up(text)'::regprocedure); n text;
|
|
4
|
+
begin
|
|
5
|
+
n := d;
|
|
6
|
+
if strpos(n, ' if not exists (
|
|
7
|
+
select 1
|
|
8
|
+
from agent_board.portal_step_up_proofs p') = 0 then raise exception 'MUTATION ANCHOR MISS (1)'; end if;
|
|
9
|
+
n := replace(n, ' if not exists (
|
|
10
|
+
select 1
|
|
11
|
+
from agent_board.portal_step_up_proofs p', ' if false and not exists (
|
|
12
|
+
select 1
|
|
13
|
+
from agent_board.portal_step_up_proofs p');
|
|
14
|
+
execute n;
|
|
15
|
+
end $m$;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
-- operator rule ignores principal and sub (D3); must fail R-14 (#62)
|
|
2
|
+
do $m$
|
|
3
|
+
declare d text := pg_get_functiondef('agent_board._require_human_step_up(text)'::regprocedure); n text;
|
|
4
|
+
begin
|
|
5
|
+
n := d;
|
|
6
|
+
if strpos(n, 'if v_service is true and v_actor is null and v_uid is null then') = 0 then raise exception 'MUTATION ANCHOR MISS (1)'; end if;
|
|
7
|
+
n := replace(n, 'if v_service is true and v_actor is null and v_uid is null then', 'if v_service is true then');
|
|
8
|
+
execute n;
|
|
9
|
+
end $m$;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
-- drop the auth.uid() IS NULL conjunct; must fail R-14b (#63)
|
|
2
|
+
do $m$
|
|
3
|
+
declare d text := pg_get_functiondef('agent_board._require_human_step_up(text)'::regprocedure); n text;
|
|
4
|
+
begin
|
|
5
|
+
n := d;
|
|
6
|
+
if strpos(n, 'if v_service is true and v_actor is null and v_uid is null then') = 0 then raise exception 'MUTATION ANCHOR MISS (1)'; end if;
|
|
7
|
+
n := replace(n, 'if v_service is true and v_actor is null and v_uid is null then', 'if v_service is true and v_actor is null then');
|
|
8
|
+
execute n;
|
|
9
|
+
end $m$;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
-- E-2 M23: an authenticated-executable SECURITY DEFINER wrapper over record_portal_step_up; must fail EC-SU-4 (#4), naming it
|
|
2
|
+
create function agent_board.zz_m23_forge_step_up(p_agent_id uuid, p_t bigint) returns boolean
|
|
3
|
+
language sql security definer set search_path = '' as $$ select agent_board.record_portal_step_up(p_agent_id, p_t) $$;
|
|
4
|
+
revoke all on function agent_board.zz_m23_forge_step_up(uuid, bigint) from public;
|
|
5
|
+
grant execute on function agent_board.zz_m23_forge_step_up(uuid, bigint) to authenticated;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
-- the Portal branch measures age from the token iat; must fail R-4 (#34)
|
|
2
|
+
do $m$
|
|
3
|
+
declare d text := pg_get_functiondef('agent_board._require_human_step_up(text)'::regprocedure); n text;
|
|
4
|
+
begin
|
|
5
|
+
n := d;
|
|
6
|
+
if strpos(n, 'if agent_board._step_up_is_fresh(v_proof, v_now) is not true then') = 0 then raise exception 'MUTATION ANCHOR MISS (1)'; end if;
|
|
7
|
+
n := replace(n, 'if agent_board._step_up_is_fresh(v_proof, v_now) is not true then', 'if agent_board._step_up_is_fresh((v_claims ->> ''iat'')::numeric, v_now) is not true then');
|
|
8
|
+
execute n;
|
|
9
|
+
end $m$;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
-- window 300 -> 900; must fail R-1 (#29), P-2 (#18)
|
|
2
|
+
do $m$
|
|
3
|
+
declare d text := pg_get_functiondef('agent_board._step_up_max_age_seconds()'::regprocedure); n text;
|
|
4
|
+
begin
|
|
5
|
+
n := d;
|
|
6
|
+
if strpos(n, 'select 300::numeric') = 0 then raise exception 'MUTATION ANCHOR MISS (1)'; end if;
|
|
7
|
+
n := replace(n, 'select 300::numeric', 'select 900::numeric');
|
|
8
|
+
execute n;
|
|
9
|
+
end $m$;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
-- `<` -> `<=` in the predicate; must fail P-2 (#18)
|
|
2
|
+
do $m$
|
|
3
|
+
declare d text := pg_get_functiondef('agent_board._step_up_is_fresh(numeric,numeric)'::regprocedure); n text;
|
|
4
|
+
begin
|
|
5
|
+
n := d;
|
|
6
|
+
if strpos(n, 'p_now - p_proof < agent_board._step_up_max_age_seconds()') = 0 then raise exception 'MUTATION ANCHOR MISS (1)'; end if;
|
|
7
|
+
n := replace(n, 'p_now - p_proof < agent_board._step_up_max_age_seconds()', 'p_now - p_proof <= agent_board._step_up_max_age_seconds()');
|
|
8
|
+
execute n;
|
|
9
|
+
end $m$;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
-- drop the future-skew bound; must fail P-4 (#20), R-6 (#47)
|
|
2
|
+
do $m$
|
|
3
|
+
declare d text := pg_get_functiondef('agent_board._step_up_is_fresh(numeric,numeric)'::regprocedure); n text;
|
|
4
|
+
begin
|
|
5
|
+
n := d;
|
|
6
|
+
if strpos(n, 'and p_proof - p_now <= agent_board._step_up_future_skew_seconds()') = 0 then raise exception 'MUTATION ANCHOR MISS (1)'; end if;
|
|
7
|
+
n := replace(n, 'and p_proof - p_now <= agent_board._step_up_future_skew_seconds()', '');
|
|
8
|
+
execute n;
|
|
9
|
+
end $m$;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
-- local proof also read from user_metadata.amr; must fail R-5 (#41)
|
|
2
|
+
do $m$
|
|
3
|
+
declare d text := pg_get_functiondef('agent_board._require_human_step_up(text)'::regprocedure); n text;
|
|
4
|
+
begin
|
|
5
|
+
n := d;
|
|
6
|
+
if strpos(n, 'v_amr := v_claims -> ''amr'';') = 0 then raise exception 'MUTATION ANCHOR MISS (1)'; end if;
|
|
7
|
+
n := replace(n, 'v_amr := v_claims -> ''amr'';', 'v_amr := coalesce(v_claims -> ''user_metadata'' -> ''amr'', v_claims -> ''amr'');');
|
|
8
|
+
execute n;
|
|
9
|
+
end $m$;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
-- Portal claim also read from app_metadata; must fail R-5b (#42)
|
|
2
|
+
do $m$
|
|
3
|
+
declare d text := pg_get_functiondef('agent_board._require_human_step_up(text)'::regprocedure); n text;
|
|
4
|
+
begin
|
|
5
|
+
n := d;
|
|
6
|
+
if strpos(n, 'v_t := v_claims -> ''agent_board_step_up_at'';') = 0 then raise exception 'MUTATION ANCHOR MISS (1)'; end if;
|
|
7
|
+
n := replace(n, 'v_t := v_claims -> ''agent_board_step_up_at'';', 'v_claims := v_claims || coalesce(v_claims -> ''app_metadata'', ''{}''::jsonb); v_t := v_claims -> ''agent_board_step_up_at'';');
|
|
8
|
+
execute n;
|
|
9
|
+
end $m$;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
-- Portal claim also read from the legacy request.jwt.claim.* GUC; must fail R-5c (#43)
|
|
2
|
+
do $m$
|
|
3
|
+
declare d text := pg_get_functiondef('agent_board._require_human_step_up(text)'::regprocedure); n text;
|
|
4
|
+
begin
|
|
5
|
+
n := d;
|
|
6
|
+
if strpos(n, 'v_t := v_claims -> ''agent_board_step_up_at'';') = 0 then raise exception 'MUTATION ANCHOR MISS (1)'; end if;
|
|
7
|
+
n := replace(n, 'v_t := v_claims -> ''agent_board_step_up_at'';', 'if nullif(current_setting(''request.jwt.claim.agent_board_step_up_at'', true), '''') is not null then v_claims := v_claims || jsonb_build_object(''agent_board_step_up_at'', current_setting(''request.jwt.claim.agent_board_step_up_at'', true)::numeric); end if; v_t := v_claims -> ''agent_board_step_up_at'';');
|
|
8
|
+
execute n;
|
|
9
|
+
end $m$;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
-- either claim honoured for any human (class decided by claim presence); must fail R-5d (#44), R-5e (#45)
|
|
2
|
+
do $m$
|
|
3
|
+
declare d text := pg_get_functiondef('agent_board._require_human_step_up(text)'::regprocedure); n text;
|
|
4
|
+
begin
|
|
5
|
+
n := d;
|
|
6
|
+
if strpos(n, 'if agent_board._step_up_is_portal_human(v_actor) is true then') = 0 then raise exception 'MUTATION ANCHOR MISS (1)'; end if;
|
|
7
|
+
n := replace(n, 'if agent_board._step_up_is_portal_human(v_actor) is true then', 'if v_claims ? ''agent_board_step_up_at'' then');
|
|
8
|
+
execute n;
|
|
9
|
+
end $m$;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
-- accept any amr method; must fail R-4b (#35), R-4c (#36-39), E-0-AL (#16)
|
|
2
|
+
do $m$
|
|
3
|
+
declare d text := pg_get_functiondef('agent_board._require_human_step_up(text)'::regprocedure); n text;
|
|
4
|
+
begin
|
|
5
|
+
n := d;
|
|
6
|
+
if strpos(n, 'continue when ((v_e ->> ''method'') = any (v_methods)) is not true;') = 0 then raise exception 'MUTATION ANCHOR MISS (1)'; end if;
|
|
7
|
+
n := replace(n, 'continue when ((v_e ->> ''method'') = any (v_methods)) is not true;', '');
|
|
8
|
+
execute n;
|
|
9
|
+
end $m$;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
-- accept aal2 as freshness; must fail R-4c aal row (#40)
|
|
2
|
+
do $m$
|
|
3
|
+
declare d text := pg_get_functiondef('agent_board._require_human_step_up(text)'::regprocedure); n text;
|
|
4
|
+
begin
|
|
5
|
+
n := d;
|
|
6
|
+
if strpos(n, 'v_amr := v_claims -> ''amr'';') = 0 then raise exception 'MUTATION ANCHOR MISS (1)'; end if;
|
|
7
|
+
n := replace(n, 'v_amr := v_claims -> ''amr'';', 'if v_claims ->> ''aal'' = ''aal2'' then return; end if; v_amr := v_claims -> ''amr'';');
|
|
8
|
+
execute n;
|
|
9
|
+
end $m$;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
-- apply to every kind (no agent exemption); must fail C-3 (#26)
|
|
2
|
+
do $m$
|
|
3
|
+
declare d text := pg_get_functiondef('agent_board._require_human_step_up(text)'::regprocedure); n text;
|
|
4
|
+
begin
|
|
5
|
+
n := d;
|
|
6
|
+
if strpos(n, 'if v_kind in (''agent'', ''system'') then') = 0 then raise exception 'MUTATION ANCHOR MISS (1)'; end if;
|
|
7
|
+
n := replace(n, 'if v_kind in (''agent'', ''system'') then', 'if false then');
|
|
8
|
+
execute n;
|
|
9
|
+
end $m$;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
-- the allowlist ships non-empty; must fail E-0-AL (#15, #16)
|
|
2
|
+
do $m$
|
|
3
|
+
declare d text := pg_get_functiondef('agent_board._step_up_amr_methods()'::regprocedure); n text;
|
|
4
|
+
begin
|
|
5
|
+
n := d;
|
|
6
|
+
if strpos(n, 'select ''{}''::text[]') = 0 then raise exception 'MUTATION ANCHOR MISS (1)'; end if;
|
|
7
|
+
n := replace(n, 'select ''{}''::text[]', 'select ''{otp}''::text[]');
|
|
8
|
+
execute n;
|
|
9
|
+
end $m$;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
-- S2-4: the writer's argument p_proof_at renamed; must fail RP-13 (#99)
|
|
2
|
+
drop function agent_board.record_portal_step_up(uuid, bigint);
|
|
3
|
+
create function agent_board.record_portal_step_up(p_agent_id uuid, p_proof bigint) returns boolean
|
|
4
|
+
language plpgsql security definer set search_path = '' as $$
|
|
5
|
+
begin
|
|
6
|
+
if p_agent_id is null or p_proof is null then return false; end if;
|
|
7
|
+
if agent_board._step_up_is_portal_human(p_agent_id) is not true then return false; end if;
|
|
8
|
+
if agent_board._step_up_proof_recordable(p_proof::numeric, extract(epoch from clock_timestamp())) is not true then return false; end if;
|
|
9
|
+
insert into agent_board.portal_step_up_proofs(agent_id, proof_at) values (p_agent_id, p_proof) on conflict (agent_id, proof_at) do nothing;
|
|
10
|
+
return true;
|
|
11
|
+
end $$;
|
|
12
|
+
revoke all on function agent_board.record_portal_step_up(uuid, bigint) from public, anon, authenticated, agent_board_delegate;
|
|
13
|
+
grant execute on function agent_board.record_portal_step_up(uuid, bigint) to service_role;
|
|
14
|
+
comment on function agent_board.record_portal_step_up(uuid, bigint) is 'mutant';
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
-- S2-3: enrollment_federation_audit.mode changes type (text -> varchar(32)); must fail EC-SU-4i (#101). (A RENAME also breaks this file's own fixture insert and aborts it, which is never counted as a kill; the type change keeps the fixture working and isolates the pin.)
|
|
2
|
+
alter table agent_board.enrollment_federation_audit alter column mode type varchar(32);
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
-- E-6(b): the helper always raises; must fail C-1..C-4b (#22-28)
|
|
2
|
+
do $m$
|
|
3
|
+
declare d text := pg_get_functiondef('agent_board._require_human_step_up(text)'::regprocedure); n text;
|
|
4
|
+
begin
|
|
5
|
+
n := d;
|
|
6
|
+
if strpos(n, ' -- Claims: parsed in their own guarded block.') = 0 then raise exception 'MUTATION ANCHOR MISS (1)'; end if;
|
|
7
|
+
n := replace(n, ' -- Claims: parsed in their own guarded block.', ' raise exception ''step_up_required'' using errcode = ''MBS01'', detail = p_operation;
|
|
8
|
+
-- Claims: parsed in their own guarded block.');
|
|
9
|
+
execute n;
|
|
10
|
+
end $m$;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
-- S1-2: an authenticated-executable SECURITY DEFINER routine (public schema) with dynamic EXECUTE; must fail EC-SU-4d (#105)
|
|
2
|
+
create function public.zz_mdx_dynamic(p_sql text) returns void
|
|
3
|
+
language plpgsql security definer set search_path = '' as $$ begin execute p_sql; end $$;
|
|
4
|
+
revoke all on function public.zz_mdx_dynamic(text) from public;
|
|
5
|
+
grant execute on function public.zz_mdx_dynamic(text) to authenticated;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
-- §6.1: DETAIL carries the claim value; must fail the DETAIL row (#68)
|
|
2
|
+
do $m$
|
|
3
|
+
declare d text := pg_get_functiondef('agent_board._require_human_step_up(text)'::regprocedure); n text;
|
|
4
|
+
begin
|
|
5
|
+
n := d;
|
|
6
|
+
if strpos(n, ' if agent_board._step_up_is_fresh(v_proof, v_now) is not true then
|
|
7
|
+
raise exception ''step_up_required'' using errcode = ''MBS01'', detail = p_operation;') = 0 then raise exception 'MUTATION ANCHOR MISS (1)'; end if;
|
|
8
|
+
n := replace(n, ' if agent_board._step_up_is_fresh(v_proof, v_now) is not true then
|
|
9
|
+
raise exception ''step_up_required'' using errcode = ''MBS01'', detail = p_operation;', ' if agent_board._step_up_is_fresh(v_proof, v_now) is not true then
|
|
10
|
+
raise exception ''step_up_required'' using errcode = ''MBS01'', detail = p_operation || '':'' || v_proof::text;');
|
|
11
|
+
execute n;
|
|
12
|
+
end $m$;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
-- EC-SU-0 discriminance: a function that calls the helper; must fail EC-SU-0 (#1), naming it
|
|
2
|
+
create function agent_board.zz_mec0_gated_write() returns void
|
|
3
|
+
language plpgsql security definer set search_path = '' as $$ begin perform agent_board._require_human_step_up('zz'); end $$;
|
|
4
|
+
revoke all on function agent_board.zz_mec0_gated_write() from public;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
-- S1-1: an OVERLOAD _require_human_step_up(uuid) that calls the helper; must fail EC-SU-0 (#1), naming the overload by signature
|
|
2
|
+
create function agent_board._require_human_step_up(p_x uuid) returns void
|
|
3
|
+
language plpgsql security definer set search_path = '' as $$ begin perform agent_board._require_human_step_up('zz'::text); end $$;
|
|
4
|
+
revoke all on function agent_board._require_human_step_up(uuid) from public;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
-- record_portal_step_up drops the Portal-class check; must fail RP-2 (#71-72), RP-3 (#73)
|
|
2
|
+
do $m$
|
|
3
|
+
declare d text := pg_get_functiondef('agent_board.record_portal_step_up(uuid,bigint)'::regprocedure); n text;
|
|
4
|
+
begin
|
|
5
|
+
n := d;
|
|
6
|
+
if strpos(n, 'if agent_board._step_up_is_portal_human(p_agent_id) is not true then') = 0 then raise exception 'MUTATION ANCHOR MISS (1)'; end if;
|
|
7
|
+
n := replace(n, 'if agent_board._step_up_is_portal_human(p_agent_id) is not true then', 'if false then');
|
|
8
|
+
execute n;
|
|
9
|
+
end $m$;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
-- the writer's window drops its lower bound; must fail WR-3 (#94), WR-4 (#95), RP-4 old (#75)
|
|
2
|
+
do $m$
|
|
3
|
+
declare d text := pg_get_functiondef('agent_board._step_up_proof_recordable(numeric,numeric)'::regprocedure); n text;
|
|
4
|
+
begin
|
|
5
|
+
n := d;
|
|
6
|
+
if strpos(n, 'p_proof >= p_now - 330 and ') = 0 then raise exception 'MUTATION ANCHOR MISS (1)'; end if;
|
|
7
|
+
n := replace(n, 'p_proof >= p_now - 330 and ', '');
|
|
8
|
+
execute n;
|
|
9
|
+
end $m$;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
-- the prune ignores the agent; must fail RP-7 (#82)
|
|
2
|
+
do $m$
|
|
3
|
+
declare d text := pg_get_functiondef('agent_board.record_portal_step_up(uuid,bigint)'::regprocedure); n text;
|
|
4
|
+
begin
|
|
5
|
+
n := d;
|
|
6
|
+
if strpos(n, ' where p.agent_id = p_agent_id
|
|
7
|
+
and p.proof_at::numeric < v_now - 86400;') = 0 then raise exception 'MUTATION ANCHOR MISS (1)'; end if;
|
|
8
|
+
n := replace(n, ' where p.agent_id = p_agent_id
|
|
9
|
+
and p.proof_at::numeric < v_now - 86400;', ' where p.proof_at::numeric < v_now - 86400;');
|
|
10
|
+
execute n;
|
|
11
|
+
end $m$;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
-- the writer's lower bound becomes exclusive (>= -> >); must fail WR-2 (#93)
|
|
2
|
+
do $m$
|
|
3
|
+
declare d text := pg_get_functiondef('agent_board._step_up_proof_recordable(numeric,numeric)'::regprocedure); n text;
|
|
4
|
+
begin
|
|
5
|
+
n := d;
|
|
6
|
+
if strpos(n, 'p_proof >= p_now - 330') = 0 then raise exception 'MUTATION ANCHOR MISS (1)'; end if;
|
|
7
|
+
n := replace(n, 'p_proof >= p_now - 330', 'p_proof > p_now - 330');
|
|
8
|
+
execute n;
|
|
9
|
+
end $m$;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
-- the writer's upper bound becomes exclusive (<= -> <); must fail WR-5 (#96)
|
|
2
|
+
do $m$
|
|
3
|
+
declare d text := pg_get_functiondef('agent_board._step_up_proof_recordable(numeric,numeric)'::regprocedure); n text;
|
|
4
|
+
begin
|
|
5
|
+
n := d;
|
|
6
|
+
if strpos(n, 'p_proof <= p_now + 60') = 0 then raise exception 'MUTATION ANCHOR MISS (1)'; end if;
|
|
7
|
+
n := replace(n, 'p_proof <= p_now + 60', 'p_proof < p_now + 60');
|
|
8
|
+
execute n;
|
|
9
|
+
end $m$;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
-- the writer's upper bound widens 60 -> 61; must fail WR-6 (#97), WR-7 (#98), RP-4 new (#76)
|
|
2
|
+
do $m$
|
|
3
|
+
declare d text := pg_get_functiondef('agent_board._step_up_proof_recordable(numeric,numeric)'::regprocedure); n text;
|
|
4
|
+
begin
|
|
5
|
+
n := d;
|
|
6
|
+
if strpos(n, 'p_proof <= p_now + 60') = 0 then raise exception 'MUTATION ANCHOR MISS (1)'; end if;
|
|
7
|
+
n := replace(n, 'p_proof <= p_now + 60', 'p_proof <= p_now + 61');
|
|
8
|
+
execute n;
|
|
9
|
+
end $m$;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
-- a second (service-only) ledger writer; must fail EC-SU-4 (#3)
|
|
2
|
+
create function agent_board.zz_mw2_second_writer(p_agent_id uuid) returns void
|
|
3
|
+
language sql security definer set search_path = '' as $$ insert into agent_board.portal_step_up_proofs(agent_id, proof_at) values (p_agent_id, 1) $$;
|
|
4
|
+
revoke all on function agent_board.zz_mw2_second_writer(uuid) from public, anon, authenticated;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
-- S1-2(b): a routine OUTSIDE agent_board naming record_portal_step_up; must fail EC-SU-4h (#103)
|
|
2
|
+
create function public.zz_mxs_wrap(p_agent uuid, p_t bigint) returns boolean
|
|
3
|
+
language sql security definer set search_path = '' as $$ select agent_board.record_portal_step_up(p_agent, p_t) $$;
|
|
4
|
+
revoke all on function public.zz_mxs_wrap(uuid, bigint) from public;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# #669 STEPUP PR-A mutation receipts (AGENTS.md rule 2; plan §10.6 rows that apply to PR-A, plus
|
|
3
|
+
# E-2's M23 and E-6(b)'s "the helper always raises"). Connection comes ONLY from the libpq
|
|
4
|
+
# environment (PGHOST/PGPORT/PGUSER/PGPASSWORD/PGDATABASE), never argv. The target must be an
|
|
5
|
+
# OWNED database holding this tree's applied bundle (CI: a throwaway job's Supabase; never a
|
|
6
|
+
# shared cluster).
|
|
7
|
+
#
|
|
8
|
+
# Per mutation:
|
|
9
|
+
# applied the mutation runs ALONE in a rolled-back transaction with ON_ERROR_STOP, and the
|
|
10
|
+
# catalog fingerprint (every non-system routine with its argument names, ACL, body and
|
|
11
|
+
# comment; the ledger's ACL and policies; the ledger's and the fedsession audit's
|
|
12
|
+
# columns) read inside that transaction must differ from the baseline. An anchor miss raises 'MUTATION ANCHOR MISS' and is reported, never
|
|
13
|
+
# counted as a kill.
|
|
14
|
+
# pgTAP the mutation and agent_board_step_up_helper.test.sql run in ONE transaction that is
|
|
15
|
+
# rolled back. The receipt records plan, emitted, ok and not ok counts and every
|
|
16
|
+
# failing line, counted from the TAP, never inferred from an absence. An aborted file
|
|
17
|
+
# (emitted < plan) is reported as ABORTED, never as a kill.
|
|
18
|
+
# The fingerprint must equal the baseline after every leg (nothing leaked past a rollback).
|
|
19
|
+
# Usage: run.sh <receipt-path> [mutation.sql ...] (default: every *.sql beside this script)
|
|
20
|
+
set -uo pipefail
|
|
21
|
+
HERE="$(cd "$(dirname "$0")" && pwd)"
|
|
22
|
+
PKG="$(cd "$HERE/../../.." && pwd)"
|
|
23
|
+
TEST="${STEPUP_TEST:-$PKG/tests/agent_board_step_up_helper.test.sql}"
|
|
24
|
+
OUT="${1:?receipt path}"; shift
|
|
25
|
+
if [ "$#" -gt 0 ]; then MUTS=("$@"); else mapfile -t MUTS < <(find "$HERE" -maxdepth 1 -name '*.sql' | sort -V); fi
|
|
26
|
+
[ -n "${PGDATABASE:-}" ] || { echo "FATAL: PGDATABASE unset (libpq environment required)" >&2; exit 3; }
|
|
27
|
+
P=(psql -X -qtA)
|
|
28
|
+
FPSQL="select md5(coalesce((select string_agg(p.oid::regprocedure::text || coalesce(p.proargnames::text, '') || coalesce(p.proacl::text, '') || p.prosrc || p.provolatile::text || p.prosecdef::text || coalesce(obj_description(p.oid, 'pg_proc'), ''), '|' order by p.oid::regprocedure::text) from pg_proc p where p.pronamespace not in ('pg_catalog'::regnamespace, 'information_schema'::regnamespace)), '') || coalesce((select string_agg(attrelid::regclass::text || '.' || attname || ':' || atttypid::regtype::text, '|' order by attrelid::regclass::text, attnum) from pg_attribute where attrelid in ('agent_board.portal_step_up_proofs'::regclass, 'agent_board.enrollment_federation_audit'::regclass) and attnum > 0 and not attisdropped), '') || coalesce((select relacl::text from pg_class where oid = 'agent_board.portal_step_up_proofs'::regclass), '') || coalesce((select string_agg(polname || pg_get_expr(polqual, polrelid), '|' order by polname) from pg_policy where polrelid = 'agent_board.portal_step_up_proofs'::regclass), ''))"
|
|
29
|
+
fp() { "${P[@]}" -c "$FPSQL"; }
|
|
30
|
+
ORIG="$(fp)"
|
|
31
|
+
|
|
32
|
+
applied() { # $1 mutation file -> prints 'applied' / 'NOT APPLIED: <why>'
|
|
33
|
+
local out
|
|
34
|
+
out="$(printf 'begin;\n\\set ON_ERROR_STOP 1\n\\i %s\n%s;\nrollback;\n' "$1" "$FPSQL" | "${P[@]}" 2>&1)"
|
|
35
|
+
if grep -qE '(ERROR|FATAL):' <<<"$out"; then
|
|
36
|
+
echo "NOT APPLIED: $(grep -E '(ERROR|FATAL):' <<<"$out" | head -1)"
|
|
37
|
+
elif [ "$(tail -1 <<<"$out")" = "$ORIG" ]; then
|
|
38
|
+
echo "NOT APPLIED: catalog fingerprint unchanged (no-op)"
|
|
39
|
+
else
|
|
40
|
+
echo "applied"
|
|
41
|
+
fi
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
tap() { # $1 label, $2 mutation file or empty
|
|
45
|
+
local out plan ok nok
|
|
46
|
+
if [ -n "$2" ]; then out="$(printf 'begin;\n\\i %s\n\\i %s\nrollback;\n' "$2" "$TEST" | "${P[@]}" 2>&1)"
|
|
47
|
+
else out="$(printf 'begin;\n\\i %s\nrollback;\n' "$TEST" | "${P[@]}" 2>&1)"; fi
|
|
48
|
+
plan="$(sed -nE 's/^1\.\.([0-9]+)$/\1/p' <<<"$out" | head -1)"
|
|
49
|
+
ok="$(grep -cE '^ok [0-9]+' <<<"$out")"; nok="$(grep -cE '^not ok [0-9]+' <<<"$out")"
|
|
50
|
+
printf '%s: pgtap plan=%s emitted=%s ok=%s not_ok=%s%s\n' "$1" "${plan:-NONE}" "$((ok + nok))" "$ok" "$nok" \
|
|
51
|
+
"$([ "${plan:-x}" = "$((ok + nok))" ] || echo ' ABORTED')"
|
|
52
|
+
grep -E '^not ok [0-9]+' <<<"$out" | sed 's/^/ /'
|
|
53
|
+
grep -E '^#\s+(have|want|caught|wanted|died):' <<<"$out" | head -8 | sed 's/^/ /'
|
|
54
|
+
grep -E '(ERROR|FATAL):' <<<"$out" | head -3 | sed 's/^/ ERR /'
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
{
|
|
58
|
+
echo "# #669 STEPUP PR-A mutation receipt -- $(date -u +%FT%TZ)"
|
|
59
|
+
echo "# tree $(git -C "$PKG" rev-parse HEAD)$(git -C "$PKG" diff --quiet HEAD -- . || echo ' + uncommitted changes')"
|
|
60
|
+
echo "# catalog fingerprint before: $ORIG"
|
|
61
|
+
tap "BASELINE" ""
|
|
62
|
+
for m in "${MUTS[@]}"; do
|
|
63
|
+
name="$(basename "$m" .sql)"
|
|
64
|
+
echo "-- $name: $(head -1 "$m" | sed 's/^-- //') [sha256 $(sha256sum "$m" | cut -c1-16)]"
|
|
65
|
+
echo " $(applied "$m")"
|
|
66
|
+
[ "$(fp)" = "$ORIG" ] || { echo "FATAL: fingerprint changed after the rolled-back apply leg of $name"; exit 3; }
|
|
67
|
+
tap "$name" "$m"
|
|
68
|
+
[ "$(fp)" = "$ORIG" ] || { echo "FATAL: fingerprint changed after the rolled-back pgTAP leg of $name"; exit 3; }
|
|
69
|
+
done
|
|
70
|
+
tap "AFTER" ""
|
|
71
|
+
echo "# catalog fingerprint after: $(fp)"
|
|
72
|
+
} | tee "$OUT"
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
-- EQUIVALENT: the helper takes the author from the message the writer inserted, not from the session
|
|
2
|
+
do $m$ declare d text := pg_get_functiondef('agent_board._record_send_outcome(text,uuid,text,uuid)'::regprocedure); n text; begin
|
|
3
|
+
if position($q$ v_author := agent_board.current_agent_id();$q$ in d) = 0 then raise exception 'mutation anchor not found in agent_board._record_send_outcome(text,uuid,text,uuid)'; end if;
|
|
4
|
+
n := replace(d, $q$ v_author := agent_board.current_agent_id();$q$, $q$ v_author := (select m.author_agent_id from agent_board.messages m where m.id = p_message_id);$q$);
|
|
5
|
+
if n = d then raise exception 'mutation is a no-op'; end if;
|
|
6
|
+
execute n;
|
|
7
|
+
end $m$;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
-- EQUIVALENT: the helper's null-principal check is removed
|
|
2
|
+
do $m$ declare d text := pg_get_functiondef('agent_board._record_send_outcome(text,uuid,text,uuid)'::regprocedure); n text; begin
|
|
3
|
+
if position($q$ if v_author is null then
|
|
4
|
+
raise exception 'send outcome requires a session principal' using errcode = '42501';
|
|
5
|
+
end if;
|
|
6
|
+
$q$ in d) = 0 then raise exception 'mutation anchor not found in agent_board._record_send_outcome(text,uuid,text,uuid)'; end if;
|
|
7
|
+
n := replace(d, $q$ if v_author is null then
|
|
8
|
+
raise exception 'send outcome requires a session principal' using errcode = '42501';
|
|
9
|
+
end if;
|
|
10
|
+
$q$, $q$$q$);
|
|
11
|
+
if n = d then raise exception 'mutation is a no-op'; end if;
|
|
12
|
+
execute n;
|
|
13
|
+
end $m$;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
-- post_board_message: the idempotency advisory lock is removed
|
|
2
|
+
do $m$ declare d text := pg_get_functiondef('agent_board.post_board_message(uuid,uuid,uuid,text,text,text,text,text,jsonb)'::regprocedure); n text; begin
|
|
3
|
+
if position($q$ perform agent_board._lock_idempotency_key(
|
|
4
|
+
'post_board_message:'$q$ in d) = 0 then raise exception 'mutation anchor not found in agent_board.post_board_message(uuid,uuid,uuid,text,text,text,text,text,jsonb)'; end if;
|
|
5
|
+
n := replace(d, $q$ perform agent_board._lock_idempotency_key(
|
|
6
|
+
'post_board_message:'$q$, $q$ perform concat(
|
|
7
|
+
'post_board_message:'$q$);
|
|
8
|
+
if n = d then raise exception 'mutation is a no-op'; end if;
|
|
9
|
+
execute n;
|
|
10
|
+
end $m$;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
-- send_outcomes: the message foreign key loses ON DELETE CASCADE
|
|
2
|
+
do $m$ declare c text; begin
|
|
3
|
+
select conname into c from pg_constraint
|
|
4
|
+
where conrelid = 'agent_board.send_outcomes'::regclass and contype = 'f' and confrelid = 'agent_board.messages'::regclass;
|
|
5
|
+
if c is null then raise exception 'M13 anchor: no message FK'; end if;
|
|
6
|
+
execute format('alter table agent_board.send_outcomes drop constraint %I', c);
|
|
7
|
+
execute format('alter table agent_board.send_outcomes add constraint %I foreign key (message_id) references agent_board.messages(id)', c);
|
|
8
|
+
end $m$;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
-- post_message: mints a receipt when its caller metadata carries an idempotencyKey
|
|
2
|
+
do $m$ declare d text := pg_get_functiondef('agent_board.post_message(uuid,uuid,text,text,uuid,jsonb)'::regprocedure); n text; begin
|
|
3
|
+
if position($q$ return query select v_message.message_id,v_message.thread_id,v_message.task_id,$q$ in d) = 0 then raise exception 'mutation anchor not found in agent_board.post_message(uuid,uuid,text,text,uuid,jsonb)'; end if;
|
|
4
|
+
n := replace(d, $q$ return query select v_message.message_id,v_message.thread_id,v_message.task_id,$q$, $q$ if p_metadata ? 'idempotencyKey' then
|
|
5
|
+
perform agent_board._record_send_outcome(coalesce(p_metadata ->> 'rpcName', 'post_board_message'), v_message.message_id,
|
|
6
|
+
p_metadata ->> 'idempotencyKey', v_board_id);
|
|
7
|
+
end if;
|
|
8
|
+
return query select v_message.message_id,v_message.thread_id,v_message.task_id,$q$);
|
|
9
|
+
if n = d then raise exception 'mutation is a no-op'; end if;
|
|
10
|
+
execute n;
|
|
11
|
+
end $m$;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
-- a second receipt writer: an overload of the helper that inserts directly
|
|
2
|
+
create function agent_board._record_send_outcome(p_operation text, p_message_id uuid, p_idempotency_key text)
|
|
3
|
+
returns void language plpgsql security definer set search_path = '' as $f$
|
|
4
|
+
begin
|
|
5
|
+
insert into agent_board.send_outcomes(operation, author_agent_id, thread_id, idempotency_key, message_id, created_at)
|
|
6
|
+
select p_operation, m.author_agent_id, m.thread_id, btrim(p_idempotency_key), m.id, m.created_at
|
|
7
|
+
from agent_board.messages m where m.id = p_message_id;
|
|
8
|
+
end $f$;
|
|
9
|
+
revoke all on function agent_board._record_send_outcome(text, uuid, text) from public, anon, authenticated, service_role, agent_board_delegate;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
-- read: the key is no longer trimmed
|
|
2
|
+
do $m$ declare d text := pg_get_functiondef('agent_board.get_send_outcome(uuid,text,text)'::regprocedure); n text; begin
|
|
3
|
+
if position($q$ v_key := nullif(btrim(p_idempotency_key), '');$q$ in d) = 0 then raise exception 'mutation anchor not found in agent_board.get_send_outcome(uuid,text,text)'; end if;
|
|
4
|
+
n := replace(d, $q$ v_key := nullif(btrim(p_idempotency_key), '');$q$, $q$ v_key := nullif(p_idempotency_key, '');$q$);
|
|
5
|
+
if n = d then raise exception 'mutation is a no-op'; end if;
|
|
6
|
+
execute n;
|
|
7
|
+
end $m$;
|