@ultimat3/testing 31.38.1 → 31.40.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 +1 -0
- package/package.json +22 -22
- package/src/matchers-steps.ts +86 -0
- package/src/matchers.ts +4 -31
package/README.md
CHANGED
|
@@ -74,6 +74,7 @@ unitTest('the clock moves only when the test moves it', ({ clock }) => {
|
|
|
74
74
|
| `auth-request.ts` | `authRequest()` — the two arguments an app's authenticator is handed, built for real |
|
|
75
75
|
| `island-state-mount.ts` | `describeIslandState()` / `mountIslandState()` — one declared island state, mounted, with the setup and teardown a mount owes |
|
|
76
76
|
| `matchers.ts` | `toBeUltimateError` `toDenyPolicy` `toEmitSteps` `toMatchOpenApi` `toBeWithinBudget` `toRejectInput` `toAcceptInput` `toEqualRow` `toBeVisible` |
|
|
77
|
+
| `matchers-steps.ts` | `recordSteps` — behind `toEmitSteps`: the job's real arguments (a worker `ctx`, ambient too, `attempt` 1, `progress`, `runId`), a never-aborted signal per step body; `waitForEvent` is a recorded step that times out (`undefined`, or `X_JOB_TIMEOUT` when `required`); `sleep` returns at once and is no step |
|
|
77
78
|
| `matcher-row.ts` | `toEqualRow` — equality over every OWN property, so a `.sealed()` column (not enumerable on a repository row) is compared; a server-only difference is named, never printed |
|
|
78
79
|
| `test-seal-key.ts` | the throwaway master key a test process seals under when the app has none — installed by the preload, handed to the app `startE2eApp` spawns, exported from nowhere |
|
|
79
80
|
| `local-tx.ts` | `memoryLocalTx()` — the client store a mutator's `local()` half writes into under test, with the record store's own rules |
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ultimat3/testing",
|
|
3
|
-
"version": "31.
|
|
3
|
+
"version": "31.40.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.
|
|
51
|
-
"@ultimat3/ai": "31.
|
|
52
|
-
"@ultimat3/auth": "31.
|
|
53
|
-
"@ultimat3/cache": "31.
|
|
54
|
-
"@ultimat3/core": "31.
|
|
55
|
-
"@ultimat3/db": "31.
|
|
56
|
-
"@ultimat3/entity": "31.
|
|
57
|
-
"@ultimat3/http": "31.
|
|
58
|
-
"@ultimat3/i18n": "31.
|
|
59
|
-
"@ultimat3/jobs": "31.
|
|
60
|
-
"@ultimat3/mail": "31.
|
|
61
|
-
"@ultimat3/notify": "31.
|
|
62
|
-
"@ultimat3/policy": "31.
|
|
63
|
-
"@ultimat3/pwa": "31.
|
|
64
|
-
"@ultimat3/query": "31.
|
|
65
|
-
"@ultimat3/realtime": "31.
|
|
66
|
-
"@ultimat3/render": "31.
|
|
67
|
-
"@ultimat3/schema": "31.
|
|
68
|
-
"@ultimat3/scraping": "31.
|
|
69
|
-
"@ultimat3/seo": "31.
|
|
70
|
-
"@ultimat3/time": "31.
|
|
50
|
+
"@ultimat3/action": "31.40.0",
|
|
51
|
+
"@ultimat3/ai": "31.40.0",
|
|
52
|
+
"@ultimat3/auth": "31.40.0",
|
|
53
|
+
"@ultimat3/cache": "31.40.0",
|
|
54
|
+
"@ultimat3/core": "31.40.0",
|
|
55
|
+
"@ultimat3/db": "31.40.0",
|
|
56
|
+
"@ultimat3/entity": "31.40.0",
|
|
57
|
+
"@ultimat3/http": "31.40.0",
|
|
58
|
+
"@ultimat3/i18n": "31.40.0",
|
|
59
|
+
"@ultimat3/jobs": "31.40.0",
|
|
60
|
+
"@ultimat3/mail": "31.40.0",
|
|
61
|
+
"@ultimat3/notify": "31.40.0",
|
|
62
|
+
"@ultimat3/policy": "31.40.0",
|
|
63
|
+
"@ultimat3/pwa": "31.40.0",
|
|
64
|
+
"@ultimat3/query": "31.40.0",
|
|
65
|
+
"@ultimat3/realtime": "31.40.0",
|
|
66
|
+
"@ultimat3/render": "31.40.0",
|
|
67
|
+
"@ultimat3/schema": "31.40.0",
|
|
68
|
+
"@ultimat3/scraping": "31.40.0",
|
|
69
|
+
"@ultimat3/seo": "31.40.0",
|
|
70
|
+
"@ultimat3/time": "31.40.0"
|
|
71
71
|
},
|
|
72
72
|
"peerDependencies": {
|
|
73
73
|
"solid-js": "^1.9.18"
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
// `recordSteps`, behind `toEmitSteps`: runs a job body against a step API that records names
|
|
2
|
+
// instead of persisting outputs. The body gets the arguments the worker hands it (`execute.ts`),
|
|
3
|
+
// so a job written against the documented surface runs here exactly as it reads.
|
|
4
|
+
|
|
5
|
+
import { ctxOf, runWithContext } from '@ultimat3/core';
|
|
6
|
+
import type { JobRunArgs, RetryPolicy, StepApi, StepOutput } from '@ultimat3/jobs';
|
|
7
|
+
import { isFinalAttempt, JobTimeoutError } from '@ultimat3/jobs';
|
|
8
|
+
import { TestJobExpectedError } from './errors';
|
|
9
|
+
import { PRELOAD_CLOCK } from './fixture-jobs';
|
|
10
|
+
|
|
11
|
+
/** A `job()` handle, structurally: `retry` is absent only on a hand-written look-alike. */
|
|
12
|
+
export interface JobLike {
|
|
13
|
+
readonly name?: string;
|
|
14
|
+
readonly retry?: RetryPolicy;
|
|
15
|
+
run(args: JobRunArgs<unknown>): Promise<unknown>;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export const isJob = (value: unknown): value is JobLike =>
|
|
19
|
+
typeof value === 'object' && value !== null && typeof Reflect.get(value, 'run') === 'function';
|
|
20
|
+
|
|
21
|
+
/** `step.waitForEvent`'s documented default, when the call names no `timeout`. */
|
|
22
|
+
const WAIT_DEFAULT = '24h';
|
|
23
|
+
|
|
24
|
+
/** The one answer a recorder can give a wait: no event came, so the timeout branch runs. */
|
|
25
|
+
async function timedOut(
|
|
26
|
+
jobName: string,
|
|
27
|
+
name: string,
|
|
28
|
+
event: string,
|
|
29
|
+
options: { readonly timeout?: string | number; readonly required?: boolean },
|
|
30
|
+
): Promise<undefined> {
|
|
31
|
+
if (options.required !== true) return undefined;
|
|
32
|
+
// The worker's own refusal for a required wait that timed out, so the body ends as it would.
|
|
33
|
+
// `@ultimat3/time` is dynamic-only from this package's barrel (CLAUDE.md).
|
|
34
|
+
const timeout = options.timeout ?? WAIT_DEFAULT;
|
|
35
|
+
const timeoutMs =
|
|
36
|
+
typeof timeout === 'number' ? timeout : (await import('@ultimat3/time')).parseDuration(timeout);
|
|
37
|
+
throw new JobTimeoutError({
|
|
38
|
+
job: jobName,
|
|
39
|
+
step: name,
|
|
40
|
+
timeoutMs,
|
|
41
|
+
fix: `step.waitForEvent('${name}', '${event}', { timeout: '1h' }) # recordSteps delivers no event: drop required: true, or drive the run with runJobs and publish "${event}"`,
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Runs the job with a recording step API, so the assertion is on the sequence, not the effects.
|
|
47
|
+
* Typed as `StepApi`, so a member the real API gains is a compile error here rather than a
|
|
48
|
+
* TypeError in a caller's test. `sleep` is not a step in the sequence; `waitForEvent` is.
|
|
49
|
+
*/
|
|
50
|
+
export async function recordSteps(job: unknown, input: unknown = {}): Promise<readonly string[]> {
|
|
51
|
+
if (!isJob(job)) throw new TestJobExpectedError();
|
|
52
|
+
const jobName = job.name ?? 'recordSteps';
|
|
53
|
+
const names: string[] = [];
|
|
54
|
+
// Never aborted: the recorder imposes no ceiling, and the run is never cancelled.
|
|
55
|
+
const signal = new AbortController().signal;
|
|
56
|
+
const step: StepApi = {
|
|
57
|
+
run: async <T>(name: string, body: (signal: AbortSignal) => Promise<T> | T) => {
|
|
58
|
+
names.push(name);
|
|
59
|
+
// Passed through, not round-tripped through JSON: the matcher asserts names, not outputs.
|
|
60
|
+
return (await body(signal)) as StepOutput<T>;
|
|
61
|
+
},
|
|
62
|
+
sleep: async () => undefined,
|
|
63
|
+
waitForEvent: async (name, event, options) => {
|
|
64
|
+
names.push(name);
|
|
65
|
+
return timedOut(jobName, name, event, options);
|
|
66
|
+
},
|
|
67
|
+
};
|
|
68
|
+
// The worker's shape: a `role: 'worker'` ctx on the frozen clock the `runJobs` fixture uses,
|
|
69
|
+
// installed as the AMBIENT context too — the ctx a body is handed and the one entity's tenant
|
|
70
|
+
// guard reads are one object, as in `execute.ts`.
|
|
71
|
+
const ctx = ctxOf({ role: 'worker', clock: PRELOAD_CLOCK });
|
|
72
|
+
const runId = `record-steps:${jobName}`;
|
|
73
|
+
await runWithContext(ctx, () =>
|
|
74
|
+
job.run({
|
|
75
|
+
input,
|
|
76
|
+
step,
|
|
77
|
+
ctx,
|
|
78
|
+
attempt: 1,
|
|
79
|
+
finalAttempt: job.retry === undefined ? true : isFinalAttempt(job.retry, 1),
|
|
80
|
+
progress: () => undefined,
|
|
81
|
+
jobId: runId,
|
|
82
|
+
runId,
|
|
83
|
+
}),
|
|
84
|
+
);
|
|
85
|
+
return names;
|
|
86
|
+
}
|
package/src/matchers.ts
CHANGED
|
@@ -22,6 +22,8 @@ import type {
|
|
|
22
22
|
} from './matcher-surface';
|
|
23
23
|
import type { VisibleOptions } from './matcher-visible';
|
|
24
24
|
import { assertVisibilityProbe, visibilityResult } from './matcher-visible';
|
|
25
|
+
import type { JobLike } from './matchers-steps';
|
|
26
|
+
import { isJob, recordSteps } from './matchers-steps';
|
|
25
27
|
// `toHaveBeenCalledWith` on a `stub()`: bun's own name, so it is installed beside bun's matcher
|
|
26
28
|
// rather than declared on `UltimateMatchers` (two declarations of one member do not merge).
|
|
27
29
|
import './matcher-stub';
|
|
@@ -33,6 +35,8 @@ export type { MatcherResult } from './matcher-result';
|
|
|
33
35
|
// `bun:test` augmentation for anyone consuming this package through `dist/` — which is every
|
|
34
36
|
// package that reaches it across a project reference.
|
|
35
37
|
export type { UltimateMatchers } from './matcher-surface';
|
|
38
|
+
// `recordSteps` lives beside its recorder; the public path (`./matchers`) is unchanged.
|
|
39
|
+
export { recordSteps } from './matchers-steps';
|
|
36
40
|
|
|
37
41
|
const isRecord = (value: unknown): value is Record<string, unknown> =>
|
|
38
42
|
typeof value === 'object' && value !== null;
|
|
@@ -128,37 +132,6 @@ async function decide(
|
|
|
128
132
|
return undefined;
|
|
129
133
|
}
|
|
130
134
|
|
|
131
|
-
interface JobLike {
|
|
132
|
-
run(context: {
|
|
133
|
-
input: unknown;
|
|
134
|
-
step: StepRecorder;
|
|
135
|
-
ctx: Record<string, unknown>;
|
|
136
|
-
}): Promise<unknown>;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
interface StepRecorder {
|
|
140
|
-
run<T>(name: string, body: () => T | Promise<T>): Promise<T>;
|
|
141
|
-
sleep(duration: string): Promise<void>;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
const isJob = (value: unknown): value is JobLike =>
|
|
145
|
-
isRecord(value) && typeof value['run'] === 'function';
|
|
146
|
-
|
|
147
|
-
/** Runs the job with a recording step API, so the assertion is on the sequence, not the effects. */
|
|
148
|
-
export async function recordSteps(job: unknown, input: unknown = {}): Promise<readonly string[]> {
|
|
149
|
-
if (!isJob(job)) throw new TestJobExpectedError();
|
|
150
|
-
const names: string[] = [];
|
|
151
|
-
const step: StepRecorder = {
|
|
152
|
-
run: async (name, body) => {
|
|
153
|
-
names.push(name);
|
|
154
|
-
return body();
|
|
155
|
-
},
|
|
156
|
-
sleep: async () => undefined,
|
|
157
|
-
};
|
|
158
|
-
await job.run({ input, step, ctx: {} });
|
|
159
|
-
return names;
|
|
160
|
-
}
|
|
161
|
-
|
|
162
135
|
/**
|
|
163
136
|
* A THUNK, never a built string. `expect.extend` reads `message()` only when the verdict is the
|
|
164
137
|
* wrong one, and building the sentence eagerly made three matchers raise from inside the assertion
|