@ultimat3/testing 31.46.0 → 31.47.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/README.md CHANGED
@@ -37,7 +37,7 @@ unitTest('the clock moves only when the test moves it', ({ clock }) => {
37
37
  | `seed-graph-order.ts` · `seed-graph-row.ts` · `seed-graph-shape.ts` | insert order over `$references()` (a cycle broken at a nullable key) · one row solved against invariants and unique keys · what the graph reads off an entity, structurally |
38
38
  | `seed-graph-error.ts` | `X_SEED_GRAPH_UNSATISFIED`, its fix naming the `defineFactory` to write; `X_SEED_GRAPH_ENTITY_UNKNOWN`, a plan and a writer built from two entity sets |
39
39
  | `seed-writer.ts` | `entitySeedWriter({ entities, client })` or `({ entities, driver? })` — the `SeedWriter` that writes a graph through each entity's own repository: Postgres or PGlite through a client, or a driver. `@ultimat3/entity` loads on the first write. `snapshot(rows)`, required on every `SeedWriter`, reads rows back as one digest each (`md5(t::text)` over a client), `null` for a row gone |
40
- | `exercise.ts` | `runExercisePass({ entities, writer, roles, seed?, overrides?, only? })` — every registered action, query and job once, each on its own committed tenant pair, one `ExerciseRecord` per primitive, the tenant proof's verdict on its `tenant`. What `x exercise` runs |
40
+ | `exercise.ts` | `runExercisePass({ entities, writer, roles, seed?, overrides?, only? })` — every registered action, query and job once, each on its own committed tenant pair, one `ExerciseRecord` per primitive, the tenant proof's verdict on its `tenant`. What `x exercise` runs, always with a `seed`; omitted, each pass draws one, for several passes on one database |
41
41
  | `exercise-route-subjects.ts` · `exercise-route-loads.ts` | `routeLoadSubjects()` — every `app/`/`site/` file route with a `load`; handed to `runExercisePass({ …, routes, onRoutes })`, each load runs after the primitives in a tenant pair of its own (an `:id` bound to a seeded row, else the route's `prerender()` sample), one `RouteLoadRecord` each with the statement ceiling, scale and plan proofs |
42
42
  | `define-exercise.ts` | `defineExercise({ <name>: { actor, input?, runs? } \| { off: '<why>' } }, { actor?: <entity>, factories?: { <entity name>: defineFactory(…) }, setup?: () => mockFetch(…) \| cassette(…) })` — an app's overrides (the second argument names the entity whose rows are the actors, and the factories that build a table no generated row satisfies — a cross-column `satisfies` — keyed by entity name, unknown ones `X_DECLARATION_UNKNOWN`), `apps/web/exercise.ts`'s one export; a blank `off` is `X_CONTRACT_EXERCISE_UNDECLARED`, an unknown name `X_DECLARATION_UNKNOWN` when the pass runs. An entry's `statements: { max, why }` moves that primitive's statement ceiling (a blank `why` is `X_CONTRACT_EXERCISE_UNDECLARED`, `max` a whole count ≥ 1) |
43
43
  | `define-exercise-routes.ts` · `exercise-route-override.ts` | `defineExercise(…, { routes: { '<pattern>': { params?, search?, actor?, statements?, empty? } \| { off } } })` — a route load's entry, keyed by its URL pattern: `params`/`search` (values or functions) and an `actor` function (of the seated actor: the app's request-boundary resolution, facts and all) run in the load's own request before the observed call; `off` makes the record `off`; an unknown pattern is `X_DECLARATION_UNKNOWN` before a row; a blank reason `X_CONTRACT_EXERCISE_UNDECLARED`. `empty: '<why>'` on any entry rides the record as `empty` |
@@ -177,6 +177,12 @@ than a missing method three awaits into a later test.
177
177
  An app adds its own with `defineFixtures` and widens the type by augmenting `Fixtures`:
178
178
 
179
179
  ```ts
180
+ import { type Actor } from '@ultimat3/core';
181
+ import { defineFixtures, type SeedHandle } from '@ultimat3/testing';
182
+
183
+ declare function loadSeed(name: string): SeedHandle;
184
+ declare function actorFor(token: string, facts: unknown): Actor;
185
+
180
186
  defineFixtures({ seed: () => loadSeed, actorFor: () => actorFor });
181
187
 
182
188
  declare module '@ultimat3/testing' {
@@ -298,6 +304,10 @@ schema-checked. `As of 2026-11`.
298
304
  ## An N+1 fails the test it happened in
299
305
 
300
306
  ```ts
307
+ import { expect, test } from '@ultimat3/testing';
308
+
309
+ declare function renderFeed(): Promise<void>;
310
+
301
311
  test('the feed reads its authors once', async ({ statements }) => {
302
312
  await renderFeed(); // a per-row findById throws here:
303
313
  // X_N_PLUS_ONE_QUERY: members.findById ran 5 times in one request — one read per row
@@ -376,8 +386,28 @@ themselves, not from a directory convention.
376
386
  ## Factories
377
387
 
378
388
  ```ts
389
+ import { entity, text, timestamp, uuid } from '@ultimat3/entity';
379
390
  import { belongsTo, defineFactory, hasMany } from '@ultimat3/testing';
380
391
 
392
+ const orgs = entity('orgs', {
393
+ columns: { id: uuid().primaryKey(), slug: text(), name: text() },
394
+ });
395
+ const posts = entity('posts', {
396
+ tenant: 'orgId',
397
+ columns: {
398
+ id: uuid().primaryKey(),
399
+ orgId: uuid(),
400
+ slug: text(),
401
+ title: text(),
402
+ status: text().default('draft'),
403
+ publishedAt: timestamp().nullable(),
404
+ },
405
+ });
406
+ const comments = entity('comments', {
407
+ tenant: 'orgId',
408
+ columns: { id: uuid().primaryKey(), orgId: uuid(), postId: uuid(), body: text() },
409
+ });
410
+
381
411
  const orgFactory = defineFactory(orgs, {
382
412
  defaults: (n, ids) => ({ id: ids.uuid(), slug: `org-${n}`, name: `Org ${n}` }),
383
413
  });
@@ -498,6 +528,11 @@ bound, one sent inside `expectedSeqScan(reason, fn)` or on an entity that declar
498
528
  ## Shared examples
499
529
 
500
530
  ```ts
531
+ import { type Action } from '@ultimat3/action';
532
+ import { behavesLike, describe, expect, sharedExamples, test } from '@ultimat3/testing';
533
+
534
+ declare const publishPost: Action;
535
+
501
536
  const anAuthenticatedAction = sharedExamples<Action>('an authenticated action', (subject) => {
502
537
  test('denies an anonymous actor', async () => {
503
538
  // The POLICY is the receiver and the context is the argument — `toDenyPolicy` evaluates it.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ultimat3/testing",
3
- "version": "31.46.0",
3
+ "version": "31.47.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,27 +47,27 @@
47
47
  "test": "bun test"
48
48
  },
49
49
  "dependencies": {
50
- "@ultimat3/action": "31.46.0",
51
- "@ultimat3/ai": "31.46.0",
52
- "@ultimat3/auth": "31.46.0",
53
- "@ultimat3/cache": "31.46.0",
54
- "@ultimat3/core": "31.46.0",
55
- "@ultimat3/db": "31.46.0",
56
- "@ultimat3/entity": "31.46.0",
57
- "@ultimat3/http": "31.46.0",
58
- "@ultimat3/i18n": "31.46.0",
59
- "@ultimat3/jobs": "31.46.0",
60
- "@ultimat3/mail": "31.46.0",
61
- "@ultimat3/notify": "31.46.0",
62
- "@ultimat3/policy": "31.46.0",
63
- "@ultimat3/pwa": "31.46.0",
64
- "@ultimat3/query": "31.46.0",
65
- "@ultimat3/realtime": "31.46.0",
66
- "@ultimat3/render": "31.46.0",
67
- "@ultimat3/schema": "31.46.0",
68
- "@ultimat3/scraping": "31.46.0",
69
- "@ultimat3/seo": "31.46.0",
70
- "@ultimat3/time": "31.46.0"
50
+ "@ultimat3/action": "31.47.0",
51
+ "@ultimat3/ai": "31.47.0",
52
+ "@ultimat3/auth": "31.47.0",
53
+ "@ultimat3/cache": "31.47.0",
54
+ "@ultimat3/core": "31.47.0",
55
+ "@ultimat3/db": "31.47.0",
56
+ "@ultimat3/entity": "31.47.0",
57
+ "@ultimat3/http": "31.47.0",
58
+ "@ultimat3/i18n": "31.47.0",
59
+ "@ultimat3/jobs": "31.47.0",
60
+ "@ultimat3/mail": "31.47.0",
61
+ "@ultimat3/notify": "31.47.0",
62
+ "@ultimat3/policy": "31.47.0",
63
+ "@ultimat3/pwa": "31.47.0",
64
+ "@ultimat3/query": "31.47.0",
65
+ "@ultimat3/realtime": "31.47.0",
66
+ "@ultimat3/render": "31.47.0",
67
+ "@ultimat3/schema": "31.47.0",
68
+ "@ultimat3/scraping": "31.47.0",
69
+ "@ultimat3/seo": "31.47.0",
70
+ "@ultimat3/time": "31.47.0"
71
71
  },
72
72
  "peerDependencies": {
73
73
  "solid-js": "^1.9.18"
@@ -6,6 +6,7 @@
6
6
  import type { Actor } from '@ultimat3/core';
7
7
  import {
8
8
  bindDrawn,
9
+ isJsonObject,
9
10
  isUltimateError,
10
11
  renderExerciseKey,
11
12
  renderFixShellArg,
@@ -76,15 +77,12 @@ export function inputThrew(name: string, key: string, error: unknown) {
76
77
  * actor is not in, and a policy comparing the two denies every run.
77
78
  */
78
79
  function rehomed(input: unknown, from: string | undefined, to: string | undefined): unknown {
79
- if (from === undefined || to === undefined || from === to || !isPlainObject(input)) return input;
80
+ if (from === undefined || to === undefined || from === to || !isJsonObject(input)) return input;
80
81
  return Object.fromEntries(
81
82
  Object.entries(input).map(([key, value]) => [key, value === from ? to : value]),
82
83
  );
83
84
  }
84
85
 
85
- const isPlainObject = (value: unknown): value is Readonly<Record<string, unknown>> =>
86
- typeof value === 'object' && value !== null && !Array.isArray(value);
87
-
88
86
  /**
89
87
  * Whether an override's input is declared `async` — state the pass computes, which a load that
90
88
  * draws with no pass behind it (`x drill`) cannot reproduce. The function's own tag, never a call:
package/src/exercise.ts CHANGED
@@ -65,9 +65,10 @@ export interface ExercisePassOptions {
65
65
  readonly entities: readonly SeedEntity[];
66
66
  readonly writer: SeedWriter;
67
67
  /**
68
- * Seeds the pass's one graph: the shared rows and every primitive's tenants. Omitted, each pass
69
- * draws a fresh one: the rows are COMMITTED, so a second pass on one seed against one database
70
- * collides on its keys. Given, the pass replays byte for byte — on a database that has not seen it.
68
+ * Seeds the pass's one graph: the shared rows and every primitive's tenants. Given, the pass
69
+ * replays byte for byte — on a database that has not seen it; `x exercise` always gives one, on
70
+ * a scratch database per pass. Omitted, for a caller running several passes on ONE database, each
71
+ * draws a fresh one: the rows are COMMITTED, so a repeated seed would collide on its keys.
71
72
  */
72
73
  readonly seed?: number;
73
74
  readonly overrides?: ExerciseOverrides;
@@ -25,6 +25,8 @@ interface QueueLike {
25
25
  enqueued(handle: EnqueuedJobRef<unknown>): Promise<readonly JobRecord[]>;
26
26
  }
27
27
 
28
+ // why: NOT core's `isJsonObject` — a FUNCTION with `enqueued`/`outbox` properties is a valid
29
+ // receiver too, which the keyed-record test refuses.
28
30
  const isRecord = (value: unknown): value is Record<string, unknown> =>
29
31
  (typeof value === 'object' || typeof value === 'function') && value !== null;
30
32
 
package/src/matchers.ts CHANGED
@@ -4,7 +4,13 @@
4
4
 
5
5
  import type { ExpectExtendMatchers } from 'bun:test';
6
6
  import { expect } from 'bun:test';
7
- import { describeValue, isUltimateError, renderCauseValue, stringField } from '@ultimat3/core';
7
+ import {
8
+ describeValue,
9
+ isJsonObject,
10
+ isUltimateError,
11
+ renderCauseValue,
12
+ stringField,
13
+ } from '@ultimat3/core';
8
14
  import { TestJobExpectedError, TestSchemaExpectedError } from './errors';
9
15
  import { toHaveEnqueued, toHaveSentMail } from './matcher-doubles';
10
16
  import {
@@ -38,9 +44,6 @@ export type { UltimateMatchers } from './matcher-surface';
38
44
  // `recordSteps` lives beside its recorder; the public path (`./matchers`) is unchanged.
39
45
  export { recordSteps } from './matchers-steps';
40
46
 
41
- const isRecord = (value: unknown): value is Record<string, unknown> =>
42
- typeof value === 'object' && value !== null;
43
-
44
47
  /**
45
48
  * The Ultimate error code carried by `value`, or `undefined` for anything that is not one.
46
49
  *
@@ -72,7 +75,7 @@ interface StandardSchema {
72
75
  }
73
76
 
74
77
  const isStandardSchema = (value: unknown): value is StandardSchema =>
75
- isRecord(value) && isRecord(value['~standard']);
78
+ isJsonObject(value) && isJsonObject(value['~standard']);
76
79
 
77
80
  /**
78
81
  * The receiver check, SYNCHRONOUS and separate from the work — measured against Bun 1.4.0: a
@@ -112,10 +115,10 @@ interface RunnablePolicy {
112
115
  }
113
116
 
114
117
  const isPolicy = (value: unknown): value is PolicyLike =>
115
- isRecord(value) && typeof value['evaluate'] === 'function';
118
+ isJsonObject(value) && typeof value['evaluate'] === 'function';
116
119
 
117
120
  const isRunnablePolicy = (value: unknown): value is RunnablePolicy =>
118
- isRecord(value) && typeof value['run'] === 'function';
121
+ isJsonObject(value) && typeof value['run'] === 'function';
119
122
 
120
123
  /**
121
124
  * `undefined` means "not a policy at all", which is a different failure from a denial.
@@ -143,7 +146,7 @@ async function decide(
143
146
  const result = (pass: boolean, message: () => string): MatcherResult => ({ pass, message });
144
147
 
145
148
  const isOpenApiLike = (value: unknown): value is OpenApiLike =>
146
- isRecord(value) &&
149
+ isJsonObject(value) &&
147
150
  Array.isArray(value['operations']) &&
148
151
  value['operations'].every(
149
152
  (entry) => typeof (entry as OpenApiLike['operations'][number] | null)?.operationId === 'string',
@@ -2,7 +2,7 @@
2
2
  // secret, so a replay needs one that the schema accepts: the masked paths are filled from a seeded
3
3
  // `arbitrary()` value of the same schema (input), or from the column's own candidates (a row).
4
4
 
5
- import { REDACTED, uuidV7 } from '@ultimat3/core';
5
+ import { isJsonObject, REDACTED, uuidV7 } from '@ultimat3/core';
6
6
  import type { EntityCore } from '@ultimat3/entity';
7
7
  import { arbitrary } from '@ultimat3/schema/sample';
8
8
  import { candidatesFor, type SeedColumn } from './seed-graph-values';
@@ -10,9 +10,6 @@ import { candidatesFor, type SeedColumn } from './seed-graph-values';
10
10
  /** The seed every stand-in draws from: the same bundle, the same replay. */
11
11
  const STAND_IN_SEED = 0x5eed;
12
12
 
13
- const isRecord = (value: unknown): value is Record<string, unknown> =>
14
- typeof value === 'object' && value !== null && !Array.isArray(value);
15
-
16
13
  /** Every `REDACTED` leaf of `value` replaced by the leaf at the same place in `sample`. */
17
14
  function fill(value: unknown, sample: unknown): unknown {
18
15
  if (value === REDACTED) return sample;
@@ -20,11 +17,11 @@ function fill(value: unknown, sample: unknown): unknown {
20
17
  const items = Array.isArray(sample) ? sample : [];
21
18
  return value.map((entry, index) => fill(entry, items[index] ?? items[0]));
22
19
  }
23
- if (!isRecord(value)) return value;
20
+ if (!isJsonObject(value)) return value;
24
21
  const out: Record<string, unknown> = {};
25
22
  for (const [key, entry] of Object.entries(value)) {
26
23
  Object.defineProperty(out, key, {
27
- value: fill(entry, isRecord(sample) ? sample[key] : undefined),
24
+ value: fill(entry, isJsonObject(sample) ? sample[key] : undefined),
28
25
  enumerable: true,
29
26
  writable: true,
30
27
  configurable: true,
@@ -4,6 +4,7 @@
4
4
 
5
5
  // why: `net.Socket` is the class every node:* client socket is, and the only place they all meet.
6
6
  import net from 'node:net';
7
+ import { isJsonObject } from '@ultimat3/core';
7
8
  import type { SocketGate } from './sealed-sockets';
8
9
 
9
10
  /** A dial target as a URL, so the gate parses one shape. IPv6 literals need their brackets. */
@@ -19,8 +20,6 @@ interface Target {
19
20
  readonly path?: unknown;
20
21
  }
21
22
 
22
- const isRecord = (value: unknown): value is Target => typeof value === 'object' && value !== null;
23
-
24
23
  /**
25
24
  * The TCP dial `connect`'s arguments name, or `undefined` for a unix socket — a path on this
26
25
  * machine, never egress. Node's three shapes: `[options, cb]` (what `net.connect`, `tls`, `http`
@@ -28,11 +27,12 @@ const isRecord = (value: unknown): value is Target => typeof value === 'object'
28
27
  */
29
28
  const tcpTarget = (args: readonly unknown[]): string | undefined => {
30
29
  const first = Array.isArray(args[0]) ? args[0][0] : args[0];
31
- if (isRecord(first)) {
32
- const host = first.host ?? first.hostname;
30
+ if (isJsonObject(first)) {
31
+ const target: Target = first;
32
+ const host = target.host ?? target.hostname;
33
33
  if (typeof host !== 'string')
34
- return typeof first.path === 'string' ? undefined : 'tcp://localhost:0';
35
- return dialUrl(host, first.port);
34
+ return typeof target.path === 'string' ? undefined : 'tcp://localhost:0';
35
+ return dialUrl(host, target.port);
36
36
  }
37
37
  if (typeof first === 'string' && !/^\d+$/.test(first)) return undefined;
38
38
  return dialUrl(typeof args[1] === 'string' ? args[1] : 'localhost', first);
package/src/sealed-udp.ts CHANGED
@@ -4,6 +4,7 @@
4
4
 
5
5
  // why: Bun's `dgram.Socket#send` drops a throw when no callback is given (measured); patched below.
6
6
  import dgram from 'node:dgram';
7
+ import { isJsonObject } from '@ultimat3/core';
7
8
  import { dialUrl } from './sealed-node-sockets';
8
9
  import type { SocketGate } from './sealed-sockets';
9
10
 
@@ -18,13 +19,10 @@ interface ConnectTarget {
18
19
  /** The refusals this seal raised: the only errors the `dgram` patch re-emits. */
19
20
  const refusals = new WeakSet<Error>();
20
21
 
21
- const isRecord = (value: unknown): value is Record<string, unknown> =>
22
- typeof value === 'object' && value !== null;
23
-
24
22
  /** The peer a `connect` option names, as the gate's URL; `undefined` for an unconnected socket. */
25
23
  const peerOf = (options: unknown): string | undefined => {
26
- const connect: unknown = isRecord(options) ? options['connect'] : undefined;
27
- if (!isRecord(connect)) return undefined;
24
+ const connect: unknown = isJsonObject(options) ? options['connect'] : undefined;
25
+ if (!isJsonObject(connect)) return undefined;
28
26
  const target: ConnectTarget = connect;
29
27
  return typeof target.hostname === 'string'
30
28
  ? dialUrl(target.hostname, target.port, 'udp')
@@ -38,7 +36,7 @@ const peerOf = (options: unknown): string | undefined => {
38
36
  */
39
37
  const remoteOf = (socket: object): string | undefined => {
40
38
  const remote: unknown = Reflect.get(socket, 'remoteAddress');
41
- if (!isRecord(remote) || typeof remote['address'] !== 'string') return undefined;
39
+ if (!isJsonObject(remote) || typeof remote['address'] !== 'string') return undefined;
42
40
  return dialUrl(remote['address'], remote['port'], 'udp');
43
41
  };
44
42
 
@@ -107,7 +105,7 @@ export function installUdpSeal(gate: SocketGate): () => void {
107
105
  if (refusal !== undefined) throw refusal;
108
106
  }
109
107
  const socket = await original(options);
110
- if (isRecord(socket)) sealSends(socket, gate);
108
+ if (isJsonObject(socket)) sealSends(socket, gate);
111
109
  return socket;
112
110
  };
113
111
  Reflect.set(Bun, 'udpSocket', sealed);