@consiliency/agent-board-schema 1.76.0 → 1.80.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 +16 -0
- package/migrations/20261120000200_agent_board_thread_key_serialize.sql +118 -0
- package/migrations/20261121000100_agent_board_thread_key_guards.sql +196 -0
- package/migrations/20261124000100_agent_board_step_up_enforcement.sql +1213 -0
- package/migrations/20261126000100_agent_board_membership_removal_requires_active.sql +243 -0
- package/package.json +1 -1
- package/schema-manifest.json +39 -3
- package/src/deployment-drift-main.test.mjs +89 -6
- package/src/deployment-drift.test.mjs +20 -1
- package/src/tooling.test.mjs +11 -2
- package/tests/agent_board_717_message_replay_scope.test.sql +39 -2
- package/tests/agent_board_717_tasking_replay_scope.test.sql +21 -2
- package/tests/agent_board_membership_removal_state.test.sql +228 -0
- package/tests/agent_board_role_guard.test.sql +3 -1
- package/tests/agent_board_send_outcome.test.sql +39 -1
- package/tests/agent_board_session_identity_approval_revocation.test.sql +5 -0
- package/tests/agent_board_step_up.test.sql +991 -0
- package/tests/agent_board_step_up_helper.test.sql +132 -28
- package/tests/agent_board_thread_key_guards.test.sql +186 -0
- package/tests/agent_board_thread_key_serialize.test.sql +182 -0
- package/tests/agent_board_write_enforcement_class.test.sql +3 -2
- package/tests/catalog/step_up_gated_closure.json +24 -0
- package/tests/fixtures/pgtap-unexposed.sql +9 -4
- package/tests/isolation/expected/create_or_find_thread_same_key_race.out +641 -0
- package/tests/isolation/expected/session_identity_links.out +4 -0
- package/tests/isolation/specs/create_or_find_thread_same_key_race.spec +252 -0
- package/tests/isolation/specs/session_identity_links.spec +5 -0
- package/tests/mutations/669/run.sh +12 -4
- package/tests/mutations/669b/M11_ceil_first.sql +10 -0
- package/tests/mutations/669b/M11_gate_first.sql +10 -0
- package/tests/mutations/669b/M11_grant_first.sql +10 -0
- package/tests/mutations/669b/M11_inv_first.sql +10 -0
- package/tests/mutations/669b/M11_mem_first.sql +10 -0
- package/tests/mutations/669b/M11_readmit_first.sql +10 -0
- package/tests/mutations/669b/M13a_gate_member_preset.sql +12 -0
- package/tests/mutations/669b/M13b_ungate_admin_preset.sql +12 -0
- package/tests/mutations/669b/M16_actor_is_target.sql +14 -0
- package/tests/mutations/669b/M19_drop_readmit.sql +9 -0
- package/tests/mutations/669b/M1_drop_grant.sql +9 -0
- package/tests/mutations/669b/M20_drop_d5_refusal.sql +9 -0
- package/tests/mutations/669b/M21_drop_removal.sql +9 -0
- package/tests/mutations/669b/M21b_only_removed.sql +9 -0
- package/tests/mutations/669b/M21c_gate_members.sql +12 -0
- package/tests/mutations/669b/M21d_requested_state.sql +9 -0
- package/tests/mutations/669b/M23b_api_wrapper_over_audit_writer.sql +6 -0
- package/tests/mutations/669b/M23c_drop_register_type_refusal.sql +9 -0
- package/tests/mutations/669b/M24_drop_kind_refusal.sql +9 -0
- package/tests/mutations/669b/M24b_drop_auth_bind_refusal.sql +9 -0
- package/tests/mutations/669b/M2a_drop_gate.sql +9 -0
- package/tests/mutations/669b/M2b_drop_ceiling.sql +9 -0
- package/tests/mutations/669b/M2c_drop_invite.sql +9 -0
- package/tests/mutations/669b/MAL2_drop_otp.sql +9 -0
- package/tests/mutations/669b/MAL3_admit_passkey.sql +9 -0
- package/tests/mutations/669b/MD7a_no_revocation.sql +2 -0
- package/tests/mutations/669b/MD7b_overwrite_revoked.sql +2 -0
- package/tests/mutations/669b/MD7c_revoke_members.sql +2 -0
- package/tests/mutations/669b/MD7d_revoke_expired.sql +2 -0
- package/tests/mutations/669b/ME1_wrapper_over_gate.sql +7 -0
- package/tests/mutations/669b/MEC2_write_after_helper.sql +10 -0
- package/tests/mutations/669b/MQX_query_to_xml_definer.sql +6 -0
- package/tests/mutations/669b/MQXb_ts_stat_other_schema.sql +4 -0
- package/tests/mutations/669b/MTR_trigger_route.sql +9 -0
- package/tests/mutations/669b/MTRb_new_assign.sql +11 -0
- package/tests/mutations/669b/MTRc_sync_assigns_value.sql +47 -0
- package/tests/mutations/669b/MTX1_tombstone_second_gated_call.sql +15 -0
- package/tests/mutations/669b/MTX2_tombstone_non_delegate_target.sql +10 -0
- package/tests/mutations/669b/MXS_other_schema_names_gated.sql +5 -0
- package/tests/mutations/669b/run.sh +83 -0
- package/tests/mutations/670/M18a_read_operation_default_dropped.sql +11 -0
- package/tests/mutations/670/M18b_read_operation_default_changed.sql +7 -0
- package/tests/mutations/670/M3-DM_helper_on_replay_branch.sql +10 -0
- package/tests/mutations/670/M3-MC_helper_on_replay_branch.sql +10 -0
- package/tests/mutations/s12/M0_identity.sql +56 -0
- package/tests/mutations/s12/M1_serialise_actor_key.sql +57 -0
- package/tests/mutations/s12/M1b_serialise_key_only.sql +57 -0
- package/tests/mutations/s12/M2_unique_index_no_handler.sql +9 -0
- package/tests/mutations/s12/M3_no_trim.sql +56 -0
- package/tests/mutations/s12/M4_casefold.sql +56 -0
- package/tests/mutations/s12/M5_lookup_ignores_actor.sql +56 -0
- package/tests/mutations/s12/M6_reuse_reports_false.sql +56 -0
- package/tests/mutations/s12/run.sh +112 -0
- package/tests/mutations/s12-fix/M0_identity.sql +83 -0
- package/tests/mutations/s12-fix/M10_security_invoker.sql +9 -0
- package/tests/mutations/s12-fix/M11_search_path_changed.sql +9 -0
- package/tests/mutations/s12-fix/M12_reuse_writes_task.sql +84 -0
- package/tests/mutations/s12-fix/M13_dead_inbox_write.sql +84 -0
- package/tests/mutations/s12-fix/M14_metadata_unchecked.sql +78 -0
- package/tests/mutations/s12-fix/M15_metadata_check_after_lock.sql +84 -0
- package/tests/mutations/s12-fix/M16_sql_null_metadata_refused.sql +83 -0
- package/tests/mutations/s12-fix/M17_isolation_unchecked.sql +70 -0
- package/tests/mutations/s12-fix/M18_isolation_check_after_lock.sql +82 -0
- package/tests/mutations/s12-fix/M19_isolation_rr_only.sql +83 -0
- package/tests/mutations/s12-fix/M1_lock_dropped.sql +78 -0
- package/tests/mutations/s12-fix/M1b_lock_key_only.sql +83 -0
- package/tests/mutations/s12-fix/M20_isolation_unsafe_levels_only.sql +83 -0
- package/tests/mutations/s12-fix/M21_isolation_check_miss_path_only.sql +83 -0
- package/tests/mutations/s12-fix/M22_isolation_inverted.sql +83 -0
- package/tests/mutations/s12-fix/M23_isolation_wrong_sqlstate.sql +83 -0
- package/tests/mutations/s12-fix/M24_create_thread_key_unchecked.sql +37 -0
- package/tests/mutations/s12-fix/M25_create_thread_key_nonnull_only.sql +45 -0
- package/tests/mutations/s12-fix/M26_create_thread_key_casefold.sql +45 -0
- package/tests/mutations/s12-fix/M27_create_thread_no_object_guard.sql +45 -0
- package/tests/mutations/s12-fix/M28_create_thread_key_stripped.sql +40 -0
- package/tests/mutations/s12-fix/M29_create_thread_key_nested_refused.sql +45 -0
- package/tests/mutations/s12-fix/M2_lock_actor_only.sql +83 -0
- package/tests/mutations/s12-fix/M30_create_thread_security_invoker.sql +9 -0
- package/tests/mutations/s12-fix/M31_create_thread_search_path_changed.sql +9 -0
- package/tests/mutations/s12-fix/M32_class_new_thread_inserter.sql +14 -0
- package/tests/mutations/s12-fix/M33_class_metadata_update.sql +12 -0
- package/tests/mutations/s12-fix/M33b_class_metadata_update_upper.sql +17 -0
- package/tests/mutations/s12-fix/M33c_class_metadata_update_row_form.sql +16 -0
- package/tests/mutations/s12-fix/M33d_class_metadata_merge_update.sql +16 -0
- package/tests/mutations/s12-fix/M33e_class_metadata_upsert.sql +16 -0
- package/tests/mutations/s12-fix/M34_class_api_role_insert.sql +9 -0
- package/tests/mutations/s12-fix/M3_lock_after_lookup.sql +83 -0
- package/tests/mutations/s12-fix/M4_lock_raw_key.sql +83 -0
- package/tests/mutations/s12-fix/M5_no_trim.sql +83 -0
- package/tests/mutations/s12-fix/M6_casefold.sql +83 -0
- package/tests/mutations/s12-fix/M7_lookup_ignores_actor.sql +82 -0
- package/tests/mutations/s12-fix/M8_reuse_reports_false.sql +83 -0
- package/tests/mutations/s12-fix/M9_blank_key_admitted.sql +83 -0
- package/tests/mutations/s12-fix/run.sh +288 -0
- package/tests/seeds/20261124000100_agent_board_step_up_enforcement.sql.pre.sql +47 -0
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# S-12 FIX mutation receipts (migrations 20261120000200_agent_board_thread_key_serialize.sql and
|
|
3
|
+
# 20261121000100_agent_board_thread_key_guards.sql, the #815/#816 follow-ups).
|
|
4
|
+
#
|
|
5
|
+
# The sibling tests/mutations/s12/run.sh (#808) mutated the PRE-fix body against the golden that
|
|
6
|
+
# pinned the defect. This one mutates the FIXED body against the regenerated golden, and adds a
|
|
7
|
+
# pgTAP leg. Each mutation beside this script
|
|
8
|
+
# is a scratch CREATE OR REPLACE (or ALTER) with a self-check that raises if it did not apply.
|
|
9
|
+
#
|
|
10
|
+
# isolation same machinery as s12/run.sh: copy this package and the REAL isolation runner into
|
|
11
|
+
# a throwaway directory holding ONLY the S-12 spec and its golden, append the mutation
|
|
12
|
+
# to that copy's operator-hardening fixture (applied after every migration,
|
|
13
|
+
# ON_ERROR_STOP, so a raising self-check aborts the template build rather than
|
|
14
|
+
# running unmutated), run the runner at ITER=1, and record WHICH permutations changed.
|
|
15
|
+
# pgTAP on a database this script builds once (and drops at exit), the mutation and each
|
|
16
|
+
# test file run in ONE transaction that is rolled back. The plan, emitted, ok and
|
|
17
|
+
# not-ok counts are recorded, and the not-ok NUMBERS are compared (counted, never
|
|
18
|
+
# inferred from absence: a file that aborts emits fewer than its plan and is BROKEN).
|
|
19
|
+
# tks = tests/agent_board_thread_key_serialize.test.sql, run for EVERY mutation;
|
|
20
|
+
# msg = tests/agent_board_717_message_replay_scope.test.sql and
|
|
21
|
+
# task = tests/agent_board_717_tasking_replay_scope.test.sql, the replay-class files
|
|
22
|
+
# whose thread-only disposition covers create_or_find_thread, run only for the
|
|
23
|
+
# mutations that DECLARE an expectation for them (a mutation such as SECURITY
|
|
24
|
+
# INVOKER breaks their fixture setup, which says nothing about the disposition).
|
|
25
|
+
# tkg = tests/agent_board_thread_key_guards.test.sql (#816, create_thread refuses the
|
|
26
|
+
# reserved key), run for the mutations that declare an expectation for it.
|
|
27
|
+
#
|
|
28
|
+
# Mutations of create_thread (M24-M31) and the class mutations (M32-M34: a new inserter, a
|
|
29
|
+
# metadata assignment in four shapes — UPDATE, row-form SET, MERGE update, upsert — and a direct
|
|
30
|
+
# API-role grant, which TKG-19/20/21 must each name) declare EXPECT_ISO
|
|
31
|
+
# as `n/a`: the S-12 spec never calls create_thread or those additions, so its golden cannot move, and each isolation run costs a full template build.
|
|
32
|
+
# `n/a` is a per-mutation declaration, not an inference: such a mutation's own self-check still
|
|
33
|
+
# proves it changed create_thread, and its pgTAP leg must fail the rows it declares.
|
|
34
|
+
#
|
|
35
|
+
# It is a check, not a log: each mutation declares what it must change in BOTH legs (EXPECT_ISO,
|
|
36
|
+
# EXPECT_TAP), and the run exits 1 on any other outcome, including changing nothing when it
|
|
37
|
+
# should have changed something. M0 re-creates the fixed body and must change nothing in either
|
|
38
|
+
# leg; that row proves the machinery itself is neutral.
|
|
39
|
+
#
|
|
40
|
+
# Connection: DATABASE_URL in the ENVIRONMENT (never argv), naming a CLUSTER on which the role
|
|
41
|
+
# can CREATE DATABASE.
|
|
42
|
+
# Usage: DATABASE_URL=... bash run.sh <receipt-path> [mutation.sql ...]
|
|
43
|
+
set -uo pipefail
|
|
44
|
+
HERE="$(cd "$(dirname "$0")" && pwd)"
|
|
45
|
+
PKG="$(cd "$HERE/../../.." && pwd)"
|
|
46
|
+
ROOT="$(cd "$PKG/../.." && pwd)"
|
|
47
|
+
NAME="create_or_find_thread_same_key_race"
|
|
48
|
+
declare -A TESTFILE=(
|
|
49
|
+
[tks]="$PKG/tests/agent_board_thread_key_serialize.test.sql"
|
|
50
|
+
[msg]="$PKG/tests/agent_board_717_message_replay_scope.test.sql"
|
|
51
|
+
[task]="$PKG/tests/agent_board_717_tasking_replay_scope.test.sql"
|
|
52
|
+
[tkg]="$PKG/tests/agent_board_thread_key_guards.test.sql"
|
|
53
|
+
)
|
|
54
|
+
OUT="${1:?receipt path}"; shift
|
|
55
|
+
[ -n "${DATABASE_URL:-}" ] || { echo "FATAL: DATABASE_URL unset (environment, not argv)" >&2; exit 3; }
|
|
56
|
+
if [ "$#" -gt 0 ]; then MUTS=("$@"); else mapfile -t MUTS < <(find "$HERE" -maxdepth 1 -name 'M*.sql' | sort -V); fi
|
|
57
|
+
[ "${#MUTS[@]}" -gt 0 ] || { echo "FATAL: no mutations found" >&2; exit 3; }
|
|
58
|
+
|
|
59
|
+
# Spec permutations (1-based, spec order) each mutation must change.
|
|
60
|
+
declare -A EXPECT_ISO=(
|
|
61
|
+
[M0_identity]=""
|
|
62
|
+
[M1_lock_dropped]="1 2"
|
|
63
|
+
[M1b_lock_key_only]="5"
|
|
64
|
+
[M2_lock_actor_only]=""
|
|
65
|
+
[M3_lock_after_lookup]="1 2"
|
|
66
|
+
[M4_lock_raw_key]="2"
|
|
67
|
+
[M5_no_trim]="2 3"
|
|
68
|
+
[M6_casefold]="4"
|
|
69
|
+
[M7_lookup_ignores_actor]="6"
|
|
70
|
+
[M8_reuse_reports_false]="1 2 3 12"
|
|
71
|
+
[M9_blank_key_admitted]=""
|
|
72
|
+
[M10_security_invoker]=""
|
|
73
|
+
[M11_search_path_changed]=""
|
|
74
|
+
[M12_reuse_writes_task]=""
|
|
75
|
+
[M13_dead_inbox_write]=""
|
|
76
|
+
[M14_metadata_unchecked]="7"
|
|
77
|
+
[M15_metadata_check_after_lock]="7"
|
|
78
|
+
[M16_sql_null_metadata_refused]=""
|
|
79
|
+
[M17_isolation_unchecked]="8 9 10 11"
|
|
80
|
+
[M18_isolation_check_after_lock]="8 9 10"
|
|
81
|
+
[M19_isolation_rr_only]="9 10"
|
|
82
|
+
[M20_isolation_unsafe_levels_only]="10"
|
|
83
|
+
[M21_isolation_check_miss_path_only]="8 9 10 11"
|
|
84
|
+
[M22_isolation_inverted]="1 2 3 4 5 6 7 8 9 10 11 12"
|
|
85
|
+
[M23_isolation_wrong_sqlstate]="8 9 10 11"
|
|
86
|
+
[M24_create_thread_key_unchecked]="n/a"
|
|
87
|
+
[M25_create_thread_key_nonnull_only]="n/a"
|
|
88
|
+
[M26_create_thread_key_casefold]="n/a"
|
|
89
|
+
[M27_create_thread_no_object_guard]="n/a"
|
|
90
|
+
[M28_create_thread_key_stripped]="n/a"
|
|
91
|
+
[M29_create_thread_key_nested_refused]="n/a"
|
|
92
|
+
[M30_create_thread_security_invoker]="n/a"
|
|
93
|
+
[M31_create_thread_search_path_changed]="n/a"
|
|
94
|
+
[M32_class_new_thread_inserter]="n/a"
|
|
95
|
+
[M33_class_metadata_update]="n/a"
|
|
96
|
+
[M33b_class_metadata_update_upper]="n/a"
|
|
97
|
+
[M33c_class_metadata_update_row_form]="n/a"
|
|
98
|
+
[M33d_class_metadata_merge_update]="n/a"
|
|
99
|
+
[M33e_class_metadata_upsert]="n/a"
|
|
100
|
+
[M34_class_api_role_insert]="n/a"
|
|
101
|
+
)
|
|
102
|
+
# pgTAP assertion numbers each mutation must turn into `not ok`, per file tag. tks is required
|
|
103
|
+
# for every mutation; msg/task are run only where a key is present.
|
|
104
|
+
declare -A EXPECT_TAP=(
|
|
105
|
+
[M0_identity:tks]="" [M0_identity:msg]="" [M0_identity:task]=""
|
|
106
|
+
[M1_lock_dropped:tks]="4 10 12" [M1_lock_dropped:msg]="49" [M1_lock_dropped:task]="55"
|
|
107
|
+
[M1b_lock_key_only:tks]="10" [M1b_lock_key_only:msg]="" [M1b_lock_key_only:task]=""
|
|
108
|
+
[M2_lock_actor_only:tks]="12"
|
|
109
|
+
[M3_lock_after_lookup:tks]=""
|
|
110
|
+
[M4_lock_raw_key:tks]="7" [M4_lock_raw_key:msg]="49" [M4_lock_raw_key:task]="55"
|
|
111
|
+
[M5_no_trim:tks]="1 6"
|
|
112
|
+
[M6_casefold:tks]=""
|
|
113
|
+
[M7_lookup_ignores_actor:tks]="9"
|
|
114
|
+
[M8_reuse_reports_false:tks]="6" [M8_reuse_reports_false:msg]="69" [M8_reuse_reports_false:task]="57"
|
|
115
|
+
[M9_blank_key_admitted:tks]="1"
|
|
116
|
+
[M10_security_invoker:tks]="13"
|
|
117
|
+
[M11_search_path_changed:tks]="14"
|
|
118
|
+
[M12_reuse_writes_task:tks]="" [M12_reuse_writes_task:msg]="68 69" [M12_reuse_writes_task:task]="57"
|
|
119
|
+
[M13_dead_inbox_write:tks]="" [M13_dead_inbox_write:msg]="68" [M13_dead_inbox_write:task]=""
|
|
120
|
+
[M14_metadata_unchecked:tks]="15 16 17 18"
|
|
121
|
+
[M15_metadata_check_after_lock:tks]=""
|
|
122
|
+
[M16_sql_null_metadata_refused:tks]="19 20"
|
|
123
|
+
[M17_isolation_unchecked:tks]="" [M17_isolation_unchecked:tkg]=""
|
|
124
|
+
[M18_isolation_check_after_lock:tks]=""
|
|
125
|
+
[M19_isolation_rr_only:tks]=""
|
|
126
|
+
[M20_isolation_unsafe_levels_only:tks]=""
|
|
127
|
+
[M21_isolation_check_miss_path_only:tks]=""
|
|
128
|
+
[M22_isolation_inverted:tks]="2 3 4 5 6 8 9 10 11 12 19 20" [M22_isolation_inverted:tkg]="14 15"
|
|
129
|
+
[M23_isolation_wrong_sqlstate:tks]=""
|
|
130
|
+
[M0_identity:tkg]=""
|
|
131
|
+
[M24_create_thread_key_unchecked:tks]="" [M24_create_thread_key_unchecked:tkg]="1 2 3 4 13 15"
|
|
132
|
+
[M25_create_thread_key_nonnull_only:tks]="" [M25_create_thread_key_nonnull_only:tkg]="2 4"
|
|
133
|
+
[M26_create_thread_key_casefold:tks]="" [M26_create_thread_key_casefold:tkg]="9 12"
|
|
134
|
+
[M27_create_thread_no_object_guard:tks]="" [M27_create_thread_no_object_guard:tkg]="11 12"
|
|
135
|
+
[M28_create_thread_key_stripped:tks]="" [M28_create_thread_key_stripped:tkg]="1 2 3 4"
|
|
136
|
+
[M29_create_thread_key_nested_refused:tks]="" [M29_create_thread_key_nested_refused:tkg]="10 12"
|
|
137
|
+
[M30_create_thread_security_invoker:tks]="" [M30_create_thread_security_invoker:tkg]="17"
|
|
138
|
+
[M31_create_thread_search_path_changed:tks]="" [M31_create_thread_search_path_changed:tkg]="18"
|
|
139
|
+
[M32_class_new_thread_inserter:tks]="" [M32_class_new_thread_inserter:tkg]="19"
|
|
140
|
+
[M33_class_metadata_update:tks]="" [M33_class_metadata_update:tkg]="20"
|
|
141
|
+
[M33b_class_metadata_update_upper:tks]="" [M33b_class_metadata_update_upper:tkg]="20"
|
|
142
|
+
[M33c_class_metadata_update_row_form:tks]="" [M33c_class_metadata_update_row_form:tkg]="20"
|
|
143
|
+
[M33d_class_metadata_merge_update:tks]="" [M33d_class_metadata_merge_update:tkg]="20"
|
|
144
|
+
[M33e_class_metadata_upsert:tks]="" [M33e_class_metadata_upsert:tkg]="19 20"
|
|
145
|
+
[M34_class_api_role_insert:tks]="" [M34_class_api_role_insert:tkg]="21"
|
|
146
|
+
)
|
|
147
|
+
|
|
148
|
+
PG_EXPORTS="$(DATABASE_URL="$DATABASE_URL" node "$ROOT/scripts/lib/pg-env-export.mjs")" || {
|
|
149
|
+
echo "FATAL: could not turn DATABASE_URL into libpq environment" >&2; exit 3; }
|
|
150
|
+
eval "$PG_EXPORTS"
|
|
151
|
+
TAPDB="mb_s12fix_tap_$(date -u +%Y%m%d%H%M%S)_$$"
|
|
152
|
+
WORK="$(mktemp -d)"
|
|
153
|
+
# The DROP is armed only once THIS run's CREATE DATABASE has succeeded. Before that the name may
|
|
154
|
+
# belong to someone else (a collision, a concurrent run): a failed create must never be followed
|
|
155
|
+
# by a drop of whatever already held the name.
|
|
156
|
+
TAPDB_CREATED=0
|
|
157
|
+
cleanup() {
|
|
158
|
+
[ "$TAPDB_CREATED" = 1 ] && psql -X -qtA -c "drop database if exists \"$TAPDB\"" >/dev/null 2>&1
|
|
159
|
+
rm -rf "$WORK"
|
|
160
|
+
}
|
|
161
|
+
trap cleanup EXIT
|
|
162
|
+
|
|
163
|
+
# --- the pgTAP database: the isolation runner's template recipe, built once ---
|
|
164
|
+
# The database is named through the ENVIRONMENT (PGDATABASE), never argv: the maintenance
|
|
165
|
+
# connection uses the URL's own database, the rest use the scratch one.
|
|
166
|
+
tpsql() { PGDATABASE="$TAPDB" psql -X -qtA "$@"; }
|
|
167
|
+
psql -X -qtA -v ON_ERROR_STOP=1 -c "create database \"$TAPDB\"" >/dev/null \
|
|
168
|
+
|| { echo "FATAL: could not create $TAPDB (nothing will be dropped)" >&2; exit 3; }
|
|
169
|
+
TAPDB_CREATED=1
|
|
170
|
+
build_tapdb() {
|
|
171
|
+
local P=(tpsql -v ON_ERROR_STOP=1) n=0 f
|
|
172
|
+
"${P[@]}" -f "$PKG/tests/fixtures/isolation-substrate.sql" >/dev/null || return 1
|
|
173
|
+
"${P[@]}" -f "$PKG/tests/fixtures/adopter-base.sql" >/dev/null || return 1
|
|
174
|
+
"${P[@]}" -f "$PKG/tests/fixtures/test-prereqs.sql" >/dev/null || return 1
|
|
175
|
+
node -e 'const m=require(process.argv[1]); for (const e of m.migrations) console.log(e.filename)' \
|
|
176
|
+
"$PKG/schema-manifest.json" > "$WORK/order" || return 1
|
|
177
|
+
while read -r f; do "${P[@]}" -1 -f "$PKG/migrations/$f" >/dev/null || return 1; n=$((n+1)); done < "$WORK/order"
|
|
178
|
+
[ "$n" -gt 0 ] && [ "$n" -eq "$(wc -l < "$WORK/order")" ] || return 1
|
|
179
|
+
"${P[@]}" -f "$PKG/tests/fixtures/operator-hardening.sql" >/dev/null || return 1
|
|
180
|
+
"${P[@]}" -f "$PKG/tests/fixtures/pgtap-unexposed.sql" >/dev/null || return 1
|
|
181
|
+
echo "$n"
|
|
182
|
+
}
|
|
183
|
+
TAP_MIGS="$(build_tapdb 2>"$WORK/tapdb.err")" || { echo "FATAL: could not build $TAPDB" >&2; grep -E 'ERROR|FATAL' "$WORK/tapdb.err" | head -5 >&2; exit 3; }
|
|
184
|
+
|
|
185
|
+
# One rolled-back transaction: mutation (if any), then test file $2. Sets TAP_PLAN/EMITTED/NOK.
|
|
186
|
+
tap() {
|
|
187
|
+
local out plan ok nok
|
|
188
|
+
if [ -n "$1" ]; then out="$(printf 'begin;\n\\i %s\n\\i %s\nrollback;\n' "$1" "$2" | tpsql 2>&1)"
|
|
189
|
+
else out="$(printf 'begin;\n\\i %s\nrollback;\n' "$2" | tpsql 2>&1)"; fi
|
|
190
|
+
plan="$(sed -nE 's/^1\.\.([0-9]+)$/\1/p' <<<"$out" | head -1)"
|
|
191
|
+
ok="$(grep -cE '^ok [0-9]+' <<<"$out")"; nok="$(grep -cE '^not ok [0-9]+' <<<"$out")"
|
|
192
|
+
TAP_PLAN="${plan:-NONE}"; TAP_EMITTED="$((ok + nok))"
|
|
193
|
+
TAP_NOK="$(grep -oE '^not ok [0-9]+' <<<"$out" | awk '{print $3}' | tr '\n' ' ' | sed 's/ $//')"
|
|
194
|
+
TAP_ERR="$(grep -E 'ERROR:' <<<"$out" | head -1)"
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
# --- the isolation copy, exactly as s12/run.sh builds it ---
|
|
198
|
+
mkdir -p "$WORK/iso/scripts" "$WORK/iso/packages"
|
|
199
|
+
cp "$ROOT/scripts/run-agent-board-isolation-tests.sh" "$WORK/iso/scripts/"
|
|
200
|
+
cp -r "$PKG" "$WORK/iso/packages/"
|
|
201
|
+
C="$WORK/iso/packages/$(basename "$PKG")"
|
|
202
|
+
find "$C/tests/isolation/specs" -name '*.spec' ! -name "$NAME.spec" -delete
|
|
203
|
+
find "$C/tests/isolation/expected" -name '*.out' ! -name "$NAME.out" -delete
|
|
204
|
+
find "$C" -maxdepth 1 -name node_modules -prune -exec rm -rf {} +
|
|
205
|
+
[ -d "$C/tests/isolation/output" ] && find "$C/tests/isolation/output" -mindepth 1 -delete
|
|
206
|
+
FIX="$C/tests/fixtures/operator-hardening.sql"
|
|
207
|
+
cp "$FIX" "$WORK/operator-hardening.orig.sql"
|
|
208
|
+
GOLDEN="$C/tests/isolation/expected/$NAME.out"
|
|
209
|
+
DECLARED="$(grep -c '^permutation ' "$C/tests/isolation/specs/$NAME.spec")"
|
|
210
|
+
|
|
211
|
+
changed_perms() {
|
|
212
|
+
python3 -I - "$1" "$2" <<'PY'
|
|
213
|
+
import re, sys
|
|
214
|
+
def perms(p):
|
|
215
|
+
t = open(p).read()
|
|
216
|
+
return [x for x in re.split(r'\n(?=starting permutation: )', t) if x.startswith('starting permutation')]
|
|
217
|
+
a, b = perms(sys.argv[1]), perms(sys.argv[2])
|
|
218
|
+
if len(a) != len(b):
|
|
219
|
+
print(f"COUNT {len(a)}!={len(b)}"); sys.exit(0)
|
|
220
|
+
print(' '.join(str(i) for i, (x, y) in enumerate(zip(a, b), 1) if x != y))
|
|
221
|
+
PY
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
bad=0; ran=0
|
|
225
|
+
{
|
|
226
|
+
echo "# S-12 FIX mutation receipt -- $(date -u +%FT%TZ)"
|
|
227
|
+
echo "# tree $(git -C "$ROOT" rev-parse HEAD)$(git -C "$ROOT" diff --quiet HEAD -- "$PKG" || echo ' + uncommitted changes')"
|
|
228
|
+
echo "# spec $NAME: $DECLARED permutations declared; golden $(grep -c '^starting permutation' "$GOLDEN") permutations"
|
|
229
|
+
for t in tks msg task tkg; do
|
|
230
|
+
tap "" "${TESTFILE[$t]}"
|
|
231
|
+
echo "# pgTAP $t=$(basename "${TESTFILE[$t]}") on $TAP_MIGS migrations, unmutated: plan=$TAP_PLAN emitted=$TAP_EMITTED not_ok='$TAP_NOK'"
|
|
232
|
+
if [ "$TAP_PLAN" = "NONE" ] || [ "$TAP_EMITTED" != "$TAP_PLAN" ] || [ -n "$TAP_NOK" ]; then
|
|
233
|
+
echo " BROKEN: the unmutated pgTAP file is not all-ok"; bad=$((bad+1))
|
|
234
|
+
fi
|
|
235
|
+
done
|
|
236
|
+
for m in "${MUTS[@]}"; do
|
|
237
|
+
name="$(basename "$m" .sql)"
|
|
238
|
+
want_iso="${EXPECT_ISO[$name]-UNDECLARED}"
|
|
239
|
+
echo "-- $name: $(head -1 "$m" | sed 's/^-- //')"
|
|
240
|
+
# isolation leg
|
|
241
|
+
if [ "$want_iso" = "n/a" ]; then
|
|
242
|
+
if grep -qE 'agent_board\.create_or_find_thread\(' "$m"; then
|
|
243
|
+
echo " BROKEN isolation: declared n/a but the mutation touches create_or_find_thread"; bad=$((bad+1))
|
|
244
|
+
else
|
|
245
|
+
echo " isolation: not run -- declared n/a (the S-12 spec never calls what this mutation changes)"
|
|
246
|
+
fi
|
|
247
|
+
else
|
|
248
|
+
cp "$WORK/operator-hardening.orig.sql" "$FIX"
|
|
249
|
+
{ echo; cat "$m"; echo; } >> "$FIX"
|
|
250
|
+
log="$WORK/$name.log"
|
|
251
|
+
(cd "$WORK/iso" && ITER=1 bash scripts/run-agent-board-isolation-tests.sh > "$log" 2>&1); rc=$?
|
|
252
|
+
applied="$(sed -nE 's/^ *applied ([0-9]+) migrations into .*/\1/p' "$log")"
|
|
253
|
+
verdict="$(grep -cE "^ (ok|FAIL) +$NAME" "$log")"
|
|
254
|
+
if [ -z "$applied" ] || [ "$verdict" -ne 1 ]; then
|
|
255
|
+
echo " BROKEN isolation: runner exit $rc, template applied='${applied:-none}', verdicts=$verdict"
|
|
256
|
+
grep -E 'FATAL|ERROR|NOT applied' "$log" | head -5 | sed 's/^/ /'
|
|
257
|
+
bad=$((bad+1))
|
|
258
|
+
else
|
|
259
|
+
tdir="$(sed -n 's/^== per-run transcripts: \(.*\) ==$/\1/p' "$log")"
|
|
260
|
+
if grep -qE "^ ok +$NAME" "$log"; then got=""
|
|
261
|
+
elif [ -f "$tdir/$NAME.out" ]; then got="$(changed_perms "$GOLDEN" "$tdir/$NAME.out")"
|
|
262
|
+
else got="NO-TRANSCRIPT"; fi
|
|
263
|
+
if [ "$got" = "$want_iso" ]; then mark="as declared"; else mark="MISMATCH (declared: '${want_iso}')"; bad=$((bad+1)); fi
|
|
264
|
+
echo " isolation: runner exit $rc; migrations $applied; changed permutations: '${got}' -- $mark"
|
|
265
|
+
if [ -n "$got" ] && [ -f "$tdir/$NAME.out" ]; then
|
|
266
|
+
diff "$GOLDEN" "$tdir/$NAME.out" | grep -E '^[<>] .*(ERROR|waiting|refused|returned|[0-9]+\|)' | head -8 | sed 's/^/ /'
|
|
267
|
+
fi
|
|
268
|
+
fi
|
|
269
|
+
fi
|
|
270
|
+
# pgTAP leg: tks always (UNDECLARED if missing); msg/task where declared
|
|
271
|
+
for t in tks msg task tkg; do
|
|
272
|
+
key="$name:$t"
|
|
273
|
+
if [ "$t" != tks ] && [ -z "${EXPECT_TAP[$key]+set}" ]; then continue; fi
|
|
274
|
+
want_tap="${EXPECT_TAP[$key]-UNDECLARED}"
|
|
275
|
+
tap "$m" "${TESTFILE[$t]}"
|
|
276
|
+
if [ "$TAP_PLAN" = "NONE" ] || [ "$TAP_EMITTED" != "$TAP_PLAN" ]; then
|
|
277
|
+
echo " BROKEN pgTAP $t: plan=$TAP_PLAN emitted=$TAP_EMITTED ${TAP_ERR}"; bad=$((bad+1))
|
|
278
|
+
else
|
|
279
|
+
if [ "$TAP_NOK" = "$want_tap" ]; then mark="as declared"; else mark="MISMATCH (declared: '${want_tap}')"; bad=$((bad+1)); fi
|
|
280
|
+
echo " pgTAP $t: plan=$TAP_PLAN emitted=$TAP_EMITTED not ok: '${TAP_NOK}' -- $mark"
|
|
281
|
+
fi
|
|
282
|
+
done
|
|
283
|
+
ran=$((ran+1))
|
|
284
|
+
done
|
|
285
|
+
cp "$WORK/operator-hardening.orig.sql" "$FIX"
|
|
286
|
+
echo "# $ran of ${#MUTS[@]} mutations reached a verdict; $bad problem(s)"
|
|
287
|
+
} | tee "$OUT"
|
|
288
|
+
grep -qE "^# ${#MUTS[@]} of ${#MUTS[@]} mutations reached a verdict; 0 problem\(s\)$" "$OUT"
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
-- #669 STEPUP PR-B pre-migration seed (plan §11.2 "D7 upgrade test"; the message-board#103 hook).
|
|
2
|
+
--
|
|
3
|
+
-- Applied by the test runner immediately BEFORE 20261124000100_agent_board_step_up_enforcement.sql,
|
|
4
|
+
-- so the schema is at the PR-A state (20261109000100). It plants the invite-token states D7 must
|
|
5
|
+
-- tell apart, so agent_board_step_up.test.sql can assert what the SHIPPED revocation DML did:
|
|
6
|
+
-- live an unexpired, unrevoked ADMIN token -> must be revoked, revoked_by_agent_id NULL
|
|
7
|
+
-- gone an ADMIN token revoked before the cutover -> must keep its original revoked_at/revoker
|
|
8
|
+
-- member an unexpired, unrevoked MEMBER token -> must stay unrevoked (D7 is admin-only)
|
|
9
|
+
-- old an EXPIRED, unrevoked ADMIN token -> left as it is (already unusable)
|
|
10
|
+
-- The creator stays an ACTIVE OWNER, so the only reason a redeem of `live` can fail afterwards is
|
|
11
|
+
-- the revocation (the test's member-token redeem is the control). Distinctive fixed ids (669bd*)
|
|
12
|
+
-- and codes so nothing collides with another file's fixtures. A test seed never goes live.
|
|
13
|
+
insert into auth.users(id, instance_id, aud, role, email)
|
|
14
|
+
values ('669bd000-0000-4000-8000-000000000001', '00000000-0000-0000-0000-000000000000',
|
|
15
|
+
'authenticated', 'authenticated', 'su669b-seed-creator@t.test')
|
|
16
|
+
on conflict (id) do nothing;
|
|
17
|
+
|
|
18
|
+
insert into agent_board.agents(id, agent_type, kind, handle, display_name, status, auth_user_id)
|
|
19
|
+
values ('669bd100-0000-4000-8000-000000000001', 'agent', 'agent', 'su669b-seed-creator',
|
|
20
|
+
'SU669B seed creator', 'active', '669bd000-0000-4000-8000-000000000001')
|
|
21
|
+
on conflict (id) do nothing;
|
|
22
|
+
|
|
23
|
+
insert into agent_board.boards(id, slug, name, created_by_agent_id, visibility, status)
|
|
24
|
+
values ('669bd200-0000-4000-8000-000000000001', 'su669b-seed-board', 'SU669B seed board',
|
|
25
|
+
'669bd100-0000-4000-8000-000000000001', 'private', 'active')
|
|
26
|
+
on conflict (id) do nothing;
|
|
27
|
+
|
|
28
|
+
insert into agent_board.board_memberships(board_id, agent_id, role, membership_state, created_by_agent_id)
|
|
29
|
+
values ('669bd200-0000-4000-8000-000000000001', '669bd100-0000-4000-8000-000000000001', 'owner', 'joined',
|
|
30
|
+
'669bd100-0000-4000-8000-000000000001');
|
|
31
|
+
|
|
32
|
+
insert into agent_board.board_invite_tokens(
|
|
33
|
+
id, code, board_id, preset_role, preset_membership_state, max_uses, expires_at,
|
|
34
|
+
created_by_agent_id, revoked_at, revoked_by_agent_id, metadata)
|
|
35
|
+
values
|
|
36
|
+
('669bd300-0000-4000-8000-000000000001', 'su669b-seed-admin-live', '669bd200-0000-4000-8000-000000000001',
|
|
37
|
+
'admin', 'joined', 5, now() + interval '6 days', '669bd100-0000-4000-8000-000000000001', null, null,
|
|
38
|
+
'{"seed":"669b-live"}'),
|
|
39
|
+
('669bd300-0000-4000-8000-000000000002', 'su669b-seed-admin-gone', '669bd200-0000-4000-8000-000000000001',
|
|
40
|
+
'admin', 'joined', 5, now() + interval '6 days', '669bd100-0000-4000-8000-000000000001',
|
|
41
|
+
timestamptz '2026-11-01 00:00:00+00', '669bd100-0000-4000-8000-000000000001', '{"seed":"669b-gone"}'),
|
|
42
|
+
('669bd300-0000-4000-8000-000000000003', 'su669b-seed-member-live', '669bd200-0000-4000-8000-000000000001',
|
|
43
|
+
'member', 'joined', 5, now() + interval '6 days', '669bd100-0000-4000-8000-000000000001', null, null,
|
|
44
|
+
'{"seed":"669b-member"}'),
|
|
45
|
+
('669bd300-0000-4000-8000-000000000004', 'su669b-seed-admin-old', '669bd200-0000-4000-8000-000000000001',
|
|
46
|
+
'admin', 'joined', 5, now() - interval '1 day', '669bd100-0000-4000-8000-000000000001', null, null,
|
|
47
|
+
'{"seed":"669b-old"}');
|