@consiliency/agent-board-schema 1.23.0 → 1.25.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 (32) hide show
  1. package/README.md +75 -1
  2. package/fixtures/already-applied.json +12 -0
  3. package/migrations/20260905000100_agent_board_consent_gating_reconcile.sql +151 -0
  4. package/migrations/20260906000100_agent_board_enroll_resumption.sql +749 -0
  5. package/migrations/20260907000100_agent_board_signed_authority_provenance.sql +243 -0
  6. package/package.json +1 -1
  7. package/schema-manifest.json +30 -3
  8. package/src/check.js +23 -0
  9. package/src/index.js +20 -0
  10. package/src/plan.js +79 -5
  11. package/src/tooling.test.mjs +237 -4
  12. package/tests/agent_board_atomic_fleet_onboarding.test.sql +124 -112
  13. package/tests/agent_board_claimkey.test.sql +25 -3
  14. package/tests/agent_board_consent_emission.test.sql +17 -13
  15. package/tests/agent_board_consent_gating.test.sql +55 -11
  16. package/tests/agent_board_delegation_policies.test.sql +3 -1
  17. package/tests/agent_board_enroll_resumption.test.sql +412 -0
  18. package/tests/agent_board_federated_lock_order_class.test.sql +1 -3
  19. package/tests/agent_board_fedsession_provider_absence_gate.test.sql +9 -6
  20. package/tests/agent_board_fleet_machine_reactivation.test.sql +56 -5
  21. package/tests/agent_board_mint_harden.test.sql +39 -4
  22. package/tests/agent_board_outbox_wake_ordering.test.sql +27 -12
  23. package/tests/agent_board_rejectsem.test.sql +1 -1
  24. package/tests/agent_board_rolereset.test.sql +23 -2
  25. package/tests/agent_board_rowid.test.sql +24 -13
  26. package/tests/agent_board_scoped_send_regrant.test.sql +8 -4
  27. package/tests/agent_board_signed_authority_provenance.test.sql +454 -0
  28. package/tests/agent_board_source_strip_helper.test.sql +285 -0
  29. package/tests/agent_board_wake_recovery.test.sql +58 -40
  30. package/tests/catalog/p_metadata_parameters.json +689 -0
  31. package/tests/fixtures/test-prereqs.sql +313 -0
  32. package/tests/isolation/expected/atomic_fleet_lifecycle_races.out +3 -3
@@ -86,9 +86,7 @@ fns as (
86
86
  select p.oid,
87
87
  p.proname,
88
88
  p.proname || '(' || pg_get_function_identity_arguments(p.oid) || ')' as sig,
89
- regexp_replace(p.prosrc,
90
- $re$(\$[A-Za-z_0-9]*\$).*?\1|('([^']|'')*')|(--[^\n]*)|(/\*([^*]|\*+[^*/])*\*+/)$re$,
91
- ' ', 'g') as body,
89
+ agent_board_test.stripped_body(p.oid) as body,
92
90
  p.proconfig
93
91
  from pg_proc p
94
92
  join pg_namespace n on n.oid = p.pronamespace
@@ -70,9 +70,12 @@ select is(
70
70
  $g$raise\s+exception\s+'issuer/audience not in the identity-provider allowlist \(rejected before any owner or board lock\)'$g$)), 0) as p_gate,
71
71
  strpos(d, '_ensure_agent_auth_user') as p_ensure,
72
72
  strpos(d, substring(d from 'from\s+auth\.users[^;]{0,250}?for\s+update')) as p_lock
73
- from (select regexp_replace(p.prosrc,
74
- $re$(\$[A-Za-z_0-9]*\$).*?\1|('([^']|'')*')|(--[^\n]*)|(/\*([^*]|\*+[^*/])*\*+/)$re$,
75
- '\2', 'g') as d
73
+ -- LITERALS KEPT (the `true`): the gate marker G-2 locates IS the raise
74
+ -- message, so stripping literals would delete it and the positional claim
75
+ -- would read 'gate-missing' forever. Comments -- including the NESTED
76
+ -- block comment of message-board#199, which the regex this replaced could
77
+ -- not see -- are still removed.
78
+ from (select agent_board_test.stripped_body(p.oid, true) as d
76
79
  from pg_proc p
77
80
  join pg_namespace n on n.oid = p.pronamespace
78
81
  where n.nspname = 'agent_board'
@@ -159,9 +162,9 @@ select is(
159
162
  join pg_namespace n on n.oid = p.pronamespace
160
163
  where n.nspname = 'agent_board'
161
164
  and p.prokind = 'f'
162
- and regexp_replace(p.prosrc,
163
- $re$(\$[A-Za-z_0-9]*\$).*?\1|('([^']|'')*')|(--[^\n]*)|(/\*([^*]|\*+[^*/])*\*+/)$re$,
164
- '\2', 'g') ~ 'not in the identity-provider allowlist'),
165
+ -- LITERALS KEPT: membership in this class is defined by a function raising
166
+ -- that MESSAGE, so the marker is a literal by construction.
167
+ and agent_board_test.stripped_body(p.oid, true) ~ 'not in the identity-provider allowlist'),
165
168
  '_enroll_federated_human_after_revocation_gate, _enroll_federated_identity_once, '
166
169
  || 'enroll_federated_human, enroll_federated_identity',
167
170
  'G-8: exactly four routes reject an absent identity provider');
@@ -43,7 +43,7 @@ set search_path = extensions, public, agent_board;
43
43
 
44
44
  begin;
45
45
 
46
- select plan(22);
46
+ select plan(23);
47
47
 
48
48
  -- (1)(2) Shape.
49
49
  select has_function(
@@ -378,6 +378,30 @@ select is(
378
378
  -- CLASS (rule #1): catalog-derived — every machine-subject revocation READER honors
379
379
  -- reactivated_at; the WRITER exemption is asserted positively.
380
380
  ------------------------------------------------------------------------------------------
381
+ -- (21a) NON-VACUITY, asserted BEFORE the class below. That class is
382
+ -- `string_agg(offender) is null` -- so it passes just as happily when the
383
+ -- enumeration reaches NOTHING as when every reader conforms. Found while
384
+ -- re-deriving the strip modes for the message-board#196 review: flipping the
385
+ -- membership predicate to a literal-stripped read empties the class (the marker
386
+ -- `fre.subject_kind = ''machine''` has a literal operand and cannot survive it)
387
+ -- and the file stayed 22/22 GREEN. A green that survives its own class being
388
+ -- deleted is not evidence, so the membership set is pinned as an exact set here
389
+ -- and a new reader NAMES ITSELF in this diff.
390
+ select is(
391
+ (select
392
+ coalesce((select string_agg(p.proname, ', ' order by p.proname)
393
+ from pg_proc p join pg_namespace n on n.oid = p.pronamespace
394
+ where n.nspname = 'agent_board' and p.prokind = 'f'
395
+ -- DATA literal -> case-SENSITIVE; see the rule at the offender class below
396
+ and agent_board_test.stripped_body(p.oid, true) ~ 'fre\.subject_kind = ''machine'''), '(none)')
397
+ || ' | ' ||
398
+ coalesce((select string_agg(c.relname, ', ' order by c.relname)
399
+ from pg_class c join pg_namespace n on n.oid = c.relnamespace
400
+ where n.nspname = 'agent_board' and c.relkind = 'v'
401
+ and agent_board_test.stripped_viewdef(c.oid, true) ~ 'fre\.subject_kind = ''machine'''), '(none)')),
402
+ 'evaluate_fleet_sender_policy, reactivate_fleet_machine | v_fleet_machine_status',
403
+ 'the machine-subject revocation reader class is REACHED and is exactly these three -- the class assertion below cannot pass by finding nothing');
404
+
381
405
  -- (21) Enumerate readers (functions + views) whose definition tests a machine-subject
382
406
  -- revocation event (`fre.subject_kind = 'machine'`) but does NOT reference reactivated_at.
383
407
  -- Expected: none. A new non-conforming reader appears here BY NAME (rule #1: offenders name
@@ -391,16 +415,43 @@ select is(
391
415
  join pg_namespace n on n.oid = p.pronamespace
392
416
  where n.nspname = 'agent_board'
393
417
  and p.prokind = 'f'
394
- and pg_get_functiondef(p.oid) ~ 'fre\.subject_kind = ''machine'''
395
- and pg_get_functiondef(p.oid) not ilike '%reactivated_at%'
418
+ -- TWO MODES ON PURPOSE, and mixing them was a live fail-open
419
+ -- (message-board#196 review, red-team seat).
420
+ --
421
+ -- MEMBERSHIP (literals KEPT): the marker `fre.subject_kind = ''machine''`
422
+ -- has a string literal as its operand, so it cannot be located in a
423
+ -- literal-stripped body. This direction is fail-CLOSED anyway -- a
424
+ -- literal that fakes the marker ADDS an offender and reddens the
425
+ -- expected-empty set.
426
+ --
427
+ -- THE GUARD CHECK (literals STRIPPED): `reactivated_at` is a COLUMN
428
+ -- NAME, i.e. code. Read with literals kept, a reader that dropped the
429
+ -- guard while any literal still mentioned `reactivated_at` fell out of
430
+ -- the offender set and the class went 22/22 GREEN with the guard gone
431
+ -- (measured on evaluate_fleet_sender_policy). That is the exemption
432
+ -- category becoming the hole, CLAUDE.md rule 1's named trap.
433
+ -- CASE: this marker is compared as DATA, so it stays case-SENSITIVE.
434
+ -- The rule the suite now follows, and the line the round-1 `gi` sweep
435
+ -- got wrong here: a marker SPELLED AS CODE (a relation, function or
436
+ -- column name) is matched case-INSENSITIVELY, because PostgreSQL folds
437
+ -- unquoted identifiers and a case-sensitive scan is fail-open for a
438
+ -- class filter. A marker COMPARED AS DATA -- a string literal operand,
439
+ -- or a raise message -- stays case-SENSITIVE, because nothing folds it:
440
+ -- `'machine' = 'MACHINE'` is FALSE at runtime, so a `~*` here cannot
441
+ -- tell a working predicate from a broken one. Measured: rewriting the
442
+ -- live predicate to `= 'MACHINE'` -- which matches no rows -- left this
443
+ -- file 23/23 GREEN under `~*`.
444
+ and agent_board_test.stripped_body(p.oid, true) ~ 'fre\.subject_kind = ''machine'''
445
+ and agent_board_test.stripped_body(p.oid) not ilike '%reactivated_at%'
396
446
  union all
397
447
  select c.relname
398
448
  from pg_class c
399
449
  join pg_namespace n on n.oid = c.relnamespace
400
450
  where n.nspname = 'agent_board'
401
451
  and c.relkind = 'v'
402
- and pg_get_viewdef(c.oid) ~ 'fre\.subject_kind = ''machine'''
403
- and pg_get_viewdef(c.oid) not ilike '%reactivated_at%'
452
+ -- same split for the view half: marker keeps literals, guard does not
453
+ and agent_board_test.stripped_viewdef(c.oid, true) ~ 'fre\.subject_kind = ''machine'''
454
+ and agent_board_test.stripped_viewdef(c.oid) not ilike '%reactivated_at%'
404
455
  ) offenders
405
456
  ),
406
457
  null,
@@ -22,7 +22,7 @@ set search_path = extensions, public, agent_board;
22
22
 
23
23
  begin;
24
24
 
25
- select plan(31);
25
+ select plan(32);
26
26
 
27
27
  create temp table _mh (
28
28
  owner_id uuid,
@@ -119,9 +119,33 @@ select is(
119
119
  where n.nspname = 'agent_board' and p.prokind = 'f')
120
120
  select coalesce(string_agg(proname, ', ' order by proname), '')
121
121
  from fns
122
- where pg_get_functiondef(oid) ~* 'insert[[:space:]]+into[[:space:]]+(agent_board\.)?agent_signing_keys'
123
- and pg_get_functiondef(oid) ~ 'fingerprint'
124
- and pg_get_functiondef(oid) !~ '_raw_key_fingerprint'),
122
+ where agent_board_test.stripped_body(oid) ~* 'insert[[:space:]]+into[[:space:]]+(agent_board\.)?agent_signing_keys'
123
+ -- CASE-INSENSITIVE, and that is load-bearing rather than tidiness. SQL folds
124
+ -- unquoted identifiers, but `prosrc` is stored VERBATIM, so a writer spelling
125
+ -- the same call `AGENT_BOARD.…` or the same column `FINGERPRINT` is identical
126
+ -- to PostgreSQL and invisible to a case-sensitive scan. For a MEMBERSHIP
127
+ -- filter that is the fail-OPEN direction: the offender simply leaves the
128
+ -- class and the expected-empty assertion stays green. (Same mechanism
129
+ -- agent_board_wake_recovery.test.sql records for its own WR-7 filter.)
130
+ and agent_board_test.stripped_body(oid) ~* 'fingerprint'
131
+ -- message-board#196 Bucket B, demonstrated: read RAW, ONE comment mentioning
132
+ -- _raw_key_fingerprint dropped the forging writer out of this set and the
133
+ -- file went fully green with the bypass live.
134
+ -- ANCHORED TO THE CALL SHAPE, not to a bare identifier substring
135
+ -- (message-board#196 review). `!~ '_raw_key_fingerprint'` is satisfied by ANY identifier
136
+ -- containing it, so a forging writer with an argument named
137
+ -- `p_raw_key_fingerprint` -- not even a suspicious name -- fell out of this
138
+ -- offender set and the file stayed green. `\m` will not match inside
139
+ -- `p_...` (both are word characters, so there is no boundary), and the
140
+ -- trailing `\(` requires an actual call rather than a mention.
141
+ -- SCHEMA-QUALIFIED, because a bare-name anchor proves call SYNTAX, not callee
142
+ -- IDENTITY: `\m_raw_key_fingerprint\s*\(` also matches
143
+ -- `zz_other._raw_key_fingerprint(...)` (measured true). Every live call
144
+ -- site in agent_board is `agent_board.`-qualified, so requiring the
145
+ -- qualification costs nothing today and is fail-CLOSED if someone later writes
146
+ -- an unqualified call (it reads as NOT calling). Overload count is pinned
147
+ -- separately, so schema + name is the identity.
148
+ and agent_board_test.stripped_body(oid) !~* '\magent_board\._raw_key_fingerprint\s*\('),
125
149
  '',
126
150
  'no agent_signing_keys.fingerprint writer bypasses _raw_key_fingerprint (catalog-derived; a new writer names itself)');
127
151
 
@@ -299,5 +323,16 @@ select ok(has_function_privilege('service_role',
299
323
  'agent_board.mint_delegated_child(uuid, text, jsonb, text, interval, boolean)', 'EXECUTE'),
300
324
  'service_role retains EXECUTE on mint_delegated_child');
301
325
 
326
+
327
+ -- The schema-qualified call anchor above treats `agent_board._raw_key_fingerprint` as an
328
+ -- IDENTITY. That is only true while the name resolves to exactly one function:
329
+ -- a second overload would be a different implementation the same anchor accepts.
330
+ -- Catalog-derived, so a new overload fails here and the count names itself.
331
+ select is(
332
+ (select count(*)::int from pg_proc p join pg_namespace n on n.oid = p.pronamespace
333
+ where n.nspname = 'agent_board' and p.proname = '_raw_key_fingerprint'),
334
+ 1,
335
+ 'agent_board._raw_key_fingerprint has exactly ONE overload, so the schema-qualified call anchor identifies it uniquely');
336
+
302
337
  select finish();
303
338
  rollback;
@@ -93,8 +93,13 @@ select is(
93
93
  where n.nspname = 'agent_board'
94
94
  and p.prokind = 'f'
95
95
  and p.prolang <> (select oid from pg_language where lanname = 'internal')
96
- and regexp_replace(pg_get_functiondef(p.oid), '--[^\n]*', '', 'g')
97
- ~ 'insert into agent_board\.callback_outbox_events'),
96
+ -- CODE marker -> case-INSENSITIVE. PostgreSQL folds unquoted identifiers, so
97
+ -- `INSERT INTO AGENT_BOARD.CALLBACK_OUTBOX_EVENTS` is the same statement and a
98
+ -- case-sensitive scan drops that writer OUT of this exact set -- the fail-open
99
+ -- direction for a class filter. Missed by the round-3 sweep because that audit
100
+ -- was LINE-anchored and this predicate's operator sits on the next line.
101
+ and agent_board_test.stripped_body(p.oid)
102
+ ~* 'insert into agent_board\.callback_outbox_events'),
98
103
  '_queue_board_post_callbacks, _queue_inbox_callbacks',
99
104
  'WO-3 CLASS: the catalog names exactly the two known outbox writers -- a new writer fails here and NAMES ITSELF');
100
105
 
@@ -108,9 +113,9 @@ select is(
108
113
  where n.nspname = 'agent_board'
109
114
  and p.prokind = 'f'
110
115
  and p.prolang <> (select oid from pg_language where lanname = 'internal')
111
- and regexp_replace(pg_get_functiondef(p.oid), '--[^\n]*', '', 'g')
116
+ and agent_board_test.stripped_body(p.oid)
112
117
  ~* 'insert into agent_board\.callback_outbox_events'
113
- and regexp_replace(pg_get_functiondef(p.oid), '--[^\n]*', '', 'g')
118
+ and agent_board_test.stripped_body(p.oid)
114
119
  ~* 'overriding\s+(system|user)\s+value'),
115
120
  '',
116
121
  'WO-3 CLASS: no outbox writer uses OVERRIDING SYSTEM VALUE -- the identity bypass stays closed');
@@ -119,16 +124,16 @@ select is(
119
124
  -- WO-4 ORDERING
120
125
  -- ---------------------------------------------------------------------------
121
126
  select ok(
122
- (select regexp_replace(pg_get_functiondef(p.oid), '--[^\n]*', '', 'g')
123
- ~ 'order by coe\.available_at asc, coe\.seq asc'
127
+ (select agent_board_test.stripped_body(p.oid)
128
+ ~* 'order by coe\.available_at asc, coe\.seq asc'
124
129
  from pg_proc p
125
130
  join pg_namespace n on n.oid = p.pronamespace
126
131
  where n.nspname = 'agent_board' and p.proname = 'claim_callback_outbox_events'),
127
132
  'WO-4 claim_callback_outbox_events orders candidates by (available_at, seq)');
128
133
 
129
134
  select ok(
130
- (select regexp_replace(pg_get_functiondef(p.oid), '--[^\n]*', '', 'g')
131
- !~ 'coe\.id asc'
135
+ (select agent_board_test.stripped_body(p.oid)
136
+ !~* 'coe\.id asc'
132
137
  from pg_proc p
133
138
  join pg_namespace n on n.oid = p.pronamespace
134
139
  where n.nspname = 'agent_board' and p.proname = 'claim_callback_outbox_events'),
@@ -141,8 +146,8 @@ select ok(
141
146
  -- mutation produces NO failure. A property no mutation can break is not covered, so the
142
147
  -- pin has to be stated where the mutation actually lands.
143
148
  select ok(
144
- (select regexp_replace(pg_get_functiondef(p.oid), '--[^\n]*', '', 'g')
145
- ~ 'order by u\.seq asc'
149
+ (select agent_board_test.stripped_body(p.oid)
150
+ ~* 'order by u\.seq asc'
146
151
  from pg_proc p
147
152
  join pg_namespace n on n.oid = p.pronamespace
148
153
  where n.nspname = 'agent_board' and p.proname = 'claim_callback_outbox_events'),
@@ -201,7 +206,12 @@ select is(
201
206
  from pg_proc p
202
207
  where p.pronamespace = 'agent_board'::regnamespace
203
208
  and p.prosecdef
204
- and pg_get_functiondef(p.oid) ~ 'callback_outbox_events'
209
+ -- CODE marker in a CLASS FILTER -> stripped + case-INSENSITIVE, matching WO-3
210
+ -- above. Raw text lets a comment pull a function IN (fail-closed, a false
211
+ -- alarm); case-sensitivity lets a function spelling the table
212
+ -- `AGENT_BOARD.CALLBACK_OUTBOX_EVENTS` drop OUT, so its executability is
213
+ -- never checked at all -- fail-OPEN, on a privilege gate.
214
+ and agent_board_test.stripped_body(p.oid) ~* 'callback_outbox_events'
205
215
  and (has_function_privilege('public', p.oid, 'EXECUTE')
206
216
  or has_function_privilege('anon', p.oid, 'EXECUTE')
207
217
  or has_function_privilege('authenticated', p.oid, 'EXECUTE'))),
@@ -213,7 +223,12 @@ select is(
213
223
  from pg_proc p
214
224
  where p.pronamespace = 'agent_board'::regnamespace
215
225
  and p.prosecdef
216
- and pg_get_functiondef(p.oid) ~ 'callback_outbox_events'
226
+ -- CODE marker in a CLASS FILTER -> stripped + case-INSENSITIVE, matching WO-3
227
+ -- above. Raw text lets a comment pull a function IN (fail-closed, a false
228
+ -- alarm); case-sensitivity lets a function spelling the table
229
+ -- `AGENT_BOARD.CALLBACK_OUTBOX_EVENTS` drop OUT, so its executability is
230
+ -- never checked at all -- fail-OPEN, on a privilege gate.
231
+ and agent_board_test.stripped_body(p.oid) ~* 'callback_outbox_events'
217
232
  and not has_function_privilege('service_role', p.oid, 'EXECUTE')),
218
233
  '',
219
234
  'WO-5 CLASS: every SECURITY DEFINER function reaching callback_outbox_events is executable by service_role -- a dropped-and-recreated function that lost its grant names itself here');
@@ -260,7 +260,7 @@ select is(pg_temp.state('b2000000-0000-4000-8000-000000000001','b1000000-0000-40
260
260
  select is(
261
261
  (select count(*)::int from pg_proc p join pg_namespace n on n.oid = p.pronamespace
262
262
  where n.nspname = 'agent_board' and p.proname = 'resolve_board_request'
263
- and regexp_replace(pg_get_functiondef(p.oid), '--[^\n]*', '', 'g') ~ 'v_effective_state'),
263
+ and agent_board_test.stripped_body(p.oid) ~* 'v_effective_state'),
264
264
  1,
265
265
  'the rewrite happens in resolve_board_request, not in the shared sink');
266
266
 
@@ -28,7 +28,7 @@ set search_path = extensions, public, agent_board;
28
28
 
29
29
  begin;
30
30
 
31
- select plan(23);
31
+ select plan(24);
32
32
 
33
33
  create temp table _rr_fixture (
34
34
  open_board uuid,
@@ -133,7 +133,17 @@ select is(
133
133
 
134
134
  -- 3. Redemption bypasses the mutator entirely, so the clamp cannot reach its preset. -
135
135
  select ok(
136
- (select pg_get_functiondef(p.oid) not like '%_upsert_board_membership_state%'
136
+ -- anchored to the CALL shape rather than a bare `like '%…%'`: the claim is
137
+ -- that redemption never CALLS the mutator, and a variable or argument merely
138
+ -- named after it is not a call.
139
+ -- SCHEMA-QUALIFIED, because a bare-name anchor proves call SYNTAX, not callee
140
+ -- IDENTITY: `\m_upsert_board_membership_state\s*\(` also matches
141
+ -- `zz_other._upsert_board_membership_state(...)` (measured true). Every live call
142
+ -- site in agent_board is `agent_board.`-qualified, so requiring the
143
+ -- qualification costs nothing today and is fail-CLOSED if someone later writes
144
+ -- an unqualified call (it reads as NOT calling). Overload count is pinned
145
+ -- separately, so schema + name is the identity.
146
+ (select agent_board_test.stripped_body(p.oid) !~* '\magent_board\._upsert_board_membership_state\s*\('
137
147
  from pg_proc p join pg_namespace n on n.oid = p.pronamespace
138
148
  where n.nspname = 'agent_board' and p.proname = '_redeem_invite_for_agent'
139
149
  limit 1),
@@ -346,6 +356,17 @@ select is(
346
356
  select set_config('request.jwt.claim.role', '', true);
347
357
  select set_config('request.jwt.claim.sub', '', true);
348
358
 
359
+
360
+ -- The schema-qualified call anchor above treats `agent_board._upsert_board_membership_state` as an
361
+ -- IDENTITY. That is only true while the name resolves to exactly one function:
362
+ -- a second overload would be a different implementation the same anchor accepts.
363
+ -- Catalog-derived, so a new overload fails here and the count names itself.
364
+ select is(
365
+ (select count(*)::int from pg_proc p join pg_namespace n on n.oid = p.pronamespace
366
+ where n.nspname = 'agent_board' and p.proname = '_upsert_board_membership_state'),
367
+ 1,
368
+ 'agent_board._upsert_board_membership_state has exactly ONE overload, so the schema-qualified call anchor identifies it uniquely');
369
+
349
370
  select finish();
350
371
 
351
372
  rollback;
@@ -26,17 +26,18 @@ with defs as (
26
26
  select
27
27
  p.proname::text as proname,
28
28
  pg_get_function_identity_arguments(p.oid) as args,
29
- regexp_replace(
30
- regexp_replace(
31
- pg_get_functiondef(p.oid),
32
- E'--[^\\n]*(\\n|$)',
33
- E'\\n',
34
- 'g'
35
- ),
36
- E'/\\*([^*]|\\*+[^*/])*\\*+/',
37
- ' ',
38
- 'g'
39
- ) as def
29
+ -- LITERALS STRIPPED, and re-derived rather than assumed. The first version of
30
+ -- this line kept literals "because some ORDER BY operands are literals"; that
31
+ -- was measured and is false for THIS view -- the derived checks over it match
32
+ -- `created_at desc` / `id desc`, which are code, and the whole file is 98/98
33
+ -- with literals stripped. Keeping them left a real, if narrow, hole: the site
34
+ -- set is built by splitting `def` on `;`, so a literal containing a semicolon
35
+ -- re-splits a statement and can drop it out of the set.
36
+ --
37
+ -- The two R-LINK-7 assertions below DO need literals (their patterns match the
38
+ -- operands `''removed''` / `''joined''`), and they read with `true`
39
+ -- individually. Verified by flipping them: they go red, assertions 12 and 13.
40
+ agent_board_test.stripped_body(p.oid) as def
40
41
  from pg_proc p
41
42
  join pg_namespace n on n.oid = p.pronamespace
42
43
  where n.nspname = 'agent_board'
@@ -582,7 +583,12 @@ select is(
582
583
 
583
584
  -- 12. EC-MBROWID-3 requires set-based removed standing, not one selected row.
584
585
  select ok(
585
- (select regexp_replace(pg_get_functiondef(p.oid), '\s+', ' ', 'g') ~*
586
+ -- DATA literals in the marker (`''removed''`, `''joined''`, `''subscribed''` are
587
+ -- compared against column data, case-SENSITIVELY, at runtime), so this match is
588
+ -- case-sensitive too: `~*` cannot distinguish a live predicate from one rewritten
589
+ -- to `= ''REMOVED''`, which matches nothing. Same class as
590
+ -- agent_board_fleet_machine_reactivation.test.sql's `= ''machine''`.
591
+ (select regexp_replace(agent_board_test.stripped_body(p.oid, true), '\s+', ' ', 'g') ~
586
592
  'exists\s*\(\s*select\s+1\s+from\s+agent_board\.board_memberships.*membership_state\s*=\s*''removed''.*\)\s+and\s+not\s+exists\s*\(\s*select\s+1\s+from\s+agent_board\.board_memberships.*membership_state\s+in\s*\(\s*''joined''\s*,\s*''subscribed''\s*\)'
587
593
  from pg_proc p
588
594
  join pg_namespace n on n.oid = p.pronamespace
@@ -593,7 +599,12 @@ select ok(
593
599
 
594
600
  -- 13. Bootstrap must carry the same R-LINK-7 shape.
595
601
  select ok(
596
- (select regexp_replace(pg_get_functiondef(p.oid), '\s+', ' ', 'g') ~*
602
+ -- DATA literals in the marker (`''removed''`, `''joined''`, `''subscribed''` are
603
+ -- compared against column data, case-SENSITIVELY, at runtime), so this match is
604
+ -- case-sensitive too: `~*` cannot distinguish a live predicate from one rewritten
605
+ -- to `= ''REMOVED''`, which matches nothing. Same class as
606
+ -- agent_board_fleet_machine_reactivation.test.sql's `= ''machine''`.
607
+ (select regexp_replace(agent_board_test.stripped_body(p.oid, true), '\s+', ' ', 'g') ~
597
608
  'not\s+exists\s*\(\s*select\s+1\s+from\s+agent_board\.board_memberships.*membership_state\s+in\s*\(\s*''joined''\s*,\s*''subscribed''\s*\).*\)\s+and\s+not\s+exists\s*\(\s*select\s+1\s+from\s+agent_board\.board_memberships.*membership_state\s*=\s*''removed'''
598
609
  from pg_proc p
599
610
  join pg_namespace n on n.oid = p.pronamespace
@@ -128,13 +128,17 @@ select set_config('request.jwt.claim.role', '', true);
128
128
  select set_config('request.jwt.claim.sub', '', true);
129
129
 
130
130
  -- 6. Portal-offline static: no send RPC body references a Portal issuer / JWKS. -----
131
+ -- LITERALS KEPT on both of these: a Portal issuer or JWKS URL would appear as a
132
+ -- string LITERAL in the body, so the literal-stripping mode would delete exactly
133
+ -- what the claim is looking for and both would pass forever. Comments are still
134
+ -- stripped, so a `-- no portal here` note can no longer satisfy them.
131
135
  select ok(
132
- position('portal' in lower(pg_get_functiondef(
133
- 'agent_board.post_board_message(uuid,uuid,uuid,text,text,text,text,text,jsonb)'::regprocedure))) = 0,
136
+ position('portal' in lower(agent_board_test.stripped_body(
137
+ 'agent_board.post_board_message(uuid,uuid,uuid,text,text,text,text,text,jsonb)'::regprocedure, true))) = 0,
134
138
  'post_board_message references no Portal issuer/URL');
135
139
  select ok(
136
- position('jwks' in lower(pg_get_functiondef(
137
- 'agent_board.post_board_message(uuid,uuid,uuid,text,text,text,text,text,jsonb)'::regprocedure))) = 0,
140
+ position('jwks' in lower(agent_board_test.stripped_body(
141
+ 'agent_board.post_board_message(uuid,uuid,uuid,text,text,text,text,text,jsonb)'::regprocedure, true))) = 0,
138
142
  'post_board_message references no JWKS');
139
143
 
140
144
  select finish();