@consiliency/agent-board-schema 1.74.0 → 1.75.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 (51) hide show
  1. package/fixtures/already-applied.json +4 -0
  2. package/migrations/20261108000100_agent_board_send_outcome.sql +708 -0
  3. package/package.json +1 -1
  4. package/schema-manifest.json +12 -3
  5. package/src/deployment-drift-main.test.mjs +20 -3
  6. package/src/deployment-drift-script.test.mjs +77 -2
  7. package/src/deployment-drift.test.mjs +60 -0
  8. package/src/tooling.test.mjs +3 -2
  9. package/tests/agent_board_667_history_class.test.sql +2 -0
  10. package/tests/agent_board_717_native_surface.test.sql +223 -0
  11. package/tests/agent_board_delegate_role_class.test.sql +2 -2
  12. package/tests/agent_board_delivery_writer_execute.test.sql +4 -2
  13. package/tests/agent_board_hosted_delegates.test.sql +8 -1
  14. package/tests/agent_board_send_outcome.test.sql +805 -0
  15. package/tests/agent_board_write_enforcement_class.test.sql +9 -5
  16. package/tests/catalog/function_execute_privileges.json +24 -0
  17. package/tests/catalog/p_metadata_parameters.json +8 -0
  18. package/tests/fixtures/isolation-substrate.sql +8 -0
  19. package/tests/fixtures/pgtap-unexposed.sql +61 -0
  20. package/tests/isolation/expected/send_outcome_cross_board.out +40 -0
  21. package/tests/isolation/expected/send_outcome_independence.out +295 -0
  22. package/tests/isolation/expected/send_outcome_membership.out +140 -0
  23. package/tests/isolation/expected/send_outcome_overlap.out +89 -0
  24. package/tests/isolation/expected/send_outcome_reader.out +87 -0
  25. package/tests/isolation/expected/send_outcome_recovery.out +107 -0
  26. package/tests/isolation/specs/send_outcome_cross_board.spec +66 -0
  27. package/tests/isolation/specs/send_outcome_independence.spec +95 -0
  28. package/tests/isolation/specs/send_outcome_membership.spec +73 -0
  29. package/tests/isolation/specs/send_outcome_overlap.spec +69 -0
  30. package/tests/isolation/specs/send_outcome_reader.spec +61 -0
  31. package/tests/isolation/specs/send_outcome_recovery.spec +68 -0
  32. package/tests/mutations/670/E1_helper_author_from_message.sql +7 -0
  33. package/tests/mutations/670/E2_helper_no_null_check.sql +13 -0
  34. package/tests/mutations/670/M10_lock_removed.sql +10 -0
  35. package/tests/mutations/670/M11_table_granted_to_authenticated.sql +2 -0
  36. package/tests/mutations/670/M12_helper_granted_to_service_role.sql +2 -0
  37. package/tests/mutations/670/M13_message_fk_no_cascade.sql +8 -0
  38. package/tests/mutations/670/M14_post_message_mints_from_metadata.sql +11 -0
  39. package/tests/mutations/670/M15_second_receipt_writer.sql +9 -0
  40. package/tests/mutations/670/M16_read_no_btrim.sql +7 -0
  41. package/tests/mutations/670/M17_read_volatile.sql +2 -0
  42. package/tests/mutations/670/M1_helper_no_service_role_guard.sql +13 -0
  43. package/tests/mutations/670/M3_helper_on_replay_branch.sql +10 -0
  44. package/tests/mutations/670/M4_read_checks_thread_existence.sql +10 -0
  45. package/tests/mutations/670/M5a_read_requires_thread_access.sql +10 -0
  46. package/tests/mutations/670/M5b_read_requires_board_membership.sql +11 -0
  47. package/tests/mutations/670/M6_read_admits_service_role.sql +14 -0
  48. package/tests/mutations/670/M7_confirmed_adds_message_sequence.sql +12 -0
  49. package/tests/mutations/670/M8_delivery_swallows_errors.sql +19 -0
  50. package/tests/mutations/670/M9_lock_key_includes_board.sql +10 -0
  51. package/tests/mutations/670/run.sh +84 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@consiliency/agent-board-schema",
3
- "version": "1.74.0",
3
+ "version": "1.75.0",
4
4
  "description": "Canonical, immutable, exact-pinnable agent_board schema bundle: ordered SQL migrations, digest + compatibility manifest, and deterministic materialize/plan/check tooling for adopters.",
5
5
  "repository": "https://github.com/Consiliency/message-board.git",
6
6
  "type": "module",
@@ -2,7 +2,7 @@
2
2
  "schema": "agent_board_schema_manifest.v1",
3
3
  "interface": "IF-0-MBPLANE-BUNDLE-1",
4
4
  "package": "@consiliency/agent-board-schema",
5
- "packageVersion": "1.74.0",
5
+ "packageVersion": "1.75.0",
6
6
  "schemaVersion": 8,
7
7
  "minClientVersion": "1.1.0",
8
8
  "source": {
@@ -46,8 +46,8 @@
46
46
  "usage": "upsert (retention/monitoring defaults; on conflict do nothing)"
47
47
  }
48
48
  ],
49
- "migrationCount": 172,
50
- "aggregateSha256": "1787dd0d972779bbdc1645b67460fc2f2c7b910f128414cf39b6dfb2b00b3b42",
49
+ "migrationCount": 173,
50
+ "aggregateSha256": "2662d0eb9f18cf195aa15014cdff9084faf6b5a3eb244a48548e4196a441b2e7",
51
51
  "migrations": [
52
52
  {
53
53
  "order": 0,
@@ -1596,6 +1596,15 @@
1596
1596
  "sourceRef": "message-board",
1597
1597
  "bytes": 15050,
1598
1598
  "sha256": "dbfd60300e8ce8ed78df8ae851f3990f58bcb43a7f9d53c2e25499a22e775a67"
1599
+ },
1600
+ {
1601
+ "order": 172,
1602
+ "id": "20261108000100_agent_board_send_outcome",
1603
+ "filename": "20261108000100_agent_board_send_outcome.sql",
1604
+ "origin": "message-board-forward",
1605
+ "sourceRef": "message-board",
1606
+ "bytes": 31049,
1607
+ "sha256": "f3e14b1bf7e8aa9f4a89a8ae0723dd63f21383477d321070d0736ff1e6912e8a"
1599
1608
  }
1600
1609
  ],
1601
1610
  "excludedBridge": {
@@ -3,7 +3,7 @@ import { afterEach, describe, expect, it } from "vitest";
3
3
  import { spawnSync } from "node:child_process";
4
4
  import { chmodSync, copyFileSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
5
5
  import { tmpdir } from "node:os";
6
- import { join } from "node:path";
6
+ import { dirname, join, posix } from "node:path";
7
7
  import { fileURLToPath, pathToFileURL } from "node:url";
8
8
 
9
9
  const ROOT = fileURLToPath(new URL("../../../", import.meta.url));
@@ -16,9 +16,26 @@ function git(cwd, args, env = {}) {
16
16
  if (r.status !== 0) throw new Error(`fixture git failed: ${r.stderr}`);
17
17
  return r.stdout.trim();
18
18
  }
19
+ // The checker plus its RELATIVE-IMPORT CLOSURE, derived from the sources rather than listed: a
20
+ // hand list of two files broke the day the checker imported release-dist-tag.mjs (#796), and
21
+ // it would break silently-in-a-different-way the next time. Bare and node: imports are builtins
22
+ // here (the checker's job never installs).
23
+ function importClosure(entry) {
24
+ const seen = new Set();
25
+ const visit = (rel) => {
26
+ if (seen.has(rel)) return;
27
+ seen.add(rel);
28
+ const src = readFileSync(join(ROOT, "scripts", rel), "utf8");
29
+ for (const m of src.matchAll(/^\s*import\s[^;]*?from\s+"(\.{1,2}\/[^"]+)";/gms)) {
30
+ visit(posix.normalize(posix.join(posix.dirname(rel), m[1])));
31
+ }
32
+ };
33
+ visit(entry);
34
+ return [...seen];
35
+ }
19
36
  function installChecker(dir) {
20
- mkdirSync(join(dir, "scripts/lib"), { recursive: true });
21
- for (const file of ["check-deployment-drift.mjs", "lib/drift-evaluate.mjs"]) {
37
+ for (const file of importClosure("check-deployment-drift.mjs")) {
38
+ mkdirSync(dirname(join(dir, "scripts", file)), { recursive: true });
22
39
  copyFileSync(join(ROOT, "scripts", file), join(dir, "scripts", file));
23
40
  }
24
41
  }
@@ -76,11 +76,14 @@ beforeAll(() => {
76
76
 
77
77
  writeFileSync(
78
78
  join(SHIMS, "npm"),
79
- `#!/bin/sh\n${logArgv}\n[ -n "\${FAKE_NPM_VERSION:-}" ] || exit 1\nprintf "%s\\n" "$FAKE_NPM_VERSION"\n`,
79
+ // `npm view <pkg> dist-tags --json` and `npm view <pkg> time --json` (message-board#796)
80
+ // answer FAKE_NPM_DIST_TAGS / FAKE_NPM_TIME, or fail; every other call answers
81
+ // FAKE_NPM_VERSION as before.
82
+ `#!/bin/sh\n${logArgv}\ncase " $* " in\n *" dist-tags "*) [ -n "\${FAKE_NPM_DIST_TAGS:-}" ] || exit 1; printf "%s\\n" "$FAKE_NPM_DIST_TAGS"; exit 0 ;;\n *" time "*) [ -n "\${FAKE_NPM_TIME:-}" ] || exit 1; printf "%s\\n" "$FAKE_NPM_TIME"; exit 0 ;;\nesac\n[ -n "\${FAKE_NPM_VERSION:-}" ] || exit 1\nprintf "%s\\n" "$FAKE_NPM_VERSION"\n`,
80
83
  );
81
84
  writeFileSync(
82
85
  join(SHIMS, "git"),
83
- `#!/bin/sh\n${logArgv}\ncase " $* " in\n *" --is-shallow-repository "*) printf "%s\n" "\${FAKE_SHALLOW:-false}" ;;\n *" cat-file "*) exit 0 ;;\n *" show "*"/package.json "*) cat "$DRIFT_SHIMS/package.json" ;;\n *" show "*"/schema-manifest.json "*) cat "$DRIFT_SHIMS/manifest.json" ;;\n *" log "*) [ -n "\${FAKE_BUMP_ISO:-}" ] || exit 1; printf "%s\n" "$FAKE_BUMP_ISO" ;;\n *) exit 1 ;;\nesac\n`,
86
+ `#!/bin/sh\n${logArgv}\ncase " $* " in\n *" --is-shallow-repository "*) printf "%s\n" "\${FAKE_SHALLOW:-false}" ;;\n *" cat-file "*) exit 0 ;;\n *" show "*"/package.json "*) cat "$DRIFT_SHIMS/package.json" ;;\n *" show "*"/schema-manifest.json "*) cat "$DRIFT_SHIMS/manifest.json" ;;\n *" show "*":release-dist-tags.json "*) [ -n "\${FAKE_RELEASE_DIST_TAGS:-}" ] || exit 1; printf "%s\n" "$FAKE_RELEASE_DIST_TAGS" ;;\n *" show "*":CHANGELOG.md "*) [ -n "\${FAKE_CHANGELOG:-}" ] || exit 1; printf "%s\n" "$FAKE_CHANGELOG" ;;\n *" log "*) [ -n "\${FAKE_BUMP_ISO:-}" ] || exit 1; printf "%s\n" "$FAKE_BUMP_ISO" ;;\n *) exit 1 ;;\nesac\n`,
84
87
  );
85
88
  chmodSync(join(SHIMS, "npm"), 0o755);
86
89
  chmodSync(join(SHIMS, "git"), 0o755);
@@ -435,3 +438,75 @@ describe("the script under test is the one that ships", () => {
435
438
  );
436
439
  });
437
440
  });
441
+
442
+ // message-board#796, end to end through the shipped script: main's committed
443
+ // release-dist-tags.json and CHANGELOG.md (served by the git shim at the authoritative commit)
444
+ // declare the channel and pass the canonical validator, the registry (npm shim) names merged on
445
+ // it and says when it got there, and the stale gap that `latest` alone reports stops being DRIFT
446
+ // — for --max-days. Every other combination keeps the strict answer.
447
+ describe("dist-tag-aware published leg, through the script (#796)", () => {
448
+ const DAY = 86_400_000;
449
+ const STALE_BUMP = new Date(Date.now() - 15 * DAY).toISOString();
450
+ const DECLARES_NEXT = JSON.stringify({ releases: { "v9.9.9": { distTag: "next", reason: "held back on a canary for this fixture" } } });
451
+ const CHANGELOG_NEXT = "# Changelog\n\n## v9.9.9 — fixture\n\nnpm dist-tag: `next`\n";
452
+ const timeOnRegistry = (msAgo) => JSON.stringify({ created: "2020-01-01T00:00:00.000Z", [MERGED]: new Date(Date.now() - msAgo).toISOString() });
453
+ const held = (env = {}) =>
454
+ runScript([], {
455
+ FAKE_NPM_VERSION: minorsBelow(MERGED, 1),
456
+ FAKE_BUMP_ISO: STALE_BUMP,
457
+ FAKE_RELEASE_DIST_TAGS: DECLARES_NEXT,
458
+ FAKE_CHANGELOG: CHANGELOG_NEXT,
459
+ FAKE_NPM_DIST_TAGS: JSON.stringify({ latest: minorsBelow(MERGED, 1), next: MERGED }),
460
+ FAKE_NPM_TIME: timeOnRegistry(2 * DAY),
461
+ ...env,
462
+ });
463
+
464
+ it("#796-ok: exits 0 when merged has been on a declared channel for 2 days, though latest is behind and the bump stale", () => {
465
+ writeFileSync(ARGV_LOG, ""); // this case's calls only
466
+ const r = held();
467
+ expect(r.status).toBe(0);
468
+ expect(r.out).toMatch(/published under the declared dist-tag `next`/);
469
+ // The dist-tags and publish times were read for the package, and only because a channel was declared.
470
+ const log = readFileSync(ARGV_LOG, "utf8");
471
+ expect(log).toMatch(/\nview\n@consiliency\/agent-board-schema\ndist-tags\n--json\n/);
472
+ expect(log).toMatch(/\nview\n@consiliency\/agent-board-schema\ntime\n--json\n/);
473
+ });
474
+
475
+ it("#796-bound: exits 1 when merged has sat on the channel for 15 days without reaching latest", () => {
476
+ const r = held({ FAKE_NPM_TIME: timeOnRegistry(15 * DAY) });
477
+ expect(r.status).toBe(1);
478
+ expect(r.out).toMatch(/held on the declared dist-tag `next` for 15d/);
479
+ });
480
+
481
+ it("#796-strict: exits 1 when the channel version's publish time cannot be read", () => {
482
+ expect(held({ FAKE_NPM_TIME: "" }).status).toBe(1);
483
+ });
484
+
485
+ it("#796-strict: exits 1 when main's release-dist-tags.json declares no channel", () => {
486
+ expect(held({ FAKE_RELEASE_DIST_TAGS: JSON.stringify({ releases: {} }) }).status).toBe(1);
487
+ });
488
+
489
+ it("#796-strict: exits 1 when the file cannot be read at main", () => {
490
+ expect(held({ FAKE_RELEASE_DIST_TAGS: "" }).status).toBe(1);
491
+ });
492
+
493
+ it("#796-validate: exits 1 when main's release-dist-tags.json is malformed (an entry with no reason)", () => {
494
+ expect(held({ FAKE_RELEASE_DIST_TAGS: JSON.stringify({ releases: { "v9.9.9": { distTag: "next" } } }) }).status).toBe(1);
495
+ });
496
+
497
+ it("#796-validate: exits 1 when the entry's CHANGELOG section lacks its `npm dist-tag:` line", () => {
498
+ expect(held({ FAKE_CHANGELOG: "# Changelog\n\n## v9.9.9 — fixture\n\nno declaration here\n" }).status).toBe(1);
499
+ });
500
+
501
+ it("#796-strict: exits 1 when the declared channel names a different version", () => {
502
+ expect(held({ FAKE_NPM_DIST_TAGS: JSON.stringify({ latest: minorsBelow(MERGED, 1), next: minorsBelow(MERGED, 2) }) }).status).toBe(1);
503
+ });
504
+
505
+ it("#796-strict: exits 1 when the registry's dist-tags cannot be read", () => {
506
+ expect(held({ FAKE_NPM_DIST_TAGS: "" }).status).toBe(1);
507
+ });
508
+
509
+ it("#796-strict: exits 1 when merged sits on an UNDECLARED tag", () => {
510
+ expect(held({ FAKE_NPM_DIST_TAGS: JSON.stringify({ latest: minorsBelow(MERGED, 1), beta: MERGED }) }).status).toBe(1);
511
+ });
512
+ });
@@ -299,3 +299,63 @@ describe("branches a mutation must not survive", () => {
299
299
  expect(r.findings.some((f) => f.level === OK && /is 1 schema version\(s\) behind main/.test(f.msg))).toBe(true);
300
300
  });
301
301
  });
302
+
303
+ // message-board#796. A release held back on a dist-tag that main's release-dist-tags.json
304
+ // declares (v1.68.0 under `next`) has PUBLISHED main's schema version; `latest` alone said it
305
+ // had not, and the 7-day clock would have turned every PR red. The grace is BOUNDED: it lasts
306
+ // --max-days from the channel version's REGISTRY publish time, and the version-count limit still
307
+ // applies. A forgotten `next` must not keep this required check green forever (review seat, #798).
308
+ describe("dist-tag-aware published leg (#796)", () => {
309
+ const STALE = "2026-08-01T17:00:00Z"; // main's bump: 15 days before NOW, past --max-days
310
+ const daysAgo = (d) => new Date(NOW - d * 86_400_000).toISOString();
311
+ const onNext = (version, publishedIso) => ({ next: { version, publishedIso } });
312
+ const held = (over = {}) => base({ merged: "1.36.0", published: "1.35.0", bumpIso: STALE, ...over });
313
+
314
+ it("#796-ok: merged on a declared channel for 2 days is OK, though latest is behind and main's bump is stale", () => {
315
+ const r = run(held({ channels: onNext("1.36.0", daysAgo(2)) }));
316
+ expect(r.status).toBe(OK);
317
+ expect(r.findings.some((f) => f.level === OK && /published under the declared dist-tag `next` \(latest is 1\.35\.0\), 2d on the channel/.test(f.msg))).toBe(true);
318
+ });
319
+
320
+ it("#796-bound: merged held on the channel for 15 days (> --max-days) is DRIFT — a forgotten `next` does not stay green", () => {
321
+ const r = run(held({ channels: onNext("1.36.0", daysAgo(15)) }));
322
+ expect(r.status).toBe(DRIFT);
323
+ expect(r.findings.some((f) => f.level === DRIFT && /held on the declared dist-tag `next` for 15d \(> 7d\) without reaching latest/.test(f.msg))).toBe(true);
324
+ });
325
+
326
+ it("#796-bound: the expiry does not depend on main's bump date — a stale channel with a FRESH bump is still DRIFT", () => {
327
+ expect(run(held({ bumpIso: daysAgo(1), channels: onNext("1.36.0", daysAgo(15)) })).status).toBe(DRIFT);
328
+ });
329
+
330
+ it("#796-bound: the boundary is exactly --max-days (7d OK, 8d DRIFT)", () => {
331
+ expect(run(held({ channels: onNext("1.36.0", daysAgo(7)) })).status).toBe(OK);
332
+ expect(run(held({ channels: onNext("1.36.0", daysAgo(8)) })).status).toBe(DRIFT);
333
+ });
334
+
335
+ it("#796-count: the version-count limit still applies on a fresh channel", () => {
336
+ expect(run(held({ merged: "1.40.0", channels: onNext("1.40.0", daysAgo(1)) })).status).toBe(DRIFT);
337
+ });
338
+
339
+ it("#796-strict: an unknown channel publish time grants no grace", () => {
340
+ expect(run(held({ channels: onNext("1.36.0", null) })).status).toBe(DRIFT);
341
+ expect(run(held({ channels: onNext("1.36.0", "not-a-date") })).status).toBe(DRIFT);
342
+ });
343
+
344
+ it("#796-strict: a channel naming an OLDER version than merged is still DRIFT (main moved past the held release)", () => {
345
+ expect(run(held({ channels: onNext("1.35.5", daysAgo(1)) })).status).toBe(DRIFT);
346
+ });
347
+
348
+ it("#796-strict: no declared channel (none passed, or the registry unread) is still DRIFT", () => {
349
+ expect(run(held({ channels: {} })).status).toBe(DRIFT);
350
+ expect(run(held({ channels: null })).status).toBe(DRIFT);
351
+ });
352
+
353
+ it("#796-strict: `latest` passed as a channel is never a channel", () => {
354
+ expect(run(held({ channels: { latest: { version: "1.36.0", publishedIso: daysAgo(1) } } })).status).toBe(DRIFT);
355
+ });
356
+
357
+ it("#796-strict: an unreadable latest stays UNKNOWN, and a registry ahead stays DRIFT, whatever the channel says", () => {
358
+ expect(run(held({ published: null, channels: onNext("1.36.0", daysAgo(1)) })).status).toBe(UNKNOWN);
359
+ expect(run(held({ merged: "1.34.0", published: "1.35.0", channels: onNext("1.34.0", daysAgo(1)) })).status).toBe(DRIFT);
360
+ });
361
+ });
@@ -41,9 +41,9 @@ describe('manifest integrity', () => {
41
41
  expect(manifest.schemaVersion).toBe(8);
42
42
  expect(manifest.minClientVersion).toMatch(/^\d+\.\d+\.\d+$/);
43
43
  });
44
- it('registers the four MBAUTHZ + four MBSENDAUTHZ + four MBSESSION + four MBDELEG + three MBFED + three MBHARDEN + two MBPORTALGATE + two MBPORTAL-PR32 + two ROOMOWN + two ROOMLINK + one ROOMDELEG + one LOCALAUTH + one ROOMUIAPI + one FEDSESSION + one FEDSESSION-AUTOJOIN + one GATENULL + one MEMBSTATE + one AGENTSDIR + one LEAVEIDEM + one ROLERESET + one MBROWID + one MBHYGIENE + one MBCONSENT-A + one MBCONSENT-B(a) + one MBCONSENT-B(i) + one MBCONSENT-B(ii) + one MBCONSENT-B(iii) + one MBHARDEN-#97 + one MBHARDEN-#118 + one INVITEPOLICY + one OBSGATE + one OBSGATE-2 + one OBSGATE-3 + one OBSGATE-4 + one FLEETMACHINERLS + one RESOLVENOOP + one ROOMDELEG-LANEB + one CLAIMKEY + two MINTHARDEN + one FLEETMACHINEHIJACK + one CLAIMGATE-SHADOW + one CLAIMGATE-ENFORCE + one FLEETMACHINEREACTIVATION + one DELEGCAPCEILING + one FLEETMACHINERECLAIM + one DELEGSOLEWRITER + one FLEETDOMAINRECLAIM + five ATOMICFLEETONBOARDING (onboarding + ceiling-lock + revocation-evidence + fedsession-gate + fedsession-lock-order) + one OUTBOXWAKE + one ENROLLLOCKORDER + one FEDPROVIDERABSENCE + one WAKERECOVERY + one CONSENTRECONCILE + one ENROLLRESUMPTION + one SIGNEDAUTHORITY + one SIGNERLIFECYCLE + one LEDGERAUTHORITY + one CEILINGLOCKCOMMENT + one LEDGERBOARDCREATE + one RECEIPTSUBJECTGATE + one TASKTHREADLOCKORDER + one CLAIMSUBJECTGATE + one FEDSESSIONIDENTITYGATE + one FEDIDENTITYSLUG + one INVITENODOWNGRADE + one SIGNEDWRITEFLAG + one SIGNEDWRITEMODEL + one RTCREDCLAIM + one ORIGINPOSTURE + one BOARDCLAIMPOLICY + one HEARTBEATPRESERVE + one LIVENESSDENOM + one OWNERLESSRENEWTTL + one OWNERLESSQUOTACENSUS + one FLEETDOMAINNODOWNGRADE + one OWNERLESSQUOTACONVERGE + one ADVISORYREVERTRESET + one CLAIMPOLICYRACE + one CLAIMPOLICYLOCKGRANT + one SESSIONCHALLENGESUPERSEDE + one ROOMCONTRACT + one CALLBACKCONSUMER + one ENROLLTOKENSINGLEUSE + one ROOMCONTRACT-ACTIVEFIRST + one ONBOARD + one HOSTED + one HOSTED-FOLLOWUPS + one OWNPOST + one SIDSCHEMA + one SIDOWNER + one GRANTTARGETROLE (#674) + one LASTOWNER (Consiliency/message-board#675) + one SESSIONPROVENANCE (Consiliency/message-board#665) + one REQUESTREMOVED (Consiliency/message-board#680) + one RLSCORRELATION (Consiliency/message-board#589) + one RESOLUTIONAUTHORITY (Consiliency/message-board#668) + one THREADASSOCIATION checkpoint (#667) + one SIDSERVER-MEASUREDMINT (Consiliency/message-board#653) + one REPLYDELIVERY (#661) + one DELIVERYWRITEREXEC (#717 F1) + one REPLAYSCOPE (#717 F2) + one MESSAGEREPLAYSCOPE (#717 F2b) forward migrations (migrationCount = prior 113 + 5 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 = 172)', () => {
44
+ it('registers the four MBAUTHZ + four MBSENDAUTHZ + four MBSESSION + four MBDELEG + three MBFED + three MBHARDEN + two MBPORTALGATE + two MBPORTAL-PR32 + two ROOMOWN + two ROOMLINK + one ROOMDELEG + one LOCALAUTH + one ROOMUIAPI + one FEDSESSION + one FEDSESSION-AUTOJOIN + one GATENULL + one MEMBSTATE + one AGENTSDIR + one LEAVEIDEM + one ROLERESET + one MBROWID + one MBHYGIENE + one MBCONSENT-A + one MBCONSENT-B(a) + one MBCONSENT-B(i) + one MBCONSENT-B(ii) + one MBCONSENT-B(iii) + one MBHARDEN-#97 + one MBHARDEN-#118 + one INVITEPOLICY + one OBSGATE + one OBSGATE-2 + one OBSGATE-3 + one OBSGATE-4 + one FLEETMACHINERLS + one RESOLVENOOP + one ROOMDELEG-LANEB + one CLAIMKEY + two MINTHARDEN + one FLEETMACHINEHIJACK + one CLAIMGATE-SHADOW + one CLAIMGATE-ENFORCE + one FLEETMACHINEREACTIVATION + one DELEGCAPCEILING + one FLEETMACHINERECLAIM + one DELEGSOLEWRITER + one FLEETDOMAINRECLAIM + five ATOMICFLEETONBOARDING (onboarding + ceiling-lock + revocation-evidence + fedsession-gate + fedsession-lock-order) + one OUTBOXWAKE + one ENROLLLOCKORDER + one FEDPROVIDERABSENCE + one WAKERECOVERY + one CONSENTRECONCILE + one ENROLLRESUMPTION + one SIGNEDAUTHORITY + one SIGNERLIFECYCLE + one LEDGERAUTHORITY + one CEILINGLOCKCOMMENT + one LEDGERBOARDCREATE + one RECEIPTSUBJECTGATE + one TASKTHREADLOCKORDER + one CLAIMSUBJECTGATE + one FEDSESSIONIDENTITYGATE + one FEDIDENTITYSLUG + one INVITENODOWNGRADE + one SIGNEDWRITEFLAG + one SIGNEDWRITEMODEL + one RTCREDCLAIM + one ORIGINPOSTURE + one BOARDCLAIMPOLICY + one HEARTBEATPRESERVE + one LIVENESSDENOM + one OWNERLESSRENEWTTL + one OWNERLESSQUOTACENSUS + one FLEETDOMAINNODOWNGRADE + one OWNERLESSQUOTACONVERGE + one ADVISORYREVERTRESET + one CLAIMPOLICYRACE + one CLAIMPOLICYLOCKGRANT + one SESSIONCHALLENGESUPERSEDE + one ROOMCONTRACT + one CALLBACKCONSUMER + one ENROLLTOKENSINGLEUSE + one ROOMCONTRACT-ACTIVEFIRST + one ONBOARD + one HOSTED + one HOSTED-FOLLOWUPS + one OWNPOST + one SIDSCHEMA + one SIDOWNER + one GRANTTARGETROLE (#674) + one LASTOWNER (Consiliency/message-board#675) + one SESSIONPROVENANCE (Consiliency/message-board#665) + one REQUESTREMOVED (Consiliency/message-board#680) + one RLSCORRELATION (Consiliency/message-board#589) + one RESOLUTIONAUTHORITY (Consiliency/message-board#668) + one THREADASSOCIATION checkpoint (#667) + one SIDSERVER-MEASUREDMINT (Consiliency/message-board#653) + one REPLYDELIVERY (#661) + one DELIVERYWRITEREXEC (#717 F1) + one REPLAYSCOPE (#717 F2) + one MESSAGEREPLAYSCOPE (#717 F2b) + one SENDOUTCOME (#670) forward migrations (migrationCount = prior 113 + 5 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 = 173)', () => {
45
45
  expect(manifest.migrationCount).toBe(manifest.migrations.length);
46
- expect(manifest.migrationCount).toBe(172);
46
+ expect(manifest.migrationCount).toBe(173);
47
47
  // MBSESSION switched enforcement on (scoped-send re-grant): the client-visible
48
48
  // schema version bumped to 8. MBDELEG tightens delegation and MBFED adds only
49
49
  // enrollment-only additive surface (identity_providers registry, enrollment audit,
@@ -374,6 +374,7 @@ describe('manifest integrity', () => {
374
374
  '20261104170000_agent_board_tasking_replay_scope.sql',
375
375
  '20261104180000_agent_board_delivery_writer_execute.sql',
376
376
  '20261104190000_agent_board_message_replay_scope.sql',
377
+ '20261108000100_agent_board_send_outcome.sql',
377
378
  ]) {
378
379
  expect(names.has(f)).toBe(true);
379
380
  }
@@ -115,6 +115,7 @@ insert into xb_onehop_reviewed values
115
115
  ('agent_board.inbox_items'::regclass,'agent_board.messages'::regclass,'inbox_items_source_message_id_fkey'),
116
116
  ('agent_board.inbox_items'::regclass,'agent_board.tasks'::regclass,'inbox_items_source_task_id_fkey'),
117
117
  ('agent_board.messages'::regclass,'agent_board.tasks'::regclass,'messages_task_id_fkey'),
118
+ ('agent_board.send_outcomes'::regclass,'agent_board.messages'::regclass,'send_outcomes_message_id_fkey'),
118
119
  ('agent_board.signature_evidence'::regclass,'agent_board.artifacts'::regclass,'signature_evidence_source_artifact_id_fkey'),
119
120
  ('agent_board.signature_evidence'::regclass,'agent_board.messages'::regclass,'signature_evidence_source_message_id_fkey'),
120
121
  ('agent_board.signature_evidence'::regclass,'agent_board.task_events'::regclass,'signature_evidence_source_task_event_id_fkey'),
@@ -532,6 +533,7 @@ create temp table xb_onehop_insert_reviewed(fn oid,relid oid,anchors text[],prim
532
533
  insert into xb_onehop_insert_reviewed values
533
534
  ('agent_board._queue_board_post_callbacks(uuid,uuid,text,text,text,jsonb)'::regprocedure,'agent_board.callback_outbox_events'::regclass,array['source_message_id']),
534
535
  ('agent_board._queue_inbox_callbacks(uuid,text)'::regprocedure,'agent_board.callback_outbox_events'::regclass,array['source_message_id','source_task_id']),
536
+ ('agent_board._record_send_outcome(text,uuid,text,uuid)'::regprocedure,'agent_board.send_outcomes'::regclass,array['message_id']),
535
537
  ('agent_board._record_signed_write_evidence(text,uuid,text,jsonb,jsonb)'::regprocedure,'agent_board.signature_evidence'::regclass,array['source_message_id','source_task_event_id']),
536
538
  ('agent_board._upsert_delivery_recipient(text,uuid,text,uuid,uuid,uuid,uuid,uuid,jsonb)'::regprocedure,'agent_board.delivery_recipients'::regclass,array['source_message_id','source_task_id']),
537
539
  ('agent_board._upsert_inbox_item(uuid,uuid,uuid,text,text,uuid,uuid,uuid,text,text,text,boolean,boolean,jsonb,jsonb)'::regprocedure,'agent_board.inbox_items'::regclass,array['source_message_id','source_task_id']),
@@ -0,0 +1,223 @@
1
+ -- #717 native-platform surface: #708 apply_rls reachability, #711 positive extension
2
+ -- SECURITY DEFINER census, #715 indirect SQL-execution sites. Every set below is derived
3
+ -- from pg_catalog; each exemption states a claim that is checked positively, so a new site
4
+ -- fails and names itself. Evidence and mutation receipts: plans/evidence/717-native/.
5
+ --
6
+ -- "Exposed" means served by PostgREST: supabase/config.toml plus the schema CI adds
7
+ -- (.github/workflows/ci.yml: public, graphql_public, agent_board). PostgREST's schema list
8
+ -- is server config, not catalog state, so it is the one input here that is not derived.
9
+ create extension if not exists pgtap with schema extensions;set search_path=extensions,public,agent_board;begin;
10
+ select to_regprocedure('realtime.apply_rls(jsonb,integer)') is not null
11
+ and to_regrole('authenticator') is not null as native_present \gset
12
+ \if :native_present
13
+ select plan(25);
14
+
15
+ create temp table ns_api_role on commit drop as
16
+ select r.oid, r.rolname from pg_roles r
17
+ where pg_has_role('authenticator', r.oid, 'SET') and r.rolname <> 'authenticator';
18
+ create temp table ns_exposed(nspname text primary key) on commit drop;
19
+ insert into ns_exposed values ('public'), ('graphql_public'), ('agent_board');
20
+
21
+ -- Every installed non-system routine, read through the suite's stripped producer.
22
+ -- body_lit keeps string literals, so a name inside dynamic-SQL text still counts as a call
23
+ -- (the fail-closed direction for a closure); is_exec reads the literal-free body.
24
+ create temp table ns_routine on commit drop as
25
+ select p.oid, n.nspname, p.proname, l.lanname, p.prosecdef, p.prorettype,
26
+ agent_board_test.stripped_body(p.oid, true) as body_lit,
27
+ regexp_split_to_array(lower(agent_board_test.stripped_body(p.oid, true)), '[^a-z0-9_$]+') as tokens,
28
+ (l.lanname = 'plpgsql' and agent_board_test.stripped_body(p.oid) ~ agent_board_test.re('\m' || agent_board_test.ci_re('execute') || '\M')) as is_exec,
29
+ (select e.extname from pg_depend d join pg_extension e on e.oid = d.refobjid
30
+ where d.classid = 'pg_proc'::regclass and d.objid = p.oid and d.deptype = 'e') ext
31
+ from pg_proc p join pg_namespace n on n.oid = p.pronamespace join pg_language l on l.oid = p.prolang
32
+ where n.nspname not in ('pg_catalog', 'information_schema') and n.nspname !~ '^pg_(toast|temp)';
33
+
34
+ -- ===================================================================== #708
35
+ -- The API caller set is what PostgREST's login role can switch to.
36
+ select is((select array_agg(rolname::text order by rolname) from ns_api_role),
37
+ array['agent_board_delegate','anon','authenticated','service_role'],
38
+ 'NS708 the PostgREST role-switch set is derived from authenticator SET membership');
39
+
40
+ -- apply_rls closure: routines whose body calls apply_rls or a routine already in it.
41
+ create temp table ns_ar_closure on commit drop as
42
+ with recursive c(oid) as (
43
+ select 'realtime.apply_rls(jsonb,integer)'::regprocedure::oid
44
+ union
45
+ select q.oid from c join ns_routine as callee on callee.oid = c.oid
46
+ cross join lateral (select agent_board_test.call_re(callee.nspname || '.' || callee.proname, true) as pat) as m
47
+ join ns_routine q on q.oid <> c.oid and lower(callee.proname) = any (q.tokens) and q.body_lit ~ m.pat)
48
+ select oid from c;
49
+ select ok((select count(*) >= 2 from ns_ar_closure),
50
+ 'NS708 the closure walk reaches apply_rls callers (discriminance)');
51
+ select is((select array_agg(p.oid::regprocedure::text order by p.oid::regprocedure::text) from ns_ar_closure c join pg_proc p on p.oid = c.oid
52
+ where p.pronamespace <> 'realtime'::regnamespace), null,
53
+ 'NS708 no routine outside realtime reaches apply_rls');
54
+ select is((select array_agg(p.oid::regprocedure::text order by p.oid::regprocedure::text) from ns_ar_closure c join pg_proc p on p.oid = c.oid
55
+ join pg_namespace n on n.oid = p.pronamespace join ns_exposed e on e.nspname = n.nspname), null,
56
+ 'NS708 no apply_rls closure member lives in a PostgREST-exposed schema');
57
+ select is((select array_agg(t.tgrelid::regclass::text || ':' || t.tgname order by t.tgrelid::regclass::text || ':' || t.tgname) from pg_trigger t
58
+ join ns_ar_closure c on c.oid = t.tgfoid
59
+ where not t.tgisinternal and (select relnamespace from pg_class where oid = t.tgrelid) <> 'realtime'::regnamespace), null,
60
+ 'NS708 no trigger outside realtime fires an apply_rls closure member');
61
+ -- PostgREST runs every request with session_user = authenticator. apply_rls resets the role
62
+ -- to the session default first, so without realtime USAGE there it cannot run at all.
63
+ select ok(not has_schema_privilege('authenticator', 'realtime', 'USAGE'),
64
+ 'NS708 the PostgREST session user has no realtime USAGE, so apply_rls fails closed there');
65
+ -- Any login that CAN complete apply_rls for an API-role subscriber absorbs that subscriber's
66
+ -- claims for the rest of its transaction. Claim checked: such a login already holds
67
+ -- authority over agent_board (superuser, or member of the schema owner).
68
+ select is((select array_agg(r.rolname::text order by r.rolname::text) from pg_roles r
69
+ where r.rolcanlogin
70
+ and has_schema_privilege(r.oid, 'realtime', 'USAGE')
71
+ and has_function_privilege(r.oid, 'realtime.apply_rls(jsonb,integer)', 'EXECUTE')
72
+ and exists (select 1 from ns_api_role a where pg_has_role(r.oid, a.oid, 'SET'))
73
+ and not r.rolsuper
74
+ and not pg_has_role(r.oid, (select nspowner from pg_namespace where nspname = 'agent_board'), 'USAGE')), null,
75
+ 'NS708 every login that can complete apply_rls for an API subscriber already owns agent_board authority');
76
+
77
+ -- Behaviour the boundary above protects, recorded not endorsed: same-transaction
78
+ -- continuation after apply_rls resolves the LAST SUBSCRIBER as the current agent.
79
+ insert into auth.users(id, instance_id, aud, role, email) values
80
+ ('71700000-0000-4000-8000-0000000000b1','00000000-0000-0000-0000-000000000000','authenticated','authenticated','ns708-victim@t.test'),
81
+ ('71700000-0000-4000-8000-0000000000b2','00000000-0000-0000-0000-000000000000','authenticated','authenticated','ns708-caller@t.test');
82
+ insert into agent_board.agents(id, agent_type, kind, handle, display_name, status, auth_user_id) values
83
+ ('71710000-0000-4000-8000-0000000000b1','agent','agent','ns708-victim','NS708 Victim','active','71700000-0000-4000-8000-0000000000b1'),
84
+ ('71710000-0000-4000-8000-0000000000b2','agent','agent','ns708-caller','NS708 Caller','active','71700000-0000-4000-8000-0000000000b2');
85
+ insert into realtime.subscription(subscription_id, entity, claims) values
86
+ ('71720000-0000-4000-8000-0000000000b1','agent_board.threads','{"role":"authenticated","sub":"71700000-0000-4000-8000-0000000000b1"}');
87
+ create temp table ns_ar_seen(phase text, agent uuid) on commit drop;
88
+ grant all on ns_ar_seen to authenticated;
89
+ -- The role switches run inside the executed block: pgTAP records results as current_user.
90
+ select lives_ok($c$do $d$ begin
91
+ perform set_config('role', 'authenticated', true);
92
+ perform set_config('request.jwt.claims', '{"role":"authenticated","sub":"71700000-0000-4000-8000-0000000000b2"}', true);
93
+ insert into ns_ar_seen values ('before', agent_board.current_agent_id());
94
+ perform count(*) from realtime.apply_rls('{"action":"I","schema":"agent_board","table":"threads","columns":[{"name":"id","type":"uuid","value":"71730000-0000-4000-8000-0000000000b1"}],"pk":[{"name":"id","type":"uuid"}]}'::jsonb);
95
+ perform set_config('role', 'authenticated', true);
96
+ insert into ns_ar_seen values ('after', agent_board.current_agent_id());
97
+ perform set_config('role', null, true);
98
+ perform set_config('request.jwt.claims', '', true);
99
+ end $d$$c$, 'NS708 apply_rls runs under a postgres-login session and returns');
100
+ select is((select array_agg(phase || '=' || agent::text order by phase desc) from ns_ar_seen),
101
+ array['before=71710000-0000-4000-8000-0000000000b2','after=71710000-0000-4000-8000-0000000000b1'],
102
+ 'NS708 leftover subscriber claims substitute the current agent for the rest of the transaction');
103
+
104
+ -- ===================================================================== #711
105
+ create temp table ns_ext_definer on commit drop as
106
+ select p.oid, e.extname, p.oid::regprocedure::text sig, p.proowner, p.proconfig, p.pronamespace
107
+ from pg_depend d join pg_extension e on e.oid = d.refobjid join pg_proc p on p.oid = d.objid
108
+ where d.classid = 'pg_proc'::regclass and d.refclassid = 'pg_extension'::regclass and d.deptype = 'e' and p.prosecdef;
109
+ select ok((select count(*) > 0 from pg_depend where deptype = 'e' and classid = 'pg_proc'::regclass),
110
+ 'NS711 the census sees extension member routines (discriminance)');
111
+ select is((select array_agg(extname || ':' || sig order by extname || ':' || sig) from ns_ext_definer),
112
+ array['supabase_vault:vault.create_secret(text,text,text,uuid)','supabase_vault:vault.update_secret(uuid,text,text,text,uuid)'],
113
+ 'NS711 the installed extension SECURITY DEFINER set is exactly the reviewed one');
114
+ select is((select array_agg(sig order by sig) from ns_ext_definer
115
+ where not exists (select 1 from unnest(coalesce(proconfig, '{}')) c where c ~ '^search_path=')), null,
116
+ 'NS711 every extension definer pins search_path');
117
+ select is((select array_agg(x.sig || '@' || a.rolname order by x.sig || '@' || a.rolname) from ns_ext_definer x cross join ns_api_role a
118
+ where a.rolname <> 'service_role'
119
+ and has_schema_privilege(a.oid, x.pronamespace, 'USAGE') and has_function_privilege(a.oid, x.oid, 'EXECUTE')), null,
120
+ 'NS711 no extension definer is callable by a non-service API role');
121
+ select is((select array_agg(pg_describe_object(d.classid, d.objid, d.objsubid) order by pg_describe_object(d.classid, d.objid, d.objsubid)) from pg_depend d
122
+ where d.deptype = 'e' and d.refclassid = 'pg_extension'::regclass and (
123
+ (d.classid = 'pg_proc'::regclass and (select pronamespace from pg_proc where oid = d.objid) = 'agent_board'::regnamespace) or
124
+ (d.classid = 'pg_class'::regclass and (select relnamespace from pg_class where oid = d.objid) = 'agent_board'::regnamespace) or
125
+ (d.classid = 'pg_type'::regclass and (select typnamespace from pg_type where oid = d.objid) = 'agent_board'::regnamespace))), null,
126
+ 'NS711 no extension member lives in agent_board');
127
+ select is((select array_agg(r.oid::regprocedure::text order by r.oid::regprocedure::text) from ns_routine r join pg_proc p on p.oid = r.oid
128
+ where r.ext is not null
129
+ and (r.body_lit ~ agent_board_test.re(agent_board_test.lead_guard() || agent_board_test.ident_re('agent_board') || '\s*\.')
130
+ or exists (select 1 from unnest(coalesce(p.proconfig, '{}')) as setting(v)
131
+ where starts_with(setting.v, 'search_path=') and 'agent_board' = any (string_to_array(replace(replace(substr(setting.v, 13), '"', ''), ' ', ''), ','))))), null,
132
+ 'NS711 no extension member routine references agent_board');
133
+ select is((select array_agg(distinct e.extname::text order by e.extname::text) from pg_depend x
134
+ join pg_depend m on m.classid = x.refclassid and m.objid = x.refobjid and m.deptype = 'e'
135
+ join pg_extension e on e.oid = m.refobjid
136
+ where x.deptype in ('n', 'a') and (
137
+ (x.classid = 'pg_proc'::regclass and (select pronamespace from pg_proc where oid = x.objid) = 'agent_board'::regnamespace) or
138
+ (x.classid = 'pg_class'::regclass and (select relnamespace from pg_class where oid = x.objid) = 'agent_board'::regnamespace) or
139
+ (x.classid = 'pg_attrdef'::regclass and (select c.relnamespace from pg_attrdef a join pg_class c on c.oid = a.adrelid where a.oid = x.objid) = 'agent_board'::regnamespace) or
140
+ (x.classid = 'pg_constraint'::regclass and (select connamespace from pg_constraint where oid = x.objid) = 'agent_board'::regnamespace) or
141
+ (x.classid = 'pg_rewrite'::regclass and (select c.relnamespace from pg_rewrite w join pg_class c on c.oid = w.ev_class where w.oid = x.objid) = 'agent_board'::regnamespace) or
142
+ (x.classid = 'pg_policy'::regclass and (select c.relnamespace from pg_policy pl join pg_class c on c.oid = pl.polrelid where pl.oid = x.objid) = 'agent_board'::regnamespace))),
143
+ array['pgcrypto','plpgsql'],
144
+ 'NS711 agent_board depends only on the reviewed extensions');
145
+
146
+ -- ===================================================================== #715
147
+ create temp table ns_sqlexec_builtin on commit drop as
148
+ select p.oid, p.proname, p.pronamespace::regnamespace::text || '.' || p.proname as qname from pg_proc p
149
+ where (p.pronamespace = 'pg_catalog'::regnamespace and p.proname in
150
+ ('query_to_xml','query_to_xmlschema','query_to_xml_and_xmlschema','cursor_to_xml','cursor_to_xmlschema','ts_stat'))
151
+ or p.proname ~ '^dblink';
152
+ -- A call is the name followed by `(`, optionally through a closing quote: `realtime."cast"(`
153
+ -- evaded the unquoted form (mutation M10, plans/evidence/717-native/).
154
+ create temp table ns_sqlexec on commit drop as
155
+ with recursive s(oid) as (
156
+ select oid from ns_routine where is_exec
157
+ union select r.oid from ns_routine r join ns_sqlexec_builtin as b on r.body_lit ~ agent_board_test.call_re(b.qname, true)
158
+ union select r.oid from s join ns_routine as callee on callee.oid = s.oid
159
+ cross join lateral (select agent_board_test.call_re(callee.nspname || '.' || callee.proname, true) as pat) as m
160
+ join ns_routine r on r.oid <> s.oid and lower(callee.proname) = any (r.tokens) and r.body_lit ~ m.pat)
161
+ select oid from s;
162
+ select ok((select count(*) >= 6 from ns_sqlexec_builtin where proname <> 'dblink') and (select count(*) > 0 from ns_sqlexec),
163
+ 'NS715 the classifier has SQL-executing builtins to match and finds sites (discriminance)');
164
+ select is((select array_agg(r.oid::regprocedure::text || ' calls ' || b.proname order by r.oid::regprocedure::text || ' calls ' || b.proname)
165
+ from ns_routine r join ns_sqlexec_builtin as b on r.body_lit ~ agent_board_test.call_re(b.qname, true)), null,
166
+ 'NS715 no installed routine calls a SQL-text-executing builtin (query_to_xml, cursor_to_xml, ts_stat, dblink)');
167
+ -- Exemption classes, each a positive claim:
168
+ -- platform: SECURITY INVOKER, owned by a native service role, in realtime/storage (not exposed);
169
+ -- the nine admitted bodies are pinned by the 667 native profiles.
170
+ -- event: returns event_trigger, so it cannot be called as a function.
171
+ -- retention: agent_board.mark_retention_metadata, allowlisted table names, service-only (asserted below).
172
+ -- pgtap: NOT an exemption in an exposed schema. The runner installs it into `extensions`
173
+ -- (tests/fixtures/pgtap-unexposed.sql); NS715-22 and NS715-23 fail if it is exposed again.
174
+ create temp table ns_sqlexec_class on commit drop as
175
+ select s.oid, r.nspname, r.ext,
176
+ case
177
+ when r.ext = 'pgtap' then 'pgtap'
178
+ when r.prorettype = 'event_trigger'::regtype then 'event'
179
+ when not r.prosecdef and r.nspname in ('realtime', 'storage')
180
+ and pg_get_userbyid((select proowner from pg_proc where oid = s.oid)) in ('supabase_realtime_admin', 'supabase_storage_admin') then 'platform'
181
+ when s.oid = 'agent_board.mark_retention_metadata(text,timestamp with time zone,uuid,text)'::regprocedure then 'retention'
182
+ end cls
183
+ from ns_sqlexec s join ns_routine r on r.oid = s.oid;
184
+ select is((select array_agg(oid::regprocedure::text order by oid::regprocedure::text) from ns_sqlexec_class where cls is null), null,
185
+ 'NS715 every indirect SQL-execution site satisfies a positively-checked exemption class');
186
+ select is((select array_agg(x.oid::regprocedure::text || '@' || a.rolname order by x.oid::regprocedure::text || '@' || a.rolname) from ns_sqlexec_class x cross join ns_api_role a
187
+ where x.cls = 'retention' and a.rolname <> 'service_role' and has_function_privilege(a.oid, x.oid, 'EXECUTE')), null,
188
+ 'NS715 the agent_board retention site is callable only by service_role among API roles');
189
+ select throws_ok($c$do $d$ begin
190
+ perform set_config('role', 'service_role', true);
191
+ perform set_config('request.jwt.claims', '{"role":"service_role"}', true);
192
+ perform agent_board.mark_retention_metadata('messages; select 1', now(), gen_random_uuid(), 'r');
193
+ end $d$$c$, '22023', null, 'NS715 the retention site refuses a non-allowlisted table name before EXECUTE');
194
+ select is((select array_agg(distinct x.cls order by x.cls) from ns_sqlexec_class x join ns_exposed e on e.nspname = x.nspname
195
+ where exists (select 1 from ns_api_role a where has_schema_privilege(a.oid, (select pronamespace from pg_proc where oid = x.oid), 'USAGE')
196
+ and has_function_privilege(a.oid, x.oid, 'EXECUTE'))),
197
+ array['retention'],
198
+ 'NS715 the only API-callable SQL-execution site in an exposed schema is the service-only retention site');
199
+ -- Fixed finding (message-board#741): the runner used to install pgTAP into exposed `public`, where
200
+ -- anon reached caller-SQL execution over PostgREST and could SET ROLE service_role (historical
201
+ -- receipt: plans/evidence/717-native/). Expected state now: no pgTAP routine in an exposed schema
202
+ -- is callable by an API role. A regression that puts it back names the schema and member count
203
+ -- here, and the class shows up in NS715-22.
204
+ select is((select array_agg(n.nspname || ':' || cnt order by n.nspname) from (
205
+ select p.pronamespace, count(*)::text cnt from pg_depend d
206
+ join pg_extension e on e.oid = d.refobjid and e.extname = 'pgtap'
207
+ join pg_proc p on p.oid = d.objid
208
+ where d.classid = 'pg_proc'::regclass and d.deptype = 'e'
209
+ and p.pronamespace in (select oid from pg_namespace where nspname in (select nspname from ns_exposed))
210
+ and exists (select 1 from ns_api_role a where has_schema_privilege(a.oid, p.pronamespace, 'USAGE')
211
+ and has_function_privilege(a.oid, p.oid, 'EXECUTE'))
212
+ group by p.pronamespace) x join pg_namespace n on n.oid = x.pronamespace), null,
213
+ 'NS715 no pgTAP routine is API-callable in a PostgREST-exposed schema');
214
+ select is((select count(*) from ns_sqlexec_class where cls = 'platform'), 15::bigint,
215
+ 'NS715 platform sites: 9 admitted native identities plus 6 wrappers');
216
+ select is((select count(*) from ns_sqlexec_class where cls = 'platform' and oid not in (
217
+ select oid from ns_routine where is_exec)), 6::bigint,
218
+ 'NS715 platform wrapper count is derived, not assumed');
219
+ \else
220
+ select plan(1);select ok(to_regprocedure('realtime.apply_rls(jsonb,integer)') is null or to_regrole('authenticator') is null,
221
+ 'NS native platform absent; no native surface credit');
222
+ \endif
223
+ select * from finish();rollback;
@@ -86,8 +86,8 @@ select is(
86
86
  select is(
87
87
  (select string_agg(kind || ':' || signature, ' | ' order by kind, signature)
88
88
  from agent_board.delegate_allowed_operations where kind in ('rpc', 'ambient_rpc', 'predicate')),
89
- 'ambient_rpc:get_schema_version() | predicate:_delegate_visible_agent(uuid) | predicate:_delegate_visible_board_ids() | predicate:current_agent_id() | rpc:create_or_find_thread(uuid, text, text, text, jsonb) | rpc:post_board_message(uuid, uuid, text, text, text, text, text, text, text, jsonb) | rpc:post_board_message(uuid, uuid, uuid, text, text, text, text, text, jsonb) | rpc:post_message(uuid, uuid, text, text, uuid, jsonb)',
90
- 'the allow set''s functions are exactly the contract''s first membership (D4): read and post, nothing else');
89
+ 'ambient_rpc:get_schema_version() | predicate:_delegate_visible_agent(uuid) | predicate:_delegate_visible_board_ids() | predicate:current_agent_id() | rpc:create_or_find_thread(uuid, text, text, text, jsonb) | rpc:get_send_outcome(uuid, text, text) | rpc:post_board_message(uuid, uuid, text, text, text, text, text, text, text, jsonb) | rpc:post_board_message(uuid, uuid, uuid, text, text, text, text, text, jsonb) | rpc:post_message(uuid, uuid, text, text, uuid, jsonb)',
90
+ 'the allow set''s functions are exactly the contract''s first membership (D4), widened additively by #670''s get_send_outcome: read, post and recover an own post''s outcome, nothing else');
91
91
 
92
92
  -- ===========================================================================
93
93
  -- 3. Read-grant completeness
@@ -12,7 +12,9 @@
12
12
  -- three closure members are NOT message/delivery/inbox sinks and are excluded, each for a
13
13
  -- stated reason: artifacts (the artifact domain; add_artifact is its own public route),
14
14
  -- signature_evidence and signature_replay_state (the signed-write evidence ledger, whose
15
- -- writers are classed by agent_board_write_enforcement_class / signed_* tests);
15
+ -- writers are classed by agent_board_write_enforcement_class / signed_* tests). send_outcomes
16
+ -- (#670's author-scoped receipts) stays a sink: its only writer, _record_send_outcome, is
17
+ -- thereby a class member, and DWX-2 pins that no API role can execute it;
16
18
  -- * plus the two thread columns a message write moves: threads.last_message_sequence and
17
19
  -- threads.board_id;
18
20
  -- * a CLASS MEMBER is any agent_board routine whose body writes a sink, or calls a member,
@@ -75,7 +77,7 @@ select is(
75
77
  (select string_agg(rel, ', ' order by rel collate "C") from dwx_closure),
76
78
  (select string_agg(r::regclass::text, ', ' order by r::regclass::text collate "C")
77
79
  from unnest(array['agent_board.artifacts', 'agent_board.callback_delivery_attempts', 'agent_board.callback_outbox_events',
78
- 'agent_board.delivery_recipients', 'agent_board.inbox_items', 'agent_board.messages',
80
+ 'agent_board.delivery_recipients', 'agent_board.inbox_items', 'agent_board.messages', 'agent_board.send_outcomes',
79
81
  'agent_board.signature_evidence', 'agent_board.signature_replay_state']) r),
80
82
  'DWX-1: the relations reaching agent_board.messages by foreign key are exactly the classified set');
81
83
 
@@ -21,7 +21,7 @@ set search_path = extensions, public, agent_board;
21
21
 
22
22
  begin;
23
23
 
24
- select plan(143);
24
+ select plan(144);
25
25
 
26
26
  -- The test role switches to agent_board_delegate. On PostgreSQL 16+ the role's creator holds
27
27
  -- ADMIN OPTION but not SET, so grant SET to the current role for this transaction only (rolled
@@ -382,6 +382,13 @@ select is(
382
382
  '8',
383
383
  'allow set (ambient): get_schema_version answers a delegate with the schema version');
384
384
  insert into _ex values ('get_schema_version()');
385
+ -- the send-outcome read (#670): the delegate's unkeyed posts above mint nothing, so its read of an
386
+ -- unused key is the all-NULL unknown row (the confirmed path is pinned in agent_board_send_outcome)
387
+ select is(
388
+ pg_temp.as_d_val(format($$ select r::text from agent_board.get_send_outcome(%L::uuid, 'hosted-670-unused', 'post_board_message') r $$, pg_temp.v('T1'))),
389
+ '(unknown,,,,,)',
390
+ 'allow set: get_send_outcome answers a delegate (unknown for a key it never sent)');
391
+ insert into _ex values ('get_send_outcome(uuid, text, text)');
385
392
  -- 25 -- every rpc / ambient_rpc in the list was exercised above (the list, not this file, is the set)
386
393
  select is(
387
394
  (select coalesce(string_agg(signature, ' | ' order by signature), '(none)')