@consiliency/agent-board-schema 1.80.0 → 1.81.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 (111) hide show
  1. package/fixtures/already-applied.json +4 -0
  2. package/migrations/20261201000100_agent_board_reply_to_message.sql +1241 -0
  3. package/package.json +1 -1
  4. package/schema-manifest.json +12 -3
  5. package/src/tooling.test.mjs +4 -2
  6. package/tests/agent_board_661_reply_delivery.test.sql +12 -12
  7. package/tests/agent_board_667_history_class.test.sql +31 -13
  8. package/tests/agent_board_717_message_replay_scope.test.sql +29 -16
  9. package/tests/agent_board_717_tasking_replay_scope.test.sql +3 -3
  10. package/tests/agent_board_bundle_endpoint_compat.test.sql +2 -2
  11. package/tests/agent_board_canary_signed_fleet_enforcement.test.sql +3 -3
  12. package/tests/agent_board_claim_subject_gate.test.sql +3 -1
  13. package/tests/agent_board_delegate_role_class.test.sql +1 -1
  14. package/tests/agent_board_delivery_writer_execute.test.sql +7 -7
  15. package/tests/agent_board_hosted_delegates.test.sql +3 -3
  16. package/tests/agent_board_inbox_rpcs.test.sql +6 -6
  17. package/tests/agent_board_refusal_atomicity.test.sql +958 -0
  18. package/tests/agent_board_reply_to.test.sql +874 -0
  19. package/tests/agent_board_scoped_send_regrant.test.sql +8 -8
  20. package/tests/agent_board_send_outcome.test.sql +10 -10
  21. package/tests/agent_board_send_role_gate.test.sql +2 -2
  22. package/tests/agent_board_write_enforcement_class.test.sql +7 -7
  23. package/tests/catalog/function_execute_privileges.json +23 -14
  24. package/tests/catalog/p_metadata_parameters.json +12 -8
  25. package/tests/isolation/expected/reply_parent_vs_thread_delete.out +55 -0
  26. package/tests/isolation/expected/reply_vs_parent_author_delete.out +56 -0
  27. package/tests/isolation/specs/reply_parent_vs_thread_delete.spec +42 -0
  28. package/tests/isolation/specs/reply_vs_parent_author_delete.spec +46 -0
  29. package/tests/mutations/655/M01_no_writer_check.sql +22 -0
  30. package/tests/mutations/655/M02_drop_fk.sql +2 -0
  31. package/tests/mutations/655/M03_existence_only.sql +13 -0
  32. package/tests/mutations/655/M04_distinct_cross_thread_error.sql +17 -0
  33. package/tests/mutations/655/M05_view_no_thread_conjunct.sql +46 -0
  34. package/tests/mutations/655/M06_thread_feed_not_invoker.sql +46 -0
  35. package/tests/mutations/655/M06b_board_feed_not_invoker.sql +49 -0
  36. package/tests/mutations/655/M07_excerpt_via_definer.sql +49 -0
  37. package/tests/mutations/655/M08_excerpt_200.sql +46 -0
  38. package/tests/mutations/655/M09_fk_restrict.sql +4 -0
  39. package/tests/mutations/655/M10_post_message_drops_arg.sql +13 -0
  40. package/tests/mutations/655/M10b_post_message_passes_null.sql +12 -0
  41. package/tests/mutations/655/M11_slug_drops_arg.sql +15 -0
  42. package/tests/mutations/655/M11b_dm_descriptor_positional.sql +31 -0
  43. package/tests/mutations/655/M12_signed_pbm_nine_args.sql +19 -0
  44. package/tests/mutations/655/M12b_signed_mc_one_branch.sql +15 -0
  45. package/tests/mutations/655/M13_undriven_entrypoint.sql +8 -0
  46. package/tests/mutations/655/M14_second_writer.sql +6 -0
  47. package/tests/mutations/655/M15_insert_primitive_public.sql +2 -0
  48. package/tests/mutations/655/M16_comment_missing.sql +2 -0
  49. package/tests/mutations/655/M17_old_allow_set_rows.sql +5 -0
  50. package/tests/mutations/655/M18_board_excerpt_139.sql +49 -0
  51. package/tests/mutations/655/M19_column_in_middle.sql +47 -0
  52. package/tests/mutations/655/M20_projects_parent_id.sql +46 -0
  53. package/tests/mutations/655/M21_replay_applies_new_parent.sql +22 -0
  54. package/tests/mutations/655/M22_fk_not_valid.sql +4 -0
  55. package/tests/mutations/655/MB4a_no_readability.sql +13 -0
  56. package/tests/mutations/655/MB4b_own_readability_message.sql +20 -0
  57. package/tests/mutations/655/MB4c_service_role_reads_all.sql +12 -0
  58. package/tests/mutations/655/MB4d_delegate_uses_authenticated_arm.sql +12 -0
  59. package/tests/mutations/655/MB4f_no_board_member_branch.sql +14 -0
  60. package/tests/mutations/655/MB4g_helper_granted_authenticated.sql +2 -0
  61. package/tests/mutations/655/MB4j_writer_uses_current_agent.sql +12 -0
  62. package/tests/mutations/655/MB4k_delegate_policy_loses_initplan.sql +5 -0
  63. package/tests/mutations/655/MB4l_board_memberships_policy_narrowed.sql +3 -0
  64. package/tests/mutations/655/W1_auth_no_membership_state.sql +13 -0
  65. package/tests/mutations/655/W2_auth_no_agent_binding.sql +13 -0
  66. package/tests/mutations/655/W3_delivery_no_recipient_binding.sql +12 -0
  67. package/tests/mutations/655/W4_delegate_no_board_conjunct.sql +18 -0
  68. package/tests/mutations/655/W5_boardset_no_membership_state.sql +13 -0
  69. package/tests/mutations/655/W6_boardset_no_agent_binding.sql +14 -0
  70. package/tests/mutations/655/run.sh +93 -0
  71. package/tests/mutations/670/M10_lock_removed.sql +2 -2
  72. package/tests/mutations/670/M14_post_message_mints_from_metadata.sql +2 -2
  73. package/tests/mutations/670/M3-DM_helper_on_replay_branch.sql +2 -2
  74. package/tests/mutations/670/M3-MC_helper_on_replay_branch.sql +2 -2
  75. package/tests/mutations/670/M3_helper_on_replay_branch.sql +2 -2
  76. package/tests/mutations/670/M8_delivery_swallows_errors.sql +2 -2
  77. package/tests/mutations/670/M9_lock_key_includes_board.sql +2 -2
  78. package/tests/mutations/670/run.sh +1 -1
  79. package/tests/mutations/717-f1/M10_wrapper_stops_delegating.sql +1 -1
  80. package/tests/mutations/717-f1/M9_public_route_revoked_from_service_role.sql +1 -1
  81. package/tests/mutations/717-f2b/L1_dm_lock_split_by_recipient.sql +2 -2
  82. package/tests/mutations/717-f2b/L2_dm_lock_removed.sql +2 -2
  83. package/tests/mutations/717-f2b/L3_mc_lock_split_by_recipients.sql +2 -2
  84. package/tests/mutations/717-f2b/L4_mc_lock_removed.sql +2 -2
  85. package/tests/mutations/717-f2b/M0_prefix_definitions.sql +1 -1
  86. package/tests/mutations/717-f2b/M10_mc_lookup_any_author.sql +2 -2
  87. package/tests/mutations/717-f2b/M11_dm_swallow_refusal.sql +2 -2
  88. package/tests/mutations/717-f2b/M12_mc_swallow_refusal.sql +2 -2
  89. package/tests/mutations/717-f2b/M15_mc_any_source.sql +1 -1
  90. package/tests/mutations/717-f2b/M1_dm_drop_recipient_proof.sql +2 -2
  91. package/tests/mutations/717-f2b/M2_mc_drop_recipient_proof.sql +2 -2
  92. package/tests/mutations/717-f2b/M3_dm_metadata_as_proof.sql +2 -2
  93. package/tests/mutations/717-f2b/M4_mc_metadata_as_proof.sql +2 -2
  94. package/tests/mutations/717-f2b/M5_dm_any_mode.sql +2 -2
  95. package/tests/mutations/717-f2b/M6_dm_board_delivery_counts.sql +2 -2
  96. package/tests/mutations/717-f2b/M7_mc_any_mode.sql +2 -2
  97. package/tests/mutations/717-f2b/M8_dm_thread_stamp_as_proof.sql +2 -2
  98. package/tests/mutations/717-f2b/M9_dm_lookup_any_author.sql +2 -2
  99. package/tests/mutations/717-f2b/run.sh +2 -2
  100. package/tests/mutations/919/M10_quoted_net_http_post_scratch.sql +5 -0
  101. package/tests/mutations/919/M11_pbm_calls_public.sql +11 -0
  102. package/tests/mutations/919/M1_pbm_refusal_swallowed_after_write.sql +14 -0
  103. package/tests/mutations/919/M2_cof_refusal_swallowed_after_write.sql +13 -0
  104. package/tests/mutations/919/M3_pbm_receipt_fault_swallowed.sql +10 -0
  105. package/tests/mutations/919/M4_pg_notify_scratch.sql +5 -0
  106. package/tests/mutations/919/M5_dynamic_notify_scratch.sql +5 -0
  107. package/tests/mutations/919/M6_trigger_outside_schema.sql +3 -0
  108. package/tests/mutations/919/M7_pbm_step_up_gate.sql +10 -0
  109. package/tests/mutations/919/M8_pbm_positive_writes_nothing.sql +10 -0
  110. package/tests/mutations/919/M9_cof_positive_writes_nothing.sql +10 -0
  111. package/tests/mutations/919/run.sh +81 -0
@@ -0,0 +1,13 @@
1
+ -- create_or_find_thread: the non-object-metadata refusal first INSERTS a thread, then raises inside a swallowed EXCEPTION block and returns a row; must fail RA-C2, RA-C2 rows, RA-C2 catalog
2
+ do $m$
3
+ declare
4
+ d text := pg_get_functiondef('agent_board.create_or_find_thread(uuid,text,text,text,jsonb)'::regprocedure);
5
+ a text := E'\n if p_metadata is not null and jsonb_typeof(p_metadata) <> ''object'' then\n raise exception ''metadata must be a JSON object'' using errcode = ''22023'';\n end if;\n';
6
+ r text := E'\n if p_metadata is not null and jsonb_typeof(p_metadata) <> ''object'' then\n'
7
+ || E' insert into agent_board.threads(thread_type, created_by_agent_id, subject) values (''coordination'', v_actor_agent_id, ''m919 partial write'');\n'
8
+ || E' begin\n raise exception ''metadata must be a JSON object'' using errcode = ''22023'';\n'
9
+ || E' exception when others then\n return query select null::uuid, ''coordination''::text, ''m919''::text, ''open''::text, 0::bigint, now(), now(), false;\n return;\n end;\n end if;\n';
10
+ begin
11
+ if (length(d) - length(replace(d, a, ''))) / length(a) <> 1 then raise exception 'MUTATION ANCHOR MISS (M2)'; end if;
12
+ execute replace(d, a, r);
13
+ end $m$;
@@ -0,0 +1,10 @@
1
+ -- post_board_message: the receipt write is wrapped in exception when others then null, so a fault after the message, deliveries, inbox and outbox writes is swallowed and the call returns a row; must fail RA-R8, RA-R8 rows, RA-R8 catalog
2
+ do $m$
3
+ declare
4
+ d text := pg_get_functiondef('agent_board.post_board_message(uuid,uuid,uuid,text,text,text,text,text,jsonb,uuid)'::regprocedure);
5
+ a text := E' perform agent_board._record_send_outcome(''post_board_message'', v_message.id, v_idempotency_key, p_board_id);\n';
6
+ r text := E' begin\n ' || a || E' exception when others then null;\n end;\n';
7
+ begin
8
+ if (length(d) - length(replace(d, a, ''))) / length(a) <> 1 then raise exception 'MUTATION ANCHOR MISS (M3)'; end if;
9
+ execute replace(d, a, r);
10
+ end $m$;
@@ -0,0 +1,5 @@
1
+ -- a scratch agent_board function calls pg_notify; must fail RA-SE-0 and RA-SE-1, naming agent_board.m919_scratch() [pg_notify]
2
+ create function agent_board.m919_scratch() returns void language plpgsql as $s$
3
+ begin
4
+ perform pg_notify('m919', 'x');
5
+ end $s$;
@@ -0,0 +1,5 @@
1
+ -- a scratch agent_board function runs NOTIFY through dynamic SQL (the call is a string literal); must fail RA-SE-0 and RA-SE-1, naming agent_board.m919_scratch_dynamic() [notify]
2
+ create function agent_board.m919_scratch_dynamic() returns void language plpgsql as $s$
3
+ begin
4
+ execute 'notify m919';
5
+ end $s$;
@@ -0,0 +1,3 @@
1
+ -- a user trigger on agent_board.messages runs a public function, outside RA-SE-1's population; must fail RA-TRG-1, naming messages.m919_trg -> public.m919_trg
2
+ create function public.m919_trg() returns trigger language plpgsql as $t$ begin return new; end $t$;
3
+ create trigger m919_trg after insert on agent_board.messages for each row execute function public.m919_trg();
@@ -0,0 +1,10 @@
1
+ -- post_board_message gains a step-up gate, so MBS01 becomes reachable from it; must fail RA-MB-1 (the agent-principal fixture is exempt, so no call changes)
2
+ do $m$
3
+ declare
4
+ d text := pg_get_functiondef('agent_board.post_board_message(uuid,uuid,uuid,text,text,text,text,text,jsonb,uuid)'::regprocedure);
5
+ a text := E' perform agent_board._record_send_outcome(''post_board_message'', v_message.id, v_idempotency_key, p_board_id);\n';
6
+ r text := a || E' perform agent_board._require_human_step_up(''post_board_message'');\n';
7
+ begin
8
+ if (length(d) - length(replace(d, a, ''))) / length(a) <> 1 then raise exception 'MUTATION ANCHOR MISS (M7)'; end if;
9
+ execute replace(d, a, r);
10
+ end $m$;
@@ -0,0 +1,10 @@
1
+ -- post_board_message returns a row before the message lookup/insert, so an allowed post writes nothing; must fail RA-P1 rows, RA-P1 catalog, RA-P2 rows, RA-P2 catalog (and R7/R8, which no longer reach their fault)
2
+ do $m$
3
+ declare
4
+ d text := pg_get_functiondef('agent_board.post_board_message(uuid,uuid,uuid,text,text,text,text,text,jsonb,uuid)'::regprocedure);
5
+ a text := E'\n if v_idempotency_key is not null then\n select *\n into v_message\n';
6
+ r text := E'\n return query select null::uuid, p_board_id, 0, 0, now();\n return;\n' || a;
7
+ begin
8
+ if (length(d) - length(replace(d, a, ''))) / length(a) <> 1 then raise exception 'MUTATION ANCHOR MISS (M8)'; end if;
9
+ execute replace(d, a, r);
10
+ end $m$;
@@ -0,0 +1,10 @@
1
+ -- create_or_find_thread returns a fabricated row instead of inserting, so an allowed call writes nothing; must fail RA-P3 rows, RA-P3 catalog (and RA-C4, which no longer reaches the INSERT)
2
+ do $m$
3
+ declare
4
+ d text := pg_get_functiondef('agent_board.create_or_find_thread(uuid,text,text,text,jsonb)'::regprocedure);
5
+ a text := E'\n insert into agent_board.threads(thread_type, created_by_agent_id, subject, metadata)\n';
6
+ r text := E'\n return query select gen_random_uuid(), ''coordination''::text, trim(p_subject), ''open''::text, 0::bigint, now(), now(), false;\n return;\n' || a;
7
+ begin
8
+ if (length(d) - length(replace(d, a, ''))) / length(a) <> 1 then raise exception 'MUTATION ANCHOR MISS (M9)'; end if;
9
+ execute replace(d, a, r);
10
+ end $m$;
@@ -0,0 +1,81 @@
1
+ #!/usr/bin/env bash
2
+ # #919 REFUSALATOMICITY mutation receipts (AGENTS.md rule 2). Same method as ../669b/run.sh, against
3
+ # agent_board_refusal_atomicity.test.sql. Run against a database whose bundle was applied by
4
+ # scripts/run-agent-board-schema-tests.sh. Connection comes ONLY from the libpq environment
5
+ # (PGHOST/PGPORT/PGUSER/PGPASSWORD/PGDATABASE), never argv. The target must be an OWNED database
6
+ # holding this tree's applied bundle (CI: a throwaway job's Supabase; never a 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,
11
+ # volatility, definer flag and comment, plus every user trigger) read inside that
12
+ # transaction must differ from the baseline. An anchor miss raises 'MUTATION ANCHOR
13
+ # MISS' and is reported as NOT APPLIED, never counted as a kill.
14
+ # pgTAP the mutation and the test file run in ONE transaction that is rolled back. The receipt
15
+ # records plan, emitted, ok and not ok counts and every failing line, counted from the
16
+ # TAP, never inferred from an absence. An aborted file (emitted < plan) is reported as
17
+ # 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="${RA_TEST:-$PKG/tests/agent_board_refusal_atomicity.test.sql}"
24
+ OUT="${1:?receipt path}"; shift
25
+ if [ "$#" -gt 0 ]; then
26
+ MUTS=()
27
+ for m in "$@"; do
28
+ [ -f "$m" ] || { echo "FATAL: mutation file not found: $m" >&2; exit 3; }
29
+ MUTS+=("$(cd "$(dirname "$m")" && pwd)/$(basename "$m")")
30
+ done
31
+ else mapfile -t MUTS < <(find "$HERE" -maxdepth 1 -name '*.sql' | sort -V); fi
32
+ [ "${#MUTS[@]}" -gt 0 ] || { echo "FATAL: no mutation files" >&2; exit 3; }
33
+ [ -n "${PGDATABASE:-}" ] || { echo "FATAL: PGDATABASE unset (libpq environment required)" >&2; exit 3; }
34
+ P=(psql -X -qtA)
35
+ 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(t.tgrelid::regclass::text || '.' || t.tgname || ':' || t.tgfoid::regprocedure::text, '|' order by t.tgrelid::regclass::text, t.tgname) from pg_trigger t where not t.tgisinternal), ''))"
36
+ fp() { "${P[@]}" -c "$FPSQL"; }
37
+ ORIG="$(fp)"
38
+ [ -n "$ORIG" ] || { echo "FATAL: could not read the catalog fingerprint" >&2; exit 3; }
39
+
40
+ applied() { # $1 mutation file -> prints 'applied' / 'NOT APPLIED: <why>'
41
+ local out
42
+ out="$(printf 'begin;\n\\set ON_ERROR_STOP 1\n\\i %s\n%s;\nrollback;\n' "$1" "$FPSQL" | "${P[@]}" 2>&1)"
43
+ if grep -qiE '(error|fatal):' <<<"$out"; then
44
+ echo "NOT APPLIED: $(grep -iE '(error|fatal):' <<<"$out" | head -1)"
45
+ elif [ "$(tail -1 <<<"$out")" = "$ORIG" ]; then
46
+ echo "NOT APPLIED: catalog fingerprint unchanged (no-op)"
47
+ else
48
+ echo "applied"
49
+ fi
50
+ }
51
+
52
+ tap() { # $1 label, $2 mutation file or empty
53
+ local out plan ok nok
54
+ if [ -n "$2" ]; then out="$(printf 'begin;\n\\i %s\n\\i %s\nrollback;\n' "$2" "$TEST" | "${P[@]}" 2>&1)"
55
+ else out="$(printf 'begin;\n\\i %s\nrollback;\n' "$TEST" | "${P[@]}" 2>&1)"; fi
56
+ plan="$(sed -nE 's/^1\.\.([0-9]+)$/\1/p' <<<"$out" | head -1)"
57
+ ok="$(grep -cE '^ok [0-9]+' <<<"$out" || true)"; nok="$(grep -cE '^not ok [0-9]+' <<<"$out" || true)"
58
+ printf '%s: pgtap plan=%s emitted=%s ok=%s not_ok=%s%s\n' "$1" "${plan:-NONE}" "$((ok + nok))" "$ok" "$nok" \
59
+ "$([ "${plan:-x}" = "$((ok + nok))" ] || echo ' ABORTED')"
60
+ grep -E '^not ok [0-9]+' <<<"$out" | sed 's/^/ /'
61
+ grep -E '^#\s+(have|want|caught|wanted|died):' <<<"$out" | head -12 | sed 's/^/ /'
62
+ grep -iE '(error|fatal):' <<<"$out" | head -3 | sed 's/^/ ERR /'
63
+ }
64
+
65
+ {
66
+ echo "# #919 REFUSALATOMICITY mutation receipt -- $(date -u +%FT%TZ)"
67
+ echo "# tree $(git -C "$PKG" rev-parse HEAD)$(git -C "$PKG" diff --quiet HEAD -- . || echo ' + uncommitted changes')"
68
+ echo "# test $(basename "$TEST") [sha256 $(sha256sum "$TEST" | cut -c1-16)]"
69
+ echo "# catalog fingerprint before: $ORIG"
70
+ tap "BASELINE" ""
71
+ for m in "${MUTS[@]}"; do
72
+ name="$(basename "$m" .sql)"
73
+ echo "-- $name: $(head -1 "$m" | sed 's/^-- //') [sha256 $(sha256sum "$m" | cut -c1-16)]"
74
+ echo " $(applied "$m")"
75
+ [ "$(fp)" = "$ORIG" ] || { echo "FATAL: fingerprint changed after the rolled-back apply leg of $name"; exit 3; }
76
+ tap "$name" "$m"
77
+ [ "$(fp)" = "$ORIG" ] || { echo "FATAL: fingerprint changed after the rolled-back pgTAP leg of $name"; exit 3; }
78
+ done
79
+ tap "AFTER" ""
80
+ echo "# catalog fingerprint after: $(fp)"
81
+ } | tee "$OUT"