@ultimat3/testing 30.9.0 → 31.1.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/CLAUDE.md +46 -55
- package/README.md +179 -39
- package/package.json +23 -17
- package/src/ai-conformance-answer.ts +67 -0
- package/src/ai-gateway-conformance.ts +105 -0
- package/src/ai-provider-conformance.ts +69 -0
- package/src/ai-provider-transport-conformance.ts +170 -0
- package/src/audit-sink-conformance.ts +204 -0
- package/src/auth-adapter-conformance-credentials.ts +124 -0
- package/src/auth-adapter-conformance-mfa.ts +70 -0
- package/src/auth-adapter-conformance-passkeys.ts +133 -0
- package/src/auth-adapter-conformance-sessions.ts +115 -0
- package/src/auth-adapter-conformance-support.ts +71 -0
- package/src/auth-adapter-conformance-users.ts +128 -0
- package/src/auth-adapter-conformance.ts +34 -0
- package/src/auth-limiter-factory-conformance.ts +224 -0
- package/src/auth-server-store-conformance-records.ts +69 -0
- package/src/auth-server-store-conformance.ts +208 -0
- package/src/cache-tier-conformance-checks.ts +142 -0
- package/src/cache-tier-conformance.ts +24 -0
- package/src/cassette-format.ts +8 -13
- package/src/cassette-record.ts +1 -1
- package/src/cdp-browser.ts +10 -11
- package/src/cdp-e2e-page.ts +2 -2
- package/src/cdp-e2e-session.ts +2 -2
- package/src/cdp-network-probe.ts +1 -1
- package/src/cdp-offline-script.ts +2 -2
- package/src/clock-conformance.ts +126 -0
- package/src/conformance.ts +239 -0
- package/src/e2e-browser-handle.ts +1 -2
- package/src/e2e-error-codes.ts +17 -16
- package/src/e2e-run.ts +4 -3
- package/src/embedder-conformance.ts +101 -0
- package/src/entity-conformance-aggregates.ts +210 -0
- package/src/entity-conformance-batches.ts +216 -0
- package/src/entity-conformance-bulk.ts +379 -0
- package/src/entity-conformance-checks.ts +27 -0
- package/src/entity-conformance-entities.ts +52 -0
- package/src/entity-conformance-locks.ts +286 -0
- package/src/entity-conformance-matrix.ts +397 -0
- package/src/entity-conformance-reads.ts +241 -0
- package/src/entity-conformance-support.ts +56 -0
- package/src/entity-conformance-tenancy.ts +296 -0
- package/src/entity-conformance-values.ts +305 -0
- package/src/entity-conformance-versions.ts +60 -0
- package/src/entity-conformance-writes.ts +348 -0
- package/src/entity-driver-conformance.ts +103 -0
- package/src/error-groups-store-conformance.ts +198 -0
- package/src/error-reporter-conformance.ts +119 -0
- package/src/errors.ts +20 -2
- package/src/event-bus-conformance.ts +161 -0
- package/src/exercise-drift-hint.ts +4 -1
- package/src/exercise-judge.ts +5 -3
- package/src/exercise-override-line.ts +98 -0
- package/src/exercise-report.ts +138 -115
- package/src/exercise-room-mail.ts +40 -0
- package/src/exercise.ts +33 -29
- package/src/factories.ts +192 -179
- package/src/factory-api.ts +131 -0
- package/src/factory-associations.ts +67 -0
- package/src/factory-errors.ts +38 -0
- package/src/factory-lint.ts +92 -0
- package/src/factory-persist.ts +74 -16
- package/src/factory-pipeline.ts +191 -0
- package/src/factory-registry.ts +2 -1
- package/src/factory-types.ts +131 -0
- package/src/failure-store-conformance.ts +137 -0
- package/src/fixture-jobs.ts +27 -11
- package/src/fixture-mail.ts +7 -7
- package/src/fixture-seed.ts +111 -0
- package/src/fixture-statements.ts +68 -52
- package/src/framework-fixtures.ts +1 -1
- package/src/idempotency-store-conformance.ts +186 -0
- package/src/idempotency-store-replay-conformance.ts +140 -0
- package/src/idempotency-store-tx-conformance.ts +132 -0
- package/src/idempotency-store-world-conformance.ts +82 -0
- package/src/identity-provider-conformance.ts +144 -0
- package/src/image-transform-conformance.ts +89 -0
- package/src/index.ts +68 -157
- package/src/isr-store-conformance.ts +113 -0
- package/src/job-sim-effects.ts +19 -31
- package/src/job-sim-world.ts +6 -15
- package/src/lease-store-conformance.ts +195 -0
- package/src/mail-driver-conformance.ts +108 -0
- package/src/matcher-doubles.ts +104 -0
- package/src/matcher-stub.ts +78 -0
- package/src/matcher-surface.ts +21 -0
- package/src/matchers.ts +19 -1
- package/src/mcp-confirmation-store-conformance.ts +262 -0
- package/src/meter-store-conformance.ts +135 -0
- package/src/notify-digest-conformance.ts +133 -0
- package/src/notify-inbox-conformance.ts +130 -0
- package/src/notify-ledger-conformance.ts +134 -0
- package/src/notify-preference-conformance.ts +49 -0
- package/src/notify-stores-conformance.ts +73 -0
- package/src/outbox-store-conformance-claims.ts +112 -0
- package/src/outbox-store-conformance-subject.ts +65 -0
- package/src/outbox-store-conformance.ts +71 -0
- package/src/per-test-reset.ts +55 -20
- package/src/preload.ts +4 -2
- package/src/purge-conformance.ts +79 -0
- package/src/push-device-conformance.ts +124 -0
- package/src/push-subscription-conformance.ts +123 -0
- package/src/quiet-logs.ts +4 -4
- package/src/rate-limit-store-conformance.ts +178 -0
- package/src/registry-leak-error.ts +8 -1
- package/src/scale-sweep-run.ts +6 -9
- package/src/scrape-driver-conformance-frame-checks.ts +97 -0
- package/src/scrape-driver-conformance-page-checks.ts +114 -0
- package/src/scrape-driver-conformance-site.ts +84 -0
- package/src/scrape-driver-conformance.ts +34 -0
- package/src/sealed-network.ts +20 -2
- package/src/search-index-conformance-list.ts +76 -0
- package/src/search-index-conformance-support.ts +69 -0
- package/src/search-index-conformance-versions.ts +66 -0
- package/src/search-index-conformance.ts +126 -0
- package/src/secret-source-conformance.ts +91 -0
- package/src/seed-factories.ts +57 -0
- package/src/seed-writer.ts +8 -19
- package/src/semantic-cache-factory-conformance.ts +86 -0
- package/src/sms-transport-conformance.ts +102 -0
- package/src/step-store-conformance.ts +171 -0
- package/src/storage-conformance-read-checks.ts +132 -0
- package/src/storage-conformance-shape.ts +121 -0
- package/src/storage-conformance-stream-checks.ts +226 -0
- package/src/storage-conformance.ts +34 -0
- package/src/stub-action.ts +24 -0
- package/src/stub-errors.ts +86 -0
- package/src/stub-job.ts +30 -0
- package/src/stub-query.ts +25 -0
- package/src/stub-script.ts +76 -0
- package/src/stub-stack.ts +29 -0
- package/src/stub.ts +73 -0
- package/src/swap-adapter.ts +135 -0
- package/src/test-scope.ts +96 -0
- package/src/test-types.ts +1 -1
- package/src/totp-replay-guard-conformance.ts +76 -0
- package/src/transport-conformance.ts +179 -0
- package/src/upload-scanner-conformance.ts +112 -0
- package/src/vector-store-conformance-checks.ts +174 -0
- package/src/vector-store-conformance.ts +21 -0
- package/src/cdp-connection.ts +0 -291
- package/src/cdp-errors.ts +0 -179
- package/src/cdp-launch-attempt.ts +0 -224
- package/src/cdp-launch-candidates.ts +0 -62
- package/src/cdp-launch-profile.ts +0 -106
- package/src/cdp-launch-reap.ts +0 -68
- package/src/cdp-launch-wire.ts +0 -171
- package/src/cdp-launch.ts +0 -175
- package/src/cdp-pipe.ts +0 -77
- package/src/cdp-wire-watch.ts +0 -113
|
@@ -0,0 +1,379 @@
|
|
|
1
|
+
// Entity conformance · MANY-ROW writes: all or nothing past the bind ceiling, an upsert that
|
|
2
|
+
// overwrites only what the caller named, a merge judged before it lands, a soft delete judged as
|
|
3
|
+
// the update it is, an append-only table refusing every rewrite, and a seed upsert's bookkeeping.
|
|
4
|
+
// Lifted from `entity/src/{bulk-write,append-only,write}-parity.test.ts`.
|
|
5
|
+
|
|
6
|
+
import { expect } from 'bun:test';
|
|
7
|
+
import type { Repo, RowPatch } from '@ultimat3/entity';
|
|
8
|
+
import { defineSeed, entity, integer, invariant, text, timestamp, uuid } from '@ultimat3/entity';
|
|
9
|
+
import { remember } from './entity-conformance-entities';
|
|
10
|
+
import { checkOver, codeOf, idAt } from './entity-conformance-support';
|
|
11
|
+
import { countries } from './entity-conformance-writes';
|
|
12
|
+
import type { EntityDriverCheck } from './entity-driver-conformance';
|
|
13
|
+
|
|
14
|
+
/** Primary key only: memory's unique check is a scan per row, and this batch is 40,000 of them. */
|
|
15
|
+
const wide = remember(
|
|
16
|
+
entity('ec_b_wide', {
|
|
17
|
+
columns: { id: text({ max: 20 }).primaryKey(), label: text({ max: 20 }) },
|
|
18
|
+
}),
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
const notes = remember(
|
|
22
|
+
entity('ec_b_notes', {
|
|
23
|
+
columns: {
|
|
24
|
+
id: uuid().primaryKey(),
|
|
25
|
+
code: text({ max: 20 }).unique(),
|
|
26
|
+
title: text({ max: 40 }),
|
|
27
|
+
body: text({ max: 40 }).nullable(),
|
|
28
|
+
},
|
|
29
|
+
}),
|
|
30
|
+
);
|
|
31
|
+
type Note = typeof notes.$row;
|
|
32
|
+
|
|
33
|
+
const stampHasReason = (deletedAt: unknown, reason: unknown): boolean =>
|
|
34
|
+
deletedAt === null || reason !== null;
|
|
35
|
+
|
|
36
|
+
/** A rule with no CHECK, over a column an upsert's set list spares and one it overwrites. */
|
|
37
|
+
const audited = remember(
|
|
38
|
+
entity('ec_b_audited', {
|
|
39
|
+
columns: {
|
|
40
|
+
id: uuid().primaryKey(),
|
|
41
|
+
code: text({ max: 20 }).unique(),
|
|
42
|
+
reason: text({ max: 40 }).nullable(),
|
|
43
|
+
deletedAt: timestamp().nullable(),
|
|
44
|
+
},
|
|
45
|
+
invariants: (c) => [
|
|
46
|
+
invariant('ec_stamp_has_reason', c.satisfies(stampHasReason, ['deletedAt', 'reason'])),
|
|
47
|
+
],
|
|
48
|
+
}),
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
/** Every kind of column `$parse` fills: a default, a nullable and a `defaultNow()`. */
|
|
52
|
+
const filled = remember(
|
|
53
|
+
entity('ec_b_filled', {
|
|
54
|
+
columns: {
|
|
55
|
+
id: uuid().primaryKey(),
|
|
56
|
+
code: text({ max: 20 }).unique(),
|
|
57
|
+
title: text({ max: 40 }),
|
|
58
|
+
label: text({ max: 20 }).default('dflt'),
|
|
59
|
+
note: text({ max: 40 }).nullable(),
|
|
60
|
+
createdAt: timestamp().defaultNow(),
|
|
61
|
+
},
|
|
62
|
+
}),
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
const stamps = remember(
|
|
66
|
+
entity('ec_b_stamps', {
|
|
67
|
+
columns: {
|
|
68
|
+
id: uuid().primaryKey(),
|
|
69
|
+
code: text({ max: 20 }).unique(),
|
|
70
|
+
title: text({ max: 40 }),
|
|
71
|
+
updatedAt: timestamp().defaultNow().onUpdateNow(),
|
|
72
|
+
},
|
|
73
|
+
}),
|
|
74
|
+
);
|
|
75
|
+
|
|
76
|
+
const pairs = remember(
|
|
77
|
+
entity('ec_b_pairs', {
|
|
78
|
+
columns: { first: text({ max: 20 }), second: text({ max: 20 }), label: text().default('d') },
|
|
79
|
+
primaryKey: ['first', 'second'],
|
|
80
|
+
}),
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
/** The same rule with a column two rows share, for a filtered delete that matches both. */
|
|
84
|
+
const sweep = remember(
|
|
85
|
+
entity('ec_b_sweep', {
|
|
86
|
+
columns: {
|
|
87
|
+
id: uuid().primaryKey(),
|
|
88
|
+
kind: text({ max: 20 }),
|
|
89
|
+
reason: text({ max: 40 }).nullable(),
|
|
90
|
+
deletedAt: timestamp().nullable(),
|
|
91
|
+
},
|
|
92
|
+
invariants: (c) => [
|
|
93
|
+
invariant('ec_sweep_stamp_has_reason', c.satisfies(stampHasReason, ['deletedAt', 'reason'])),
|
|
94
|
+
],
|
|
95
|
+
}),
|
|
96
|
+
);
|
|
97
|
+
|
|
98
|
+
const ledger = remember(
|
|
99
|
+
entity('ec_b_ledger', {
|
|
100
|
+
columns: { id: uuid().primaryKey(), account: text({ max: 20 }), amount: integer() },
|
|
101
|
+
appendOnly: true,
|
|
102
|
+
}),
|
|
103
|
+
);
|
|
104
|
+
|
|
105
|
+
const ID = idAt(1);
|
|
106
|
+
const OTHER = idAt(2);
|
|
107
|
+
const REFUSED = 'X_INVARIANT_VIOLATED';
|
|
108
|
+
const UPSERT = ['upsert'] as const;
|
|
109
|
+
const WHEN = new Date('2020-01-02T03:04:05.000Z');
|
|
110
|
+
const STORED = { code: 'a', label: 'kept', note: 'kept note', title: 'old', createdAt: WHEN };
|
|
111
|
+
|
|
112
|
+
const batches: readonly EntityDriverCheck[] = [
|
|
113
|
+
checkOver({ wide }, 'a 40,000-row batch failing on a duplicate leaves no row', async (db) => {
|
|
114
|
+
// 2 columns: past the 65,535 bind ceiling, so one statement cannot carry it.
|
|
115
|
+
const batch = Array.from({ length: 40_000 }, (_, index) => ({
|
|
116
|
+
id: `r${index === 35_000 ? 0 : index}`,
|
|
117
|
+
label: 'l',
|
|
118
|
+
}));
|
|
119
|
+
expect(await codeOf(() => db.wide.insertAll(batch))).toBe('X_DB_UNIQUE_VIOLATION');
|
|
120
|
+
expect(await db.wide.count()).toBe(0);
|
|
121
|
+
}),
|
|
122
|
+
checkOver({ notes }, 'an empty batch writes nothing and answers empty', async (db) => {
|
|
123
|
+
expect(await db.notes.insertAll([])).toEqual([]);
|
|
124
|
+
expect(await db.notes.count()).toBe(0);
|
|
125
|
+
}),
|
|
126
|
+
checkOver(
|
|
127
|
+
{ notes },
|
|
128
|
+
'an empty upsert answers empty, and a target no unique covers is still refused',
|
|
129
|
+
async (db) => {
|
|
130
|
+
expect(await db.notes.upsertAll([], { onConflict: ['code'] })).toEqual([]);
|
|
131
|
+
expect(await codeOf(() => db.notes.upsertAll([], { onConflict: ['title'] }))).toBe(REFUSED);
|
|
132
|
+
},
|
|
133
|
+
UPSERT,
|
|
134
|
+
),
|
|
135
|
+
];
|
|
136
|
+
|
|
137
|
+
const upserts: readonly EntityDriverCheck[] = [
|
|
138
|
+
checkOver(
|
|
139
|
+
{ notes },
|
|
140
|
+
'a present undefined in an upsert is absent: the stored column keeps its value',
|
|
141
|
+
async (_db, { driver }) => {
|
|
142
|
+
const repo: Repo<Note> = driver.repo(notes);
|
|
143
|
+
await repo.insert({ id: ID, code: 'a', title: 'kept', body: 'kept body' });
|
|
144
|
+
const incoming: RowPatch<Note> = { id: OTHER, code: 'a', title: 'moved', body: undefined };
|
|
145
|
+
const [written] = await repo.upsertAll([incoming as Note], { onConflict: ['code'] });
|
|
146
|
+
expect(written).toEqual({ id: ID, code: 'a', title: 'moved', body: 'kept body' });
|
|
147
|
+
},
|
|
148
|
+
UPSERT,
|
|
149
|
+
),
|
|
150
|
+
checkOver(
|
|
151
|
+
{ notes },
|
|
152
|
+
'a row writing undefined where another writes a value is an uneven batch',
|
|
153
|
+
async (_db, { driver }) => {
|
|
154
|
+
const uneven: readonly RowPatch<Note>[] = [
|
|
155
|
+
{ id: ID, code: 'a', title: 't', body: 'new' },
|
|
156
|
+
{ id: OTHER, code: 'b', title: 't', body: undefined },
|
|
157
|
+
];
|
|
158
|
+
const call = () => driver.repo(notes).upsertAll(uneven as Note[], { onConflict: ['code'] });
|
|
159
|
+
expect(await codeOf(call)).toBe(REFUSED);
|
|
160
|
+
},
|
|
161
|
+
UPSERT,
|
|
162
|
+
),
|
|
163
|
+
checkOver(
|
|
164
|
+
{ audited },
|
|
165
|
+
'a merged upsert breaking a JS-only rule is refused, and the row stays',
|
|
166
|
+
async (_db, { driver }) => {
|
|
167
|
+
const repo = driver.repo(audited);
|
|
168
|
+
const row = { id: ID, code: 'a', reason: 'because', deletedAt: null as Date | null };
|
|
169
|
+
await repo.insert(row);
|
|
170
|
+
await repo.delete(ID);
|
|
171
|
+
expect(
|
|
172
|
+
await codeOf(() => repo.upsertAll([{ ...row, reason: null }], { onConflict: ['code'] })),
|
|
173
|
+
).toBe(REFUSED);
|
|
174
|
+
const { rows } = await repo.findMany({ includeDeleted: true });
|
|
175
|
+
expect(rows.map((one) => one.reason)).toEqual(['because']);
|
|
176
|
+
// onMatch: 'nothing' merges nothing, so it has nothing to judge.
|
|
177
|
+
const skipped = await repo.upsertAll([{ ...row, reason: null }], {
|
|
178
|
+
onConflict: ['code'],
|
|
179
|
+
onMatch: 'nothing',
|
|
180
|
+
});
|
|
181
|
+
expect(skipped).toEqual([]);
|
|
182
|
+
},
|
|
183
|
+
UPSERT,
|
|
184
|
+
),
|
|
185
|
+
checkOver(
|
|
186
|
+
{ filled },
|
|
187
|
+
'upsertAll overwrites what the caller named, never what $parse filled in',
|
|
188
|
+
async (db) => {
|
|
189
|
+
await db.filled.insert(STORED);
|
|
190
|
+
const written = await db.filled.upsertAll(
|
|
191
|
+
[
|
|
192
|
+
{ code: 'a', title: 'new' },
|
|
193
|
+
{ code: 'b', title: 'fresh' },
|
|
194
|
+
],
|
|
195
|
+
{ onConflict: ['code'] },
|
|
196
|
+
);
|
|
197
|
+
const shape = written.map((row) => [row.code, row.title, row.label, row.note]);
|
|
198
|
+
expect(shape).toEqual([
|
|
199
|
+
['a', 'new', 'kept', 'kept note'],
|
|
200
|
+
['b', 'fresh', 'dflt', null],
|
|
201
|
+
]);
|
|
202
|
+
expect(written[0]?.createdAt).toEqual(WHEN);
|
|
203
|
+
},
|
|
204
|
+
UPSERT,
|
|
205
|
+
),
|
|
206
|
+
checkOver(
|
|
207
|
+
{ filled, pairs },
|
|
208
|
+
'an uneven batch, or a set list naming only the target, is refused and writes nothing',
|
|
209
|
+
async (db) => {
|
|
210
|
+
await db.filled.insert(STORED);
|
|
211
|
+
const uneven = [
|
|
212
|
+
{ code: 'a', title: 't', note: 'new' },
|
|
213
|
+
{ code: 'b', title: 't' },
|
|
214
|
+
];
|
|
215
|
+
expect(await codeOf(() => db.filled.upsertAll(uneven, { onConflict: ['code'] }))).toBe(
|
|
216
|
+
REFUSED,
|
|
217
|
+
);
|
|
218
|
+
expect(await db.filled.count()).toBe(1);
|
|
219
|
+
const keysOnly = () =>
|
|
220
|
+
db.pairs.upsertAll([{ first: 'a', second: 'b' }], { onConflict: ['first', 'second'] });
|
|
221
|
+
expect(await codeOf(keysOnly)).toBe(REFUSED);
|
|
222
|
+
},
|
|
223
|
+
UPSERT,
|
|
224
|
+
),
|
|
225
|
+
checkOver(
|
|
226
|
+
{ stamps },
|
|
227
|
+
'onUpdateNow moves on an upsert collision, though no caller named it',
|
|
228
|
+
async (db) => {
|
|
229
|
+
const first = await db.stamps.insert({ code: 'a', title: 'one', updatedAt: WHEN });
|
|
230
|
+
const [second] = await db.stamps.upsertAll([{ code: 'a', title: 'two' }], {
|
|
231
|
+
onConflict: ['code'],
|
|
232
|
+
});
|
|
233
|
+
expect([first.updatedAt.getTime(), second?.updatedAt.getTime() === WHEN.getTime()]).toEqual([
|
|
234
|
+
WHEN.getTime(),
|
|
235
|
+
false,
|
|
236
|
+
]);
|
|
237
|
+
},
|
|
238
|
+
UPSERT,
|
|
239
|
+
),
|
|
240
|
+
checkOver(
|
|
241
|
+
{ filled },
|
|
242
|
+
"onMatch: 'nothing' inserts the new row and leaves the stored one",
|
|
243
|
+
async (db) => {
|
|
244
|
+
await db.filled.insert(STORED);
|
|
245
|
+
const written = await db.filled.upsertAll(
|
|
246
|
+
[
|
|
247
|
+
{ code: 'a', title: 'x' },
|
|
248
|
+
{ code: 'c', title: 'y' },
|
|
249
|
+
],
|
|
250
|
+
{ onConflict: ['code'], onMatch: 'nothing' },
|
|
251
|
+
);
|
|
252
|
+
expect(written.map((row) => [row.code, row.label])).toEqual([['c', 'dflt']]);
|
|
253
|
+
expect((await db.filled.where({ code: 'a' }).one())?.title).toBe('old');
|
|
254
|
+
},
|
|
255
|
+
UPSERT,
|
|
256
|
+
),
|
|
257
|
+
];
|
|
258
|
+
|
|
259
|
+
const softDeletes: readonly EntityDriverCheck[] = [
|
|
260
|
+
checkOver(
|
|
261
|
+
{ audited },
|
|
262
|
+
'a soft delete that breaks a JS-only rule is refused; the row stays',
|
|
263
|
+
async (_db, { driver }) => {
|
|
264
|
+
const repo = driver.repo(audited);
|
|
265
|
+
await repo.insert({ id: ID, code: 'a', reason: null, deletedAt: null });
|
|
266
|
+
expect(await codeOf(() => repo.delete(ID))).toBe(REFUSED);
|
|
267
|
+
expect(await repo.count({})).toBe(1);
|
|
268
|
+
},
|
|
269
|
+
),
|
|
270
|
+
checkOver(
|
|
271
|
+
{ sweep },
|
|
272
|
+
'deleteWhere over a mixed set refuses as one; a passing one deletes',
|
|
273
|
+
async (_db, { driver }) => {
|
|
274
|
+
const repo = driver.repo(sweep);
|
|
275
|
+
await repo.insertAll([
|
|
276
|
+
{ id: ID, kind: 'k', reason: 'fine', deletedAt: null },
|
|
277
|
+
{ id: OTHER, kind: 'k', reason: null, deletedAt: null },
|
|
278
|
+
]);
|
|
279
|
+
expect(await codeOf(() => repo.deleteWhere({ kind: 'k' }))).toBe(REFUSED);
|
|
280
|
+
expect(await repo.count({})).toBe(2);
|
|
281
|
+
await repo.insert({ id: idAt(3), kind: 'j', reason: 'fine', deletedAt: null });
|
|
282
|
+
expect(await repo.deleteWhere({ kind: 'j' })).toBe(1);
|
|
283
|
+
expect(await repo.count({})).toBe(2);
|
|
284
|
+
},
|
|
285
|
+
),
|
|
286
|
+
];
|
|
287
|
+
|
|
288
|
+
const appendOnly: readonly EntityDriverCheck[] = [
|
|
289
|
+
checkOver(
|
|
290
|
+
{ ledger },
|
|
291
|
+
'an append-only table refuses update, delete and their filtered forms',
|
|
292
|
+
async (db) => {
|
|
293
|
+
await db.ledger.insert({ id: ID, account: 'cash', amount: 100 });
|
|
294
|
+
const rewrites: readonly (() => Promise<unknown>)[] = [
|
|
295
|
+
() => db.ledger.update(ID, { amount: 1 }),
|
|
296
|
+
() => db.ledger.delete(ID),
|
|
297
|
+
() => db.ledger.updateWhere({ account: 'cash' }, { amount: 1 }),
|
|
298
|
+
() => db.ledger.deleteWhere({ account: 'cash' }),
|
|
299
|
+
];
|
|
300
|
+
for (const rewrite of rewrites) expect(await codeOf(rewrite)).toBe('X_ENTITY_APPEND_ONLY');
|
|
301
|
+
expect((await db.ledger.all()).map((row) => row.amount)).toEqual([100]);
|
|
302
|
+
},
|
|
303
|
+
),
|
|
304
|
+
checkOver(
|
|
305
|
+
{ ledger },
|
|
306
|
+
'an append-only table refuses an upsert, and appending still sums',
|
|
307
|
+
async (db) => {
|
|
308
|
+
await db.ledger.insert({ id: ID, account: 'cash', amount: 100 });
|
|
309
|
+
const upsert = () =>
|
|
310
|
+
db.ledger.upsertAll([{ id: ID, account: 'cash', amount: 1 }], { onConflict: ['id'] });
|
|
311
|
+
expect(await codeOf(upsert)).toBe('X_ENTITY_APPEND_ONLY');
|
|
312
|
+
await db.ledger.insert({ id: OTHER, account: 'cash', amount: -40 });
|
|
313
|
+
expect(await db.ledger.sum('amount')).toBe('60');
|
|
314
|
+
},
|
|
315
|
+
['upsert', 'aggregate:sum'],
|
|
316
|
+
),
|
|
317
|
+
];
|
|
318
|
+
|
|
319
|
+
const seeds: readonly EntityDriverCheck[] = [
|
|
320
|
+
checkOver(
|
|
321
|
+
{ countries },
|
|
322
|
+
'a seed upsert re-run is skipped, and a changed column is an update in place',
|
|
323
|
+
async (_db, { driver }) => {
|
|
324
|
+
let name = 'New Zealand';
|
|
325
|
+
const seed = defineSeed('ec_countries', async ({ upsert }) => {
|
|
326
|
+
await upsert(countries, { by: ['iso'] }, { iso: 'NZ', name });
|
|
327
|
+
});
|
|
328
|
+
await seed.run({ driver });
|
|
329
|
+
expect((await seed.run({ driver })).metrics).toEqual({ inserted: 0, updated: 0, skipped: 1 });
|
|
330
|
+
const before = (await driver.repo(countries).findMany({})).rows[0]?.id;
|
|
331
|
+
name = 'Aotearoa New Zealand';
|
|
332
|
+
expect((await seed.run({ driver })).metrics).toEqual({ inserted: 0, updated: 1, skipped: 0 });
|
|
333
|
+
const after = (await driver.repo(countries).findMany({})).rows;
|
|
334
|
+
expect(after.map((row): readonly unknown[] => [row.id, row.name])).toEqual([[before, name]]);
|
|
335
|
+
},
|
|
336
|
+
UPSERT,
|
|
337
|
+
),
|
|
338
|
+
checkOver(
|
|
339
|
+
{ countries },
|
|
340
|
+
'a seed dry run reports what the real run then does, and stores nothing',
|
|
341
|
+
async (_db, { driver }) => {
|
|
342
|
+
const seed = defineSeed('ec_countries_dry', async ({ upsert }) => {
|
|
343
|
+
await upsert(countries, { by: ['iso'] }, { iso: 'NZ', name: 'New Zealand' });
|
|
344
|
+
await upsert(countries, { by: ['iso'] }, { iso: 'NZ', name: 'New Zealand' });
|
|
345
|
+
});
|
|
346
|
+
const dry = await seed.run({ driver, dryRun: true });
|
|
347
|
+
expect(dry.metrics).toEqual({ inserted: 1, updated: 0, skipped: 1 });
|
|
348
|
+
expect((await driver.repo(countries).findMany({})).rows).toEqual([]);
|
|
349
|
+
expect((await seed.run({ driver })).metrics).toEqual(dry.metrics);
|
|
350
|
+
},
|
|
351
|
+
['upsert', 'transactions'],
|
|
352
|
+
),
|
|
353
|
+
checkOver(
|
|
354
|
+
{ filled },
|
|
355
|
+
'a seed upsert keeps a column the seed never mentioned',
|
|
356
|
+
async (db, { driver }) => {
|
|
357
|
+
await db.filled.insert({ code: 'a', title: 'old', label: 'kept', note: 'kept note' });
|
|
358
|
+
const answers: unknown[] = [];
|
|
359
|
+
const seed = defineSeed('ec_filled_replay', async ({ upsert }) => {
|
|
360
|
+
answers.push(await upsert(filled, { by: ['code'] }, { code: 'a', title: 'new' }));
|
|
361
|
+
});
|
|
362
|
+
await seed.run({ driver });
|
|
363
|
+
const row = await db.filled.where({ code: 'a' }).one();
|
|
364
|
+
expect([...answers, [row?.title, row?.label, row?.note]]).toEqual([
|
|
365
|
+
'updated',
|
|
366
|
+
['new', 'kept', 'kept note'],
|
|
367
|
+
]);
|
|
368
|
+
},
|
|
369
|
+
UPSERT,
|
|
370
|
+
),
|
|
371
|
+
];
|
|
372
|
+
|
|
373
|
+
export const BULK_CHECKS: readonly EntityDriverCheck[] = [
|
|
374
|
+
...batches,
|
|
375
|
+
...upserts,
|
|
376
|
+
...softDeletes,
|
|
377
|
+
...appendOnly,
|
|
378
|
+
...seeds,
|
|
379
|
+
];
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// Every entity conformance check, in one ordered list: the suite runs them in this order, one
|
|
2
|
+
// test each. Grouped by the file that states them; a new group is one import and one spread here.
|
|
3
|
+
|
|
4
|
+
import { AGGREGATE_CHECKS } from './entity-conformance-aggregates';
|
|
5
|
+
import { BATCH_CHECKS } from './entity-conformance-batches';
|
|
6
|
+
import { BULK_CHECKS } from './entity-conformance-bulk';
|
|
7
|
+
import { LOCK_CHECKS } from './entity-conformance-locks';
|
|
8
|
+
import { MATRIX_CHECKS } from './entity-conformance-matrix';
|
|
9
|
+
import { READ_CHECKS } from './entity-conformance-reads';
|
|
10
|
+
import { TENANCY_CHECKS } from './entity-conformance-tenancy';
|
|
11
|
+
import { VALUE_CHECKS } from './entity-conformance-values';
|
|
12
|
+
import { VERSION_CHECKS } from './entity-conformance-versions';
|
|
13
|
+
import { WRITE_CHECKS } from './entity-conformance-writes';
|
|
14
|
+
import type { EntityDriverCheck } from './entity-driver-conformance';
|
|
15
|
+
|
|
16
|
+
export const ENTITY_DRIVER_CHECKS: readonly EntityDriverCheck[] = [
|
|
17
|
+
...WRITE_CHECKS,
|
|
18
|
+
...VALUE_CHECKS,
|
|
19
|
+
...READ_CHECKS,
|
|
20
|
+
...BULK_CHECKS,
|
|
21
|
+
...AGGREGATE_CHECKS,
|
|
22
|
+
...TENANCY_CHECKS,
|
|
23
|
+
...BATCH_CHECKS,
|
|
24
|
+
...LOCK_CHECKS,
|
|
25
|
+
...MATRIX_CHECKS,
|
|
26
|
+
...VERSION_CHECKS,
|
|
27
|
+
];
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
// The entity conformance suite's own registry bookkeeping and the capability probes: every fixture
|
|
2
|
+
// entity is `remember`ed so a neighbour's `clearRegistry()` cannot take it (relations read the
|
|
3
|
+
// registry), and `probes` is one call per `DriverCapability` an undeclared one must refuse.
|
|
4
|
+
|
|
5
|
+
import type { Driver, RegistryEntry } from '@ultimat3/entity';
|
|
6
|
+
import { database, entity, getEntity, integer, text, timestamp, uuid } from '@ultimat3/entity';
|
|
7
|
+
import type { DriverCapability } from '@ultimat3/entity/adapter';
|
|
8
|
+
|
|
9
|
+
const entries: RegistryEntry[] = [];
|
|
10
|
+
|
|
11
|
+
/** Every fixture entity the suite declared, as the registry held it at declaration. */
|
|
12
|
+
export const CONFORMANCE_ENTRIES: readonly RegistryEntry[] = entries;
|
|
13
|
+
|
|
14
|
+
/** Records a just-declared fixture entity's registry entry; answers the entity unchanged. */
|
|
15
|
+
export const remember = <E extends { readonly $name: string }>(made: E): E => {
|
|
16
|
+
const entry = getEntity(made.$name);
|
|
17
|
+
if (entry !== undefined) entries.push(entry);
|
|
18
|
+
return made;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
/** The table a capability probe opens: one row of every kind a probe needs. */
|
|
22
|
+
export const probe = remember(
|
|
23
|
+
entity('ec_probe', {
|
|
24
|
+
columns: { id: uuid().primaryKey(), label: text({ max: 20 }), n: integer(), at: timestamp() },
|
|
25
|
+
}),
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
const PROBE_ROW = {
|
|
29
|
+
id: '00000000-0000-7000-8000-0000000000e1',
|
|
30
|
+
label: 'probe',
|
|
31
|
+
n: 1,
|
|
32
|
+
at: new Date('2026-01-01T00:00:00.000Z'),
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
/** One call per capability, each reaching the member `defineDriver` gates on that capability. */
|
|
36
|
+
export const probes = (driver: Driver): Readonly<Record<DriverCapability, () => unknown>> => {
|
|
37
|
+
const repo = () => driver.repo(probe);
|
|
38
|
+
const table = () => database({ probe }, { driver }).probe;
|
|
39
|
+
return {
|
|
40
|
+
transactions: () => driver.transactor(),
|
|
41
|
+
lock: () => table().lock(PROBE_ROW.id, () => undefined),
|
|
42
|
+
series: () => repo().series?.({ on: 'at', unit: 'day', timeZone: 'UTC', value: 'count' }),
|
|
43
|
+
upsert: () => repo().upsertAll([PROBE_ROW], { onConflict: ['id'] }),
|
|
44
|
+
matches: () => repo().findMany({ where: [{ column: '$search', op: 'matches', value: 'x' }] }),
|
|
45
|
+
'aggregate:countBy': () => repo().countBy('label'),
|
|
46
|
+
'aggregate:sum': () => repo().aggregate('sum', 'n'),
|
|
47
|
+
'aggregate:avg': () => repo().aggregate('avg', 'n'),
|
|
48
|
+
'aggregate:min': () => repo().aggregate('min', 'n'),
|
|
49
|
+
'aggregate:max': () => repo().aggregate('max', 'n'),
|
|
50
|
+
'aggregate:approximateCount': () => repo().approximateCount(),
|
|
51
|
+
};
|
|
52
|
+
};
|