@consiliency/agent-board-schema 1.51.0 → 1.52.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 (39) hide show
  1. package/package.json +1 -1
  2. package/schema-manifest.json +1 -1
  3. package/tests/agent_board_agent_liveness.test.sql +3 -1
  4. package/tests/agent_board_atomic_fleet_onboarding.test.sql +33 -36
  5. package/tests/agent_board_authbound_boundary.test.sql +4 -3
  6. package/tests/agent_board_board_claim_policy.test.sql +17 -6
  7. package/tests/agent_board_claim_subject_gate.test.sql +7 -8
  8. package/tests/agent_board_claimkey.test.sql +9 -6
  9. package/tests/agent_board_claimpolicy_race.test.sql +1466 -342
  10. package/tests/agent_board_consent_emission.test.sql +5 -4
  11. package/tests/agent_board_consent_gating.test.sql +20 -9
  12. package/tests/agent_board_enroll_resumption.test.sql +1 -1
  13. package/tests/agent_board_enrollment_audit_content.test.sql +5 -4
  14. package/tests/agent_board_federated_identity_injective_slug.test.sql +3 -1
  15. package/tests/agent_board_federated_lock_order_class.test.sql +69 -52
  16. package/tests/agent_board_fedsession.test.sql +3 -1
  17. package/tests/agent_board_fedsession_provider_absence_gate.test.sql +9 -4
  18. package/tests/agent_board_fedsession_stored_identity_gate.test.sql +18 -6
  19. package/tests/agent_board_fk_lock_edges.test.sql +64 -5
  20. package/tests/agent_board_fleet_domain_reclaim.test.sql +2 -4
  21. package/tests/agent_board_fleet_machine_hijack.test.sql +2 -4
  22. package/tests/agent_board_fleet_machine_reactivation.test.sql +5 -1
  23. package/tests/agent_board_fleet_machine_reclaim.test.sql +2 -4
  24. package/tests/agent_board_invite_no_downgrade.test.sql +24 -18
  25. package/tests/agent_board_ledger_authority.test.sql +29 -21
  26. package/tests/agent_board_mint_harden.test.sql +5 -5
  27. package/tests/agent_board_outbox_wake_ordering.test.sql +4 -3
  28. package/tests/agent_board_ownerless_renew_quota.test.sql +7 -2
  29. package/tests/agent_board_portal_offline_invariant.test.sql +5 -4
  30. package/tests/agent_board_receipt_subject_gate.test.sql +7 -8
  31. package/tests/agent_board_rolereset.test.sql +5 -3
  32. package/tests/agent_board_rowid.test.sql +34 -15
  33. package/tests/agent_board_signer_lifecycle.test.sql +24 -13
  34. package/tests/agent_board_source_strip_helper.test.sql +2 -1
  35. package/tests/agent_board_task_event_origin_posture.test.sql +21 -9
  36. package/tests/agent_board_wake_recovery.test.sql +53 -26
  37. package/tests/agent_board_write_enforcement_class.test.sql +130 -12
  38. package/tests/catalog/function_execute_privileges.json +1923 -0
  39. package/tests/fixtures/test-prereqs.sql +644 -237
@@ -392,12 +392,15 @@ select is(pg_temp.nd_state(), 'joined',
392
392
  -- cannot satisfy a claim (message-board#196/#199), and it RAISES rather than returning
393
393
  -- NULL for a body it cannot read, which a `where … ~ …` scan would drop silently.
394
394
  --
395
- -- * The statement alternation and the optional-qualifier spelling are TAKEN VERBATIM from
396
- -- agent_board_receipt_subject_gate.test.sql rather than written fresh. That file already
397
- -- paid for this: it records `merge into`, `update only`, `delete from only`,
398
- -- `agent_board."board_memberships"` and `"agent_board" . "board_memberships"` as
399
- -- VERIFIED-LEGAL spellings that were each invisible to a narrower pattern. A second pattern
400
- -- written here would be a second list to drift -- rule 1 applied to the predicate itself.
395
+ -- * The write-family conjunct is `agent_board_test.write_re('board_memberships')`, the shared
396
+ -- matcher in tests/fixtures/test-prereqs.sql, rather than a statement alternation written
397
+ -- here (message-board#416/#417/#424). The hand-rolled alternation it replaced was copied
398
+ -- VERBATIM from agent_board_receipt_subject_gate.test.sql, which had already paid for it:
399
+ -- `merge into`, `update only`, `delete from only`, `agent_board."board_memberships"` and
400
+ -- `"agent_board" . "board_memberships"` are each VERIFIED-LEGAL spellings that were
401
+ -- invisible to a narrower pattern. A copy is still a second list to drift -- rule 1
402
+ -- applied to the predicate itself -- so the family now lives in ONE place, behind a
403
+ -- behaviour table (CPR-0) that pins every spelling above.
401
404
  -- The first draft of THIS file required `update agent_board.board_memberships` alone, and
402
405
  -- FOUR separate decoys each left it 19/19 green: `insert ... on conflict ... do update set`,
403
406
  -- `merge into`, an UNQUALIFIED `update board_memberships` under a search_path, and dynamic
@@ -410,8 +413,9 @@ select is(pg_temp.nd_state(), 'joined',
410
413
  -- so prose naming the pattern still cannot satisfy the claim. Keeping literals can only
411
414
  -- produce a LOUD false positive on an exact-set assertion, never a silent miss.
412
415
  --
413
- -- * `lower(...)` with `~` rather than `~*`: same effect, and it matches the neighbouring file
414
- -- so the two cannot drift on case handling.
416
+ -- * Case handling belongs to the matcher (`ci_re` folds each keyword; the `(?c)` director in
417
+ -- `re()` keeps identifiers exact-case when quoted), so no `lower(...)` / `~*` at this site --
418
+ -- the column conjuncts below still spell their own, until they move too.
415
419
  --
416
420
  -- WHAT THIS SCAN CANNOT SEE, stated exactly rather than generously, because a scan that reports
417
421
  -- clean on its own boundary forms is worth less than one that says which forms it declines to
@@ -434,7 +438,8 @@ select is(pg_temp.nd_state(), 'joined',
434
438
  --
435
439
  -- * `prokind in ('f','p')`. A PROCEDURE writer is exempt under `prokind = 'f'`.
436
440
  --
437
- -- * `\m` word boundaries. Without them the role canary below silently matched nothing.
441
+ -- * `\m` word boundaries (the matcher's `lead_guard`/`trail_guard`, and the column
442
+ -- conjuncts' own `\m`). Without them the role canary below silently matched nothing.
438
443
  --
439
444
  -- A `BEGIN ATOMIC` writer is covered too: stripped_body falls back to
440
445
  -- pg_get_function_sqlbody, verified with a BEGIN ATOMIC decoy that this assertion named.
@@ -445,8 +450,7 @@ select is(
445
450
  where n.nspname = 'agent_board'
446
451
  and p.prokind in ('f', 'p')
447
452
  and p.prolang <> (select oid from pg_language where lanname = 'internal')
448
- and lower(agent_board_test.stripped_body(p.oid, true))
449
- ~ '(insert\s+into|merge\s+into|update|delete\s+from|copy|truncate(\s+table)?)(\s+only)?\s+(("?agent_board"?\s*\.\s*)?board_memberships\M|("?agent_board"?\s*\.\s*)?"board_memberships")'),
453
+ and agent_board_test.stripped_body(p.oid, true) ~ agent_board_test.write_re('board_memberships')),
450
454
  array['_fedsession_autojoin_default_board', '_redeem_unbounded_invite_for_agent',
451
455
  '_upsert_board_membership_state', 'bootstrap_board_owner_memberships',
452
456
  'create_board', 'grant_board_role']::text[],
@@ -464,10 +468,12 @@ select is(
464
468
  where n.nspname = 'agent_board'
465
469
  and p.prokind in ('f', 'p')
466
470
  and p.prolang <> (select oid from pg_language where lanname = 'internal')
467
- and lower(agent_board_test.stripped_body(p.oid, true))
468
- ~ '(insert\s+into|merge\s+into|update|delete\s+from|copy|truncate(\s+table)?)(\s+only)?\s+(("?agent_board"?\s*\.\s*)?board_memberships\M|("?agent_board"?\s*\.\s*)?"board_memberships")'
469
- and lower(agent_board_test.stripped_body(p.oid, true))
470
- ~ '(set\s[^;]*\mmembership_state"?\s*=|set\s*\([^;()]*\mmembership_state"?[^;()]*\)\s*=)'),
471
+ and agent_board_test.stripped_body(p.oid, true) ~ agent_board_test.write_re('board_memberships')
472
+ -- the SET-clause arms of the family (UPDATE scalar/row form, MERGE then-update, INSERT …
473
+ -- ON CONFLICT DO UPDATE), relation-scoped; the INSERT column-list arm of col_write_re is
474
+ -- deliberately NOT here — a column list creates a row, it does not MOVE one
475
+ and agent_board_test.stripped_body(p.oid, true)
476
+ ~ agent_board_test.re(agent_board_test.col_assign_frag('board_memberships', 'membership_state', agent_board_test.bare_ok(p.oid)))),
471
477
  array['_upsert_board_membership_state']::text[],
472
478
  '#317: the shared sink is the ONLY writer that assigns membership_state IN A SET CLAUSE — i.e. the only one that can MOVE an existing row between states');
473
479
 
@@ -482,9 +488,9 @@ select is(
482
488
  where n.nspname = 'agent_board'
483
489
  and p.prokind in ('f', 'p')
484
490
  and p.prolang <> (select oid from pg_language where lanname = 'internal')
485
- and lower(agent_board_test.stripped_body(p.oid, true))
486
- ~ '(insert\s+into|merge\s+into|update|delete\s+from|copy|truncate(\s+table)?)(\s+only)?\s+(("?agent_board"?\s*\.\s*)?board_memberships\M|("?agent_board"?\s*\.\s*)?"board_memberships")'
487
- and lower(agent_board_test.stripped_body(p.oid, true)) ~ 'set\s[^;]*\mrole\s*='),
491
+ and agent_board_test.stripped_body(p.oid, true) ~ agent_board_test.write_re('board_memberships')
492
+ and agent_board_test.stripped_body(p.oid, true)
493
+ ~ agent_board_test.re(agent_board_test.col_assign_frag('board_memberships', 'role', agent_board_test.bare_ok(p.oid)))),
488
494
  array['_redeem_unbounded_invite_for_agent', '_upsert_board_membership_state',
489
495
  'bootstrap_board_owner_memberships', 'create_board', 'grant_board_role']::text[],
490
496
  '#317 canary: the SET-clause predicate still matches real SET clauses (these five assign `role`) — so an empty membership_state result means empty, not blind');
@@ -535,17 +535,17 @@ select is(
535
535
  (select string_agg(p.proname, ',' order by p.proname)
536
536
  from pg_proc p join pg_namespace n on n.oid = p.pronamespace
537
537
  where n.nspname = 'agent_board'
538
- and (agent_board_test.stripped_body(p.oid) ~* 'insert\s+into\s+agent_board\.board_memberships\M'
539
- or agent_board_test.stripped_body(p.oid) ~* 'update\s+agent_board\.board_memberships\M[^;]*\mset\M[^;]*\mrole\s*='
540
- or agent_board_test.stripped_body(p.oid) ~* '(insert\s+into|update)\s+agent_board\.board_authority_ceilings\M'
541
- or agent_board_test.stripped_body(p.oid) ~* 'update\s+agent_board\.boards\M[^;]*\mset\M[^;]*\mrole_gate_enforced\s*='
538
+ and (agent_board_test.stripped_body(p.oid) ~ agent_board_test.stmt_re('insert into', 'board_memberships')
539
+ or agent_board_test.stripped_body(p.oid) ~ agent_board_test.col_write_re('board_memberships', 'role')
540
+ or agent_board_test.stripped_body(p.oid) ~ agent_board_test.stmt_re('insert into|update', 'board_authority_ceilings')
541
+ or agent_board_test.stripped_body(p.oid) ~ agent_board_test.col_write_re('boards', 'role_gate_enforced')
542
542
  -- BOARDCLAIMPOLICY: boards.claim_policy is the same SHAPE of authority as
543
543
  -- role_gate_enforced above -- a board-level switch deciding what a later gate does
544
544
  -- (there the creator-identity exemption, here whether our ownerless claim guards apply
545
545
  -- at all). Counting it as an authority write is what makes the pairing assertion below
546
546
  -- hold, and is why set_board_claim_policy carries the ledger check.
547
- or agent_board_test.stripped_body(p.oid) ~* 'update\s+agent_board\.boards\M[^;]*\mset\M[^;]*\mclaim_policy\s*='
548
- or agent_board_test.stripped_body(p.oid) ~* 'insert\s+into\s+agent_board\.board_invite_tokens\M')),
547
+ or agent_board_test.stripped_body(p.oid) ~ agent_board_test.col_write_re('boards', 'claim_policy')
548
+ or agent_board_test.stripped_body(p.oid) ~ agent_board_test.stmt_re('insert into', 'board_invite_tokens'))),
549
549
  '_fedsession_autojoin_default_board,_redeem_unbounded_invite_for_agent,'
550
550
  || '_upsert_board_membership_state,bootstrap_board_owner_memberships,create_board,'
551
551
  || 'create_invite_link,grant_board_role,set_board_authority_ceiling,set_board_claim_policy,'
@@ -563,7 +563,9 @@ select is(
563
563
  from pg_proc p join pg_namespace n on n.oid = p.pronamespace
564
564
  where n.nspname = 'agent_board'
565
565
  and p.proname not in ('_assert_actor_not_fleet_revoked', '_actor_fleet_revoked')
566
- and agent_board_test.stripped_body(p.oid) ~ '\m(_assert_actor_not_fleet_revoked|_actor_fleet_revoked)\s*\('),
566
+ and agent_board_test.stripped_body(p.oid)
567
+ ~ agent_board_test.re(agent_board_test.call_frag('_assert_actor_not_fleet_revoked')
568
+ || '|' || agent_board_test.call_frag('_actor_fleet_revoked'))),
567
569
  '_redeem_unbounded_invite_for_agent,create_board,create_invite_link,grant_board_role,'
568
570
  || 'set_board_authority_ceiling,set_board_claim_policy,set_board_role_gate',
569
571
  'the functions that consult the fleet revocation ledger are exactly these seven (#280 added '
@@ -579,7 +581,9 @@ select is(
579
581
  (select string_agg(x.proname || ':' || x.why, '; ' order by x.proname)
580
582
  from (
581
583
  select p.proname,
582
- case when agent_board_test.stripped_body(p.oid) ~ '\m(_assert_actor_not_fleet_revoked|_actor_fleet_revoked)\s*\('
584
+ case when agent_board_test.stripped_body(p.oid)
585
+ ~ agent_board_test.re(agent_board_test.call_frag('_assert_actor_not_fleet_revoked')
586
+ || '|' || agent_board_test.call_frag('_actor_fleet_revoked'))
583
587
  then 'consults the ledger but writes no authority relation'
584
588
  else 'writes an authority relation with NO ledger gate'
585
589
  end as why
@@ -591,13 +595,15 @@ select is(
591
595
  '_fedsession_autojoin_default_board', 'bootstrap_board_owner_memberships',
592
596
  -- ...and the two helpers, which ARE the gate rather than users of it
593
597
  '_assert_actor_not_fleet_revoked', '_actor_fleet_revoked')
594
- and ((agent_board_test.stripped_body(p.oid) ~* 'insert\s+into\s+agent_board\.board_memberships\M'
595
- or agent_board_test.stripped_body(p.oid) ~* 'update\s+agent_board\.board_memberships\M[^;]*\mset\M[^;]*\mrole\s*='
596
- or agent_board_test.stripped_body(p.oid) ~* '(insert\s+into|update)\s+agent_board\.board_authority_ceilings\M'
597
- or agent_board_test.stripped_body(p.oid) ~* 'update\s+agent_board\.boards\M[^;]*\mset\M[^;]*\mrole_gate_enforced\s*='
598
- or agent_board_test.stripped_body(p.oid) ~* 'update\s+agent_board\.boards\M[^;]*\mset\M[^;]*\mclaim_policy\s*='
599
- or agent_board_test.stripped_body(p.oid) ~* 'insert\s+into\s+agent_board\.board_invite_tokens\M')
600
- <> (agent_board_test.stripped_body(p.oid) ~ '\m(_assert_actor_not_fleet_revoked|_actor_fleet_revoked)\s*\('))
598
+ and ((agent_board_test.stripped_body(p.oid) ~ agent_board_test.stmt_re('insert into', 'board_memberships')
599
+ or agent_board_test.stripped_body(p.oid) ~ agent_board_test.col_write_re('board_memberships', 'role')
600
+ or agent_board_test.stripped_body(p.oid) ~ agent_board_test.stmt_re('insert into|update', 'board_authority_ceilings')
601
+ or agent_board_test.stripped_body(p.oid) ~ agent_board_test.col_write_re('boards', 'role_gate_enforced')
602
+ or agent_board_test.stripped_body(p.oid) ~ agent_board_test.col_write_re('boards', 'claim_policy')
603
+ or agent_board_test.stripped_body(p.oid) ~ agent_board_test.stmt_re('insert into', 'board_invite_tokens'))
604
+ <> (agent_board_test.stripped_body(p.oid)
605
+ ~ agent_board_test.re(agent_board_test.call_frag('_assert_actor_not_fleet_revoked')
606
+ || '|' || agent_board_test.call_frag('_actor_fleet_revoked'))))
601
607
  ) x),
602
608
  null,
603
609
  'no function writes an authority relation without the ledger gate, or vice versa');
@@ -681,7 +687,7 @@ select is(
681
687
  from pg_proc p join pg_namespace n on n.oid = p.pronamespace
682
688
  where n.nspname = 'agent_board'
683
689
  and p.proname <> '_upsert_board_membership_state'
684
- and agent_board_test.stripped_body(p.oid) ~ '\m_upsert_board_membership_state\s*\('),
690
+ and agent_board_test.stripped_body(p.oid) ~ agent_board_test.call_re('_upsert_board_membership_state')),
685
691
  'invite_board_member(p_board_id uuid, p_agent_id uuid, p_created_by_agent_id uuid, p_metadata jsonb)'
686
692
  || ' | join_board(p_board_id uuid, p_agent_id uuid, p_membership_state text, p_created_by_agent_id uuid, p_metadata jsonb)'
687
693
  || ' | request_join_board(p_board_id uuid, p_agent_id uuid, p_metadata jsonb)'
@@ -894,7 +900,7 @@ select is(
894
900
  (select string_agg(p.proname, ',' order by p.proname)
895
901
  from pg_proc p join pg_namespace n on n.oid = p.pronamespace
896
902
  where n.nspname = 'agent_board'
897
- and agent_board_test.stripped_body(p.oid) ~ '\m_redeem_unbounded_invite_for_agent\s*\('),
903
+ and agent_board_test.stripped_body(p.oid) ~ agent_board_test.call_re('_redeem_unbounded_invite_for_agent')),
898
904
  '_redeem_fleet_invite_for_agent,_redeem_invite_for_agent',
899
905
  'and those are the only two callers of it, so no redemption route bypasses the gate');
900
906
 
@@ -906,7 +912,7 @@ select is(
906
912
  (select string_agg(p.proname, ',' order by p.proname)
907
913
  from pg_proc p join pg_namespace n on n.oid = p.pronamespace
908
914
  where n.nspname = 'agent_board'
909
- and agent_board_test.stripped_body(p.oid) ~* '(insert\s+into|update)\s+agent_board\.fleet_revocation_events\M'),
915
+ and agent_board_test.stripped_body(p.oid) ~ agent_board_test.stmt_re('insert into|update', 'fleet_revocation_events')),
910
916
  '_revoke_agent_principal,revoke_fleet_subject',
911
917
  'the writers of the fleet revocation ledger are exactly these two');
912
918
 
@@ -958,9 +964,9 @@ select ok(
958
964
  -- stay unlocked — an `agents` lock reappearing in it is the deadlock the header enumerates.
959
965
  select ok(
960
966
  agent_board_test.stripped_body('agent_board._actor_fleet_revoked(uuid)'::regprocedure)
961
- ~ 'agent_board\.fleet_revocation_events'
967
+ ~ agent_board_test.re(agent_board_test.qname_frag('fleet_revocation_events', false))
962
968
  and agent_board_test.stripped_body('agent_board._actor_fleet_revoked(uuid)'::regprocedure)
963
- !~ '\mfor\s+(share|update|key\s+share|no\s+key\s+update)\M',
969
+ !~ agent_board_test.re(agent_board_test.row_lock_frag()),
964
970
  'the unlocked predicate reads the ledger and takes NO row lock — what makes it safe to call '
965
971
  'from the invite redeem path, which is reached holding a boards lock');
966
972
 
@@ -977,7 +983,9 @@ select is(
977
983
  -- would mean a machine reactivation could restore a revoked agent's authority.
978
984
  select ok(
979
985
  agent_board_test.stripped_body('agent_board._assert_actor_not_fleet_revoked(uuid,text)'::regprocedure)
980
- !~ '\m(effective_at|reactivated_at)\M',
986
+ -- qualified or bare (col_ref_frag): `col_frag` alone rejects a preceding dot, so `e.effective_at`
987
+ -- would pass this absence (measured on evaluate_fleet_sender_policy, which only names it qualified).
988
+ !~ agent_board_test.re(agent_board_test.col_ref_frag('effective_at') || '|' || agent_board_test.col_ref_frag('reactivated_at')),
981
989
  'the gate has no supersession clause, matching the send path''s agent-subject predicate');
982
990
 
983
991
  -- ===========================================================================
@@ -119,7 +119,7 @@ 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 agent_board_test.stripped_body(oid) ~* 'insert[[:space:]]+into[[:space:]]+(agent_board\.)?agent_signing_keys'
122
+ where agent_board_test.stripped_body(oid) ~ agent_board_test.stmt_re('insert into', 'agent_signing_keys')
123
123
  -- CASE-INSENSITIVE, and that is load-bearing rather than tidiness. SQL folds
124
124
  -- unquoted identifiers, but `prosrc` is stored VERBATIM, so a writer spelling
125
125
  -- the same call `AGENT_BOARD.…` or the same column `FINGERPRINT` is identical
@@ -138,14 +138,14 @@ select is(
138
138
  -- offender set and the file stayed green. `\m` will not match inside
139
139
  -- `p_...` (both are word characters, so there is no boundary), and the
140
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
141
+ -- SCHEMA-QUALIFIED (`bare_ok => false`), because a bare-name anchor proves call
142
+ -- SYNTAX, not callee IDENTITY: the old `\m_raw_key_fingerprint\s*\(` also matched
143
143
  -- `zz_other._raw_key_fingerprint(...)` (measured true). Every live call
144
144
  -- site in agent_board is `agent_board.`-qualified, so requiring the
145
145
  -- qualification costs nothing today and is fail-CLOSED if someone later writes
146
146
  -- an unqualified call (it reads as NOT calling). Overload count is pinned
147
147
  -- separately, so schema + name is the identity.
148
- and agent_board_test.stripped_body(oid) !~* '\magent_board\._raw_key_fingerprint\s*\('),
148
+ and agent_board_test.stripped_body(oid) !~ agent_board_test.call_re('_raw_key_fingerprint', false)),
149
149
  '',
150
150
  'no agent_signing_keys.fingerprint writer bypasses _raw_key_fingerprint (catalog-derived; a new writer names itself)');
151
151
 
@@ -156,7 +156,7 @@ select ok(
156
156
  from pg_proc p join pg_namespace n on n.oid = p.pronamespace
157
157
  where n.nspname = 'agent_board' and p.prokind = 'f'
158
158
  and p.proname in ('mint_delegated_child', 'enroll_federated_identity'))
159
- select bool_and(pg_get_functiondef(oid) ~ '_raw_key_fingerprint') from fns),
159
+ select bool_and(agent_board_test.stripped_body(oid) ~ agent_board_test.call_re('_raw_key_fingerprint', false)) from fns),
160
160
  'mint_delegated_child and enroll_federated_identity both derive via _raw_key_fingerprint');
161
161
 
162
162
  -- The helper derives over the RAW bytes, not the base64url string (revert => this flips).
@@ -99,7 +99,7 @@ select is(
99
99
  -- direction for a class filter. Missed by the round-3 sweep because that audit
100
100
  -- was LINE-anchored and this predicate's operator sits on the next line.
101
101
  and agent_board_test.stripped_body(p.oid)
102
- ~* 'insert into agent_board\.callback_outbox_events'),
102
+ ~ agent_board_test.stmt_re('insert into', 'callback_outbox_events')),
103
103
  '_queue_board_post_callbacks, _queue_inbox_callbacks',
104
104
  'WO-3 CLASS: the catalog names exactly the two known outbox writers -- a new writer fails here and NAMES ITSELF');
105
105
 
@@ -114,9 +114,10 @@ select is(
114
114
  and p.prokind = 'f'
115
115
  and p.prolang <> (select oid from pg_language where lanname = 'internal')
116
116
  and agent_board_test.stripped_body(p.oid)
117
- ~* 'insert into agent_board\.callback_outbox_events'
117
+ ~ agent_board_test.stmt_re('insert into', 'callback_outbox_events')
118
118
  and agent_board_test.stripped_body(p.oid)
119
- ~* 'overriding\s+(system|user)\s+value'),
119
+ ~ agent_board_test.re('\m' || agent_board_test.ci_re('overriding') || '\s+(?:' || agent_board_test.ci_re('system') || '|' || agent_board_test.ci_re('user') || ')\s+'
120
+ || agent_board_test.ci_re('value') || '\M')),
120
121
  '',
121
122
  'WO-3 CLASS: no outbox writer uses OVERRIDING SYSTEM VALUE -- the identity bypass stays closed');
122
123
 
@@ -533,7 +533,10 @@ select is(
533
533
  (select string_agg(p.proname, ', ' order by p.proname)
534
534
  from pg_proc p join pg_namespace n on n.oid = p.pronamespace
535
535
  where n.nspname = 'agent_board'
536
- and agent_board_test.stripped_body(p.oid, true) ~ '(lease_expires_at\s*=[^=]|insert into agent_board\.claims\s*\([^)]*lease_expires_at)'),
536
+ -- every write form of claims.lease_expires_at (UPDATE/MERGE/ON CONFLICT assignment, INSERT
537
+ -- column list, ...) -- the old hand form was `lease_expires_at =` anywhere plus one INSERT
538
+ -- shape, which also read as a WHERE comparison; measured: the same three, in either strip mode
539
+ and agent_board_test.stripped_body(p.oid) ~ agent_board_test.col_write_re('claims', 'lease_expires_at')),
537
540
  'acquire_claim, renew_claim, set_board_claim_policy',
538
541
  'ORQ-14 CLASS: acquire_claim, renew_claim and (since #400) set_board_claim_policy''s advisory-revert cap reset are the ONLY functions that write a claim lease — a new one names itself here instead of quietly inheriting an unconverged renewal path');
539
542
 
@@ -549,7 +552,9 @@ select is(
549
552
  (select string_agg(p.proname, ', ' order by p.proname)
550
553
  from pg_proc p join pg_namespace n on n.oid = p.pronamespace
551
554
  where n.nspname = 'agent_board'
552
- and agent_board_test.stripped_body(p.oid, true) ~ 'count\(\*\)[^;]*from agent_board\.claims'),
555
+ and agent_board_test.stripped_body(p.oid)
556
+ ~ agent_board_test.re('\m' || agent_board_test.ci_re('count') || '\s*\(\s*\*\s*\)' || agent_board_test.same_stmt()
557
+ || agent_board_test.stmt_frag('from', 'claims', agent_board_test.bare_ok(p.oid)))),
553
558
  '_claimgate_active_ownerless_claims',
554
559
  'ORQ-15 CLASS: exactly ONE function counts rows of agent_board.claims — an enforcement path that re-derives the ownerless count instead of asking the helper fails here and names itself');
555
560
 
@@ -119,25 +119,26 @@ select isnt(
119
119
  -- Grep (paired supplement): the DB write/session path references no Portal string. --
120
120
  select is(
121
121
  (select count(*)::int from (
122
- select pg_get_functiondef(p.oid) as def
122
+ -- literals KEPT (a Portal reference IS a string); comments dropped (prose is not a reference)
123
+ select agent_board_test.stripped_body(p.oid, true) as def
123
124
  from pg_proc p join pg_namespace n on n.oid = p.pronamespace
124
125
  where n.nspname = 'agent_board'
125
126
  and p.proname in (
126
127
  'mint_fleet_agent_session', 'post_board_message', 'send_direct_message',
127
128
  'send_multicast_message', 'create_tasking_delivery')
128
129
  ) d
129
- where lower(d.def) ~ '(portal|jwks|\.well-known|openid|oidc)'),
130
+ where d.def ~* '(portal|jwks|\.well-known|openid|oidc)'),
130
131
  0, 'no write/session-path RPC body references a Portal issuer/JWKS/OIDC string');
131
132
  select is(
132
133
  (select count(*)::int from (
133
- select pg_get_functiondef(p.oid) as def
134
+ select agent_board_test.stripped_body(p.oid, true) as def
134
135
  from pg_proc p join pg_namespace n on n.oid = p.pronamespace
135
136
  where n.nspname = 'agent_board'
136
137
  and p.proname in (
137
138
  'mint_fleet_agent_session', 'post_board_message', 'send_direct_message',
138
139
  'send_multicast_message', 'create_tasking_delivery')
139
140
  ) d
140
- where lower(d.def) ~ '(enroll_federated_identity|/enroll)'),
141
+ where d.def ~* '(enroll_federated_identity|/enroll)'),
141
142
  0, 'no write/session-path RPC body references the /enroll enrollment surface');
142
143
 
143
144
  select finish();
@@ -477,8 +477,7 @@ select is(
477
477
  (select coalesce(string_agg(p.proname, ',' order by p.proname), '(none)')
478
478
  from pg_proc p
479
479
  where p.pronamespace = 'agent_board'::regnamespace
480
- and lower(agent_board_test.stripped_body(p.oid, true))
481
- ~ '(insert\s+into|merge\s+into|update|delete\s+from)(\s+only)?\s+(("?agent_board"?\s*\.\s*)?read_receipts\M|("?agent_board"?\s*\.\s*)?"read_receipts")'),
480
+ and agent_board_test.stripped_body(p.oid, true) ~ agent_board_test.write_re('read_receipts')),
482
481
  'mark_read',
483
482
  'catalog: mark_read is the ONLY agent_board function that writes read_receipts -- a new writer names itself here');
484
483
 
@@ -486,10 +485,10 @@ select is(
486
485
  (select coalesce(string_agg(p.proname, ',' order by p.proname), '(none)')
487
486
  from pg_proc p
488
487
  where p.pronamespace = 'agent_board'::regnamespace
489
- and lower(agent_board_test.stripped_body(p.oid, true))
490
- ~ '(insert\s+into|merge\s+into|update|delete\s+from)(\s+only)?\s+(("?agent_board"?\s*\.\s*)?read_receipts\M|("?agent_board"?\s*\.\s*)?"read_receipts")'
491
- and lower(agent_board_test.stripped_body(p.oid))
492
- !~ 'not\s+agent_board\._agent_can_access_thread\s*\('),
488
+ and agent_board_test.stripped_body(p.oid, true) ~ agent_board_test.write_re('read_receipts')
489
+ and agent_board_test.stripped_body(p.oid)
490
+ !~ agent_board_test.re('\m' || agent_board_test.ci_re('not') || '\s+'
491
+ || agent_board_test.call_frag('_agent_can_access_thread', false))),
493
492
  '(none)',
494
493
  'catalog: every read_receipts writer contains a REFUSING reference to _agent_can_access_thread (source shape only -- assertion 2 is what proves it refuses)');
495
494
 
@@ -512,8 +511,8 @@ select is(
512
511
  (select coalesce(string_agg(p.proname, ',' order by p.proname), '(none)')
513
512
  from pg_proc p
514
513
  where p.pronamespace = 'agent_board'::regnamespace
515
- and lower(agent_board_test.stripped_body(p.oid, true))
516
- ~ '(delete\s+from|merge\s+into|truncate)(\s+table)?(\s+only)?\s+(("?agent_board"?\s*\.\s*)?read_receipts\M|("?agent_board"?\s*\.\s*)?"read_receipts")'),
514
+ and agent_board_test.stripped_body(p.oid, true)
515
+ ~ agent_board_test.stmt_re('delete from|merge into|truncate|truncate table', 'read_receipts')),
517
516
  '(none)',
518
517
  'catalog: no agent_board function deletes or truncates a read receipt -- the grandfather is permanent by construction');
519
518
 
@@ -143,7 +143,7 @@ select ok(
143
143
  -- qualification costs nothing today and is fail-CLOSED if someone later writes
144
144
  -- an unqualified call (it reads as NOT calling). Overload count is pinned
145
145
  -- separately, so schema + name is the identity.
146
- (select agent_board_test.stripped_body(p.oid) !~* '\magent_board\._upsert_board_membership_state\s*\('
146
+ (select agent_board_test.stripped_body(p.oid) !~ agent_board_test.call_re('_upsert_board_membership_state', false)
147
147
  from pg_proc p join pg_namespace n on n.oid = p.pronamespace
148
148
  where n.nspname = 'agent_board' and p.proname = '_redeem_invite_for_agent'
149
149
  limit 1),
@@ -268,8 +268,10 @@ select is(
268
268
  select ok(
269
269
  (select (
270
270
  select count(*) from regexp_matches(
271
- pg_get_functiondef(p.oid),
272
- 'membership_state\s+in\s*\(\s*''joined''\s*,\s*''subscribed''\s*\)',
271
+ agent_board_test.stripped_body(p.oid, true),
272
+ -- the column qualified or bare (`bm.membership_state` is the UPDATE's spelling)
273
+ agent_board_test.re(agent_board_test.col_ref_frag('membership_state')
274
+ || '\s+' || agent_board_test.ci_re('in') || '\s*\(\s*''joined''\s*,\s*''subscribed''\s*\)'),
273
275
  'g')) >= 2
274
276
  from pg_proc p join pg_namespace n on n.oid = p.pronamespace
275
277
  where n.nspname = 'agent_board' and p.proname = 'grant_board_role'
@@ -48,7 +48,8 @@ statements as (
48
48
  proname,
49
49
  args,
50
50
  statement_ordinality::int as statement_ordinality,
51
- statement
51
+ -- bound through `def` so the source-scan lint can follow `statement` to its producer
52
+ split.statement as statement
52
53
  from defs
53
54
  cross join lateral regexp_split_to_table(def, ';')
54
55
  with ordinality as split(statement, statement_ordinality)
@@ -57,33 +58,45 @@ select
57
58
  proname,
58
59
  args,
59
60
  statement_ordinality,
61
+ -- `from <rel>` through stmt_re: the verb is a word, the relation is schema-qualified
62
+ -- (`bare_ok => false`, as the hand-rolled `agent_board\.` was), case folded by the family
63
+ -- rather than by `~*`. The ORDER BY operands are `created_at` and `id`, qualified or bare
64
+ -- (col_ref_frag: `m.created_at desc` is the common spelling).
60
65
  case
61
- when statement ~* 'from\s+agent_board\.board_memberships'
66
+ when statement ~ agent_board_test.stmt_re('from', 'board_memberships', false)
62
67
  then 'board_memberships'
63
- when statement ~* 'from\s+agent_board\.tasks'
68
+ when statement ~ agent_board_test.stmt_re('from', 'tasks', false)
64
69
  then 'tasks'
65
- when statement ~* 'from\s+agent_board\.messages'
70
+ when statement ~ agent_board_test.stmt_re('from', 'messages', false)
66
71
  then 'messages'
67
72
  end as source_relation,
68
73
  (select count(*)::int
69
- from regexp_matches(statement, 'created_at\s+desc', 'gi')) as created_at_desc_count,
74
+ from regexp_matches(statement,
75
+ agent_board_test.re(agent_board_test.col_ref_frag('created_at')
76
+ || '\s+' || agent_board_test.ci_re('desc') || agent_board_test.trail_guard()),
77
+ 'g')) as created_at_desc_count,
70
78
  (select count(*)::int
71
79
  from regexp_matches(
72
80
  statement,
73
- 'created_at\s+desc\s*,\s*(?:[a-z_][a-z_0-9]*\.)?id\s+desc',
74
- 'gi'
81
+ agent_board_test.re(agent_board_test.col_ref_frag('created_at')
82
+ || '\s+' || agent_board_test.ci_re('desc') || agent_board_test.trail_guard() || '\s*,\s*'
83
+ || agent_board_test.col_ref_frag('id')
84
+ || '\s+' || agent_board_test.ci_re('desc') || agent_board_test.trail_guard()),
85
+ 'g'
75
86
  )) as total_order_count
76
87
  from statements
77
- where statement ~* 'order\s+by.*created_at\s+desc'
88
+ where statement ~ agent_board_test.re('\m' || agent_board_test.ci_re('order by') || '\M.*'
89
+ || agent_board_test.col_ref_frag('created_at')
90
+ || '\s+' || agent_board_test.ci_re('desc') || agent_board_test.trail_guard())
78
91
  and (
79
- statement ~* 'from\s+agent_board\.board_memberships'
92
+ statement ~ agent_board_test.stmt_re('from', 'board_memberships', false)
80
93
  or (
81
94
  proname = 'create_tasking_delivery'
82
- and statement ~* 'from\s+agent_board\.tasks'
95
+ and statement ~ agent_board_test.stmt_re('from', 'tasks', false)
83
96
  )
84
97
  or (
85
98
  proname = 'post_board_message'
86
- and statement ~* 'from\s+agent_board\.messages'
99
+ and statement ~ agent_board_test.stmt_re('from', 'messages', false)
87
100
  )
88
101
  );
89
102
 
@@ -564,7 +577,7 @@ select is(
564
577
 
565
578
  -- 11. The live view is catalog-derived too; its last definer uses DROP + CREATE.
566
579
  with d as (
567
- select pg_get_viewdef(c.oid, true) as def
580
+ select agent_board_test.stripped_viewdef(c.oid) as def
568
581
  from pg_class c
569
582
  join pg_namespace n on n.oid = c.relnamespace
570
583
  where n.nspname = 'agent_board'
@@ -572,12 +585,18 @@ with d as (
572
585
  and c.relkind = 'v'
573
586
  )
574
587
  select is(
575
- (select count(*)::int from d, regexp_matches(def, 'created_at\s+desc', 'gi')),
588
+ (select count(*)::int from d, regexp_matches(def,
589
+ agent_board_test.re(agent_board_test.col_ref_frag('created_at')
590
+ || '\s+' || agent_board_test.ci_re('desc') || agent_board_test.trail_guard()),
591
+ 'g')),
576
592
  (select count(*)::int
577
593
  from d, regexp_matches(
578
594
  def,
579
- 'created_at\s+desc\s*,\s*(?:[a-z_][a-z_0-9]*\.)?id\s+desc',
580
- 'gi'
595
+ agent_board_test.re(agent_board_test.col_ref_frag('created_at')
596
+ || '\s+' || agent_board_test.ci_re('desc') || agent_board_test.trail_guard() || '\s*,\s*'
597
+ || agent_board_test.col_ref_frag('id')
598
+ || '\s+' || agent_board_test.ci_re('desc') || agent_board_test.trail_guard()),
599
+ 'g'
581
600
  )),
582
601
  'v_board_directory live catalog definition gives its membership read the id DESC tiebreak');
583
602
 
@@ -463,7 +463,9 @@ select is(
463
463
  where n.nspname = 'agent_board'
464
464
  and p.proname like 'signed\_%'
465
465
  and agent_board_test.stripped_body(p.oid)
466
- ~ '\m(grant_board_role|set_board_authority_ceiling|set_board_role_gate)\s*\('),
466
+ ~ agent_board_test.re(agent_board_test.call_frag('grant_board_role')
467
+ || '|' || agent_board_test.call_frag('set_board_authority_ceiling')
468
+ || '|' || agent_board_test.call_frag('set_board_role_gate'))),
467
469
  'signed_grant_board_role,signed_set_board_authority_ceiling',
468
470
  'the signed wrappers that perform an AUTHORITY write are exactly these two');
469
471
 
@@ -474,7 +476,7 @@ select is(
474
476
  where n.nspname = 'agent_board'
475
477
  and p.proname like 'signed\_%'
476
478
  and agent_board_test.stripped_body(p.oid)
477
- ~ '\m_assert_signed_authority_signer_live\s*\('),
479
+ ~ agent_board_test.call_re('_assert_signed_authority_signer_live')),
478
480
  'signed_grant_board_role,signed_set_board_authority_ceiling',
479
481
  'the signed wrappers that revalidate the signer are exactly these two');
480
482
 
@@ -485,7 +487,9 @@ select is(
485
487
  from (
486
488
  select p.proname,
487
489
  case when agent_board_test.stripped_body(p.oid)
488
- ~ '\m(grant_board_role|set_board_authority_ceiling|set_board_role_gate)\s*\('
490
+ ~ agent_board_test.re(agent_board_test.call_frag('grant_board_role')
491
+ || '|' || agent_board_test.call_frag('set_board_authority_ceiling')
492
+ || '|' || agent_board_test.call_frag('set_board_role_gate'))
489
493
  then 'authority write with NO signer revalidation'
490
494
  else 'revalidates a signer but performs no authority write'
491
495
  end as why
@@ -494,9 +498,11 @@ select is(
494
498
  where n.nspname = 'agent_board'
495
499
  and p.proname like 'signed\_%'
496
500
  and (agent_board_test.stripped_body(p.oid)
497
- ~ '\m(grant_board_role|set_board_authority_ceiling|set_board_role_gate)\s*\(')
501
+ ~ agent_board_test.re(agent_board_test.call_frag('grant_board_role')
502
+ || '|' || agent_board_test.call_frag('set_board_authority_ceiling')
503
+ || '|' || agent_board_test.call_frag('set_board_role_gate')))
498
504
  <> (agent_board_test.stripped_body(p.oid)
499
- ~ '\m_assert_signed_authority_signer_live\s*\(')
505
+ ~ agent_board_test.call_re('_assert_signed_authority_signer_live'))
500
506
  ) x),
501
507
  null,
502
508
  'no signed wrapper is on one side of the authority/revalidation pairing without the other');
@@ -511,7 +517,12 @@ select is(
511
517
  where n.nspname = 'agent_board'
512
518
  and p.proname like 'signed\_%'
513
519
  and agent_board_test.stripped_body(p.oid)
514
- ~ '\m(send_direct_message|send_multicast_message|post_board_message|_?append_task_event|create_tasking_delivery)\s*\('),
520
+ ~ agent_board_test.re(agent_board_test.call_frag('send_direct_message')
521
+ || '|' || agent_board_test.call_frag('send_multicast_message')
522
+ || '|' || agent_board_test.call_frag('post_board_message')
523
+ || '|' || agent_board_test.call_frag('append_task_event')
524
+ || '|' || agent_board_test.call_frag('_append_task_event')
525
+ || '|' || agent_board_test.call_frag('create_tasking_delivery'))),
515
526
  'signed_append_task_event,signed_create_tasking_delivery,signed_post_board_message,'
516
527
  || 'signed_send_direct_message,signed_send_multicast_message',
517
528
  'the five exempt wrappers each perform a message/task write, which is why they are exempt');
@@ -524,7 +535,7 @@ select is(
524
535
  join pg_namespace n on n.oid = p.pronamespace
525
536
  where n.nspname = 'agent_board'
526
537
  and p.proname like 'signed\_%'
527
- and agent_board_test.stripped_body(p.oid) ~ '\m_signed_write_actor_id\s*\('),
538
+ and agent_board_test.stripped_body(p.oid) ~ agent_board_test.call_re('_signed_write_actor_id')),
528
539
  'signed_append_task_event,signed_create_tasking_delivery,signed_grant_board_role,'
529
540
  || 'signed_post_board_message,signed_send_direct_message,signed_send_multicast_message,'
530
541
  || 'signed_set_board_authority_ceiling',
@@ -532,7 +543,7 @@ select is(
532
543
 
533
544
  select ok(
534
545
  agent_board_test.stripped_body('agent_board._signed_write_actor_id(jsonb,jsonb,text)'::regprocedure)
535
- !~ '\m(agents|agent_signing_keys)\M',
546
+ !~ agent_board_test.re(agent_board_test.qname_frag('agents') || '|' || agent_board_test.qname_frag('agent_signing_keys')),
536
547
  'the shared actor chokepoint reads no lifecycle table: the five message wrappers are unchanged');
537
548
 
538
549
  -- ===========================================================================
@@ -690,17 +701,17 @@ select is(
690
701
  ), edges as (
691
702
  select f.proname as caller, g.proname as callee
692
703
  from fns f join fns g on g.proname <> f.proname
693
- where f.b ~ ('\m' || g.proname || '\s*\(')
704
+ where f.b ~ agent_board_test.call_re(g.proname)
694
705
  ), closure as (
695
706
  select proname as root, proname as reached from fns
696
707
  union
697
708
  select c.root, e.callee from closure c join edges e on e.caller = c.reached
698
709
  ), direct as (
699
710
  select proname,
700
- (b ~ 'agent_board\.agents[^;]*for (update|share)') as locks_agents,
701
- (b ~ 'agent_board\.board_memberships[^;]*for (update|share)'
702
- or b ~ 'update agent_board\.board_memberships') as locks_memberships,
703
- (b ~ '\magent_board\._lock_board_authority_ceiling\s*\(') as takes_advisory
711
+ (b ~ agent_board_test.row_lock_re('agents')) as locks_agents,
712
+ (b ~ agent_board_test.row_lock_re('board_memberships')
713
+ or b ~ agent_board_test.stmt_re('update', 'board_memberships')) as locks_memberships,
714
+ (b ~ agent_board_test.call_re('_lock_board_authority_ceiling')) as takes_advisory
704
715
  from fns
705
716
  ), agg as (
706
717
  select c.root,
@@ -334,7 +334,7 @@ select is(
334
334
  join pg_namespace n on n.oid = p.pronamespace
335
335
  where n.nspname = 'agent_board'
336
336
  and p.prolang <> (select oid from pg_language where lanname = 'internal')
337
- and agent_board_test.stripped_body(p.oid) ~* 'insert\s+into\s+agent_board\._mb293_sentinel\M'),
337
+ and agent_board_test.stripped_body(p.oid) ~ agent_board_test.stmt_re('insert into', '_mb293_sentinel', false)),
338
338
  '_mb293_atomic_writer, _mb293_prosrc_writer',
339
339
  'SQLBODY-11: a catalog-derived exact-set writer scan -- the shape every consumer file uses -- now names the BEGIN ATOMIC writer alongside the ordinary one');
340
340
 
@@ -508,6 +508,7 @@ select cmp_ok(
508
508
  join pg_namespace n on n.oid = p.pronamespace
509
509
  where n.nspname = 'agent_board'
510
510
  and p.prolang <> (select oid from pg_language where lanname = 'internal')
511
+ -- source-scan: raw-subject this census COUNTS comments, which the strip would remove
511
512
  and p.prosrc ~ '--'),
512
513
  '>', 20,
513
514
  'CORPUS NON-VACUITY: the corpus really does contain `--` comments for the strip to remove');