@ultimat3/testing 30.9.0 → 31.0.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 (148) hide show
  1. package/CLAUDE.md +46 -55
  2. package/README.md +179 -39
  3. package/package.json +23 -17
  4. package/src/ai-conformance-answer.ts +67 -0
  5. package/src/ai-gateway-conformance.ts +105 -0
  6. package/src/ai-provider-conformance.ts +69 -0
  7. package/src/ai-provider-transport-conformance.ts +170 -0
  8. package/src/audit-sink-conformance.ts +204 -0
  9. package/src/auth-adapter-conformance-credentials.ts +124 -0
  10. package/src/auth-adapter-conformance-mfa.ts +70 -0
  11. package/src/auth-adapter-conformance-passkeys.ts +133 -0
  12. package/src/auth-adapter-conformance-sessions.ts +115 -0
  13. package/src/auth-adapter-conformance-support.ts +71 -0
  14. package/src/auth-adapter-conformance-users.ts +128 -0
  15. package/src/auth-adapter-conformance.ts +34 -0
  16. package/src/auth-limiter-factory-conformance.ts +224 -0
  17. package/src/auth-server-store-conformance-records.ts +69 -0
  18. package/src/auth-server-store-conformance.ts +208 -0
  19. package/src/cache-tier-conformance-checks.ts +142 -0
  20. package/src/cache-tier-conformance.ts +24 -0
  21. package/src/cassette-format.ts +8 -13
  22. package/src/cassette-record.ts +1 -1
  23. package/src/cdp-browser.ts +10 -11
  24. package/src/cdp-e2e-page.ts +2 -2
  25. package/src/cdp-e2e-session.ts +2 -2
  26. package/src/cdp-network-probe.ts +1 -1
  27. package/src/cdp-offline-script.ts +2 -2
  28. package/src/clock-conformance.ts +126 -0
  29. package/src/conformance.ts +239 -0
  30. package/src/e2e-browser-handle.ts +1 -2
  31. package/src/e2e-error-codes.ts +17 -16
  32. package/src/e2e-run.ts +4 -3
  33. package/src/embedder-conformance.ts +101 -0
  34. package/src/entity-conformance-aggregates.ts +210 -0
  35. package/src/entity-conformance-batches.ts +216 -0
  36. package/src/entity-conformance-bulk.ts +379 -0
  37. package/src/entity-conformance-checks.ts +27 -0
  38. package/src/entity-conformance-entities.ts +52 -0
  39. package/src/entity-conformance-locks.ts +286 -0
  40. package/src/entity-conformance-matrix.ts +397 -0
  41. package/src/entity-conformance-reads.ts +241 -0
  42. package/src/entity-conformance-support.ts +56 -0
  43. package/src/entity-conformance-tenancy.ts +296 -0
  44. package/src/entity-conformance-values.ts +305 -0
  45. package/src/entity-conformance-versions.ts +60 -0
  46. package/src/entity-conformance-writes.ts +348 -0
  47. package/src/entity-driver-conformance.ts +103 -0
  48. package/src/error-groups-store-conformance.ts +198 -0
  49. package/src/error-reporter-conformance.ts +119 -0
  50. package/src/errors.ts +20 -2
  51. package/src/event-bus-conformance.ts +161 -0
  52. package/src/exercise-drift-hint.ts +4 -1
  53. package/src/exercise-judge.ts +5 -3
  54. package/src/exercise-override-line.ts +98 -0
  55. package/src/exercise-report.ts +30 -51
  56. package/src/exercise.ts +12 -6
  57. package/src/factories.ts +192 -179
  58. package/src/factory-api.ts +131 -0
  59. package/src/factory-associations.ts +67 -0
  60. package/src/factory-errors.ts +38 -0
  61. package/src/factory-lint.ts +92 -0
  62. package/src/factory-persist.ts +74 -16
  63. package/src/factory-pipeline.ts +191 -0
  64. package/src/factory-registry.ts +2 -1
  65. package/src/factory-types.ts +131 -0
  66. package/src/failure-store-conformance.ts +137 -0
  67. package/src/fixture-jobs.ts +27 -11
  68. package/src/fixture-mail.ts +7 -7
  69. package/src/fixture-seed.ts +111 -0
  70. package/src/fixture-statements.ts +68 -52
  71. package/src/framework-fixtures.ts +1 -1
  72. package/src/idempotency-store-conformance.ts +186 -0
  73. package/src/idempotency-store-replay-conformance.ts +140 -0
  74. package/src/idempotency-store-tx-conformance.ts +132 -0
  75. package/src/idempotency-store-world-conformance.ts +82 -0
  76. package/src/identity-provider-conformance.ts +144 -0
  77. package/src/image-transform-conformance.ts +89 -0
  78. package/src/index.ts +68 -157
  79. package/src/isr-store-conformance.ts +113 -0
  80. package/src/job-sim-effects.ts +19 -31
  81. package/src/job-sim-world.ts +6 -15
  82. package/src/lease-store-conformance.ts +195 -0
  83. package/src/mail-driver-conformance.ts +108 -0
  84. package/src/matcher-doubles.ts +104 -0
  85. package/src/matcher-stub.ts +78 -0
  86. package/src/matcher-surface.ts +21 -0
  87. package/src/matchers.ts +19 -1
  88. package/src/mcp-confirmation-store-conformance.ts +262 -0
  89. package/src/meter-store-conformance.ts +135 -0
  90. package/src/notify-digest-conformance.ts +133 -0
  91. package/src/notify-inbox-conformance.ts +130 -0
  92. package/src/notify-ledger-conformance.ts +134 -0
  93. package/src/notify-preference-conformance.ts +49 -0
  94. package/src/notify-stores-conformance.ts +73 -0
  95. package/src/outbox-store-conformance-claims.ts +112 -0
  96. package/src/outbox-store-conformance-subject.ts +65 -0
  97. package/src/outbox-store-conformance.ts +71 -0
  98. package/src/per-test-reset.ts +55 -20
  99. package/src/preload.ts +4 -2
  100. package/src/purge-conformance.ts +79 -0
  101. package/src/push-device-conformance.ts +124 -0
  102. package/src/push-subscription-conformance.ts +123 -0
  103. package/src/quiet-logs.ts +4 -4
  104. package/src/rate-limit-store-conformance.ts +178 -0
  105. package/src/registry-leak-error.ts +8 -1
  106. package/src/scrape-driver-conformance-frame-checks.ts +97 -0
  107. package/src/scrape-driver-conformance-page-checks.ts +114 -0
  108. package/src/scrape-driver-conformance-site.ts +84 -0
  109. package/src/scrape-driver-conformance.ts +34 -0
  110. package/src/search-index-conformance-list.ts +76 -0
  111. package/src/search-index-conformance-support.ts +69 -0
  112. package/src/search-index-conformance-versions.ts +66 -0
  113. package/src/search-index-conformance.ts +126 -0
  114. package/src/secret-source-conformance.ts +91 -0
  115. package/src/seed-factories.ts +57 -0
  116. package/src/seed-writer.ts +8 -19
  117. package/src/semantic-cache-factory-conformance.ts +86 -0
  118. package/src/sms-transport-conformance.ts +102 -0
  119. package/src/step-store-conformance.ts +171 -0
  120. package/src/storage-conformance-read-checks.ts +132 -0
  121. package/src/storage-conformance-shape.ts +121 -0
  122. package/src/storage-conformance-stream-checks.ts +226 -0
  123. package/src/storage-conformance.ts +34 -0
  124. package/src/stub-action.ts +24 -0
  125. package/src/stub-errors.ts +86 -0
  126. package/src/stub-job.ts +30 -0
  127. package/src/stub-query.ts +25 -0
  128. package/src/stub-script.ts +76 -0
  129. package/src/stub-stack.ts +29 -0
  130. package/src/stub.ts +73 -0
  131. package/src/swap-adapter.ts +135 -0
  132. package/src/test-scope.ts +96 -0
  133. package/src/test-types.ts +1 -1
  134. package/src/totp-replay-guard-conformance.ts +76 -0
  135. package/src/transport-conformance.ts +179 -0
  136. package/src/upload-scanner-conformance.ts +112 -0
  137. package/src/vector-store-conformance-checks.ts +174 -0
  138. package/src/vector-store-conformance.ts +21 -0
  139. package/src/cdp-connection.ts +0 -291
  140. package/src/cdp-errors.ts +0 -179
  141. package/src/cdp-launch-attempt.ts +0 -224
  142. package/src/cdp-launch-candidates.ts +0 -62
  143. package/src/cdp-launch-profile.ts +0 -106
  144. package/src/cdp-launch-reap.ts +0 -68
  145. package/src/cdp-launch-wire.ts +0 -171
  146. package/src/cdp-launch.ts +0 -175
  147. package/src/cdp-pipe.ts +0 -77
  148. package/src/cdp-wire-watch.ts +0 -113
@@ -0,0 +1,130 @@
1
+ // The `InboxStore` contract of `@ultimat3/notify` as checks: a write that converges under an
2
+ // at-least-once job, seen and read as two facts, an unread count derived from the rows, and ONE
3
+ // total page order `(createdAt desc, notifier, key)` by code point. Every check reads its own
4
+ // recipient, so one shared table serves them all.
5
+
6
+ import { expect } from 'bun:test';
7
+ import type { InboxStore, InboxWrite } from '@ultimat3/notify/adapter';
8
+
9
+ export interface InboxStoreCheck {
10
+ readonly name: string;
11
+ run(inbox: InboxStore): Promise<void>;
12
+ }
13
+
14
+ const AT = new Date('2026-08-24T09:00:00Z');
15
+ const LATER = new Date('2026-08-24T10:00:00Z');
16
+
17
+ let minted = 0;
18
+ const recipientOf = (): string => {
19
+ minted += 1;
20
+ return `conformance-${process.pid.toString(36)}-${minted.toString(36)}`;
21
+ };
22
+
23
+ const writeFor = (recipient: string, overrides: Partial<InboxWrite> = {}): InboxWrite => ({
24
+ recipient,
25
+ notifier: 'post.liked',
26
+ key: 'like:p1',
27
+ params: { postId: 'p1', tags: ['a', 'b'] },
28
+ createdAt: AT,
29
+ ...overrides,
30
+ });
31
+
32
+ const pageKeys = async (inbox: InboxStore, recipient: string): Promise<readonly string[]> =>
33
+ (await inbox.list({ recipient })).map((row) => `${row.notifier}/${row.key}`);
34
+
35
+ export const INBOX_STORE_CHECKS: readonly InboxStoreCheck[] = [
36
+ {
37
+ name: 'a replayed add answers the FIRST row, its timestamps and its read state unmoved',
38
+ async run(inbox) {
39
+ const ana = recipientOf();
40
+ const first = await inbox.add(writeFor(ana));
41
+ expect(first).toMatchObject({ recipient: ana, seenAt: null, readAt: null, createdAt: AT });
42
+ expect(first.params).toEqual({ postId: 'p1', tags: ['a', 'b'] });
43
+ await inbox.markRead({ recipient: ana, ids: [first.id], at: AT });
44
+ const again = await inbox.add(writeFor(ana, { createdAt: LATER, params: { other: 1 } }));
45
+ expect([again.id, again.createdAt, again.readAt]).toEqual([first.id, AT, AT]);
46
+ expect(await inbox.list({ recipient: ana })).toHaveLength(1);
47
+ },
48
+ },
49
+ {
50
+ name: 'the unread count is derived from the rows, so the badge and the list cannot disagree',
51
+ async run(inbox) {
52
+ const ana = recipientOf();
53
+ const one = await inbox.add(writeFor(ana));
54
+ await inbox.add(writeFor(ana, { key: 'like:p2', createdAt: LATER }));
55
+ expect(await inbox.unreadCount(ana)).toBe(2);
56
+ expect(await inbox.markRead({ recipient: ana, ids: [one.id], at: LATER })).toBe(1);
57
+ expect(await inbox.markRead({ recipient: ana, ids: [one.id], at: LATER })).toBe(0);
58
+ expect(await inbox.unreadCount(ana)).toBe(1);
59
+ const unread = await inbox.list({ recipient: ana, unreadOnly: true });
60
+ expect(unread.map((row) => row.key)).toEqual(['like:p2']);
61
+ },
62
+ },
63
+ {
64
+ name: 'marking read is scoped by recipient: a stranger id, or no id at all, is simply absent',
65
+ async run(inbox) {
66
+ const [ana, ben] = [recipientOf(), recipientOf()];
67
+ const mine = await inbox.add(writeFor(ana));
68
+ const good = await inbox.add(writeFor(ana, { key: 'like:p2' }));
69
+ expect(await inbox.markRead({ recipient: ben, ids: [mine.id], at: LATER })).toBe(0);
70
+ // One malformed id must not cost the batch the good ones beside it.
71
+ const ids = ['not-an-id', good.id, crypto.randomUUID()];
72
+ expect(await inbox.markRead({ recipient: ana, ids, at: LATER })).toBe(1);
73
+ expect(await inbox.unreadCount(ana)).toBe(1);
74
+ },
75
+ },
76
+ {
77
+ name: 'seen and read are two facts: showing the badge does not dismiss the message',
78
+ async run(inbox) {
79
+ const ana = recipientOf();
80
+ await inbox.add(writeFor(ana));
81
+ expect(await inbox.markSeen({ recipient: ana, at: AT })).toBe(1);
82
+ expect(await inbox.unreadCount(ana)).toBe(1);
83
+ expect((await inbox.list({ recipient: ana }))[0]?.seenAt).toEqual(AT);
84
+ expect(await inbox.markSeen({ recipient: ana, at: LATER })).toBe(0);
85
+ },
86
+ },
87
+ {
88
+ name: 'the page is newest first and bounded, and limit 0 is an empty page',
89
+ async run(inbox) {
90
+ const ana = recipientOf();
91
+ await inbox.add(writeFor(ana, { key: 'a', createdAt: AT }));
92
+ await inbox.add(writeFor(ana, { key: 'b', createdAt: LATER }));
93
+ expect((await inbox.list({ recipient: ana, limit: 1 })).map((r) => r.key)).toEqual(['b']);
94
+ expect(await inbox.list({ recipient: ana, limit: 0 })).toEqual([]);
95
+ },
96
+ },
97
+ {
98
+ name: 'a limit that is not a count is refused, never answered as a page',
99
+ async run(inbox) {
100
+ const ana = recipientOf();
101
+ await inbox.add(writeFor(ana));
102
+ for (const limit of [Number.NaN, Number.POSITIVE_INFINITY, 2.5, -1]) {
103
+ await expect(inbox.list({ recipient: ana, limit })).rejects.toThrow();
104
+ }
105
+ },
106
+ },
107
+ {
108
+ name: 'one millisecond: the tie breaks on notifier, then key, by code point',
109
+ async run(inbox) {
110
+ const ana = recipientOf();
111
+ // Inserted against the order, so a store keeping insertion order fails.
112
+ for (const [notifier, key] of [
113
+ ['zeta', 'aa'],
114
+ ['alpha', 'zz'],
115
+ ['alpha', 'école'],
116
+ ['alpha', 'Zürich'],
117
+ ['alpha', 'aa'],
118
+ ] as const) {
119
+ await inbox.add(writeFor(ana, { notifier, key }));
120
+ }
121
+ expect(await pageKeys(inbox, ana)).toEqual([
122
+ 'alpha/Zürich',
123
+ 'alpha/aa',
124
+ 'alpha/zz',
125
+ 'alpha/école',
126
+ 'zeta/aa',
127
+ ]);
128
+ },
129
+ },
130
+ ];
@@ -0,0 +1,134 @@
1
+ // The `DeliveryLedger` contract of `@ultimat3/notify` as checks: the claim that stops a replayed
2
+ // attempt short of a second send. The reclaim window is READ from the ledger (the `held` answer a
3
+ // fresh claim's twin gets), so a ledger of any window proves itself; every check names its own
4
+ // notifier, so one shared table serves them all.
5
+
6
+ import { expect } from 'bun:test';
7
+ import type { DeliveryClaim, DeliveryClaimAnswer, DeliveryLedger } from '@ultimat3/notify/adapter';
8
+
9
+ export interface DeliveryLedgerCheck {
10
+ readonly name: string;
11
+ run(ledger: DeliveryLedger): Promise<void>;
12
+ }
13
+
14
+ const AT = new Date('2026-08-24T09:00:00Z');
15
+ const after = (ms: number): Date => new Date(AT.getTime() + ms);
16
+
17
+ let minted = 0;
18
+ /** A bulk claim (NULL recipient) no other check, run or process shares. */
19
+ const claimOf = (): DeliveryClaim => {
20
+ minted += 1;
21
+ const notifier = `conformance.${process.pid.toString(36)}.${minted.toString(36)}`;
22
+ return { notifier, key: 'k1', recipient: null, channel: 'slack' };
23
+ };
24
+
25
+ /** The claim id of an answer that must have been `owned`. */
26
+ const owned = (answer: DeliveryClaimAnswer): string =>
27
+ answer.outcome === 'owned' ? answer.claimId : expect.unreachable(`got ${answer.outcome}`);
28
+
29
+ /** The ledger's reclaim window, as its own `held` answer states it. */
30
+ async function windowOf(ledger: DeliveryLedger): Promise<number> {
31
+ const probe = claimOf();
32
+ owned(await ledger.claim(probe, AT));
33
+ const answer = await ledger.claim(probe, AT);
34
+ if (answer.outcome !== 'held')
35
+ return expect.unreachable(`a live claim answered ${answer.outcome}`);
36
+ expect(answer.retryAfterMs).toBeGreaterThan(0);
37
+ return answer.retryAfterMs;
38
+ }
39
+
40
+ export const DELIVERY_LEDGER_CHECKS: readonly DeliveryLedgerCheck[] = [
41
+ {
42
+ name: 'a NULL and an empty recipient are ONE delivery: sent once, never claimed again',
43
+ async run(ledger) {
44
+ const bulk = claimOf();
45
+ await ledger.settle(bulk, 'sent', AT, owned(await ledger.claim(bulk, AT)));
46
+ expect(await ledger.claim({ ...bulk, recipient: '' }, AT)).toEqual({ outcome: 'sent' });
47
+ expect(await ledger.find({ ...bulk, recipient: '' })).toMatchObject({
48
+ recipient: null,
49
+ status: 'sent',
50
+ attempts: 1,
51
+ });
52
+ },
53
+ },
54
+ {
55
+ name: 'a settle with no claim records nothing, so the claim after it still sends',
56
+ async run(ledger) {
57
+ const bulk = claimOf();
58
+ expect(await ledger.settle(bulk, 'sent', AT, crypto.randomUUID())).toBe(false);
59
+ expect(await ledger.find(bulk)).toBeUndefined();
60
+ owned(await ledger.claim(bulk, AT));
61
+ },
62
+ },
63
+ {
64
+ name: 'two claims at once: one owner, and the other is told when to come back',
65
+ async run(ledger) {
66
+ const window = await windowOf(ledger);
67
+ const bulk = claimOf();
68
+ const answers = await Promise.all([ledger.claim(bulk, AT), ledger.claim(bulk, AT)]);
69
+ expect(answers.filter((answer) => answer.outcome === 'owned')).toHaveLength(1);
70
+ const other = answers.find((answer) => answer.outcome !== 'owned');
71
+ expect(other).toEqual({ outcome: 'held', retryAfterMs: window });
72
+ expect(await ledger.find(bulk)).toMatchObject({ status: 'sending', attempts: 1 });
73
+ },
74
+ },
75
+ {
76
+ name: 'a live claim is held up to the window, and reclaimed one past it',
77
+ async run(ledger) {
78
+ const window = await windowOf(ledger);
79
+ const bulk = claimOf();
80
+ owned(await ledger.claim(bulk, AT));
81
+ expect(await ledger.claim(bulk, after(window))).toEqual({ outcome: 'held', retryAfterMs: 0 });
82
+ owned(await ledger.claim(bulk, after(window + 1)));
83
+ expect(await ledger.find(bulk)).toMatchObject({ status: 'sending', attempts: 2 });
84
+ },
85
+ },
86
+ {
87
+ name: "a late settle changes nothing: the row is its reclaimer's",
88
+ async run(ledger) {
89
+ const window = await windowOf(ledger);
90
+ const bulk = claimOf();
91
+ const late = owned(await ledger.claim(bulk, AT));
92
+ const current = owned(await ledger.claim(bulk, after(window + 1)));
93
+ expect(current).not.toBe(late);
94
+ expect(await ledger.settle(bulk, 'failed', after(window + 2), late)).toBe(false);
95
+ expect(await ledger.find(bulk)).toMatchObject({ status: 'sending' });
96
+ expect(await ledger.settle(bulk, 'sent', after(window + 3), current)).toBe(true);
97
+ expect(await ledger.settle(bulk, 'failed', after(window + 4), late)).toBe(false);
98
+ expect(await ledger.find(bulk)).toMatchObject({ status: 'sent' });
99
+ },
100
+ },
101
+ {
102
+ name: 'an attempt cannot move its own `sent` back to `failed`',
103
+ async run(ledger) {
104
+ const bulk = claimOf();
105
+ const claimId = owned(await ledger.claim(bulk, AT));
106
+ expect(await ledger.settle(bulk, 'sent', AT, claimId)).toBe(true);
107
+ expect(await ledger.settle(bulk, 'failed', AT, claimId)).toBe(false);
108
+ expect(await ledger.find(bulk)).toMatchObject({ status: 'sent' });
109
+ },
110
+ },
111
+ {
112
+ name: 'a failed delivery is re-claimable at once, counting the attempt',
113
+ async run(ledger) {
114
+ const bulk = claimOf();
115
+ await ledger.settle(bulk, 'failed', AT, owned(await ledger.claim(bulk, AT)));
116
+ owned(await ledger.claim({ ...bulk, recipient: '' }, AT));
117
+ expect(await ledger.find(bulk)).toMatchObject({
118
+ recipient: null,
119
+ status: 'sending',
120
+ attempts: 2,
121
+ });
122
+ },
123
+ },
124
+ {
125
+ name: 'two recipients of one notification are two deliveries',
126
+ async run(ledger) {
127
+ const base = claimOf();
128
+ const ana = { ...base, recipient: 'ana' };
129
+ await ledger.settle(ana, 'sent', AT, owned(await ledger.claim(ana, AT)));
130
+ owned(await ledger.claim({ ...base, recipient: 'ben' }, AT));
131
+ expect(await ledger.claim(ana, AT)).toEqual({ outcome: 'sent' });
132
+ },
133
+ },
134
+ ];
@@ -0,0 +1,49 @@
1
+ // The `PreferenceStore` contract of `@ultimat3/notify` as checks. The seam has no write side — the
2
+ // taxonomy and the opt-outs are the app's (axiom 8) — so what a store owes every caller is the
3
+ // shape of its answer: one read per chunk, ids as strings, and the same answer to the same question.
4
+
5
+ import { expect } from 'bun:test';
6
+ import { ctxOf, frozenClock } from '@ultimat3/core';
7
+ import type { Recipient } from '@ultimat3/notify';
8
+ import { NOTIFY_CHUNK_SIZE } from '@ultimat3/notify';
9
+ import type { PreferenceBatchQuery, PreferenceStore } from '@ultimat3/notify/adapter';
10
+
11
+ export interface PreferenceStoreCheck {
12
+ readonly name: string;
13
+ run(store: PreferenceStore): Promise<void>;
14
+ }
15
+
16
+ const AT = new Date('2026-08-24T09:00:00Z');
17
+
18
+ const queryFor = (recipients: readonly Recipient[]): PreferenceBatchQuery => ({
19
+ recipients,
20
+ notifier: 'post.liked',
21
+ channel: 'email',
22
+ event: { notifier: 'post.liked', key: 'like:p1', params: {}, at: AT },
23
+ ctx: ctxOf({ clock: frozenClock(AT) }),
24
+ });
25
+
26
+ const audience = (size: number): readonly Recipient[] =>
27
+ Array.from({ length: size }, (_, index) => ({ id: `r${index.toString()}`, tz: 'UTC' }));
28
+
29
+ const answer = async (store: PreferenceStore, query: PreferenceBatchQuery): Promise<string[]> => [
30
+ ...(await store.allowsMany(query)),
31
+ ];
32
+
33
+ export const PREFERENCE_STORE_CHECKS: readonly PreferenceStoreCheck[] = [
34
+ {
35
+ name: `a full chunk of ${NOTIFY_CHUNK_SIZE.toString()} is answered by one call, in string ids`,
36
+ async run(store) {
37
+ const ids = await answer(store, queryFor(audience(NOTIFY_CHUNK_SIZE)));
38
+ expect(ids.every((id) => typeof id === 'string')).toBe(true);
39
+ },
40
+ },
41
+ {
42
+ name: 'the same question answers the same set',
43
+ async run(store) {
44
+ const query = queryFor(audience(16));
45
+ const [first, second] = [await answer(store, query), await answer(store, query)];
46
+ expect([...second].sort()).toEqual([...first].sort());
47
+ },
48
+ },
49
+ ];
@@ -0,0 +1,73 @@
1
+ // The `NotifyStores` port of `@ultimat3/notify` as shared examples: `notifyStoresConformance` asks
2
+ // all four seams an app's `notifyStores:` line hands over; one seam alone is
3
+ // `behavesLike(inboxStoreConformance, () => inbox)`. The subject is called once per test — every
4
+ // check names its own recipient, notifier or slot, so a store with rows from other checks is fine.
5
+
6
+ import { describe, test } from 'bun:test';
7
+ import type {
8
+ DeliveryLedger,
9
+ DigestStore,
10
+ InboxStore,
11
+ PreferenceStore,
12
+ } from '@ultimat3/notify/adapter';
13
+ import { DIGEST_STORE_CHECKS } from './notify-digest-conformance';
14
+ import { INBOX_STORE_CHECKS } from './notify-inbox-conformance';
15
+ import { DELIVERY_LEDGER_CHECKS } from './notify-ledger-conformance';
16
+ import { PREFERENCE_STORE_CHECKS } from './notify-preference-conformance';
17
+ import type { SharedExamples } from './shared-examples';
18
+ import { sharedExamples } from './shared-examples';
19
+
20
+ type Maybe<T> = T | Promise<T>;
21
+
22
+ /** Every seam present: an app installing fewer runs the per-seam suites for the ones it wrote. */
23
+ export interface NotifyStoresSubject {
24
+ readonly ledger: DeliveryLedger;
25
+ readonly inbox: InboxStore;
26
+ readonly preferences: PreferenceStore;
27
+ readonly digest: DigestStore;
28
+ }
29
+
30
+ interface Check<S> {
31
+ readonly name: string;
32
+ run(store: S): Promise<void>;
33
+ }
34
+
35
+ const register = <S>(checks: readonly Check<S>[], subject: () => Maybe<S>): void => {
36
+ for (const check of checks) {
37
+ test(check.name, async () => {
38
+ await check.run(await subject());
39
+ });
40
+ }
41
+ };
42
+
43
+ export const deliveryLedgerConformance: SharedExamples<Maybe<DeliveryLedger>> = sharedExamples(
44
+ 'a delivery ledger',
45
+ (subject) => register(DELIVERY_LEDGER_CHECKS, subject),
46
+ );
47
+
48
+ export const inboxStoreConformance: SharedExamples<Maybe<InboxStore>> = sharedExamples(
49
+ 'an inbox store',
50
+ (subject) => register(INBOX_STORE_CHECKS, subject),
51
+ );
52
+
53
+ export const digestStoreConformance: SharedExamples<Maybe<DigestStore>> = sharedExamples(
54
+ 'a digest store',
55
+ (subject) => register(DIGEST_STORE_CHECKS, subject),
56
+ );
57
+
58
+ export const preferenceStoreConformance: SharedExamples<Maybe<PreferenceStore>> = sharedExamples(
59
+ 'a preference store',
60
+ (subject) => register(PREFERENCE_STORE_CHECKS, subject),
61
+ );
62
+
63
+ export const notifyStoresConformance: SharedExamples<Maybe<NotifyStoresSubject>> = sharedExamples(
64
+ 'the notify stores',
65
+ (subject) => {
66
+ describe('ledger', () =>
67
+ register(DELIVERY_LEDGER_CHECKS, async () => (await subject()).ledger));
68
+ describe('inbox', () => register(INBOX_STORE_CHECKS, async () => (await subject()).inbox));
69
+ describe('preferences', () =>
70
+ register(PREFERENCE_STORE_CHECKS, async () => (await subject()).preferences));
71
+ describe('digest', () => register(DIGEST_STORE_CHECKS, async () => (await subject()).digest));
72
+ },
73
+ );
@@ -0,0 +1,112 @@
1
+ // The outbox store's claim checks: a claim is a lease, it lapses, it is handed back or retired by
2
+ // its claimant only, and its order is total. A store that hands one row to two relays hands one
3
+ // job to two workers, and the idempotency key collapses that only while the first is still live.
4
+
5
+ import { expect } from 'bun:test';
6
+ import type { OutboxRecord, OutboxStore } from '@ultimat3/jobs';
7
+ import type { OutboxStoreCheck } from './outbox-store-conformance-subject';
8
+ import { committed, elapse, outboxRecord, STAGED_AT } from './outbox-store-conformance-subject';
9
+
10
+ const ids = (records: readonly OutboxRecord[]): readonly string[] => records.map((each) => each.id);
11
+
12
+ /** The one claimant a batch was stamped with. */
13
+ const claimantOf = (records: readonly OutboxRecord[]): string =>
14
+ records[0]?.claimedBy ?? expect.unreachable('a claimed batch carries its claimant');
15
+
16
+ /** Two committed rows, claimed by `store`. */
17
+ async function claimedPair(
18
+ subject: Parameters<OutboxStoreCheck['run']>[0],
19
+ store: OutboxStore,
20
+ ): Promise<readonly OutboxRecord[]> {
21
+ await committed(subject, store, [
22
+ outboxRecord(crypto.randomUUID()),
23
+ outboxRecord(crypto.randomUUID()),
24
+ ]);
25
+ const claims = await store.claim(10);
26
+ expect(claims).toHaveLength(2);
27
+ return claims;
28
+ }
29
+
30
+ export const OUTBOX_STORE_CLAIM_CHECKS: readonly OutboxStoreCheck[] = [
31
+ {
32
+ name: 'a claim is a lease: inside it, no relay claims the same rows again',
33
+ async run(subject) {
34
+ const [first, second] = [subject.relay(), subject.relay()];
35
+ await claimedPair(subject, first);
36
+ expect(await first.claim(10)).toEqual([]);
37
+ expect(await second.claim(10)).toEqual([]);
38
+ expect(await first.pendingCount()).toBe(2);
39
+ },
40
+ },
41
+ {
42
+ name: 'a lapsed claim is claimable again, so a relay that died strands nothing',
43
+ async run(subject) {
44
+ const [dead, live] = [subject.relay(), subject.relay()];
45
+ const claims = await claimedPair(subject, dead);
46
+ await elapse(subject, subject.claimLeaseMs * 2);
47
+ expect(ids(await live.claim(10))).toEqual(ids(claims));
48
+ },
49
+ },
50
+ {
51
+ name: 'release, when the store has it, hands its claimant’s batch back at once',
52
+ async run(subject) {
53
+ const store = subject.relay();
54
+ if (store.release === undefined) return;
55
+ const claims = await claimedPair(subject, store);
56
+ await store.release(ids(claims), claimantOf(claims));
57
+ expect(ids(await subject.relay().claim(10))).toEqual(ids(claims));
58
+ },
59
+ },
60
+ {
61
+ name: 'a published row leaves the claim and the pending count, one or a batch at a time',
62
+ async run(subject) {
63
+ const store = subject.relay();
64
+ const claims = await claimedPair(subject, store);
65
+ const [one, other] = ids(claims);
66
+ const by = claimantOf(claims);
67
+ await store.markPublished(one ?? '', STAGED_AT + 5, by);
68
+ expect(await store.pendingCount()).toBe(1);
69
+ if (store.markPublishedMany === undefined) {
70
+ await store.markPublished(other ?? '', STAGED_AT + 5, by);
71
+ } else {
72
+ await store.markPublishedMany([other ?? ''], STAGED_AT + 5, by);
73
+ }
74
+ expect(await store.pendingCount()).toBe(0);
75
+ await elapse(subject, subject.claimLeaseMs * 2);
76
+ expect(await subject.relay().claim(10)).toEqual([]);
77
+ },
78
+ },
79
+ {
80
+ // A relay that stalled past its lease wakes into a world where its batch is another relay's.
81
+ name: 'a lapsed claimant can neither release nor retire what a newer claimant holds',
82
+ async run(subject) {
83
+ const [stale, fresh] = [subject.relay(), subject.relay()];
84
+ const lapsed = await claimedPair(subject, stale);
85
+ await elapse(subject, subject.claimLeaseMs * 2);
86
+ const held = await fresh.claim(10);
87
+ expect(ids(held)).toEqual(ids(lapsed));
88
+ const staleBy = claimantOf(lapsed);
89
+ await stale.release?.(ids(lapsed), staleBy);
90
+ expect(await subject.relay().claim(10)).toEqual([]);
91
+ for (const id of ids(lapsed)) await stale.markPublished(id, STAGED_AT + 5, staleBy);
92
+ await stale.markPublishedMany?.(ids(lapsed), STAGED_AT + 5, staleBy);
93
+ expect(await fresh.pendingCount()).toBe(2);
94
+ for (const id of ids(held)) await fresh.markPublished(id, STAGED_AT + 9, claimantOf(held));
95
+ expect(await fresh.pendingCount()).toBe(0);
96
+ },
97
+ },
98
+ {
99
+ // Every row of one transaction shares a `stagedAt`: a tie left which rows a limit takes, and
100
+ // the order they publish in, to whatever the store iterated first.
101
+ name: 'the claim order is total — stagedAt, then id — and a limit takes its head',
102
+ async run(subject) {
103
+ const store = subject.relay();
104
+ const tied = Array.from({ length: 3 }, () => outboxRecord(crypto.randomUUID()));
105
+ const earlier = outboxRecord(crypto.randomUUID(), { stagedAt: STAGED_AT - 1_000 });
106
+ const byId = [...tied].sort((a, b) => (a.id < b.id ? -1 : 1));
107
+ await committed(subject, store, [...[...byId].reverse(), earlier]);
108
+ expect(ids(await store.claim(2))).toEqual([earlier.id, ...ids(byId.slice(0, 1))]);
109
+ expect(ids(await store.claim(10))).toEqual(ids(byId.slice(1)));
110
+ },
111
+ },
112
+ ];
@@ -0,0 +1,65 @@
1
+ // What an outbox-store check is handed — the subject: relays over shared rows, a transaction of
2
+ // the backing store, its clock — and the record and staging helpers every check builds on.
3
+
4
+ import type { Tx } from '@ultimat3/entity';
5
+ import type { OutboxRecord, OutboxStore } from '@ultimat3/jobs';
6
+
7
+ export interface OutboxStoreSubject {
8
+ /**
9
+ * One relay's store over the subject's shared rows. Called once per relay a check plays: a store
10
+ * whose fence token is per instance (`postgresOutboxStore`'s `relayId`) answers a new one each
11
+ * call; one whose token is per claim (`memoryOutboxStore`) may answer itself.
12
+ */
13
+ relay(): OutboxStore;
14
+ /** The `claimLeaseMs` every relay was built with. */
15
+ readonly claimLeaseMs: number;
16
+ /**
17
+ * Run `body` inside a transaction of the backing store that then commits or rolls back, and
18
+ * answer the `Tx` it was handed. The suite calls `commit`/`rollback` on the store after, as the
19
+ * transaction runner does.
20
+ */
21
+ transaction(outcome: 'commit' | 'rollback', body: (tx: Tx) => Promise<void>): Promise<Tx>;
22
+ /** Let `ms` pass for every claim: `clock.advance`, or `claimed_at` moved back by `ms`. */
23
+ readonly elapse: (ms: number) => void | Promise<void>;
24
+ }
25
+
26
+ export interface OutboxStoreCheck {
27
+ readonly name: string;
28
+ run(subject: OutboxStoreSubject): Promise<void>;
29
+ }
30
+
31
+ /** One instant for every staged row: the claim's sort key then ties, and `id` must break it. */
32
+ export const STAGED_AT = Date.UTC(2026, 10, 9, 9, 0, 0);
33
+
34
+ /** A record with every optional field set, so a store that drops one is seen dropping it. */
35
+ export const outboxRecord = (id: string, extra: Partial<OutboxRecord> = {}): OutboxRecord => ({
36
+ id,
37
+ runId: crypto.randomUUID(),
38
+ job: 'conformance.outbox',
39
+ queue: 'conformance',
40
+ input: { id, nested: { at: '2026-11-09' } },
41
+ idempotencyKey: `conformance:${id}`,
42
+ maxAttempts: 4,
43
+ runAt: STAGED_AT + 1_000,
44
+ stagedAt: STAGED_AT,
45
+ tenantId: 'org-conformance',
46
+ traceparent: '00-0af7651916cd43dd8448eb211c80319c-b7ad6b7169203331-01',
47
+ enqueuedBy: 'user-conformance',
48
+ ...extra,
49
+ });
50
+
51
+ /** Stage `records` in one transaction that commits, and answer what `commit` reported. */
52
+ export async function committed(
53
+ subject: OutboxStoreSubject,
54
+ store: OutboxStore,
55
+ records: readonly OutboxRecord[],
56
+ ): Promise<readonly OutboxRecord[]> {
57
+ const tx = await subject.transaction('commit', async (open) => {
58
+ for (const record of records) await store.stage(open, record);
59
+ });
60
+ return store.commit(tx);
61
+ }
62
+
63
+ export const elapse = async (subject: OutboxStoreSubject, ms: number): Promise<void> => {
64
+ await subject.elapse(ms);
65
+ };
@@ -0,0 +1,71 @@
1
+ // The `OutboxStore` contract of `@ultimat3/jobs` as shared examples: `behavesLike(
2
+ // outboxStoreConformance, () => subject)`. A staged row lives or dies with its transaction; a claim
3
+ // is a LEASE fenced on its claimant, so two relays never publish one row and a lapsed one cannot
4
+ // touch a newer claimant's batch. The subject is called once per test and holds no rows.
5
+
6
+ import { expect, test } from 'bun:test';
7
+ import type { OutboxRecord } from '@ultimat3/jobs';
8
+ import { OUTBOX_STORE_CLAIM_CHECKS } from './outbox-store-conformance-claims';
9
+ import type { OutboxStoreCheck, OutboxStoreSubject } from './outbox-store-conformance-subject';
10
+ import { committed, outboxRecord } from './outbox-store-conformance-subject';
11
+ import type { SharedExamples } from './shared-examples';
12
+ import { sharedExamples } from './shared-examples';
13
+
14
+ export type { OutboxStoreCheck, OutboxStoreSubject } from './outbox-store-conformance-subject';
15
+
16
+ const ids = (records: readonly OutboxRecord[]): readonly string[] => records.map((each) => each.id);
17
+
18
+ const STAGE_CHECKS: readonly OutboxStoreCheck[] = [
19
+ {
20
+ name: 'a row staged in a rolled-back transaction is never claimed',
21
+ async run(subject) {
22
+ const store = subject.relay();
23
+ const tx = await subject.transaction('rollback', (open) =>
24
+ store.stage(open, outboxRecord(crypto.randomUUID())),
25
+ );
26
+ await store.rollback(tx);
27
+ expect(await store.claim(10)).toEqual([]);
28
+ expect(await store.pendingCount()).toBe(0);
29
+ },
30
+ },
31
+ {
32
+ name: 'commit reports what was staged; a claim hands each row back whole, claimant stamped',
33
+ async run(subject) {
34
+ const store = subject.relay();
35
+ const records = [outboxRecord(crypto.randomUUID()), outboxRecord(crypto.randomUUID())];
36
+ const sorted = [...records].sort((a, b) => (a.id < b.id ? -1 : 1));
37
+ expect(ids(await committed(subject, store, records))).toEqual(ids(records));
38
+ expect(await store.pendingCount()).toBe(2);
39
+ const claims = await store.claim(10);
40
+ expect(claims).toEqual(sorted.map((each) => ({ ...each, claimedBy: expect.any(String) })));
41
+ expect(new Set(claims.map((each) => each.claimedBy)).size).toBe(1);
42
+ },
43
+ },
44
+ {
45
+ name: 'stageMany, when the store has it, stages every record of one transaction in order',
46
+ async run(subject) {
47
+ const store = subject.relay();
48
+ const stageMany = store.stageMany?.bind(store);
49
+ if (stageMany === undefined) return;
50
+ const records = Array.from({ length: 3 }, () => outboxRecord(crypto.randomUUID()));
51
+ const tx = await subject.transaction('commit', (open) => stageMany(open, records));
52
+ expect(ids(await store.commit(tx))).toEqual(ids(records));
53
+ expect(await store.pendingCount()).toBe(3);
54
+ },
55
+ },
56
+ ];
57
+
58
+ export const OUTBOX_STORE_CHECKS: readonly OutboxStoreCheck[] = [
59
+ ...STAGE_CHECKS,
60
+ ...OUTBOX_STORE_CLAIM_CHECKS,
61
+ ];
62
+
63
+ export const outboxStoreConformance: SharedExamples<
64
+ OutboxStoreSubject | Promise<OutboxStoreSubject>
65
+ > = sharedExamples('an outbox store', (subject) => {
66
+ for (const check of OUTBOX_STORE_CHECKS) {
67
+ test(check.name, async () => {
68
+ await check.run(await subject());
69
+ });
70
+ }
71
+ });