@ultimat3/testing 31.13.0 → 31.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ultimat3/testing",
3
- "version": "31.13.0",
3
+ "version": "31.14.0",
4
4
  "description": "Test harness: cloned template DBs per worker, frozen clock, sealed network, 6 test types",
5
5
  "keywords": [
6
6
  "ultimate",
@@ -47,26 +47,26 @@
47
47
  "test": "bun test"
48
48
  },
49
49
  "dependencies": {
50
- "@ultimat3/action": "31.13.0",
51
- "@ultimat3/ai": "31.13.0",
52
- "@ultimat3/auth": "31.13.0",
53
- "@ultimat3/cache": "31.13.0",
54
- "@ultimat3/core": "31.13.0",
55
- "@ultimat3/db": "31.13.0",
56
- "@ultimat3/entity": "31.13.0",
57
- "@ultimat3/http": "31.13.0",
58
- "@ultimat3/i18n": "31.13.0",
59
- "@ultimat3/jobs": "31.13.0",
60
- "@ultimat3/mail": "31.13.0",
61
- "@ultimat3/notify": "31.13.0",
62
- "@ultimat3/policy": "31.13.0",
63
- "@ultimat3/pwa": "31.13.0",
64
- "@ultimat3/query": "31.13.0",
65
- "@ultimat3/realtime": "31.13.0",
66
- "@ultimat3/render": "31.13.0",
67
- "@ultimat3/schema": "31.13.0",
68
- "@ultimat3/scraping": "31.13.0",
69
- "@ultimat3/seo": "31.13.0",
70
- "@ultimat3/time": "31.13.0"
50
+ "@ultimat3/action": "31.14.0",
51
+ "@ultimat3/ai": "31.14.0",
52
+ "@ultimat3/auth": "31.14.0",
53
+ "@ultimat3/cache": "31.14.0",
54
+ "@ultimat3/core": "31.14.0",
55
+ "@ultimat3/db": "31.14.0",
56
+ "@ultimat3/entity": "31.14.0",
57
+ "@ultimat3/http": "31.14.0",
58
+ "@ultimat3/i18n": "31.14.0",
59
+ "@ultimat3/jobs": "31.14.0",
60
+ "@ultimat3/mail": "31.14.0",
61
+ "@ultimat3/notify": "31.14.0",
62
+ "@ultimat3/policy": "31.14.0",
63
+ "@ultimat3/pwa": "31.14.0",
64
+ "@ultimat3/query": "31.14.0",
65
+ "@ultimat3/realtime": "31.14.0",
66
+ "@ultimat3/render": "31.14.0",
67
+ "@ultimat3/schema": "31.14.0",
68
+ "@ultimat3/scraping": "31.14.0",
69
+ "@ultimat3/seo": "31.14.0",
70
+ "@ultimat3/time": "31.14.0"
71
71
  }
72
72
  }
@@ -0,0 +1,184 @@
1
+ // What a debounce must survive besides a live holder: its OWN request published again (the outbox
2
+ // relay crashed before its mark), its holder finished in between, and a newer request's expiry —
3
+ // plus what `x jobs retry` must forget. A driver that re-ran a stale replace compiled and ran old
4
+ // input. Type-only imports from `@ultimat3/jobs`: the barrel never loads it.
5
+
6
+ import { expect } from 'bun:test';
7
+ import { finiteCount, uuidV7 } from '@ultimat3/core';
8
+ import type { JobDriver, JobRecord } from '@ultimat3/jobs';
9
+ import type { JobDriverCheck } from './job-driver-checks';
10
+
11
+ let minted = 0;
12
+
13
+ /** As `job-driver-checks-enqueue.ts`: instants the database's clock and a frozen one agree on. */
14
+ const LONG_AGO = 1;
15
+ const FAR_AHEAD = Date.UTC(9999, 0, 1);
16
+
17
+ /** A queue and a job name of this check's own, so checks sharing one store never see each other. */
18
+ const scope = (): { readonly queue: string; readonly name: string } => {
19
+ minted += 1;
20
+ const tag = `${process.pid.toString(36)}-d${minted.toString(36)}`;
21
+ return { queue: `conformance-${tag}`, name: `conformance.job-${tag}` };
22
+ };
23
+
24
+ const claimAll = (
25
+ driver: JobDriver,
26
+ queue: string,
27
+ extra: { visibilityTimeoutMs?: number; onExhausted?: (rows: readonly JobRecord[]) => void } = {},
28
+ ) =>
29
+ driver.claim({
30
+ queues: [queue],
31
+ limit: 10,
32
+ visibilityTimeoutMs: finiteCount(
33
+ 'claimAll',
34
+ 'visibilityTimeoutMs',
35
+ extra.visibilityTimeoutMs ?? 30_000,
36
+ ),
37
+ workerId: 'w-debounce',
38
+ ...(extra.onExhausted === undefined ? {} : { onExhausted: extra.onExhausted }),
39
+ });
40
+
41
+ export const DEBOUNCE_CHECKS: readonly JobDriverCheck[] = [
42
+ {
43
+ name: 'a replace published again never overwrites the newer replace that landed after it',
44
+ async run(driver) {
45
+ const at = scope();
46
+ const base = { name: at.name, queue: at.queue, idempotencyKey: 'fenced', maxAttempts: 3 };
47
+ const holder = await driver.enqueue({ ...base, input: { v: 1 }, runAt: FAR_AHEAD });
48
+ // Two staged rows, in staged order — the outbox mints each id at stage time.
49
+ const older = uuidV7();
50
+ const newer = uuidV7();
51
+ const replace = { ...base, onConflict: 'replace' as const };
52
+ await driver.enqueue({ ...replace, id: older, input: { v: 2 }, runAt: FAR_AHEAD });
53
+ await driver.enqueue({ ...replace, id: newer, input: { v: 3 }, runAt: LONG_AGO });
54
+ // The relay publishing each a second time — `older` LAST, the order a lapsed relay lease
55
+ // allows: answered as the dedupe it is, and nothing moved.
56
+ for (const [id, v] of [
57
+ [newer, 3],
58
+ [older, 2],
59
+ ] as const) {
60
+ const repeat = await driver.enqueue({ ...replace, id, input: { v }, runAt: 1 });
61
+ expect({ id: repeat.id, deduped: repeat.deduped }).toEqual({
62
+ id: holder.id,
63
+ deduped: true,
64
+ });
65
+ }
66
+ const taken = await claimAll(driver, at.queue);
67
+ expect(taken.map((row) => [row.id, row.input])).toEqual([[holder.id, { v: 3 }]]);
68
+ },
69
+ },
70
+ {
71
+ name: 'a replace published again after its holder finished inserts no second, stale run',
72
+ async run(driver) {
73
+ const at = scope();
74
+ const base = { name: at.name, queue: at.queue, idempotencyKey: 'finished', maxAttempts: 3 };
75
+ const replace = { ...base, onConflict: 'replace' as const };
76
+ const stale = uuidV7();
77
+ const holder = await driver.enqueue({ ...replace, input: { v: 1 }, runAt: LONG_AGO });
78
+ const landed = uuidV7();
79
+ await driver.enqueue({ ...replace, id: landed, input: { v: 2 }, runAt: LONG_AGO });
80
+ const [taken] = await claimAll(driver, at.queue);
81
+ if (taken === undefined) return expect.unreachable('the holder was claimable');
82
+ expect(taken.input).toEqual({ v: 2 });
83
+ expect(await driver.ack(taken.id, { workerId: 'w-debounce', claim: taken.claim })).toBe(true);
84
+ // The landed replace, published again, and one staged before the holder was ever made.
85
+ for (const id of [landed, stale]) {
86
+ const repeat = await driver.enqueue({ ...replace, id, input: { v: 0 }, runAt: LONG_AGO });
87
+ expect({ id: repeat.id, deduped: repeat.deduped }).toEqual({
88
+ id: holder.id,
89
+ deduped: true,
90
+ });
91
+ }
92
+ expect(await claimAll(driver, at.queue)).toEqual([]);
93
+ // A NEW request after the run is new work, as it always was.
94
+ const fresh = await driver.enqueue({ ...replace, input: { v: 4 }, runAt: LONG_AGO });
95
+ expect(fresh.deduped).toBe(false);
96
+ },
97
+ },
98
+ {
99
+ name: "a replace takes the newer request's expiresAt, or its absence",
100
+ async run(driver) {
101
+ const at = scope();
102
+ const replace = {
103
+ name: at.name,
104
+ queue: at.queue,
105
+ maxAttempts: 3,
106
+ onConflict: 'replace' as const,
107
+ runAt: LONG_AGO,
108
+ };
109
+ // Lapsed at first, then the newer request says the work is worth something until 9999.
110
+ const revived = await driver.enqueue({ ...replace, idempotencyKey: 'a', input: { v: 1 } });
111
+ await driver.enqueue({ ...replace, idempotencyKey: 'a', input: { v: 2 }, expiresAt: 1 });
112
+ await driver.enqueue({
113
+ ...replace,
114
+ idempotencyKey: 'a',
115
+ input: { v: 3 },
116
+ expiresAt: FAR_AHEAD,
117
+ });
118
+ // Never expiring at first, then the newer request is already worthless.
119
+ const lapsed = await driver.enqueue({ ...replace, idempotencyKey: 'b', input: { v: 1 } });
120
+ await driver.enqueue({ ...replace, idempotencyKey: 'b', input: { v: 2 }, expiresAt: 1 });
121
+ // A third key: an expiry, then a newer request with none at all clears it.
122
+ const cleared = await driver.enqueue({
123
+ ...replace,
124
+ idempotencyKey: 'c',
125
+ input: { v: 1 },
126
+ expiresAt: 1,
127
+ });
128
+ await driver.enqueue({ ...replace, idempotencyKey: 'c', input: { v: 2 } });
129
+ const buried: string[] = [];
130
+ const taken = await claimAll(driver, at.queue, {
131
+ onExhausted: (rows) => buried.push(...rows.map((row) => row.id)),
132
+ });
133
+ expect(taken.map((row) => row.id).sort()).toEqual([revived.id, cleared.id].sort());
134
+ expect(buried).toEqual([lapsed.id]);
135
+ },
136
+ },
137
+ {
138
+ name: 'x jobs retry forgets an expiry: a requeued row runs instead of being buried again',
139
+ async run(driver) {
140
+ const requeue = driver.introspect?.requeue;
141
+ // A driver without the operator surface has no retry to check.
142
+ if (requeue === undefined) return;
143
+ const at = scope();
144
+ const { id } = await driver.enqueue({
145
+ name: at.name,
146
+ queue: at.queue,
147
+ input: {},
148
+ idempotencyKey: 'expired',
149
+ maxAttempts: 3,
150
+ expiresAt: LONG_AGO,
151
+ });
152
+ expect(await claimAll(driver, at.queue)).toEqual([]);
153
+ await requeue(id);
154
+ const taken = await claimAll(driver, at.queue);
155
+ expect(taken.map((row) => row.id)).toEqual([id]);
156
+ },
157
+ },
158
+ {
159
+ name: 'x jobs retry forgets an onSettled debt: a requeued row is not re-told its old ending',
160
+ async run(driver) {
161
+ const requeue = driver.introspect?.requeue;
162
+ const debt = driver.settleDebt;
163
+ if (requeue === undefined || debt === undefined) return;
164
+ const at = scope();
165
+ const { id } = await driver.enqueue({
166
+ name: at.name,
167
+ queue: at.queue,
168
+ input: {},
169
+ idempotencyKey: 'owed',
170
+ maxAttempts: 1,
171
+ });
172
+ const [first] = await claimAll(driver, at.queue);
173
+ if (first === undefined) return expect.unreachable('the row was claimable');
174
+ const by = { workerId: 'w-debounce', claim: first.claim, owesSettle: true };
175
+ expect(await driver.ack(id, by)).toBe(true);
176
+ await requeue(id);
177
+ // Claimed with no lease to speak of, then buried by the next claim: an ending no settle wrote,
178
+ // so whatever debt the row still carries is the old run's.
179
+ await claimAll(driver, at.queue, { visibilityTimeoutMs: 0 });
180
+ await claimAll(driver, at.queue);
181
+ expect(await debt.takeLost([{ name: at.name, graceMs: 0 }], 10)).toEqual([]);
182
+ },
183
+ },
184
+ ];
@@ -0,0 +1,138 @@
1
+ // What every `JobDriver`'s enqueue does past "insert or dedupe": debounce (`onConflict: 'replace'`),
2
+ // expiry (`expiresAt`, settled by the claim), the backlog count `maxPending` reads and the key probe
3
+ // (`holds`) it asks once full. A driver that ignored any of them compiled, and ran a stale input, a
4
+ // worthless job, or an unbounded queue. Type-only imports: the barrel never loads `@ultimat3/jobs`.
5
+
6
+ import { expect } from 'bun:test';
7
+ import type { JobDriver, JobRecord } from '@ultimat3/jobs';
8
+ import type { JobDriverCheck } from './job-driver-checks';
9
+
10
+ let minted = 0;
11
+
12
+ /**
13
+ * Instants no clock disagrees about. The test process's `Date` may be frozen by its preload while
14
+ * the database answers its own `now()`, so "past" and "future" are the epoch and the year 9999.
15
+ */
16
+ const LONG_AGO = 1;
17
+ const FAR_AHEAD = Date.UTC(9999, 0, 1);
18
+
19
+ /** A queue and a job name of this check's own, so checks sharing one store never see each other. */
20
+ const scope = (): { readonly queue: string; readonly name: string } => {
21
+ minted += 1;
22
+ const tag = `${process.pid.toString(36)}-e${minted.toString(36)}`;
23
+ return { queue: `conformance-${tag}`, name: `conformance.job-${tag}` };
24
+ };
25
+
26
+ const claimOne = (
27
+ driver: JobDriver,
28
+ queue: string,
29
+ onExhausted?: (rows: readonly JobRecord[]) => void,
30
+ ) =>
31
+ driver.claim({
32
+ queues: [queue],
33
+ limit: 10,
34
+ visibilityTimeoutMs: 30_000,
35
+ workerId: 'w-enqueue',
36
+ ...(onExhausted === undefined ? {} : { onExhausted }),
37
+ });
38
+
39
+ export const ENQUEUE_CHECKS: readonly JobDriverCheck[] = [
40
+ {
41
+ name: "onConflict: 'replace' gives a waiting holder the new input and runAt, never a running one",
42
+ async run(driver) {
43
+ const at = scope();
44
+ const base = { name: at.name, queue: at.queue, idempotencyKey: 'debounced', maxAttempts: 3 };
45
+ const first = await driver.enqueue({ ...base, input: { v: 1 }, runAt: FAR_AHEAD });
46
+ // Delayed: nothing to claim yet.
47
+ expect(await claimOne(driver, at.queue)).toEqual([]);
48
+ const second = await driver.enqueue({
49
+ ...base,
50
+ input: { v: 2 },
51
+ runAt: LONG_AGO,
52
+ onConflict: 'replace',
53
+ });
54
+ expect({ id: second.id, deduped: second.deduped }).toEqual({ id: first.id, deduped: true });
55
+ // The SAME row, now due, carrying the replacing input.
56
+ const [taken] = await claimOne(driver, at.queue);
57
+ expect(taken?.id).toBe(first.id);
58
+ expect(taken?.input).toEqual({ v: 2 });
59
+ // Running: past replacing. Answered as a dedupe, and the run keeps its input.
60
+ const third = await driver.enqueue({ ...base, input: { v: 3 }, onConflict: 'replace' });
61
+ expect({ id: third.id, deduped: third.deduped }).toEqual({ id: first.id, deduped: true });
62
+ if (taken === undefined) return expect.unreachable('the replaced row was claimable');
63
+ const by = { workerId: 'w-enqueue', claim: taken.claim, delayMs: 0, countsAsAttempt: false };
64
+ expect(await driver.nack(taken.id, by)).toBe(true);
65
+ const [again] = await claimOne(driver, at.queue);
66
+ expect(again?.input).toEqual({ v: 2 });
67
+ },
68
+ },
69
+ {
70
+ name: 'a waiting row past its expiresAt is settled failed by the claim, reported, never run',
71
+ async run(driver) {
72
+ const at = scope();
73
+ const base = { name: at.name, queue: at.queue, input: {}, maxAttempts: 3 };
74
+ const lapsed = await driver.enqueue({
75
+ ...base,
76
+ idempotencyKey: 'lapsed',
77
+ expiresAt: LONG_AGO,
78
+ });
79
+ const fresh = await driver.enqueue({
80
+ ...base,
81
+ idempotencyKey: 'fresh',
82
+ expiresAt: FAR_AHEAD,
83
+ });
84
+ const buried: (readonly [string, string, string | undefined])[] = [];
85
+ const report = (rows: readonly JobRecord[]): void => {
86
+ for (const row of rows) buried.push([row.id, row.state, row.lastError]);
87
+ };
88
+ const taken = await claimOne(driver, at.queue, report);
89
+ expect(taken.map((row) => row.id)).toEqual([fresh.id]);
90
+ expect(buried).toEqual([[lapsed.id, 'failed', 'expired']]);
91
+ // Settled for good: the next claim neither hands it out nor reports it again.
92
+ buried.length = 0;
93
+ expect(await claimOne(driver, at.queue, report)).toEqual([]);
94
+ expect(buried).toEqual([]);
95
+ },
96
+ },
97
+ {
98
+ name: 'backlog counts the ready and delayed rows of one queue, no further than its cap',
99
+ async run(driver) {
100
+ if (driver.backlog === undefined) return expect.unreachable('the driver counts no backlog');
101
+ const at = scope();
102
+ const base = { name: at.name, queue: at.queue, input: {}, maxAttempts: 3 };
103
+ await driver.enqueue({ ...base, idempotencyKey: 'a' });
104
+ await driver.enqueue({ ...base, idempotencyKey: 'b' });
105
+ await driver.enqueue({ ...base, idempotencyKey: 'c', runAt: FAR_AHEAD });
106
+ expect(await driver.backlog(at.queue, 10)).toBe(3);
107
+ await driver.claim({
108
+ queues: [at.queue],
109
+ limit: 1,
110
+ visibilityTimeoutMs: 30_000,
111
+ workerId: 'w-backlog',
112
+ });
113
+ // The running row no longer waits.
114
+ expect(await driver.backlog(at.queue, 10)).toBe(2);
115
+ expect(await driver.backlog(at.queue, 1)).toBe(1);
116
+ expect(await driver.backlog(scope().queue, 10)).toBe(0);
117
+ },
118
+ },
119
+ {
120
+ name: 'holds answers whether a live row of that name and tenant holds the key',
121
+ async run(driver) {
122
+ if (driver.holds === undefined) return expect.unreachable('the driver answers no holds');
123
+ const at = scope();
124
+ const base = { name: at.name, queue: at.queue, input: {}, maxAttempts: 3 };
125
+ await driver.enqueue({ ...base, idempotencyKey: 'held', tenantId: 'org-1' });
126
+ expect(await driver.holds(at.name, 'held', 'org-1')).toBe(true);
127
+ // Another tenant's, another job's and an unheld key are not held.
128
+ expect(await driver.holds(at.name, 'held')).toBe(false);
129
+ expect(await driver.holds(scope().name, 'held', 'org-1')).toBe(false);
130
+ expect(await driver.holds(at.name, 'free', 'org-1')).toBe(false);
131
+ // A finished row holds nothing.
132
+ const [row] = await claimOne(driver, at.queue);
133
+ if (row === undefined) return expect.unreachable('the row was claimable');
134
+ await driver.ack(row.id, { workerId: 'w-enqueue', claim: row.claim });
135
+ expect(await driver.holds(at.name, 'held', 'org-1')).toBe(false);
136
+ },
137
+ },
138
+ ];
@@ -0,0 +1,96 @@
1
+ // What every `JobDriver` records for `onSettled` (J11): a settle that ENDS a run of a job with a
2
+ // hook owes it, the hook's return clears the debt under that claim, and a debt a crash left is
3
+ // taken once per grace. A driver with no `settleDebt` runs the hook at most once, and fails here.
4
+ // Type-only imports: the barrel never loads `@ultimat3/jobs`.
5
+
6
+ import { expect } from 'bun:test';
7
+ import type { JobDriver, SettleDebt } from '@ultimat3/jobs';
8
+ import type { JobDriverCheck } from './job-driver-checks';
9
+
10
+ let minted = 0;
11
+
12
+ /** A queue and a job name of this check's own, so checks sharing one store never see each other. */
13
+ const scope = (): { readonly queue: string; readonly name: string } => {
14
+ minted += 1;
15
+ const tag = `${process.pid.toString(36)}-s${minted.toString(36)}`;
16
+ return { queue: `conformance-${tag}`, name: `conformance.job-${tag}` };
17
+ };
18
+
19
+ /** One fresh row of `name` on `queue`, claimed by `workerId`. */
20
+ async function claimedRow(
21
+ driver: JobDriver,
22
+ at: { readonly queue: string; readonly name: string },
23
+ key: string,
24
+ ): Promise<{ readonly id: string; readonly by: { workerId: string; claim: number } }> {
25
+ await driver.enqueue({
26
+ name: at.name,
27
+ queue: at.queue,
28
+ input: {},
29
+ idempotencyKey: key,
30
+ maxAttempts: 3,
31
+ });
32
+ const [row] = await driver.claim({
33
+ queues: [at.queue],
34
+ limit: 1,
35
+ visibilityTimeoutMs: 30_000,
36
+ workerId: 'w-settle',
37
+ });
38
+ if (row === undefined) return expect.unreachable('the row is claimable');
39
+ return { id: row.id, by: { workerId: 'w-settle', claim: row.claim } };
40
+ }
41
+
42
+ const debtOf = (driver: JobDriver): SettleDebt => {
43
+ if (driver.settleDebt === undefined) {
44
+ return expect.unreachable('the driver has no settleDebt: onSettled would run at most once');
45
+ }
46
+ return driver.settleDebt;
47
+ };
48
+
49
+ /** The ids `takeLost` hands out for `name`, with a grace of `graceMs`. */
50
+ const lost = async (debt: SettleDebt, name: string, graceMs = 0): Promise<readonly string[]> =>
51
+ (await debt.takeLost([{ name, graceMs }], 50)).map((row) => row.id);
52
+
53
+ export const SETTLE_DEBT_CHECKS: readonly JobDriverCheck[] = [
54
+ {
55
+ name: 'an ending settle of a hooked job owes onSettled until cleared under its claim',
56
+ async run(driver) {
57
+ const debt = debtOf(driver);
58
+ const at = scope();
59
+ const acked = await claimedRow(driver, at, 'acked');
60
+ expect(await driver.ack(acked.id, { ...acked.by, owesSettle: true })).toBe(true);
61
+ const dead = await claimedRow(driver, at, 'dead');
62
+ expect(
63
+ await driver.nack(dead.id, { ...dead.by, delayMs: 0, deadLetter: true, owesSettle: true }),
64
+ ).toBe(true);
65
+ // Owed, and TAKEN: inside the grace a second pass hands neither out again.
66
+ expect([...(await lost(debt, at.name))].sort()).toEqual([acked.id, dead.id].sort());
67
+ expect(await lost(debt, at.name, 60_000)).toEqual([]);
68
+ // Never for a name this deploy has no hook for.
69
+ expect(await lost(debt, `${at.name}-other`)).toEqual([]);
70
+ // A clear under another claim pays nothing; under its own, the debt is gone for good.
71
+ expect(await debt.clear(acked.id, acked.by.claim + 1)).toBe(false);
72
+ expect(await debt.clear(acked.id, acked.by.claim)).toBe(true);
73
+ expect(await debt.clear(acked.id, acked.by.claim)).toBe(false);
74
+ expect(await lost(debt, at.name)).toEqual([dead.id]);
75
+ const [row] = await debt.takeLost([{ name: at.name, graceMs: 0 }], 50);
76
+ expect(row?.state).toBe('dead');
77
+ expect(row?.claim).toBe(dead.by.claim);
78
+ },
79
+ },
80
+ {
81
+ name: 'a retry, a suspension and an un-hooked settle owe nothing',
82
+ async run(driver) {
83
+ const debt = debtOf(driver);
84
+ const at = scope();
85
+ const retried = await claimedRow(driver, at, 'retried');
86
+ expect(await driver.nack(retried.id, { ...retried.by, delayMs: 0, owesSettle: true })).toBe(
87
+ true,
88
+ );
89
+ const parked = await claimedRow(driver, at, 'parked');
90
+ await driver.nack(parked.id, { ...parked.by, delayMs: 0, park: true, owesSettle: true });
91
+ const plain = await claimedRow(driver, at, 'plain');
92
+ expect(await driver.ack(plain.id, plain.by)).toBe(true);
93
+ expect(await lost(debt, at.name)).toEqual([]);
94
+ },
95
+ },
96
+ ];
@@ -6,6 +6,9 @@
6
6
  import { expect } from 'bun:test';
7
7
  import type { ClaimOptions, JobDriver, JobRecord, QueueStats } from '@ultimat3/jobs';
8
8
  import { CLAIM_ANSWER_CHECKS } from './job-driver-checks-claim';
9
+ import { DEBOUNCE_CHECKS } from './job-driver-checks-debounce';
10
+ import { ENQUEUE_CHECKS } from './job-driver-checks-enqueue';
11
+ import { SETTLE_DEBT_CHECKS } from './job-driver-checks-settle';
9
12
 
10
13
  export interface JobDriverCheck {
11
14
  readonly name: string;
@@ -176,4 +179,7 @@ export const JOB_DRIVER_CHECKS: readonly JobDriverCheck[] = [
176
179
  },
177
180
  },
178
181
  ...CLAIM_ANSWER_CHECKS,
182
+ ...ENQUEUE_CHECKS,
183
+ ...DEBOUNCE_CHECKS,
184
+ ...SETTLE_DEBT_CHECKS,
179
185
  ];
@@ -1,14 +1,14 @@
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.
1
+ // `OutboxStore` contract of `@ultimat3/jobs` as shared examples (`behavesLike(outboxStoreConformance,
2
+ // () => subject)`; one fresh, empty subject per test). A staged row lives or dies with its
3
+ // transaction; a claim is a LEASE fenced on its claimant, so two relays never publish one row nor a
4
+ // lapsed one touch a newer batch; a debounced or expiring row keeps both through the claim.
5
5
 
6
6
  import { expect, test } from 'bun:test';
7
7
  import type { OutboxRecord } from '@ultimat3/jobs';
8
8
  import { OUTBOX_STORE_CLAIM_CHECKS } from './outbox-store-conformance-claims';
9
9
  import { OUTBOX_STORE_HORIZON_CHECKS } from './outbox-store-conformance-horizon';
10
10
  import type { OutboxStoreCheck, OutboxStoreSubject } from './outbox-store-conformance-subject';
11
- import { committed, outboxRecord } from './outbox-store-conformance-subject';
11
+ import { committed, outboxRecord, STAGED_AT } from './outbox-store-conformance-subject';
12
12
  import type { SharedExamples } from './shared-examples';
13
13
  import { sharedExamples } from './shared-examples';
14
14
 
@@ -54,6 +54,31 @@ const STAGE_CHECKS: readonly OutboxStoreCheck[] = [
54
54
  expect(await store.pendingCount()).toBe(3);
55
55
  },
56
56
  },
57
+ {
58
+ // Debounce and expiry enqueued inside a transaction: a store that drops either hands the relay
59
+ // a plain row, and the job runs with a stale input, or after its work stopped being worth it.
60
+ name: "a staged row keeps onConflict: 'replace' and expiresAt, through stage and stageMany",
61
+ async run(subject) {
62
+ const store = subject.relay();
63
+ const debounced = { onConflict: 'replace', expiresAt: STAGED_AT + 60_000 } as const;
64
+ const one = outboxRecord(crypto.randomUUID(), debounced);
65
+ const plain = outboxRecord(crypto.randomUUID());
66
+ await committed(subject, store, [one, plain]);
67
+ const many = [outboxRecord(crypto.randomUUID(), { ...debounced, stagedAt: STAGED_AT + 1 })];
68
+ const stageMany = store.stageMany?.bind(store);
69
+ if (stageMany !== undefined) {
70
+ await store.commit(await subject.transaction('commit', (open) => stageMany(open, many)));
71
+ }
72
+ const claims = await store.claim(10);
73
+ const expected = [one, plain, ...(stageMany === undefined ? [] : many)];
74
+ const byId = (id: string) => claims.find((each) => each.id === id);
75
+ for (const record of expected) {
76
+ expect(byId(record.id)).toEqual({ ...record, claimedBy: expect.any(String) });
77
+ }
78
+ expect(Object.keys(byId(plain.id) ?? {})).not.toContain('onConflict');
79
+ expect(Object.keys(byId(plain.id) ?? {})).not.toContain('expiresAt');
80
+ },
81
+ },
57
82
  ];
58
83
 
59
84
  export const OUTBOX_STORE_CHECKS: readonly OutboxStoreCheck[] = [