@consiliency/agent-board-schema 1.83.0 → 1.84.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 (36) hide show
  1. package/README.md +5 -0
  2. package/fixtures/already-applied.json +4 -0
  3. package/migrations/20261203000200_agent_board_signed_seat_gates.sql +695 -0
  4. package/package.json +1 -1
  5. package/schema-manifest.json +12 -3
  6. package/src/tooling.test.mjs +4 -2
  7. package/tests/agent_board_954_signed_seat_gates.test.sql +472 -0
  8. package/tests/catalog/function_execute_privileges.json +36 -0
  9. package/tests/catalog/p_metadata_parameters.json +16 -0
  10. package/tests/mutations/954/MA1_resolver_ignores_signer.sql +15 -0
  11. package/tests/mutations/954/MA2_null_actor_resolves_to_signer.sql +22 -0
  12. package/tests/mutations/954/MB1_no_bind.sql +14 -0
  13. package/tests/mutations/954/MC1_context_any_role.sql +15 -0
  14. package/tests/mutations/954/MG1_has_board_access_service_bypass.sql +18 -0
  15. package/tests/mutations/954/MG2_can_send_to_board_service_bypass.sql +18 -0
  16. package/tests/mutations/954/MG3_can_access_thread_service_bypass.sql +18 -0
  17. package/tests/mutations/954/MG4_can_post_to_thread_service_bypass.sql +13 -0
  18. package/tests/mutations/954/MG5_can_access_task_service_bypass.sql +18 -0
  19. package/tests/mutations/954/MG6_can_mutate_task_service_bypass.sql +18 -0
  20. package/tests/mutations/954/MR1_post_board_message_no_release.sql +14 -0
  21. package/tests/mutations/954/MR2_send_direct_message_no_release.sql +14 -0
  22. package/tests/mutations/954/MR3_send_multicast_message_no_release.sql +14 -0
  23. package/tests/mutations/954/MR4_create_tasking_delivery_no_release.sql +14 -0
  24. package/tests/mutations/954/MR5_append_task_event_no_release.sql +14 -0
  25. package/tests/mutations/954/MR6_grant_board_role_no_release.sql +14 -0
  26. package/tests/mutations/954/MR7_set_board_authority_ceiling_no_release.sql +14 -0
  27. package/tests/mutations/954/MW1_post_board_message_unbound.sql +25 -0
  28. package/tests/mutations/954/MW2_send_direct_message_unbound.sql +25 -0
  29. package/tests/mutations/954/MW3_send_multicast_message_unbound.sql +25 -0
  30. package/tests/mutations/954/MW4_create_tasking_delivery_unbound.sql +25 -0
  31. package/tests/mutations/954/MW5_append_task_event_unbound.sql +25 -0
  32. package/tests/mutations/954/MW6_grant_board_role_unbound.sql +25 -0
  33. package/tests/mutations/954/MW7_set_board_authority_ceiling_unbound.sql +25 -0
  34. package/tests/mutations/954/MX1_bind_session_level.sql +13 -0
  35. package/tests/mutations/954/MX2_release_session_level.sql +13 -0
  36. package/tests/mutations/954/run.sh +93 -0
@@ -0,0 +1,93 @@
1
+ #!/usr/bin/env bash
2
+ # #954 signed-seat-gate mutation receipts (AGENTS.md rule 2). Same method as ../655/run.sh (and
3
+ # ../919/run.sh before it): every mutant removes or reverts ONE piece of the #954 fix, and the receipt
4
+ # counts which assertions of agent_board_954_signed_seat_gates.test.sql turn red under it. Run against a database
5
+ # whose bundle was applied by scripts/run-agent-board-schema-tests.sh. Connection comes ONLY from the
6
+ # libpq environment (PGHOST/PGPORT/PGUSER/PGPASSWORD/PGDATABASE), never argv. The target must be an
7
+ # OWNED database holding this tree's applied bundle (CI: a throwaway job's Supabase).
8
+ #
9
+ # Per mutation:
10
+ # applied the mutation runs ALONE in a rolled-back transaction with ON_ERROR_STOP, and the catalog
11
+ # fingerprint (every non-system routine with argument names, ACL, body, volatility, definer
12
+ # flag and comment; every user trigger; every agent_board constraint, view definition and
13
+ # reloptions, and policy; the delegate allow set) read inside that transaction must differ
14
+ # from the baseline. An anchor miss raises 'MUTATION ANCHOR MISS' and is NOT APPLIED.
15
+ # overloads (NIT-8) inside the same transaction, the overload count of every agent_board routine
16
+ # name that existed before must be unchanged: a mutant that creates an overload instead of
17
+ # replacing the function is reported INERT, never counted as a kill.
18
+ # pgTAP for each test file: the mutation and the file run in ONE transaction that is rolled
19
+ # back; plan, emitted, ok and not ok are COUNTED from the TAP, every failing line is
20
+ # listed, and an aborted file (emitted < plan) is reported ABORTED.
21
+ # The fingerprint must equal the baseline after every leg (nothing leaked past a rollback).
22
+ # Usage: run.sh <receipt-path> [mutation.sql ...] (default: every *.sql beside this script)
23
+ # TESTS="a.test.sql b.test.sql" overrides the test files (names relative to tests/).
24
+ set -uo pipefail
25
+ HERE="$(cd "$(dirname "$0")" && pwd)"
26
+ PKG="$(cd "$HERE/../../.." && pwd)"
27
+ TDIR="$PKG/tests"
28
+ read -r -a TESTS <<< "${TESTS:-agent_board_954_signed_seat_gates.test.sql}"
29
+ OUT="${1:?receipt path}"; shift
30
+ if [ "$#" -gt 0 ]; then
31
+ MUTS=()
32
+ for m in "$@"; do
33
+ [ -f "$m" ] || { echo "FATAL: mutation file not found: $m" >&2; exit 3; }
34
+ MUTS+=("$(cd "$(dirname "$m")" && pwd)/$(basename "$m")")
35
+ done
36
+ else mapfile -t MUTS < <(find "$HERE" -maxdepth 1 -name '*.sql' | sort -V); fi
37
+ [ "${#MUTS[@]}" -gt 0 ] || { echo "FATAL: no mutation files" >&2; exit 3; }
38
+ [ -n "${PGDATABASE:-}" ] || { echo "FATAL: PGDATABASE unset (libpq environment required)" >&2; exit 3; }
39
+ P=(psql -X -qtA)
40
+ 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), '') || coalesce((select string_agg(c.conrelid::regclass::text || '.' || c.conname || ':' || pg_get_constraintdef(c.oid) || c.convalidated::text, '|' order by c.conrelid::regclass::text, c.conname) from pg_constraint c where c.connamespace = 'agent_board'::regnamespace), '') || coalesce((select string_agg(c.relname || ':' || pg_get_viewdef(c.oid) || coalesce(array_to_string(c.reloptions, ','), '') || coalesce(c.relacl::text, ''), '|' order by c.relname) from pg_class c where c.relnamespace = 'agent_board'::regnamespace and c.relkind = 'v'), '') || coalesce((select string_agg(polrelid::regclass::text || '.' || polname || ':' || coalesce(pg_get_expr(polqual, polrelid), ''), '|' order by polrelid::regclass::text, polname) from pg_policy), '') || coalesce((select string_agg(kind || signature, '|' order by kind, signature) from agent_board.delegate_allowed_operations), ''))"
41
+ OVSQL="select coalesce(string_agg(proname || '=' || n, ',' order by proname), '') from (select proname, count(*) n from pg_proc where pronamespace = 'agent_board'::regnamespace group by proname) x"
42
+ fp() { "${P[@]}" -c "$FPSQL"; }
43
+ ORIG="$(fp)"
44
+ [ -n "$ORIG" ] || { echo "FATAL: could not read the catalog fingerprint" >&2; exit 3; }
45
+ OV0="$("${P[@]}" -c "$OVSQL")"
46
+
47
+ applied() { # $1 mutation file -> 'applied overloads-unchanged' / 'NOT APPLIED: ...' / 'INERT: ...'
48
+ local out fpl ovl changed
49
+ out="$(printf 'begin;\n\\set ON_ERROR_STOP 1\n\\i %s\n%s;\n%s;\nrollback;\n' "$1" "$FPSQL" "$OVSQL" | "${P[@]}" 2>&1)"
50
+ if grep -qiE '(error|fatal):' <<<"$out"; then
51
+ echo "NOT APPLIED: $(grep -iE '(error|fatal):' <<<"$out" | head -1)"; return
52
+ fi
53
+ fpl="$(tail -2 <<<"$out" | head -1)"; ovl="$(tail -1 <<<"$out")"
54
+ if [ "$fpl" = "$ORIG" ]; then echo "NOT APPLIED: catalog fingerprint unchanged (no-op)"; return; fi
55
+ changed="$(OV0="$OV0" OVL="$ovl" python3 -c '
56
+ import os
57
+ a=dict(x.split("=") for x in os.environ["OV0"].split(",") if x)
58
+ b=dict(x.split("=") for x in os.environ["OVL"].split(",") if x)
59
+ print(",".join(f"{k}:{a[k]}->{b.get(k,0)}" for k in sorted(a) if b.get(k,"0")!=a[k]))')"
60
+ if [ -n "$changed" ]; then echo "INERT: overload count changed ($changed)"; else echo "applied; overloads unchanged"; fi
61
+ }
62
+
63
+ tap() { # $1 label, $2 mutation file or empty, $3 test file
64
+ local out plan ok nok t="$TDIR/$3"
65
+ if [ -n "$2" ]; then out="$(printf 'begin;\n\\i %s\n\\i %s\nrollback;\n' "$2" "$t" | "${P[@]}" 2>&1)"
66
+ else out="$(printf 'begin;\n\\i %s\nrollback;\n' "$t" | "${P[@]}" 2>&1)"; fi
67
+ plan="$(sed -nE 's/^1\.\.([0-9]+)$/\1/p' <<<"$out" | head -1)"
68
+ ok="$(grep -cE '^ok [0-9]+' <<<"$out" || true)"; nok="$(grep -cE '^not ok [0-9]+' <<<"$out" || true)"
69
+ printf ' %s %s: plan=%s emitted=%s ok=%s not_ok=%s%s\n' "$1" "${3%.test.sql}" "${plan:-NONE}" "$((ok + nok))" "$ok" "$nok" \
70
+ "$([ "${plan:-x}" = "$((ok + nok))" ] || echo ' ABORTED')"
71
+ grep -E '^not ok [0-9]+' <<<"$out" | sed 's/^/ /'
72
+ grep -iE '(error|fatal):' <<<"$out" | head -2 | sed 's/^/ ERR /'
73
+ }
74
+
75
+ {
76
+ echo "# #954 signed-seat-gate mutation receipt -- $(date -u +%FT%TZ)"
77
+ echo "# tree $(git -C "$PKG" rev-parse HEAD)$(git -C "$PKG" diff --quiet HEAD -- . || echo ' + uncommitted changes')"
78
+ for t in "${TESTS[@]}"; do echo "# test $t [sha256 $(sha256sum "$TDIR/$t" | cut -c1-16)]"; done
79
+ echo "# catalog fingerprint before: $ORIG"
80
+ for t in "${TESTS[@]}"; do tap "BASELINE" "" "$t"; done
81
+ for m in "${MUTS[@]}"; do
82
+ name="$(basename "$m" .sql)"
83
+ echo "-- $name: $(head -1 "$m" | sed 's/^-- //') [sha256 $(sha256sum "$m" | cut -c1-16)]"
84
+ status="$(applied "$m")"
85
+ echo " $status"
86
+ [ "$(fp)" = "$ORIG" ] || { echo "FATAL: fingerprint changed after the rolled-back apply leg of $name"; exit 3; }
87
+ case "$status" in applied*) ;; *) continue ;; esac
88
+ for t in "${TESTS[@]}"; do tap "$name" "$m" "$t"; done
89
+ [ "$(fp)" = "$ORIG" ] || { echo "FATAL: fingerprint changed after the rolled-back pgTAP legs of $name"; exit 3; }
90
+ done
91
+ for t in "${TESTS[@]}"; do tap "AFTER" "" "$t"; done
92
+ echo "# catalog fingerprint after: $(fp)"
93
+ } | tee "$OUT"