@consiliency/agent-board-schema 1.75.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.
Files changed (52) hide show
  1. package/fixtures/already-applied.json +4 -0
  2. package/migrations/20261109000100_agent_board_step_up_groundwork.sql +343 -0
  3. package/package.json +1 -1
  4. package/schema-manifest.json +12 -3
  5. package/src/tooling.test.mjs +3 -2
  6. package/tests/agent_board_enrollment_audit_content.test.sql +6 -1
  7. package/tests/agent_board_step_up_helper.test.sql +711 -0
  8. package/tests/agent_board_write_enforcement_class.test.sql +5 -2
  9. package/tests/catalog/function_execute_privileges.json +72 -0
  10. package/tests/catalog/p_metadata_parameters.json +32 -0
  11. package/tests/mutations/669/M10_service_role_blanket.sql +10 -0
  12. package/tests/mutations/669/M12a_no_parse_wrapper.sql +17 -0
  13. package/tests/mutations/669/M12b_no_session_wrapper.sql +23 -0
  14. package/tests/mutations/669/M12c_no_claim_type_guard.sql +13 -0
  15. package/tests/mutations/669/M12d_no_amr_element_guards.sql +15 -0
  16. package/tests/mutations/669/M14_now_not_clock.sql +9 -0
  17. package/tests/mutations/669/M15_classifier_reads_metadata.sql +17 -0
  18. package/tests/mutations/669/M17_skip_ledger.sql +15 -0
  19. package/tests/mutations/669/M18_service_role_sub_insensitive.sql +9 -0
  20. package/tests/mutations/669/M18b_drop_uid_conjunct.sql +9 -0
  21. package/tests/mutations/669/M23_definer_wrapper_over_writer.sql +5 -0
  22. package/tests/mutations/669/M3_age_from_iat.sql +9 -0
  23. package/tests/mutations/669/M4_window_900.sql +9 -0
  24. package/tests/mutations/669/M4b_lt_to_le.sql +9 -0
  25. package/tests/mutations/669/M5_no_skew_bound.sql +9 -0
  26. package/tests/mutations/669/M6a_user_metadata_amr.sql +9 -0
  27. package/tests/mutations/669/M6b_app_metadata_claim.sql +9 -0
  28. package/tests/mutations/669/M6c_legacy_guc.sql +9 -0
  29. package/tests/mutations/669/M7_either_claim_any_human.sql +9 -0
  30. package/tests/mutations/669/M8_any_amr_method.sql +9 -0
  31. package/tests/mutations/669/M8b_accept_aal2.sql +9 -0
  32. package/tests/mutations/669/M9_every_kind.sql +9 -0
  33. package/tests/mutations/669/MAL_allowlist_nonempty.sql +9 -0
  34. package/tests/mutations/669/MAR_writer_arg_renamed.sql +14 -0
  35. package/tests/mutations/669/MAU_audit_mode_retyped.sql +2 -0
  36. package/tests/mutations/669/MA_helper_always_raises.sql +10 -0
  37. package/tests/mutations/669/MDX_dynamic_execute_definer.sql +5 -0
  38. package/tests/mutations/669/MD_detail_carries_value.sql +12 -0
  39. package/tests/mutations/669/MEC0_caller_of_helper.sql +4 -0
  40. package/tests/mutations/669/MEC0b_overload_caller.sql +4 -0
  41. package/tests/mutations/669/MG1_helper_granted_authenticated.sql +2 -0
  42. package/tests/mutations/669/MG2_ledger_insert_authenticated.sql +2 -0
  43. package/tests/mutations/669/MG3_ledger_policy.sql +2 -0
  44. package/tests/mutations/669/MR1_writer_no_class_check.sql +9 -0
  45. package/tests/mutations/669/MR2_writer_wide_window.sql +9 -0
  46. package/tests/mutations/669/MR3_writer_prunes_everyone.sql +11 -0
  47. package/tests/mutations/669/MR4_writer_lower_exclusive.sql +9 -0
  48. package/tests/mutations/669/MR5_writer_upper_exclusive.sql +9 -0
  49. package/tests/mutations/669/MR6_writer_upper_61.sql +9 -0
  50. package/tests/mutations/669/MW2_second_ledger_writer.sql +4 -0
  51. package/tests/mutations/669/MXS_cross_schema_wrapper.sql +4 -0
  52. package/tests/mutations/669/run.sh +72 -0
@@ -435,10 +435,13 @@ select distinct p.oid,
435
435
  -- 64 -> 65 with #670's agent_board.send_outcomes (20261108000100). Its only writer,
436
436
  -- _record_send_outcome, is EXECUTE-able by no API role but is reached from the authenticated-
437
437
  -- executable message cores, so the relation joins WEC-2's set below.
438
+ -- 65 -> 66 with #669 PR-A's agent_board.portal_step_up_proofs (20261109000100). Its only writer,
439
+ -- record_portal_step_up, is EXECUTE-able by service_role only and is called by no function, so
440
+ -- it adds no member to the `authenticated` writer population and WEC-2's set is unchanged.
438
441
  select is(
439
442
  (select count(*)::text from _wec_target where relkind = 'r'),
440
- '65',
441
- '#325 canary: agent_board has 65 base tables — the universe the write scan runs over, pinned so an empty violating set below cannot mean an empty universe');
443
+ '66',
444
+ '#325 canary: agent_board has 66 base tables — the universe the write scan runs over, pinned so an empty violating set below cannot mean an empty universe');
442
445
 
443
446
  -- WEC-2. The relations the class writes, as an EXACT SET. A new one names itself.
444
447
  select is(
@@ -784,6 +784,15 @@
784
784
  "authenticated": false
785
785
  }
786
786
  },
787
+ {
788
+ "name": "_require_human_step_up",
789
+ "signature": "_require_human_step_up(p_operation text)",
790
+ "executable_by": {
791
+ "anon": false,
792
+ "service_role": false,
793
+ "authenticated": false
794
+ }
795
+ },
787
796
  {
788
797
  "name": "_require_platform_admin_user_id",
789
798
  "signature": "_require_platform_admin_user_id()",
@@ -964,6 +973,60 @@
964
973
  "authenticated": false
965
974
  }
966
975
  },
976
+ {
977
+ "name": "_step_up_amr_methods",
978
+ "signature": "_step_up_amr_methods()",
979
+ "executable_by": {
980
+ "anon": false,
981
+ "service_role": false,
982
+ "authenticated": false
983
+ }
984
+ },
985
+ {
986
+ "name": "_step_up_future_skew_seconds",
987
+ "signature": "_step_up_future_skew_seconds()",
988
+ "executable_by": {
989
+ "anon": false,
990
+ "service_role": false,
991
+ "authenticated": false
992
+ }
993
+ },
994
+ {
995
+ "name": "_step_up_is_fresh",
996
+ "signature": "_step_up_is_fresh(p_proof numeric, p_now numeric)",
997
+ "executable_by": {
998
+ "anon": false,
999
+ "service_role": false,
1000
+ "authenticated": false
1001
+ }
1002
+ },
1003
+ {
1004
+ "name": "_step_up_is_portal_human",
1005
+ "signature": "_step_up_is_portal_human(p_agent_id uuid)",
1006
+ "executable_by": {
1007
+ "anon": false,
1008
+ "service_role": false,
1009
+ "authenticated": false
1010
+ }
1011
+ },
1012
+ {
1013
+ "name": "_step_up_max_age_seconds",
1014
+ "signature": "_step_up_max_age_seconds()",
1015
+ "executable_by": {
1016
+ "anon": false,
1017
+ "service_role": false,
1018
+ "authenticated": false
1019
+ }
1020
+ },
1021
+ {
1022
+ "name": "_step_up_proof_recordable",
1023
+ "signature": "_step_up_proof_recordable(p_proof numeric, p_now numeric)",
1024
+ "executable_by": {
1025
+ "anon": false,
1026
+ "service_role": false,
1027
+ "authenticated": false
1028
+ }
1029
+ },
967
1030
  {
968
1031
  "name": "_trim_inbox_text",
969
1032
  "signature": "_trim_inbox_text(p_value text, p_max_length integer)",
@@ -1630,6 +1693,15 @@
1630
1693
  "authenticated": false
1631
1694
  }
1632
1695
  },
1696
+ {
1697
+ "name": "record_portal_step_up",
1698
+ "signature": "record_portal_step_up(p_agent_id uuid, p_proof_at bigint)",
1699
+ "executable_by": {
1700
+ "anon": false,
1701
+ "service_role": true,
1702
+ "authenticated": false
1703
+ }
1704
+ },
1633
1705
  {
1634
1706
  "name": "record_session_identity_state",
1635
1707
  "signature": "record_session_identity_state(p_identity_agent_id uuid, p_fingerprint jsonb)",
@@ -349,6 +349,10 @@
349
349
  "signature": "_refuse_delegate_membership_target(p_agent_id uuid, p_operation text)",
350
350
  "declares_p_metadata": false
351
351
  },
352
+ {
353
+ "signature": "_require_human_step_up(p_operation text)",
354
+ "declares_p_metadata": false
355
+ },
352
356
  {
353
357
  "signature": "_require_platform_admin_user_id()",
354
358
  "declares_p_metadata": false
@@ -429,6 +433,30 @@
429
433
  "signature": "_signed_write_actor_id(p_payload jsonb, p_gateway_decision jsonb, p_actor_field text)",
430
434
  "declares_p_metadata": false
431
435
  },
436
+ {
437
+ "signature": "_step_up_amr_methods()",
438
+ "declares_p_metadata": false
439
+ },
440
+ {
441
+ "signature": "_step_up_future_skew_seconds()",
442
+ "declares_p_metadata": false
443
+ },
444
+ {
445
+ "signature": "_step_up_is_fresh(p_proof numeric, p_now numeric)",
446
+ "declares_p_metadata": false
447
+ },
448
+ {
449
+ "signature": "_step_up_is_portal_human(p_agent_id uuid)",
450
+ "declares_p_metadata": false
451
+ },
452
+ {
453
+ "signature": "_step_up_max_age_seconds()",
454
+ "declares_p_metadata": false
455
+ },
456
+ {
457
+ "signature": "_step_up_proof_recordable(p_proof numeric, p_now numeric)",
458
+ "declares_p_metadata": false
459
+ },
432
460
  {
433
461
  "signature": "_trim_inbox_text(p_value text, p_max_length integer)",
434
462
  "declares_p_metadata": false
@@ -725,6 +753,10 @@
725
753
  "signature": "record_callback_delivery_terminal_failure(p_outbox_event_id uuid, p_endpoint_id uuid, p_http_status integer, p_error_summary text, p_metadata jsonb)",
726
754
  "declares_p_metadata": true
727
755
  },
756
+ {
757
+ "signature": "record_portal_step_up(p_agent_id uuid, p_proof_at bigint)",
758
+ "declares_p_metadata": false
759
+ },
728
760
  {
729
761
  "signature": "record_session_identity_state(p_identity_agent_id uuid, p_fingerprint jsonb)",
730
762
  "declares_p_metadata": false
@@ -0,0 +1,10 @@
1
+ -- every service_role call exempt (early return); 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, ' -- (a) The operator key') = 0 then raise exception 'MUTATION ANCHOR MISS (1)'; end if;
7
+ n := replace(n, ' -- (a) The operator key', ' if v_service is true then return; end if;
8
+ -- (a) The operator key');
9
+ execute n;
10
+ end $m$;
@@ -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,2 @@
1
+ -- EC-SU-5: the helper granted to authenticated; must fail #9
2
+ grant execute on function agent_board._require_human_step_up(text) to authenticated;
@@ -0,0 +1,2 @@
1
+ -- EC-SU-4: INSERT on the ledger granted to authenticated; must fail #6
2
+ grant insert on agent_board.portal_step_up_proofs to authenticated;
@@ -0,0 +1,2 @@
1
+ -- EC-SU-4: a permissive policy on the ledger; must fail #7
2
+ create policy zz_mg3 on agent_board.portal_step_up_proofs for select to authenticated using (true);
@@ -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;