@ultimat3/testing 31.26.0 → 31.28.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 +3 -0
- package/README.md +42 -1
- package/package.json +25 -22
- package/src/define-exercise-routes.ts +97 -0
- package/src/define-exercise.ts +24 -2
- package/src/drill-services.ts +6 -6
- package/src/exercise-judge.ts +13 -2
- package/src/exercise-observed.ts +6 -0
- package/src/exercise-queued.ts +43 -0
- package/src/exercise-report.ts +31 -1
- package/src/exercise-room-storage.ts +58 -0
- package/src/exercise-route-loads.ts +55 -16
- package/src/exercise-route-override.ts +105 -0
- package/src/exercise-shard.ts +13 -0
- package/src/exercise.ts +23 -50
- package/src/fixture-island-coverage.ts +26 -0
- package/src/fixture-island.ts +27 -2
- package/src/framework-fixtures.ts +7 -1
- package/src/index.ts +3 -0
- package/src/test-types-services.ts +36 -0
- package/src/test-types.ts +20 -0
package/CLAUDE.md
CHANGED
|
@@ -54,6 +54,7 @@ the off-barrel entry points `registry-isolation.ts`, `conformance.ts`. Full rule
|
|
|
54
54
|
| Every `e2eTest` is audited | `e2e-a11y*.ts`, `ax-node.ts`; no switch, `allow` needs a `because` † |
|
|
55
55
|
| The exercise pass runs what is registered | `exercise.ts` (`runExercisePass`): every action, query, job once, own tenant pair; overrides only via `defineExercise` † |
|
|
56
56
|
| A route `load` is exercised like a read | `exercise-route-loads.ts`: after the primitives, own tenant pair, swept and planned with them; its record is `RouteLoadRecord`, never in `records`; the crash proof's runs pace on the frozen clock (`exercise-crash.ts`) |
|
|
57
|
+
| Route entries, push, storage | `defineExercise(…, { routes })` (`define-exercise-routes.ts`); a push is a `push` effect (`exercise-report.ts`), a disk write a `storage` one (`exercise-room-storage.ts`) |
|
|
57
58
|
| An override `input` is awaited, as the call's actor | `exercise-override-input.ts`: inside the call's own request — the one way to a signed input † |
|
|
58
59
|
| A passkey test signs for real | `softAuthenticator` is `@ultimat3/auth/soft-authenticator`'s, never re-exported here (one value, one path: `flight-copies`) and never a second one (auth's own suites need it, and auth cannot import testing) |
|
|
59
60
|
| A reached job is crash-proven | `exercise-crash.ts`: only `diverged` is red (`X_JOB_CRASH_DIVERGED`) † |
|
|
@@ -69,6 +70,7 @@ the off-barrel entry points `registry-isolation.ts`, `conformance.ts`. Full rule
|
|
|
69
70
|
| One seed writer | `entitySeedWriter({ entities, client \| driver })` (`seed-writer.ts`) writes through each entity's own repository; `snapshot` is required; `entity` loads on the first write, so the barrel stays entity-free |
|
|
70
71
|
| Factory values are DECLARED | `seed-graph-values.ts` for `factoriesFor` and `seedGraph`: default, enum, kind, pattern, `$meta.schema` — never the name † |
|
|
71
72
|
| e2e without a driver | `e2eTest` becomes `test.skip`; the gate reports the step SKIPPED (or `X_VERIFY_SUITE_VANISHED` when `x.verify.json` requires it), never passed |
|
|
73
|
+
| A server is DECLARED, never probed by hand | `{ needs: ['postgres' \| 'redis' \| 'nats'] }` on every typed registrar (`test-types-services.ts`, `TEST_SERVICE_ENV`): unset `TEST_*_URL` is a `test.skip` whose name carries the variable and the start command, never a hand-rolled runner or `describe.skipIf` |
|
|
72
74
|
| The seam has an inverse | `resetE2eDriver()`: `useE2eDriver` writes MODULE scope, so a file that installs a browser undoes it |
|
|
73
75
|
| Built vs declared | `clock` `mail` `network` `runJobs` `statements` `subscribe` are built in-process; `page` `budget` `signIn` `deploy` are declared and wait for a driver (`X_TEST_FIXTURE_UNAVAILABLE`). |
|
|
74
76
|
| `page` HAS a driver; `budget`, `signIn`, `deploy` do not | `installE2eDriver({ page, baseUrl })` registers `page` only. Byte counts, a sign-in route and a new build id are facts no page port can answer; a no-op would read as proof |
|
|
@@ -108,6 +110,7 @@ the off-barrel entry points `registry-isolation.ts`, `conformance.ts`. Full rule
|
|
|
108
110
|
| A port's contract is shared examples | one suite per port on `@ultimat3/testing/conformance`: `behavesLike(<port>Conformance, () => yours)`, each with a broken adapter that must fail † |
|
|
109
111
|
| An island needs a BUILDER, not an import | `buildIslands` is `@ultimat3/cli`'s; `testing → cli` fails `bun run boundaries` |
|
|
110
112
|
| `mountIsland` AWAITS `mount` | `IslandEntry['mount']` returns `unknown`, not `void`, and the call is awaited |
|
|
113
|
+
| An island chunk counts for its source | under `ISLAND_COVERAGE_ENV` (`runCovered` sets it) `mountIsland` asks the builder for `coverage: true` and records each chunk's `map` (`fixture-island-coverage.ts`); the CLI credits the chunk's lines to the `.island.tsx` |
|
|
111
114
|
| Dispose STOPS the island, then restores the globals | when `mount` resolved to a function, `[Symbol.dispose]` calls it BEFORE `restore()` |
|
|
112
115
|
| The micro-DOM is the fixture's, once **for islands** | `island-dom.ts`. Full rule: `docs/history/testing.md` |
|
|
113
116
|
| The micro-DOM records and does not pretend | records `style`/`classList`; the box is 0 until written; `ResizeObserver` never fires itself † |
|
package/README.md
CHANGED
|
@@ -40,6 +40,10 @@ unitTest('the clock moves only when the test moves it', ({ clock }) => {
|
|
|
40
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 |
|
|
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
|
+
| `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` |
|
|
44
|
+
| `exercise-shard.ts` | `runExercisePass({ …, shard: { index, total } })` — the `index`-th of `total` disjoint slices (primitives, then routes, by registry position); ignored beside `only` |
|
|
45
|
+
| `exercise-report.ts` (push) | `{ kind: 'push', host, count }`: each `outbound.request` with vendor `push` the observed call made — a pusher that sends nothing leaves none |
|
|
46
|
+
| `exercise-room-storage.ts` | `{ kind: 'storage', disk, op: 'put' \| 'copy' \| 'delete', count }`: each `storage.<verb>` write the observed call made through a `defineStorage` disk; a read, or a write the driver refused, leaves none |
|
|
43
47
|
| `exercise-setup.ts` | `withExerciseSetup(room, setup)`: the app's `setup` run inside the sealed room before the first row, its handle disposed before the room restores the network; an `allowHost` in it is `X_EXERCISE_SETUP_UNSEALED`. Types `ExerciseSetup`, `ExerciseSetupHandle` |
|
|
44
48
|
| `exercise-actor.ts` · `exercise-input.ts` · `exercise-report.ts` | the first `x policy explain` actor the policy allows, minted in the primitive's tenant · the input: override, then a seeded id by field stem, then the minimal draw (`@ultimat3/schema/sample`, loaded dynamically) · the room one run executes in (network sealed, mail captured, clock frozen) and its record |
|
|
45
49
|
| `exercise-override-line.ts` | `overrideLine`, the entry an unreached record says to paste: valid TS — the actor the pass ran as (`testActor(name, { roles, permissions }).actor`, `null` signed out, left out when the entry declares one) and each id field bound to the seeded row the pass used; an id it could not bind is the string `UNBOUND_ID` |
|
|
@@ -78,6 +82,7 @@ unitTest('the clock moves only when the test moves it', ({ clock }) => {
|
|
|
78
82
|
| `fixture-{clock,mail,jobs,network,statements}.ts` | the five fixtures the framework builds in-process |
|
|
79
83
|
| `fixture-drivers.ts` | the five it declares but a driver must build — `page` `budget` `signIn` `deploy` `subscribe` |
|
|
80
84
|
| `fixture-island.ts` | `mountIsland()` — build an island, import its chunk, run its `mount`. The BUILDER is a parameter |
|
|
85
|
+
| `fixture-island-coverage.ts` | `ISLAND_COVERAGE_ENV` — under `x verify`'s coverage run, each mounted chunk's source map is recorded so its lines count for the island's source |
|
|
81
86
|
| `island-dom.ts` | the micro-DOM `mountIsland` drives: what compiled Solid touches, and nothing else |
|
|
82
87
|
| `island-selector.ts` | the selector grammar `find`/`all` read — compounds and two combinators — and the refusal for the rest |
|
|
83
88
|
| `island-observers.ts` | `ResizeObserver`, recording; `deliverResize` is the test's hand on the browser's layout |
|
|
@@ -321,7 +326,7 @@ there is no flag on the fixture and no code to silence.
|
|
|
321
326
|
| `contractTest` | OpenAPI diff vs the committed spec, MCP exposure | `contract` |
|
|
322
327
|
| `liveTest` | exactly what each subscriber receives | `live` |
|
|
323
328
|
| `jobTest` | step sequence, retries, idempotency | `job` |
|
|
324
|
-
| `e2eTest` | a browser driver; with none registered it SKIPS, and
|
|
329
|
+
| `e2eTest` | a browser driver; with none registered it SKIPS, and a step that ran nothing is reported SKIPPED, never passed; with `e2e` in `x.verify.json` it is red — `X_VERIFY_E2E_BROWSER_MISSING`, whose fix installs a browser, when this machine has none. `hasE2eDriver()` says which state a harness is in. Every one audits the page's accessibility tree; the only exception is `{ a11y: { allow: [{ role, selector, because }] } }` ([Testing](https://github.com/developerz-ai/ultimate/wiki/Testing#the-accessibility-audit)) | `e2e` |
|
|
325
330
|
| `evalTest` | LLM output scoring against a threshold | `eval` |
|
|
326
331
|
|
|
327
332
|
Each takes an optional `{ timeoutMs }` after the body — `unitTest(name, body, { timeoutMs: 30_000 })`,
|
|
@@ -1397,3 +1402,39 @@ X_TEST_MODULE_MOCK_UNRESTORABLE: a mocked module could not be put back at the fi
|
|
|
1397
1402
|
"/app/a.test.ts" mocked "/app/vendor.ts", whose real module failed to load (…)
|
|
1398
1403
|
fix: x test unit --isolate # or hand the mocked dependency to the code under test as a parameter
|
|
1399
1404
|
```
|
|
1405
|
+
|
|
1406
|
+
## A test that needs a real server
|
|
1407
|
+
|
|
1408
|
+
Declared, never hand-rolled: `{ needs: [...] }` on any typed registrar (`unitTest`, `contractTest`,
|
|
1409
|
+
`liveTest`, `jobTest`, `e2eTest`, `evalTest`) names the services the test talks to. Each is read
|
|
1410
|
+
from the variable `docker/test-services.env` publishes it under — set, the test runs; unset or
|
|
1411
|
+
blank, it is **skipped**, and its reported name carries the service, the variable and the command
|
|
1412
|
+
that starts them. An app needs no Postgres runner or `describe.skipIf` of its own.
|
|
1413
|
+
|
|
1414
|
+
| `needs` | Variable |
|
|
1415
|
+
|---|---|
|
|
1416
|
+
| `postgres` | `TEST_DATABASE_URL` |
|
|
1417
|
+
| `redis` | `TEST_REDIS_URL` |
|
|
1418
|
+
| `nats` | `TEST_NATS_URL` |
|
|
1419
|
+
|
|
1420
|
+
The map is `TEST_SERVICE_ENV` and the start command `TEST_SERVICES_START`, both exported with the
|
|
1421
|
+
`TestService` type — the same map `x drill` reads its services from.
|
|
1422
|
+
|
|
1423
|
+
```ts
|
|
1424
|
+
import { expect, unitTest } from '@ultimat3/testing';
|
|
1425
|
+
|
|
1426
|
+
unitTest(
|
|
1427
|
+
'a uuid[] column decodes from the real driver',
|
|
1428
|
+
async () => {
|
|
1429
|
+
const url = Bun.env['TEST_DATABASE_URL'];
|
|
1430
|
+
expect(url).toBeDefined();
|
|
1431
|
+
},
|
|
1432
|
+
{ needs: ['postgres'] },
|
|
1433
|
+
);
|
|
1434
|
+
```
|
|
1435
|
+
|
|
1436
|
+
Unset, the line reads `unit · a uuid[] column decodes from the real driver (needs postgres
|
|
1437
|
+
(TEST_DATABASE_URL) unset: docker compose -f docker/docker-compose.test.yml up -d --wait && set -a
|
|
1438
|
+
&& . docker/test-services.env && set +a)`. A skip is never a pass: a step whose every test skipped
|
|
1439
|
+
is `X_VERIFY_SUITE_VANISHED` when `x.verify.json` requires it, and under `CI` the `skipCeiling`
|
|
1440
|
+
judges how many may skip.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ultimat3/testing",
|
|
3
|
-
"version": "31.
|
|
3
|
+
"version": "31.28.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,29 @@
|
|
|
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.28.0",
|
|
51
|
+
"@ultimat3/ai": "31.28.0",
|
|
52
|
+
"@ultimat3/auth": "31.28.0",
|
|
53
|
+
"@ultimat3/cache": "31.28.0",
|
|
54
|
+
"@ultimat3/core": "31.28.0",
|
|
55
|
+
"@ultimat3/db": "31.28.0",
|
|
56
|
+
"@ultimat3/entity": "31.28.0",
|
|
57
|
+
"@ultimat3/http": "31.28.0",
|
|
58
|
+
"@ultimat3/i18n": "31.28.0",
|
|
59
|
+
"@ultimat3/jobs": "31.28.0",
|
|
60
|
+
"@ultimat3/mail": "31.28.0",
|
|
61
|
+
"@ultimat3/notify": "31.28.0",
|
|
62
|
+
"@ultimat3/policy": "31.28.0",
|
|
63
|
+
"@ultimat3/pwa": "31.28.0",
|
|
64
|
+
"@ultimat3/query": "31.28.0",
|
|
65
|
+
"@ultimat3/realtime": "31.28.0",
|
|
66
|
+
"@ultimat3/render": "31.28.0",
|
|
67
|
+
"@ultimat3/schema": "31.28.0",
|
|
68
|
+
"@ultimat3/scraping": "31.28.0",
|
|
69
|
+
"@ultimat3/seo": "31.28.0",
|
|
70
|
+
"@ultimat3/time": "31.28.0"
|
|
71
|
+
},
|
|
72
|
+
"peerDependencies": {
|
|
73
|
+
"solid-js": "^1.9.18"
|
|
71
74
|
}
|
|
72
75
|
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
// A route `load`'s entry in `defineExercise(…, { routes: { '/posts/:id': { … } } })`: the params
|
|
2
|
+
// and the actor a page needs that a seeded id and a role cannot give it, its statement ceiling, why
|
|
3
|
+
// a load that reads nothing is right (`empty`), or why it cannot run (`off`). Keyed by the URL
|
|
4
|
+
// pattern `x routes` prints; an unknown one is refused when the pass runs.
|
|
5
|
+
|
|
6
|
+
import type { Actor } from '@ultimat3/core';
|
|
7
|
+
import { finiteCount, renderCauseValue, renderFixLiteral, UltimateError } from '@ultimat3/core';
|
|
8
|
+
import type { ExerciseStatementCeiling } from './exercise-statement-ceiling';
|
|
9
|
+
|
|
10
|
+
export type RouteParamsRecord = Readonly<Record<string, string>>;
|
|
11
|
+
|
|
12
|
+
/** What a route's load runs with — each field optional, the pass's own pick where omitted. */
|
|
13
|
+
export interface RouteExerciseEntry {
|
|
14
|
+
/**
|
|
15
|
+
* The params, or a function computing them — awaited inside the load's own request as its
|
|
16
|
+
* actor, so `useContext().actor.orgId` names the seeded tenant and `db()` reads its rows.
|
|
17
|
+
*/
|
|
18
|
+
readonly params?: RouteParamsRecord | (() => Promise<RouteParamsRecord> | RouteParamsRecord);
|
|
19
|
+
/**
|
|
20
|
+
* The query string the load's URL carries (`response_type=code&…`, a leading `?` optional), or a
|
|
21
|
+
* function computing it in the load's request — a page that reads `url`, not params.
|
|
22
|
+
*/
|
|
23
|
+
readonly search?: string | (() => Promise<string> | string);
|
|
24
|
+
/**
|
|
25
|
+
* Who loads it: an actor (moved into the route's tenant), or a function of the actor the pass
|
|
26
|
+
* seated — awaited in its request — answering the actor as the app's request boundary would
|
|
27
|
+
* resolve it (its facts: the member row, the org).
|
|
28
|
+
*/
|
|
29
|
+
readonly actor?: Actor | null | ((seated: Actor | null) => Promise<Actor | null> | Actor | null);
|
|
30
|
+
/** The ceiling one load is held to, `STATEMENTS_MAX` when omitted. */
|
|
31
|
+
readonly statements?: ExerciseStatementCeiling;
|
|
32
|
+
/** Why a load that sends no statement and has no effect is right: its proofs are vacuous. */
|
|
33
|
+
readonly empty?: string;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export type RouteExerciseOverride = RouteExerciseEntry | { readonly off: string };
|
|
37
|
+
|
|
38
|
+
/** The one refusal for a stated reason left blank: the skip, or the exception, is silent. */
|
|
39
|
+
export const blankWhy = (where: string, field: string, paste: string): UltimateError =>
|
|
40
|
+
new UltimateError({
|
|
41
|
+
code: 'X_CONTRACT_EXERCISE_UNDECLARED',
|
|
42
|
+
cause: `defineExercise() gives ${renderCauseValue(where)} a blank ${field}, so the exception is silent`,
|
|
43
|
+
fix: `${paste} # in apps/web/exercise.ts`,
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
const blankText = (value: unknown): boolean =>
|
|
47
|
+
typeof value !== 'string' || value.trim().length === 0;
|
|
48
|
+
|
|
49
|
+
/** `empty: '<why>'` on any entry, primitive or route: present means stated. */
|
|
50
|
+
export function checkEmptyWhy(where: string, empty: unknown, paste: string): void {
|
|
51
|
+
if (empty !== undefined && blankText(empty)) throw blankWhy(where, 'empty why', paste);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** Each route entry, its reasons stated and its ceiling a whole count ≥ 1. */
|
|
55
|
+
export function routeEntries(
|
|
56
|
+
routes: Readonly<Record<string, RouteExerciseOverride>>,
|
|
57
|
+
): ReadonlyMap<string, RouteExerciseOverride> {
|
|
58
|
+
const entries = new Map<string, RouteExerciseOverride>();
|
|
59
|
+
for (const [path, entry] of Object.entries(routes)) {
|
|
60
|
+
const at = renderFixLiteral(path, '<pattern>');
|
|
61
|
+
const paste = (field: string): string =>
|
|
62
|
+
`defineExercise({}, { routes: { ${at}: { ${field} } } })`;
|
|
63
|
+
if ('off' in entry) {
|
|
64
|
+
if (blankText(entry.off)) throw blankWhy(path, 'off reason', paste("off: '<why>'"));
|
|
65
|
+
} else {
|
|
66
|
+
checkEmptyWhy(path, entry.empty, paste("empty: '<why it reads nothing>'"));
|
|
67
|
+
if (entry.statements !== undefined) {
|
|
68
|
+
finiteCount('defineExercise()', `${path}.statements.max`, entry.statements.max, 1);
|
|
69
|
+
if (blankText(entry.statements.why)) {
|
|
70
|
+
throw blankWhy(path, 'statements why', paste("statements: { max: <n>, why: '<why>' }"));
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
entries.set(path, entry);
|
|
75
|
+
}
|
|
76
|
+
return entries;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Every route entry names a registered route's pattern — checked when the pass runs, the route
|
|
81
|
+
* table full. `X_DECLARATION_UNKNOWN`, the code every unknown name answers; the cause lists them.
|
|
82
|
+
*/
|
|
83
|
+
export function assertRoutesKnown(
|
|
84
|
+
overrides: { readonly routes?: ReadonlyMap<string, RouteExerciseOverride> } | undefined,
|
|
85
|
+
registered: readonly string[],
|
|
86
|
+
): void {
|
|
87
|
+
const known = new Set(registered);
|
|
88
|
+
const unknown = [...(overrides?.routes?.keys() ?? [])].filter((path) => !known.has(path)).sort();
|
|
89
|
+
if (unknown.length === 0) return;
|
|
90
|
+
const listed = [...known].sort();
|
|
91
|
+
throw new UltimateError({
|
|
92
|
+
code: 'X_DECLARATION_UNKNOWN',
|
|
93
|
+
cause: `defineExercise() routes name ${unknown.map((path) => renderCauseValue(path)).join(', ')}, which no app/ or site/ route with a load is (registered: ${listed.length === 0 ? 'none' : renderCauseValue(listed.join(', '))})`,
|
|
94
|
+
fix: 'x routes --json # then rename or remove the entry under routes in apps/web/exercise.ts',
|
|
95
|
+
meta: { unknown, registered: listed },
|
|
96
|
+
});
|
|
97
|
+
}
|
package/src/define-exercise.ts
CHANGED
|
@@ -5,16 +5,22 @@
|
|
|
5
5
|
|
|
6
6
|
import type { ExerciseActorOptions, ExerciseOffOptions } from '@ultimat3/action';
|
|
7
7
|
import { finiteCount, renderCauseValue, renderFixLiteral, UltimateError } from '@ultimat3/core';
|
|
8
|
+
import type { RouteExerciseOverride } from './define-exercise-routes';
|
|
9
|
+
import { checkEmptyWhy, routeEntries } from './define-exercise-routes';
|
|
8
10
|
import type { ExerciseSetup } from './exercise-setup';
|
|
9
11
|
import type { ExerciseStatementCeiling } from './exercise-statement-ceiling';
|
|
10
12
|
import type { SeedFactory } from './seed-graph-plan';
|
|
11
13
|
|
|
12
14
|
/**
|
|
13
15
|
* 39's option type — `{ actor, input?, runs? }` or `{ off: '<reason>' }` — and the pass's own
|
|
14
|
-
* `statements: { max, why }`: the ceiling one call is held to, `STATEMENTS_MAX` when omitted
|
|
16
|
+
* `statements: { max, why }`: the ceiling one call is held to, `STATEMENTS_MAX` when omitted; and
|
|
17
|
+
* `empty: '<why>'`: why a reach with no statement and no effect is right (`X_EXERCISE_EMPTY_REACH`).
|
|
15
18
|
*/
|
|
16
19
|
export type ExerciseOverride =
|
|
17
|
-
| (ExerciseActorOptions & {
|
|
20
|
+
| (ExerciseActorOptions & {
|
|
21
|
+
readonly statements?: ExerciseStatementCeiling;
|
|
22
|
+
readonly empty?: string;
|
|
23
|
+
})
|
|
18
24
|
| ExerciseOffOptions;
|
|
19
25
|
|
|
20
26
|
/**
|
|
@@ -32,6 +38,8 @@ export interface ExerciseOverrides {
|
|
|
32
38
|
readonly factories?: Readonly<Record<string, SeedFactory>>;
|
|
33
39
|
/** The app's hooks, run once each, in order, inside the pass's sealed room (`exercise-setup.ts`). */
|
|
34
40
|
readonly setup?: ExerciseSetup | readonly ExerciseSetup[];
|
|
41
|
+
/** Each route load's entry, by URL pattern (`define-exercise-routes.ts`). */
|
|
42
|
+
readonly routes?: ReadonlyMap<string, RouteExerciseOverride>;
|
|
35
43
|
}
|
|
36
44
|
|
|
37
45
|
/** The three kinds an entry may be qualified by. */
|
|
@@ -77,6 +85,11 @@ export interface ExerciseAppOptions {
|
|
|
77
85
|
* disposed in reverse; one that throws disposes those that already ran.
|
|
78
86
|
*/
|
|
79
87
|
readonly setup?: ExerciseSetup | readonly ExerciseSetup[];
|
|
88
|
+
/**
|
|
89
|
+
* By URL pattern (`x routes`), what a route's `load` runs with: `params`, `actor`, `statements`,
|
|
90
|
+
* `empty` or `off` (`define-exercise-routes.ts`). An unknown pattern is refused when the pass runs.
|
|
91
|
+
*/
|
|
92
|
+
readonly routes?: Readonly<Record<string, RouteExerciseOverride>>;
|
|
80
93
|
}
|
|
81
94
|
|
|
82
95
|
/** `X_CONTRACT_EXERCISE_UNDECLARED`, 39's code for the same silence: an `off` with no reason. */
|
|
@@ -113,6 +126,14 @@ export function defineExercise(
|
|
|
113
126
|
for (const [name, override] of Object.entries(overrides)) {
|
|
114
127
|
if ('off' in override && override.off.trim().length === 0) throw blankReason(name);
|
|
115
128
|
checkCeiling(name, override);
|
|
129
|
+
if (!('off' in override)) {
|
|
130
|
+
const at = renderFixLiteral(name, '<name>');
|
|
131
|
+
checkEmptyWhy(
|
|
132
|
+
name,
|
|
133
|
+
override.empty,
|
|
134
|
+
`defineExercise({ ${at}: { empty: '<why it reads nothing>' } })`,
|
|
135
|
+
);
|
|
136
|
+
}
|
|
116
137
|
entries.set(name, override);
|
|
117
138
|
}
|
|
118
139
|
return Object.freeze({
|
|
@@ -125,6 +146,7 @@ export function defineExercise(
|
|
|
125
146
|
: { actorEntity: app.actor.$name }),
|
|
126
147
|
...(app.factories === undefined ? {} : { factories: app.factories }),
|
|
127
148
|
...(app.setup === undefined ? {} : { setup: app.setup }),
|
|
149
|
+
...(app.routes === undefined ? {} : { routes: routeEntries(app.routes) }),
|
|
128
150
|
});
|
|
129
151
|
}
|
|
130
152
|
|
package/src/drill-services.ts
CHANGED
|
@@ -6,13 +6,13 @@ import { DrillServiceMissingError } from './drill-errors';
|
|
|
6
6
|
import type { DrillServiceUrls } from './drill-fleet';
|
|
7
7
|
import type { Drill } from './drills';
|
|
8
8
|
import { drillService } from './drills';
|
|
9
|
+
import { TEST_SERVICE_ENV } from './test-types-services';
|
|
9
10
|
|
|
10
|
-
/**
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
} as const;
|
|
11
|
+
/**
|
|
12
|
+
* The variables the test services are published under (`docker/test-services.env`): the same map a
|
|
13
|
+
* typed test's `{ needs }` reads, never a second copy of it.
|
|
14
|
+
*/
|
|
15
|
+
export const DRILL_SERVICE_ENV = TEST_SERVICE_ENV;
|
|
16
16
|
|
|
17
17
|
/** What the app's config says it uses, beyond the Postgres every drill needs. */
|
|
18
18
|
export interface DrillDeclarations {
|
package/src/exercise-judge.ts
CHANGED
|
@@ -4,12 +4,13 @@
|
|
|
4
4
|
|
|
5
5
|
import type { ExerciseVerdict } from '@ultimat3/core';
|
|
6
6
|
import { isUltimateError, renderThrowable } from '@ultimat3/core';
|
|
7
|
-
import {
|
|
7
|
+
import type { ExerciseOverrides } from './define-exercise';
|
|
8
|
+
import { exerciseEntryKey, overrideFor } from './define-exercise';
|
|
8
9
|
import { driftOverrideLine } from './exercise-drift-hint';
|
|
9
10
|
import type { Sampler } from './exercise-input';
|
|
10
11
|
import { idStem } from './exercise-input';
|
|
11
12
|
import { type OverrideHint, overrideLine } from './exercise-override-line';
|
|
12
|
-
import type { Observed } from './exercise-report';
|
|
13
|
+
import type { ExerciseRecord, Observed } from './exercise-report';
|
|
13
14
|
import type { Subject } from './exercise-subjects';
|
|
14
15
|
|
|
15
16
|
/**
|
|
@@ -78,3 +79,13 @@ export function judged(
|
|
|
78
79
|
}
|
|
79
80
|
return unreached(codeOf(run.lastError), reasonOf(run.lastError));
|
|
80
81
|
}
|
|
82
|
+
|
|
83
|
+
/** A reach with nothing to prove carries its entry's `empty` reason, when the entry gives one. */
|
|
84
|
+
export function withEmptyWhy(record: ExerciseRecord, overrides: ExerciseOverrides | undefined) {
|
|
85
|
+
if (record.outcome !== 'reached' || record.statements > 0 || record.effects.length > 0) {
|
|
86
|
+
return record;
|
|
87
|
+
}
|
|
88
|
+
const entry = overrideFor(overrides, record.kind, record.name);
|
|
89
|
+
const why = entry === undefined || 'off' in entry ? undefined : entry.empty;
|
|
90
|
+
return why === undefined ? record : { ...record, empty: why.trim() };
|
|
91
|
+
}
|
package/src/exercise-observed.ts
CHANGED
|
@@ -11,6 +11,8 @@ const countKey = (effect: ExerciseEffect): string | undefined => {
|
|
|
11
11
|
if (effect.kind === 'row') return `row\u0000${effect.entity}\u0000${effect.op}`;
|
|
12
12
|
if (effect.kind === 'mail') return `mail\u0000${effect.mail}`;
|
|
13
13
|
if (effect.kind === 'enqueue') return `enqueue\u0000${effect.job}`;
|
|
14
|
+
if (effect.kind === 'push') return `push\u0000${effect.host}`;
|
|
15
|
+
if (effect.kind === 'storage') return `storage\u0000${effect.disk}\u0000${effect.op}`;
|
|
14
16
|
return undefined;
|
|
15
17
|
};
|
|
16
18
|
|
|
@@ -21,6 +23,10 @@ const added = (one: ExerciseEffect, other: ExerciseEffect): ExerciseEffect => {
|
|
|
21
23
|
if (one.kind === 'enqueue' && other.kind === 'enqueue') {
|
|
22
24
|
return { ...one, count: one.count + other.count };
|
|
23
25
|
}
|
|
26
|
+
if (one.kind === 'push' && other.kind === 'push')
|
|
27
|
+
return { ...one, count: one.count + other.count };
|
|
28
|
+
if (one.kind === 'storage' && other.kind === 'storage')
|
|
29
|
+
return { ...one, count: one.count + other.count };
|
|
24
30
|
return one;
|
|
25
31
|
};
|
|
26
32
|
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// What a primitive's call left on its queue, read off the call's own ambient queue: the jobs it
|
|
2
|
+
// enqueued (its effects) and, for a tenant proof's B leg, every queued job's input (its payloads).
|
|
3
|
+
|
|
4
|
+
import { LIVE_STATES, registeredJobs } from '@ultimat3/jobs';
|
|
5
|
+
import { ambientJobRows } from './exercise-job-run';
|
|
6
|
+
import type { EffectPayload, ExerciseEffect } from './exercise-report';
|
|
7
|
+
import type { Subject } from './exercise-subjects';
|
|
8
|
+
|
|
9
|
+
/** The ids of every row the call's queue holds now: what an attempt adds is the call's. */
|
|
10
|
+
export const queuedIds = async (): Promise<ReadonlySet<string>> =>
|
|
11
|
+
new Set((await ambientJobRows()).map((record) => record.id));
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Jobs the primitive queued — rows an ATTEMPT added (`mine`), still live — its own job excepted.
|
|
15
|
+
* Never run: a job's children are left queued as an action's are (`exercise-job-run.ts`). A row
|
|
16
|
+
* the override's input added between calls is on the same queue, so the call can find it, and is
|
|
17
|
+
* not in `mine`: the input's enqueue is never the primitive's.
|
|
18
|
+
*/
|
|
19
|
+
export async function enqueued(subject: Subject, mine: ReadonlySet<string>) {
|
|
20
|
+
const counts = new Map<string, number>();
|
|
21
|
+
for (const record of await ambientJobRows()) {
|
|
22
|
+
if (!mine.has(record.id) || !LIVE_STATES.has(record.state)) continue;
|
|
23
|
+
if (subject.kind === 'job' && record.name === subject.name) continue;
|
|
24
|
+
counts.set(record.name, (counts.get(record.name) ?? 0) + 1);
|
|
25
|
+
}
|
|
26
|
+
const order = registeredJobs().map((handle) => handle.name);
|
|
27
|
+
return [...counts]
|
|
28
|
+
.sort(([a], [b]) => order.indexOf(a) - order.indexOf(b))
|
|
29
|
+
.map(([job, count]): ExerciseEffect => ({ kind: 'enqueue', job, count }));
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Every job a B leg's queue holds or ran, with its input — the subject's own job excepted, whose
|
|
34
|
+
* input is what B was handed. Read off the leg's own queue, page by page.
|
|
35
|
+
*/
|
|
36
|
+
export async function queuedPayloads(subject: Subject): Promise<readonly EffectPayload[]> {
|
|
37
|
+
return (await ambientJobRows())
|
|
38
|
+
.filter((record) => !(subject.kind === 'job' && record.name === subject.name))
|
|
39
|
+
.map((record, i) => ({
|
|
40
|
+
path: `effect.enqueue[${i}]`,
|
|
41
|
+
value: { job: record.name, input: record.input },
|
|
42
|
+
}));
|
|
43
|
+
}
|
package/src/exercise-report.ts
CHANGED
|
@@ -9,6 +9,8 @@ import { expectedSeqScanReason, statementFingerprint } from '@ultimat3/db';
|
|
|
9
9
|
import { captureDeterminism, installDeterminism, restoreCapturedDeterminism } from './determinism';
|
|
10
10
|
import type { ExerciseDefect } from './exercise-defect';
|
|
11
11
|
import { roomMail } from './exercise-room-mail';
|
|
12
|
+
import type { StorageWrite } from './exercise-room-storage';
|
|
13
|
+
import { roomStorage } from './exercise-room-storage';
|
|
12
14
|
import type { StatementCeilingProof } from './exercise-statement-ceiling';
|
|
13
15
|
import { routeMatches } from './mock-route';
|
|
14
16
|
import type { PlanProof, SentStatement } from './plan-sweep';
|
|
@@ -34,7 +36,16 @@ export type ExerciseEffect =
|
|
|
34
36
|
readonly host: string;
|
|
35
37
|
readonly refused: boolean;
|
|
36
38
|
}
|
|
37
|
-
| { readonly kind: 'enqueue'; readonly job: string; readonly count: number }
|
|
39
|
+
| { readonly kind: 'enqueue'; readonly job: string; readonly count: number }
|
|
40
|
+
/** Web Push messages sent to `host`'s push service: a notifier that pushes nothing has none. */
|
|
41
|
+
| { readonly kind: 'push'; readonly host: string; readonly count: number }
|
|
42
|
+
/** Objects `disk` was written, copied into or deleted from, or an upload session it changed. */
|
|
43
|
+
| {
|
|
44
|
+
readonly kind: 'storage';
|
|
45
|
+
readonly disk: string;
|
|
46
|
+
readonly op: StorageWrite;
|
|
47
|
+
readonly count: number;
|
|
48
|
+
};
|
|
38
49
|
|
|
39
50
|
export type ExerciseOutcome = 'reached' | 'refused' | 'unreached' | 'off';
|
|
40
51
|
|
|
@@ -123,6 +134,11 @@ export interface ExerciseRecord {
|
|
|
123
134
|
* whose `tenant(input)` names one fixed org (`exercise-subjects.ts`'s `fixedTenant`).
|
|
124
135
|
*/
|
|
125
136
|
readonly fix?: string;
|
|
137
|
+
/**
|
|
138
|
+
* On a reached one with no statement and no effect: the entry's `empty` reason, why that reach
|
|
139
|
+
* is right. Absent, the reach is `X_EXERCISE_EMPTY_REACH` — its proofs prove nothing.
|
|
140
|
+
*/
|
|
141
|
+
readonly empty?: string;
|
|
126
142
|
/** On every record that ran — absent only on `off` and `refused`. The fields above are A's. */
|
|
127
143
|
readonly tenant?: TenantProof;
|
|
128
144
|
/** On a reached job only: its control's input, killed at every step boundary. */
|
|
@@ -286,6 +302,14 @@ export async function openExerciseRoom(): Promise<ExerciseRoom> {
|
|
|
286
302
|
const offDials = onDial((call) => {
|
|
287
303
|
if (owns()) calls.push(call);
|
|
288
304
|
});
|
|
305
|
+
// A push travels through an injected fetch (the pass's push stand-in), never a dial: what tells
|
|
306
|
+
// of it is `outbound()`'s own event, vendor `push`, which every send emits whatever answers it.
|
|
307
|
+
const pushes: string[] = [];
|
|
308
|
+
const offPushes = subscribe('outbound.request', (event) => {
|
|
309
|
+
if (owns() && event.payload.vendor === 'push') pushes.push(event.payload.host);
|
|
310
|
+
});
|
|
311
|
+
// A disk write: `storage.<verb>` is reported in the writer's own context, after its await.
|
|
312
|
+
const objects = roomStorage(owns);
|
|
289
313
|
|
|
290
314
|
const begin = (name: string | undefined): object => {
|
|
291
315
|
subject = name;
|
|
@@ -295,6 +319,8 @@ export async function openExerciseRoom(): Promise<ExerciseRoom> {
|
|
|
295
319
|
unattributed = false;
|
|
296
320
|
rows.length = 0;
|
|
297
321
|
calls.length = 0;
|
|
322
|
+
pushes.length = 0;
|
|
323
|
+
objects.clear();
|
|
298
324
|
mail.clear();
|
|
299
325
|
marker = {};
|
|
300
326
|
return marker;
|
|
@@ -321,6 +347,8 @@ export async function openExerciseRoom(): Promise<ExerciseRoom> {
|
|
|
321
347
|
refused: refused(call),
|
|
322
348
|
}),
|
|
323
349
|
),
|
|
350
|
+
...[...tally(pushes)].map(([host, count]): ExerciseEffect => ({ kind: 'push', host, count })),
|
|
351
|
+
...objects.effects(),
|
|
324
352
|
];
|
|
325
353
|
const refusedHosts = calls.filter(refused).map((c) => hostOf(c.url));
|
|
326
354
|
const payloads: EffectPayload[] = [
|
|
@@ -366,6 +394,8 @@ export async function openExerciseRoom(): Promise<ExerciseRoom> {
|
|
|
366
394
|
try {
|
|
367
395
|
mail[Symbol.dispose]();
|
|
368
396
|
} finally {
|
|
397
|
+
objects.off();
|
|
398
|
+
offPushes();
|
|
369
399
|
offDials();
|
|
370
400
|
offRows();
|
|
371
401
|
offStatements();
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
// The exercise room's storage seam: every object a disk wrote, copied or deleted while the observed
|
|
2
|
+
// call was in flight, read off core's `storage.<verb>` events. A write is the call's effect as a
|
|
3
|
+
// row or a mail is — an upload action that only stores an object is a reach that did something.
|
|
4
|
+
|
|
5
|
+
import { subscribe } from '@ultimat3/core';
|
|
6
|
+
import type { ExerciseEffect } from './exercise-report';
|
|
7
|
+
|
|
8
|
+
/** The verbs that change what a disk holds, each by its event; a get, stat or list leaves it be. */
|
|
9
|
+
const WRITES = [
|
|
10
|
+
['put', 'storage.put'],
|
|
11
|
+
['copy', 'storage.copy'],
|
|
12
|
+
['delete', 'storage.delete'],
|
|
13
|
+
] as const;
|
|
14
|
+
|
|
15
|
+
/** A write's effect `op`: the verb, or `multipart.<op>` for a change to an upload session. */
|
|
16
|
+
export type StorageWrite =
|
|
17
|
+
| (typeof WRITES)[number][0]
|
|
18
|
+
| `multipart.${'create' | 'part' | 'complete' | 'abort'}`;
|
|
19
|
+
|
|
20
|
+
interface WriteEvent {
|
|
21
|
+
readonly payload: { readonly disk: string; readonly error?: unknown };
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface RoomStorage {
|
|
25
|
+
/** The observed call's writes since `clear()`: one effect per disk and verb, counted. */
|
|
26
|
+
effects(): readonly ExerciseEffect[];
|
|
27
|
+
clear(): void;
|
|
28
|
+
/** Releases the subscriptions; the bus's other subscribers are untouched. */
|
|
29
|
+
off(): void;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** Subscribe to every write verb, keeping those made while `owns()` answers true. */
|
|
33
|
+
export function roomStorage(owns: () => boolean): RoomStorage {
|
|
34
|
+
const kept = new Map<string, { disk: string; op: StorageWrite; count: number }>();
|
|
35
|
+
const keep =
|
|
36
|
+
(verb: StorageWrite) =>
|
|
37
|
+
(event: WriteEvent): void => {
|
|
38
|
+
// A refused write changed nothing, so it is no effect: the error is the call's answer.
|
|
39
|
+
if (!owns() || event.payload.error !== undefined) return;
|
|
40
|
+
const { disk } = event.payload;
|
|
41
|
+
const key = `${disk}\u0000${verb}`;
|
|
42
|
+
const known = kept.get(key) ?? { disk, op: verb, count: 0 };
|
|
43
|
+
known.count += 1;
|
|
44
|
+
kept.set(key, known);
|
|
45
|
+
};
|
|
46
|
+
const offs = [
|
|
47
|
+
...WRITES.map(([verb, event]) => subscribe(event, keep(verb))),
|
|
48
|
+
subscribe('storage.multipart', (event) => keep(`multipart.${event.payload.op}`)(event)),
|
|
49
|
+
];
|
|
50
|
+
return {
|
|
51
|
+
effects: () =>
|
|
52
|
+
[...kept.values()].map(({ disk, op, count }) => ({ kind: 'storage', disk, op, count })),
|
|
53
|
+
clear: () => kept.clear(),
|
|
54
|
+
off: () => {
|
|
55
|
+
for (const off of offs) off();
|
|
56
|
+
},
|
|
57
|
+
};
|
|
58
|
+
}
|
|
@@ -16,8 +16,16 @@ import type {
|
|
|
16
16
|
ProofMs,
|
|
17
17
|
} from './exercise-report';
|
|
18
18
|
import { withExerciseRequest } from './exercise-request';
|
|
19
|
+
import {
|
|
20
|
+
entryActor,
|
|
21
|
+
entryActorChoice,
|
|
22
|
+
entryParams,
|
|
23
|
+
entrySearch,
|
|
24
|
+
liveEntry,
|
|
25
|
+
routeEntryFor,
|
|
26
|
+
} from './exercise-route-override';
|
|
19
27
|
import type { RouteLoadSubject, RouteParamsValue } from './exercise-route-subjects';
|
|
20
|
-
import {
|
|
28
|
+
import { routeParams, routeUrl } from './exercise-route-subjects';
|
|
21
29
|
import type { StatementCeilingProof } from './exercise-statement-ceiling';
|
|
22
30
|
import { judgeStatementCeiling } from './exercise-statement-ceiling';
|
|
23
31
|
import { actorRowsOf, seated } from './exercise-sweeps';
|
|
@@ -32,13 +40,15 @@ export interface RouteLoadRecord {
|
|
|
32
40
|
readonly kind: 'route';
|
|
33
41
|
readonly name: string;
|
|
34
42
|
readonly file: string;
|
|
35
|
-
readonly outcome: 'reached' | 'refused' | 'unreached';
|
|
43
|
+
readonly outcome: 'reached' | 'refused' | 'unreached' | 'off';
|
|
36
44
|
readonly code?: string;
|
|
37
45
|
readonly reason?: string;
|
|
38
46
|
readonly statements: number;
|
|
39
47
|
readonly effects: readonly ExerciseEffect[];
|
|
40
48
|
readonly ms: number;
|
|
41
49
|
readonly statementCeiling?: StatementCeilingProof;
|
|
50
|
+
/** Reached with no statement and no effect, and the entry says why that is right. */
|
|
51
|
+
readonly empty?: string;
|
|
42
52
|
readonly plans?: PlanProof;
|
|
43
53
|
readonly scale?: ScaleProof;
|
|
44
54
|
readonly proofMs?: ProofMs;
|
|
@@ -57,31 +67,51 @@ export interface RouteCallOptions {
|
|
|
57
67
|
/** The page's data, resolved as a render resolves it, in a request as `actor`. */
|
|
58
68
|
export const callRoute = (
|
|
59
69
|
route: RouteLoadSubject,
|
|
60
|
-
|
|
70
|
+
call: RouteCallInput,
|
|
61
71
|
actor: Actor | null,
|
|
62
72
|
): Promise<unknown> =>
|
|
63
73
|
withExerciseRequest(routeLabel(route.path), actor, () =>
|
|
64
|
-
route.load({ params, url: routeUrl(route.path, params) }),
|
|
74
|
+
route.load({ params: call.params, url: `${routeUrl(route.path, call.params)}${call.search}` }),
|
|
65
75
|
);
|
|
66
76
|
|
|
67
|
-
/**
|
|
77
|
+
/** What one load is handed: its params and the query string its URL carries (`''`, or `?…`). */
|
|
78
|
+
export interface RouteCallInput {
|
|
79
|
+
readonly params: RouteParamsValue;
|
|
80
|
+
readonly search: string;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Who loads `route` in `tenant` of `graph`, and with which params — or none. The route's
|
|
85
|
+
* `defineExercise` entry speaks first (`exercise-route-override.ts`); the pass picks the rest.
|
|
86
|
+
*/
|
|
68
87
|
export async function routeCall(
|
|
69
88
|
route: RouteLoadSubject,
|
|
70
89
|
options: RouteCallOptions,
|
|
71
90
|
graph: SeedGraph,
|
|
72
91
|
tenant: string,
|
|
73
92
|
): Promise<
|
|
74
|
-
| { readonly actor: Actor | null
|
|
93
|
+
| ({ readonly actor: Actor | null } & RouteCallInput)
|
|
75
94
|
| { readonly refused?: true; readonly reason: string }
|
|
76
95
|
> {
|
|
77
|
-
const
|
|
96
|
+
const entry = liveEntry(routeEntryFor(options.overrides, route.path));
|
|
97
|
+
const label = routeLabel(route.path);
|
|
98
|
+
const chosen = entryActorChoice(entry, route.permission, options.roles, tenant);
|
|
78
99
|
if (chosen.kind === 'refused') return { refused: true, reason: chosen.reason };
|
|
79
|
-
const
|
|
100
|
+
const base = seated(chosen.actor, tenant, actorRowsOf(options, graph));
|
|
101
|
+
// A user, as a request's actor always is: its `x_users` row before any call.
|
|
102
|
+
await seatActorUsers([base]);
|
|
103
|
+
const resolved = await entryActor(label, entry, base);
|
|
104
|
+
if (resolved.kind === 'threw') return { reason: resolved.reason };
|
|
105
|
+
const actor = resolved.value;
|
|
106
|
+
if (actor !== base) await seatActorUsers([actor]);
|
|
107
|
+
const search = await entrySearch(label, entry, actor);
|
|
108
|
+
if (search.kind === 'threw') return { reason: search.reason };
|
|
109
|
+
const declared = await entryParams(label, entry, actor);
|
|
110
|
+
if (declared?.kind === 'threw') return { reason: declared.reason };
|
|
111
|
+
if (declared !== undefined) return { actor, params: declared.value, search: search.value };
|
|
80
112
|
const params = await routeParams(route, graph, options.entities, { tenant, actorId: actor?.id });
|
|
81
113
|
if (params.kind === 'none') return { reason: params.reason };
|
|
82
|
-
|
|
83
|
-
await seatActorUsers([actor]);
|
|
84
|
-
return { actor, params: params.params };
|
|
114
|
+
return { actor, params: params.params, search: search.value };
|
|
85
115
|
}
|
|
86
116
|
|
|
87
117
|
const unreachedBy = (seen: Observation<unknown>) => {
|
|
@@ -107,6 +137,10 @@ export async function exerciseRouteLoad(
|
|
|
107
137
|
): Promise<RouteLoadRecord> {
|
|
108
138
|
const none = { kind: 'route' as const, name: route.path, file: route.file };
|
|
109
139
|
const empty = { ...none, statements: 0, effects: [], ms: 0 };
|
|
140
|
+
const entry = routeEntryFor(options.overrides, route.path);
|
|
141
|
+
if (entry !== undefined && 'off' in entry) {
|
|
142
|
+
return { ...empty, outcome: 'off', reason: entry.off.trim() };
|
|
143
|
+
}
|
|
110
144
|
const call = await routeCall(route, options, at.graph, at.tenant);
|
|
111
145
|
if ('reason' in call) {
|
|
112
146
|
return {
|
|
@@ -117,25 +151,28 @@ export async function exerciseRouteLoad(
|
|
|
117
151
|
}
|
|
118
152
|
const started = performance.now();
|
|
119
153
|
const seen = await at.room.observe(routeLabel(route.path), () =>
|
|
120
|
-
callRoute(route, call
|
|
154
|
+
callRoute(route, call, call.actor),
|
|
121
155
|
);
|
|
122
156
|
const ms = Math.round(performance.now() - started);
|
|
123
157
|
const { observed } = seen;
|
|
124
158
|
const ran = { ...none, statements: observed.statements, effects: observed.effects, ms };
|
|
125
|
-
const statementCeiling = judgeStatementCeiling([observed]);
|
|
159
|
+
const statementCeiling = judgeStatementCeiling([observed], liveEntry(entry).statements);
|
|
126
160
|
const failed = unreachedBy(seen);
|
|
161
|
+
const why = liveEntry(entry).empty;
|
|
162
|
+
const vacuous = failed === undefined && ran.statements === 0 && ran.effects.length === 0;
|
|
127
163
|
return {
|
|
128
164
|
...ran,
|
|
129
165
|
...(failed ?? { outcome: 'reached' as const }),
|
|
166
|
+
...(vacuous && why !== undefined ? { empty: why.trim() } : {}),
|
|
130
167
|
...(statementCeiling === undefined ? {} : { statementCeiling }),
|
|
131
168
|
};
|
|
132
169
|
}
|
|
133
170
|
|
|
134
|
-
/** The route as the scale sweep calls it: `input` is
|
|
171
|
+
/** The route as the scale sweep calls it: `input` is what `routeCall` bound at each size. */
|
|
135
172
|
export const routeScaleSubject = (route: RouteLoadSubject): ScaleSubject => ({
|
|
136
173
|
name: routeLabel(route.path),
|
|
137
174
|
call: async (input, actor) => {
|
|
138
|
-
await callRoute(route, input as
|
|
175
|
+
await callRoute(route, input as RouteCallInput, actor);
|
|
139
176
|
return {};
|
|
140
177
|
},
|
|
141
178
|
});
|
|
@@ -172,7 +209,9 @@ export async function routeSizedCall(
|
|
|
172
209
|
const route = routes.find((one) => routeLabel(one.path) === at.label);
|
|
173
210
|
if (route === undefined) return undefined;
|
|
174
211
|
const call = await routeCall(route, options, at.graph, at.tenant);
|
|
175
|
-
return 'reason' in call
|
|
212
|
+
return 'reason' in call
|
|
213
|
+
? undefined
|
|
214
|
+
: { actor: call.actor, input: { params: call.params, search: call.search } };
|
|
176
215
|
}
|
|
177
216
|
|
|
178
217
|
/** The sweeps' key for a record of either kind: a route's label, else the primitive's own. */
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
// What a route's `defineExercise(…, { routes })` entry changes about its call: the actor (declared,
|
|
2
|
+
// or the app's resolution of the one the pass seated) and the params (declared, or computed in the
|
|
3
|
+
// load's own request). Each function the app wrote runs in that request, so its reads see the
|
|
4
|
+
// route's tenant — and before the observed call, so its statements are never the load's.
|
|
5
|
+
|
|
6
|
+
import type { Actor } from '@ultimat3/core';
|
|
7
|
+
import { renderThrowable } from '@ultimat3/core';
|
|
8
|
+
import type { ExerciseOverrides } from './define-exercise';
|
|
9
|
+
import type { RouteExerciseEntry, RouteExerciseOverride } from './define-exercise-routes';
|
|
10
|
+
import type { RoleGrants } from './exercise-actor';
|
|
11
|
+
import { inTenant } from './exercise-actor';
|
|
12
|
+
import { withExerciseRequest } from './exercise-request';
|
|
13
|
+
import type { RouteActorChoice, RouteParamsValue } from './exercise-route-subjects';
|
|
14
|
+
import { chooseRouteActor } from './exercise-route-subjects';
|
|
15
|
+
|
|
16
|
+
/** The route's entry, by its URL pattern, or none. */
|
|
17
|
+
export const routeEntryFor = (
|
|
18
|
+
overrides: ExerciseOverrides | undefined,
|
|
19
|
+
path: string,
|
|
20
|
+
): RouteExerciseOverride | undefined => overrides?.routes?.get(path);
|
|
21
|
+
|
|
22
|
+
/** The entry as a call reads it: an `off` entry never reaches a call. */
|
|
23
|
+
export const liveEntry = (entry: RouteExerciseOverride | undefined): RouteExerciseEntry =>
|
|
24
|
+
entry === undefined || 'off' in entry ? {} : entry;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Who the pass seats before the entry speaks: a declared actor, moved into `tenant`; else the role
|
|
28
|
+
* the guard admits — and for an actor FUNCTION whose guard no role holds, the first signed-in one,
|
|
29
|
+
* which the function is there to complete.
|
|
30
|
+
*/
|
|
31
|
+
export function entryActorChoice(
|
|
32
|
+
entry: RouteExerciseEntry,
|
|
33
|
+
permission: string | undefined,
|
|
34
|
+
grants: RoleGrants,
|
|
35
|
+
tenant: string,
|
|
36
|
+
): RouteActorChoice {
|
|
37
|
+
const { actor } = entry;
|
|
38
|
+
if (actor !== undefined && typeof actor !== 'function') {
|
|
39
|
+
return { kind: 'actor', actor: inTenant(actor, tenant) };
|
|
40
|
+
}
|
|
41
|
+
const chosen = chooseRouteActor(permission, grants, tenant);
|
|
42
|
+
if (chosen.kind === 'actor' || actor === undefined) return chosen;
|
|
43
|
+
return chooseRouteActor(undefined, grants, tenant);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export type EntryOutcome<T> =
|
|
47
|
+
| { readonly kind: 'value'; readonly value: T }
|
|
48
|
+
| { readonly kind: 'threw'; readonly reason: string };
|
|
49
|
+
|
|
50
|
+
const threw = (field: string, error: unknown) => ({
|
|
51
|
+
kind: 'threw' as const,
|
|
52
|
+
reason: `its exercise.ts ${field} threw: ${renderThrowable(error)}`,
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
/** The actor the load runs as: the seated one, or what the entry's function made of it. */
|
|
56
|
+
export async function entryActor(
|
|
57
|
+
label: string,
|
|
58
|
+
entry: RouteExerciseEntry,
|
|
59
|
+
seated: Actor | null,
|
|
60
|
+
): Promise<EntryOutcome<Actor | null>> {
|
|
61
|
+
const resolve = entry.actor;
|
|
62
|
+
if (typeof resolve !== 'function') return { kind: 'value', value: seated };
|
|
63
|
+
try {
|
|
64
|
+
const value = await withExerciseRequest(label, seated, async () => resolve(seated));
|
|
65
|
+
return { kind: 'value', value };
|
|
66
|
+
} catch (error) {
|
|
67
|
+
return threw('actor', error);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** The entry's params, computed in the load's request when a function; `undefined`: the pass's. */
|
|
72
|
+
export async function entryParams(
|
|
73
|
+
label: string,
|
|
74
|
+
entry: RouteExerciseEntry,
|
|
75
|
+
actor: Actor | null,
|
|
76
|
+
): Promise<EntryOutcome<RouteParamsValue> | undefined> {
|
|
77
|
+
const { params } = entry;
|
|
78
|
+
if (params === undefined) return undefined;
|
|
79
|
+
if (typeof params !== 'function') return { kind: 'value', value: params };
|
|
80
|
+
try {
|
|
81
|
+
return { kind: 'value', value: await withExerciseRequest(label, actor, async () => params()) };
|
|
82
|
+
} catch (error) {
|
|
83
|
+
return threw('params', error);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** The query string the load's URL carries: the entry's (`?` added), computed in its request. */
|
|
88
|
+
export async function entrySearch(
|
|
89
|
+
label: string,
|
|
90
|
+
entry: RouteExerciseEntry,
|
|
91
|
+
actor: Actor | null,
|
|
92
|
+
): Promise<EntryOutcome<string>> {
|
|
93
|
+
const { search } = entry;
|
|
94
|
+
if (search === undefined) return { kind: 'value', value: '' };
|
|
95
|
+
try {
|
|
96
|
+
const value =
|
|
97
|
+
typeof search === 'function'
|
|
98
|
+
? await withExerciseRequest(label, actor, async () => search())
|
|
99
|
+
: search;
|
|
100
|
+
const bare = value.startsWith('?') ? value.slice(1) : value;
|
|
101
|
+
return { kind: 'value', value: bare.length === 0 ? '' : `?${bare}` };
|
|
102
|
+
} catch (error) {
|
|
103
|
+
return threw('search', error);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// `x exercise --shard i/n`: which primitives and route loads one of n processes runs. A pure
|
|
2
|
+
// function of the position in the registry's own order, so shard 3 of 8 is the same slice on every
|
|
3
|
+
// machine — and each subject's tenant pair is its own, so the slices share no row.
|
|
4
|
+
|
|
5
|
+
/** 1-based, as a CI matrix counts: `{ index: 2, total: 4 }` is the second of four. */
|
|
6
|
+
export interface ExerciseShard {
|
|
7
|
+
readonly index: number;
|
|
8
|
+
readonly total: number;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/** Whether the subject at `position` (primitives first, then routes) is this shard's. */
|
|
12
|
+
export const inShard = (position: number, shard: ExerciseShard | undefined): boolean =>
|
|
13
|
+
shard === undefined || position % shard.total === shard.index - 1;
|
package/src/exercise.ts
CHANGED
|
@@ -12,9 +12,9 @@
|
|
|
12
12
|
|
|
13
13
|
import type { Actor, ExerciseAttempt, ExerciseVerdict } from '@ultimat3/core';
|
|
14
14
|
import { runExercise, subscribe } from '@ultimat3/core';
|
|
15
|
-
import { LIVE_STATES, registeredJobs } from '@ultimat3/jobs';
|
|
16
15
|
import type { ExerciseOverride, ExerciseOverrides } from './define-exercise';
|
|
17
16
|
import { assertOverridesKnown, overrideFor, unknownDeclaration } from './define-exercise';
|
|
17
|
+
import { assertRoutesKnown } from './define-exercise-routes';
|
|
18
18
|
import type { RoleGrants } from './exercise-actor';
|
|
19
19
|
import { chooseActor } from './exercise-actor';
|
|
20
20
|
import { seatActorUsers } from './exercise-actor-user';
|
|
@@ -22,20 +22,13 @@ import { proveCrash } from './exercise-crash';
|
|
|
22
22
|
import { defectDetail } from './exercise-defect';
|
|
23
23
|
import type { IdLookup, Sampler } from './exercise-input';
|
|
24
24
|
import { bindIds, drawInput, loadSampler, namesActorEntity, seededIds } from './exercise-input';
|
|
25
|
-
import {
|
|
26
|
-
import { judged, labelFor } from './exercise-judge';
|
|
25
|
+
import { judged, labelFor, withEmptyWhy } from './exercise-judge';
|
|
27
26
|
import { mergeObserved } from './exercise-observed';
|
|
28
27
|
import type { OverrideInput } from './exercise-override-input';
|
|
29
28
|
import { inputThrew, overrideInput } from './exercise-override-input';
|
|
30
29
|
import { actorHintOf, type OverrideHint, seededIn } from './exercise-override-line';
|
|
31
|
-
import
|
|
32
|
-
|
|
33
|
-
ExerciseEffect,
|
|
34
|
-
ExercisePhaseMs,
|
|
35
|
-
ExerciseRecord,
|
|
36
|
-
ExerciseRoom,
|
|
37
|
-
Observed,
|
|
38
|
-
} from './exercise-report';
|
|
30
|
+
import { enqueued, queuedIds, queuedPayloads } from './exercise-queued';
|
|
31
|
+
import type { ExercisePhaseMs, ExerciseRecord, ExerciseRoom, Observed } from './exercise-report';
|
|
39
32
|
import { openExerciseRoom } from './exercise-report';
|
|
40
33
|
import type { RouteLoadRecord } from './exercise-route-loads';
|
|
41
34
|
import {
|
|
@@ -47,6 +40,8 @@ import {
|
|
|
47
40
|
} from './exercise-route-loads';
|
|
48
41
|
import type { RouteLoadSubject } from './exercise-route-subjects';
|
|
49
42
|
import { withExerciseSetup } from './exercise-setup';
|
|
43
|
+
import type { ExerciseShard } from './exercise-shard';
|
|
44
|
+
import { inShard } from './exercise-shard';
|
|
50
45
|
import type { ExerciseStatementCeiling } from './exercise-statement-ceiling';
|
|
51
46
|
import { judgeStatementCeiling } from './exercise-statement-ceiling';
|
|
52
47
|
import type { Subject } from './exercise-subjects';
|
|
@@ -88,6 +83,8 @@ export interface ExercisePassOptions {
|
|
|
88
83
|
readonly routes?: readonly RouteLoadSubject[];
|
|
89
84
|
/** Told once, as the pass returns: each route load's record, the sweeps' proofs on it. */
|
|
90
85
|
readonly onRoutes?: (records: readonly RouteLoadRecord[]) => void;
|
|
86
|
+
/** One of n slices of the whole pass (`exercise-shard.ts`); ignored beside `only`. */
|
|
87
|
+
readonly shard?: ExerciseShard;
|
|
91
88
|
}
|
|
92
89
|
|
|
93
90
|
const isOff = (overrides: ExerciseOverrides | undefined, subject: Subject): boolean => {
|
|
@@ -95,42 +92,6 @@ const isOff = (overrides: ExerciseOverrides | undefined, subject: Subject): bool
|
|
|
95
92
|
return override !== undefined && 'off' in override;
|
|
96
93
|
};
|
|
97
94
|
|
|
98
|
-
/** The ids of every row the call's queue holds now: what an attempt adds is the call's. */
|
|
99
|
-
const queuedIds = async (): Promise<ReadonlySet<string>> =>
|
|
100
|
-
new Set((await ambientJobRows()).map((record) => record.id));
|
|
101
|
-
|
|
102
|
-
/**
|
|
103
|
-
* Jobs the primitive queued — rows an ATTEMPT added (`mine`), still live — its own job excepted.
|
|
104
|
-
* Never run: a job's children are left queued as an action's are (`exercise-job-run.ts`). A row
|
|
105
|
-
* the override's input added between calls is on the same queue, so the call can find it, and is
|
|
106
|
-
* not in `mine`: the input's enqueue is never the primitive's.
|
|
107
|
-
*/
|
|
108
|
-
async function enqueued(subject: Subject, mine: ReadonlySet<string>) {
|
|
109
|
-
const counts = new Map<string, number>();
|
|
110
|
-
for (const record of await ambientJobRows()) {
|
|
111
|
-
if (!mine.has(record.id) || !LIVE_STATES.has(record.state)) continue;
|
|
112
|
-
if (subject.kind === 'job' && record.name === subject.name) continue;
|
|
113
|
-
counts.set(record.name, (counts.get(record.name) ?? 0) + 1);
|
|
114
|
-
}
|
|
115
|
-
const order = registeredJobs().map((handle) => handle.name);
|
|
116
|
-
return [...counts]
|
|
117
|
-
.sort(([a], [b]) => order.indexOf(a) - order.indexOf(b))
|
|
118
|
-
.map(([job, count]): ExerciseEffect => ({ kind: 'enqueue', job, count }));
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
/**
|
|
122
|
-
* Every job a B leg's queue holds or ran, with its input — the subject's own job excepted, whose
|
|
123
|
-
* input is what B was handed. Read off the leg's own queue, page by page.
|
|
124
|
-
*/
|
|
125
|
-
async function queuedPayloads(subject: Subject): Promise<readonly EffectPayload[]> {
|
|
126
|
-
return (await ambientJobRows())
|
|
127
|
-
.filter((record) => !(subject.kind === 'job' && record.name === subject.name))
|
|
128
|
-
.map((record, i) => ({
|
|
129
|
-
path: `effect.enqueue[${i}]`,
|
|
130
|
-
value: { job: record.name, input: record.input },
|
|
131
|
-
}));
|
|
132
|
-
}
|
|
133
|
-
|
|
134
95
|
/** Everything one primitive's calls share: who acts in each tenant, and how ids are bound. */
|
|
135
96
|
interface Prepared {
|
|
136
97
|
readonly subject: Subject;
|
|
@@ -403,18 +364,30 @@ export async function runExercisePass(
|
|
|
403
364
|
});
|
|
404
365
|
const known = new Set(subjects.map((subject) => subject.name));
|
|
405
366
|
assertOverridesKnown(options.overrides, subjects);
|
|
367
|
+
// Judged only where the route table was handed over: an `only` run never reads one.
|
|
368
|
+
if (options.routes !== undefined && options.only === undefined) {
|
|
369
|
+
assertRoutesKnown(
|
|
370
|
+
options.overrides,
|
|
371
|
+
options.routes.map((route) => route.path),
|
|
372
|
+
);
|
|
373
|
+
}
|
|
406
374
|
const label = labelFor(subjects);
|
|
407
375
|
if (options.only !== undefined && !known.has(options.only)) {
|
|
408
376
|
throw unknownDeclaration([options.only], known, 'x exercise');
|
|
409
377
|
}
|
|
410
|
-
const
|
|
378
|
+
const shard = options.only === undefined ? options.shard : undefined;
|
|
379
|
+
const chosen = subjects.filter((s, i) =>
|
|
380
|
+
options.only === undefined ? inShard(i, shard) : s.name === options.only,
|
|
381
|
+
);
|
|
411
382
|
const sampler = await loadSampler();
|
|
412
383
|
// Not `Math.random`: the frozen RNG answers the same sequence in every process.
|
|
413
384
|
const passSeed = options.seed ?? (crypto.getRandomValues(new Uint32Array(1))[0] as number);
|
|
414
385
|
// The app's setup runs inside the seal, before the first row: its routes answer every call.
|
|
415
386
|
const room = await withExerciseSetup(await openExerciseRoom(), options.overrides?.setup);
|
|
416
387
|
const live = chosen.filter((subject) => !isOff(options.overrides, subject));
|
|
417
|
-
const routes = options.only === undefined ? (options.routes ?? []) : []
|
|
388
|
+
const routes = (options.only === undefined ? (options.routes ?? []) : []).filter((_, i) =>
|
|
389
|
+
inShard(subjects.length + i, shard),
|
|
390
|
+
);
|
|
418
391
|
const records: ExerciseRecord[] = [];
|
|
419
392
|
let routeRecords: readonly RouteLoadRecord[] = [];
|
|
420
393
|
let graph: SeedGraph;
|
|
@@ -481,5 +454,5 @@ export async function runExercisePass(
|
|
|
481
454
|
options.onPhases?.({ seed, primitives, ...swept.ms });
|
|
482
455
|
const split = splitRouteRecords(swept.records);
|
|
483
456
|
options.onRoutes?.(split.routes);
|
|
484
|
-
return split.primitives;
|
|
457
|
+
return split.primitives.map((record) => withEmptyWhy(record, options.overrides));
|
|
485
458
|
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// What `mountIsland` leaves behind for coverage: each chunk's source map, written where the
|
|
2
|
+
// coverage run asked, under the file name the chunk was imported by. The run (`@ultimat3/cli`'s
|
|
3
|
+
// `coverage-island.ts`) reads them and credits the chunk's lines to the island's own source.
|
|
4
|
+
|
|
5
|
+
// why: Bun ships no path-join primitive.
|
|
6
|
+
import { join } from 'node:path';
|
|
7
|
+
|
|
8
|
+
/** Set by `x verify`'s coverage run (`@ultimat3/cli`'s `runCovered`) to a directory per process. */
|
|
9
|
+
export const ISLAND_COVERAGE_ENV = 'ULTIMATE_ISLAND_COVERAGE_DIR';
|
|
10
|
+
|
|
11
|
+
/** The directory to record into, or nothing outside a coverage run. */
|
|
12
|
+
export const islandCoverageDir = (
|
|
13
|
+
env: Readonly<Record<string, string | undefined>> = Bun.env,
|
|
14
|
+
): string | undefined => {
|
|
15
|
+
const dir = env[ISLAND_COVERAGE_ENV];
|
|
16
|
+
return dir === undefined || dir === '' ? undefined : dir;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* One chunk's map, as `{ module, cwd, map }`. The map is kept as the builder's text: its `sources`
|
|
21
|
+
* are relative to THIS process's cwd (Bun's convention), which is why the cwd rides beside it.
|
|
22
|
+
* Named by the module, so a second mount of the same bytes rewrites the same file.
|
|
23
|
+
*/
|
|
24
|
+
export async function recordChunkMap(dir: string, module: string, map: string): Promise<void> {
|
|
25
|
+
await Bun.write(join(dir, `${module}.json`), JSON.stringify({ module, cwd: process.cwd(), map }));
|
|
26
|
+
}
|
package/src/fixture-island.ts
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
import { basename, join } from 'node:path';
|
|
7
7
|
import { onFileBoundary } from './file-boundary';
|
|
8
|
+
import { islandCoverageDir, recordChunkMap } from './fixture-island-coverage';
|
|
8
9
|
import { createIslandDocument, FakeElement, handlerFor, parseHtml } from './island-dom';
|
|
9
10
|
import { islandMountMissing, islandNotBuilt } from './island-errors';
|
|
10
11
|
import { installGlobals } from './island-globals';
|
|
@@ -22,12 +23,19 @@ export interface IslandChunkLike {
|
|
|
22
23
|
* is why `shared` below is written beside it before it is imported.
|
|
23
24
|
*/
|
|
24
25
|
readonly code: string;
|
|
26
|
+
/**
|
|
27
|
+
* The chunk's external source map, as text. Optional: under a coverage run the fixture records
|
|
28
|
+
* it (`fixture-island-coverage.ts`) so the chunk's lines count for the island's own source.
|
|
29
|
+
*/
|
|
30
|
+
readonly map?: string;
|
|
25
31
|
}
|
|
26
32
|
|
|
27
33
|
/** A module two or more islands import, served beside them under its own name. */
|
|
28
34
|
export interface SharedChunkLike {
|
|
29
35
|
readonly url: string;
|
|
30
36
|
readonly code: string;
|
|
37
|
+
/** Its source map, recorded the same way as an entry's. */
|
|
38
|
+
readonly map?: string;
|
|
31
39
|
}
|
|
32
40
|
|
|
33
41
|
export interface IslandBundleLike {
|
|
@@ -46,7 +54,14 @@ export interface IslandBundleLike {
|
|
|
46
54
|
*/
|
|
47
55
|
export type IslandBuilder = (
|
|
48
56
|
root: string,
|
|
49
|
-
options?: {
|
|
57
|
+
options?: {
|
|
58
|
+
readonly only?: string;
|
|
59
|
+
/**
|
|
60
|
+
* Asked only under a coverage run: a build whose lines a map can name — whitespace kept, a
|
|
61
|
+
* map on every chunk. A builder that ignores it still mounts; its chunk just credits nothing.
|
|
62
|
+
*/
|
|
63
|
+
readonly coverage?: boolean;
|
|
64
|
+
},
|
|
50
65
|
) => Promise<IslandBundleLike>;
|
|
51
66
|
|
|
52
67
|
export interface MountIslandOptions {
|
|
@@ -201,7 +216,11 @@ export async function mountIsland(options: MountIslandOptions): Promise<MountedI
|
|
|
201
216
|
// `bun test`, fixed in 1.4.0, and asking for the island we actually want walks around it while
|
|
202
217
|
// being the faster and more honest call regardless. A builder that ignores the argument still
|
|
203
218
|
// works: the `find` below is unchanged.
|
|
204
|
-
const
|
|
219
|
+
const coverage = islandCoverageDir();
|
|
220
|
+
const bundle = await options.build(options.root, {
|
|
221
|
+
only: options.file,
|
|
222
|
+
...(coverage === undefined ? {} : { coverage: true }),
|
|
223
|
+
});
|
|
205
224
|
const chunk = bundle.chunks.find((each) => each.file === options.file);
|
|
206
225
|
if (chunk === undefined) {
|
|
207
226
|
throw islandNotBuilt(
|
|
@@ -240,9 +259,15 @@ export async function mountIsland(options: MountIslandOptions): Promise<MountedI
|
|
|
240
259
|
// bytes at the same name.
|
|
241
260
|
for (const shared of bundle.shared ?? []) {
|
|
242
261
|
await Bun.write(join(scratch, basename(shared.url)), shared.code);
|
|
262
|
+
if (coverage !== undefined && shared.map !== undefined) {
|
|
263
|
+
await recordChunkMap(coverage, basename(shared.url), shared.map);
|
|
264
|
+
}
|
|
243
265
|
}
|
|
244
266
|
const path = modulePathFor(scratch, chunk.code);
|
|
245
267
|
await Bun.write(path, chunk.code);
|
|
268
|
+
if (coverage !== undefined && chunk.map !== undefined) {
|
|
269
|
+
await recordChunkMap(coverage, basename(path), chunk.map);
|
|
270
|
+
}
|
|
246
271
|
// By `file:` URL, never the bare path: Bun on macOS caches a directory's entries on its first
|
|
247
272
|
// resolution, and a bare-path import of a file written there afterwards is "Cannot find module"
|
|
248
273
|
// (#704, Bun 1.4.0 arm64). The per-mount directory already avoids it; the URL form holds even
|
|
@@ -60,6 +60,12 @@ export function registerFrameworkFixtures(): void {
|
|
|
60
60
|
// After the spread, so it REPLACES the `unavailableFixture('subscribe')` declaration above it —
|
|
61
61
|
// `defineFixtures` merges and the last registration wins, which is the same seam an app's own
|
|
62
62
|
// driver uses.
|
|
63
|
-
|
|
63
|
+
// The function, carrying the driver's `stop` as its disposer: handing back `.subscribe` alone
|
|
64
|
+
// dropped it, so the replicator's `entity.row` subscription outlived the test into every later
|
|
65
|
+
// file — where each `countedIn` write read its parents back as one more statement.
|
|
66
|
+
subscribe: async () => {
|
|
67
|
+
const driver = await subscribeDriver();
|
|
68
|
+
return Object.assign(driver.subscribe, { [Symbol.asyncDispose]: driver.stop });
|
|
69
|
+
},
|
|
64
70
|
});
|
|
65
71
|
}
|
package/src/index.ts
CHANGED
|
@@ -248,6 +248,7 @@ export type {
|
|
|
248
248
|
SharedChunkLike,
|
|
249
249
|
} from './fixture-island';
|
|
250
250
|
export { mountIsland } from './fixture-island';
|
|
251
|
+
export { ISLAND_COVERAGE_ENV } from './fixture-island-coverage';
|
|
251
252
|
export type {
|
|
252
253
|
JobDrainAs,
|
|
253
254
|
JobEnqueueAs,
|
|
@@ -487,3 +488,5 @@ export {
|
|
|
487
488
|
unitTest,
|
|
488
489
|
useE2eDriver,
|
|
489
490
|
} from './test-types';
|
|
491
|
+
export type { TestService } from './test-types-services';
|
|
492
|
+
export { TEST_SERVICE_ENV, TEST_SERVICES_START } from './test-types-services';
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// What a typed test may declare it needs from a real server, and how that need is answered: the
|
|
2
|
+
// `TEST_*_URL` variable `docker/test-services.env` writes for each service. Set, the test runs;
|
|
3
|
+
// unset, it is skipped with the service and the command that starts it in its own reported name.
|
|
4
|
+
|
|
5
|
+
/** The services a test may declare, each under the variable the test services publish it as. */
|
|
6
|
+
export const TEST_SERVICE_ENV = {
|
|
7
|
+
postgres: 'TEST_DATABASE_URL',
|
|
8
|
+
redis: 'TEST_REDIS_URL',
|
|
9
|
+
nats: 'TEST_NATS_URL',
|
|
10
|
+
} as const;
|
|
11
|
+
|
|
12
|
+
export type TestService = keyof typeof TEST_SERVICE_ENV;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* The lines that start every service and point this shell at them — the same two the generated
|
|
16
|
+
* `docker/docker-compose.test.yml` header names, so a skipped test's reason is a paste, not a hunt.
|
|
17
|
+
*/
|
|
18
|
+
export const TEST_SERVICES_START =
|
|
19
|
+
'docker compose -f docker/docker-compose.test.yml up -d --wait && set -a && . docker/test-services.env && set +a';
|
|
20
|
+
|
|
21
|
+
type Env = Readonly<Record<string, string | undefined>>;
|
|
22
|
+
|
|
23
|
+
/** The declared services whose variable is unset or blank in `env`, in declared order. */
|
|
24
|
+
export const missingServices = (needs: readonly TestService[], env: Env): readonly TestService[] =>
|
|
25
|
+
needs.filter((service) => (env[TEST_SERVICE_ENV[service]]?.trim() ?? '') === '');
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* The suffix a skipped test's name carries: each missing service, the variable it is read from,
|
|
29
|
+
* and the command that starts them. `undefined` when nothing is missing — the test runs.
|
|
30
|
+
*/
|
|
31
|
+
export function serviceSkipReason(needs: readonly TestService[], env: Env): string | undefined {
|
|
32
|
+
const missing = missingServices(needs, env);
|
|
33
|
+
if (missing.length === 0) return undefined;
|
|
34
|
+
const named = missing.map((service) => `${service} (${TEST_SERVICE_ENV[service]})`).join(', ');
|
|
35
|
+
return `needs ${named} unset: ${TEST_SERVICES_START}`;
|
|
36
|
+
}
|
package/src/test-types.ts
CHANGED
|
@@ -8,6 +8,8 @@ import { TestEvalThresholdError } from './errors';
|
|
|
8
8
|
import type { FixtureBody } from './fixtures';
|
|
9
9
|
import { runWithFixtures } from './fixtures';
|
|
10
10
|
import { paced } from './test-pace';
|
|
11
|
+
import type { TestService } from './test-types-services';
|
|
12
|
+
import { serviceSkipReason } from './test-types-services';
|
|
11
13
|
|
|
12
14
|
export const TEST_TYPES = ['unit', 'contract', 'live', 'job', 'e2e', 'eval'] as const;
|
|
13
15
|
|
|
@@ -28,8 +30,23 @@ export interface TestOptions {
|
|
|
28
30
|
* (`paced`). Absent is the run's default, which `x verify` paces the same way.
|
|
29
31
|
*/
|
|
30
32
|
readonly timeoutMs?: number;
|
|
33
|
+
/**
|
|
34
|
+
* The real servers this test needs, by name (`TEST_SERVICE_ENV`: `postgres` is
|
|
35
|
+
* `TEST_DATABASE_URL`). Every one set, the test runs; one unset, it is SKIPPED with the service,
|
|
36
|
+
* its variable and the command that starts it in its reported name — the declaration a live
|
|
37
|
+
* suite's `describe.skipIf(!Bun.env.TEST_DATABASE_URL)` spelled by hand, on every registrar.
|
|
38
|
+
*/
|
|
39
|
+
readonly needs?: readonly TestService[];
|
|
31
40
|
}
|
|
32
41
|
|
|
42
|
+
/** The skip a test whose declared services are unset becomes, or `false` when it may run. */
|
|
43
|
+
const skippedFor = (type: TestType, name: string, options: TestOptions | undefined): boolean => {
|
|
44
|
+
const reason = serviceSkipReason(options?.needs ?? [], Bun.env);
|
|
45
|
+
if (reason === undefined) return false;
|
|
46
|
+
test.skip(testName(type, `${name} (${reason})`), () => undefined);
|
|
47
|
+
return true;
|
|
48
|
+
};
|
|
49
|
+
|
|
33
50
|
/**
|
|
34
51
|
* One typed registrar. The body is `test`'s own (`FixtureBody`): it is handed the fixture bag and
|
|
35
52
|
* only what it destructures is built, so `unitTest('…', async ({ runJobs }) => …)` is a job body
|
|
@@ -39,6 +56,7 @@ export interface TestOptions {
|
|
|
39
56
|
const typed =
|
|
40
57
|
(type: TestType) =>
|
|
41
58
|
(name: string, body: FixtureBody, options?: TestOptions): void => {
|
|
59
|
+
if (skippedFor(type, name, options)) return;
|
|
42
60
|
test(
|
|
43
61
|
testName(type, name),
|
|
44
62
|
() => runWithFixtures(body),
|
|
@@ -162,6 +180,7 @@ export const resetE2eDriver = (): void => {
|
|
|
162
180
|
};
|
|
163
181
|
|
|
164
182
|
export const e2eTest = (name: string, body: E2eBody, options?: E2eTestOptions): void => {
|
|
183
|
+
if (skippedFor('e2e', name, options)) return;
|
|
165
184
|
if (e2eDriver === undefined) {
|
|
166
185
|
test.skip(
|
|
167
186
|
testName('e2e', `${name} (no browser driver: x build --target static && x e2e)`),
|
|
@@ -193,6 +212,7 @@ export function evalTest<TInput, TOutput>(
|
|
|
193
212
|
name: string,
|
|
194
213
|
options: EvalOptions<TInput, TOutput>,
|
|
195
214
|
): void {
|
|
215
|
+
if (skippedFor('eval', name, options)) return;
|
|
196
216
|
test(
|
|
197
217
|
testName('eval', name),
|
|
198
218
|
async () => {
|