@ultimat3/testing 31.24.0 → 31.26.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 +7 -0
- package/package.json +22 -22
- package/src/admin-mount-boundary.ts +29 -0
- package/src/cdp-e2e-page.ts +112 -2
- package/src/declaration-boundary.ts +226 -0
- package/src/driver-store-boundary.ts +39 -0
- package/src/e2e-driver.ts +8 -12
- package/src/e2e-page.ts +6 -6
- package/src/factory-persist.ts +3 -0
- package/src/import-graph.ts +102 -0
- package/src/index.ts +2 -2
- package/src/job-driver-checks-settle.ts +61 -2
- package/src/registry-environment.ts +82 -0
- package/src/registry-leak-guard.ts +110 -14
- package/src/registry-snapshot.ts +27 -5
- package/src/scrape-driver-conformance-frame-checks.ts +1 -7
- package/src/scrape-driver-conformance-page-checks.ts +2 -6
package/CLAUDE.md
CHANGED
|
@@ -85,6 +85,9 @@ the off-barrel entry points `registry-isolation.ts`, `conformance.ts`. Full rule
|
|
|
85
85
|
| Leaks are the file's, not the next file's | `installRegistryLeakGuard()` runs from the preload and fails the run naming the FILE that left cache tags declared or a cache tier registered after its last test (`X_TEST_REGISTRY_LEAK`). |
|
|
86
86
|
| Reported and restored are different sets | the guard also RESTORES, at the same file boundary, the registries whose module-scope declarations a neighbour's cleanup destroys |
|
|
87
87
|
| A catalog restore is a MERGE, never a replace | the other three registries are replaced with the snapshot. `registerCatalog` has no inverse, so all a file can cost its neighbour is a `resetCatalogs()` |
|
|
88
|
+
| A file's policy environment is ITS import graph | at the body's start the permission set and role map narrow to names a module the file's import graph reaches declared (`import-graph.ts`, `registry-environment.ts`), plus the preload's and any first declared during this load; the body's own declarations end with the file. Framework repo only: an app keeps the union (`loadApp()` is no static edge) |
|
|
89
|
+
| Noted driver stores and mounted admins end with the file | `driver-store-boundary.ts`: back to the preload's notes (a store noted at a fixture's import is no later file's); `admin-mount-boundary.ts`: back to what the body inherited. Read through the require cache / the global symbol — never an import |
|
|
90
|
+
| So do channels, mcp recipes/remote servers, the authenticator and the persister | `declaration-boundary.ts` (`DECLARATION_TABLES`) and `factory-persist.ts`: back to what the body inherited; an owner unloaded at the body's start is left alone. `process-registries.test.ts` ledgers every module-scope `Map`/`Set` beside a `register*`/`define*` export — a new one reds until its row says restored, rerun, reported, boot or open |
|
|
88
91
|
| Permissions are still REPLACED at a file boundary, and it is measured | a dynamic `loadApp()`'s `definePermissions()` is dropped there. Open. Full rule: `docs/history/testing.md` |
|
|
89
92
|
| Guarded state is boot state | the guard covers only registries that must be clean at file end — `declareTags` and `registerTier` are boot installs; "filled" and "cleared" are two questions. Full rule: `docs/history/testing.md` |
|
|
90
93
|
| An empty registry is a premise you state | a test whose subject is "nothing is declared" — `x db gen` with nothing to generate — calls `isolateEntityRegistry()` and restores in a `finally`. |
|
package/README.md
CHANGED
|
@@ -345,6 +345,13 @@ It registers `page` and nothing else. `budget`, `signIn` and `deploy` keep refus
|
|
|
345
345
|
browser's own network state and a second build id are not things a page port can answer for, and a
|
|
346
346
|
fixture that silently no-opped would make the assertion after it read as proof.
|
|
347
347
|
|
|
348
|
+
**Real input, `As of 2026-11`.** A raw-CDP tab (`cdpE2eTab`, the `E2eTab` the framework implements)
|
|
349
|
+
sends trusted input the page cannot forge: `tab.touchDrag(from, to, steps)` is a finger
|
|
350
|
+
(`Input.dispatchTouchEvent`, touch emulation on once per tab) and `tab.press(key)` a key
|
|
351
|
+
(`Input.dispatchKeyEvent`, so Tab really moves focus) — a key from `PRESS_KEYS`, a letter or a digit.
|
|
352
|
+
A touch `PointerEvent` dispatched from page script is refused by `setPointerCapture`, so a drag
|
|
353
|
+
proven that way proves nothing; `TouchPoint` is the `{ x, y }` both ends take.
|
|
354
|
+
|
|
348
355
|
**A browser call that is never answered says why.** `X_CDP_TIMEOUT` from the connection carries
|
|
349
356
|
`meta.reading` — `target-gone` (session detached, target destroyed or crashed), `lost-in-transport`
|
|
350
357
|
(`meta.framesDropped` frames arrived unparseable after the call) or `no-answer` — beside
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ultimat3/testing",
|
|
3
|
-
"version": "31.
|
|
3
|
+
"version": "31.26.0",
|
|
4
4
|
"description": "Test harness: cloned template DBs per worker, frozen clock, sealed network, 6 test types",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ultimate",
|
|
@@ -47,26 +47,26 @@
|
|
|
47
47
|
"test": "bun test"
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
|
50
|
-
"@ultimat3/action": "31.
|
|
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.26.0",
|
|
51
|
+
"@ultimat3/ai": "31.26.0",
|
|
52
|
+
"@ultimat3/auth": "31.26.0",
|
|
53
|
+
"@ultimat3/cache": "31.26.0",
|
|
54
|
+
"@ultimat3/core": "31.26.0",
|
|
55
|
+
"@ultimat3/db": "31.26.0",
|
|
56
|
+
"@ultimat3/entity": "31.26.0",
|
|
57
|
+
"@ultimat3/http": "31.26.0",
|
|
58
|
+
"@ultimat3/i18n": "31.26.0",
|
|
59
|
+
"@ultimat3/jobs": "31.26.0",
|
|
60
|
+
"@ultimat3/mail": "31.26.0",
|
|
61
|
+
"@ultimat3/notify": "31.26.0",
|
|
62
|
+
"@ultimat3/policy": "31.26.0",
|
|
63
|
+
"@ultimat3/pwa": "31.26.0",
|
|
64
|
+
"@ultimat3/query": "31.26.0",
|
|
65
|
+
"@ultimat3/realtime": "31.26.0",
|
|
66
|
+
"@ultimat3/render": "31.26.0",
|
|
67
|
+
"@ultimat3/schema": "31.26.0",
|
|
68
|
+
"@ultimat3/scraping": "31.26.0",
|
|
69
|
+
"@ultimat3/seo": "31.26.0",
|
|
70
|
+
"@ultimat3/time": "31.26.0"
|
|
71
71
|
}
|
|
72
72
|
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// The admins `defineAdmin()` mounted, put back at the file boundary to what the file inherited:
|
|
2
|
+
// ~50 admin suites mount one and never clear it, and the `i18n` step audits EVERY mounted admin,
|
|
3
|
+
// so on a shared worker one file's admin was a later file's X_CATALOG_MISSING_KEYS.
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* `@ultimat3/admin`'s `ADMIN_MOUNTS`, restated as `@ultimat3/cli`'s `runtime-admin.ts` does —
|
|
7
|
+
* never imported: `testing` is tier 5 beside `admin`, and an app with no admin must not load one.
|
|
8
|
+
*/
|
|
9
|
+
const ADMIN_MOUNTS = Symbol.for('ultimate.admin.mounts');
|
|
10
|
+
|
|
11
|
+
type Mounted = readonly (readonly [string, unknown])[];
|
|
12
|
+
|
|
13
|
+
const held = (): Map<string, unknown> | undefined => {
|
|
14
|
+
const value = (globalThis as { [key: symbol]: unknown })[ADMIN_MOUNTS];
|
|
15
|
+
return value instanceof Map ? (value as Map<string, unknown>) : undefined;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
/** Every mount by base path, in declaration order; nothing while no admin was ever declared. */
|
|
19
|
+
export function captureAdminMounts(): Mounted {
|
|
20
|
+
return [...(held() ?? new Map<string, unknown>())];
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** Exactly `mounted` again, in its order — the same Map, so a reader holding it sees the change. */
|
|
24
|
+
export function restoreAdminMounts(mounted: Mounted): void {
|
|
25
|
+
const live = held();
|
|
26
|
+
if (live === undefined) return;
|
|
27
|
+
live.clear();
|
|
28
|
+
for (const [basePath, app] of mounted) live.set(basePath, app);
|
|
29
|
+
}
|
package/src/cdp-e2e-page.ts
CHANGED
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
// condition, the init scripts, the socket and request log. Launching is `cdp-launch.ts` and the
|
|
4
4
|
// wire is `cdp-connection.ts`.
|
|
5
5
|
//
|
|
6
|
-
//
|
|
7
|
-
// through it: `ScrapePage` is a full scraping surface whose intended implementation is
|
|
6
|
+
// A handful of methods — and a real finger (`touchDrag`) and key (`press`) — which is why this sits
|
|
7
|
+
// next to `@ultimat3/scraping` rather than going through it: `ScrapePage` is a full scraping surface whose intended implementation is
|
|
8
8
|
// `puppeteer-core`, and an e2e driver needs none of it.
|
|
9
9
|
|
|
10
10
|
import type { CdpConnection } from '@ultimat3/scraping/cdp';
|
|
@@ -70,6 +70,19 @@ export interface E2eTab extends E2eBrowserPage {
|
|
|
70
70
|
* dispatches straight at the element and can never see that.
|
|
71
71
|
*/
|
|
72
72
|
pointerClick(selector: string): Promise<void>;
|
|
73
|
+
/**
|
|
74
|
+
* A REAL finger (`Input.dispatchTouchEvent`, touch emulation on for the tab the first time): a
|
|
75
|
+
* start at `from`, `steps` moves to `to`, an end, in viewport CSS px. Trusted input, so the
|
|
76
|
+
* browser hit-tests it, honours `touch-action`, and may take it for a scroll and send
|
|
77
|
+
* `pointercancel` — what a page-dispatched touch PointerEvent can never show (no active pointer).
|
|
78
|
+
*/
|
|
79
|
+
touchDrag(from: TouchPoint, to: TouchPoint, steps?: number): Promise<void>;
|
|
80
|
+
/**
|
|
81
|
+
* A REAL key press (`Input.dispatchKeyEvent`, down then up) at whatever has focus, so its default
|
|
82
|
+
* action runs: Tab moves focus, which a dispatched `KeyboardEvent` never does. A name in
|
|
83
|
+
* `PRESS_KEYS` or one printable character.
|
|
84
|
+
*/
|
|
85
|
+
press(key: string): Promise<void>;
|
|
73
86
|
/** Required on a tab: the audit of every `e2eTest` reads it (`e2e-a11y-run.ts`). */
|
|
74
87
|
accessibilityTree(request: AxTreeRequest): Promise<readonly AxTreeNode[]>;
|
|
75
88
|
/** Reload and wait for the load, at the url the tab already had. */
|
|
@@ -81,6 +94,52 @@ export interface E2eTab extends E2eBrowserPage {
|
|
|
81
94
|
close(): Promise<void>;
|
|
82
95
|
}
|
|
83
96
|
|
|
97
|
+
/** A viewport point in CSS px, as `getBoundingClientRect()` answers it. */
|
|
98
|
+
export interface TouchPoint {
|
|
99
|
+
readonly x: number;
|
|
100
|
+
readonly y: number;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/** Named keys `press()` knows, with the Windows virtual key code Chrome routes them by. */
|
|
104
|
+
export const PRESS_KEYS: Readonly<Record<string, number>> = {
|
|
105
|
+
Tab: 9,
|
|
106
|
+
Enter: 13,
|
|
107
|
+
Escape: 27,
|
|
108
|
+
' ': 32,
|
|
109
|
+
PageUp: 33,
|
|
110
|
+
PageDown: 34,
|
|
111
|
+
End: 35,
|
|
112
|
+
Home: 36,
|
|
113
|
+
ArrowLeft: 37,
|
|
114
|
+
ArrowUp: 38,
|
|
115
|
+
ArrowRight: 39,
|
|
116
|
+
ArrowDown: 40,
|
|
117
|
+
Backspace: 8,
|
|
118
|
+
Delete: 46,
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
/** The key code of a printable character: its upper-case code point for a letter or digit. */
|
|
122
|
+
const charCode = (key: string): number | undefined =>
|
|
123
|
+
key.length === 1 && /[a-z0-9]/i.test(key) ? key.toUpperCase().charCodeAt(0) : undefined;
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* The text a key TYPES, as puppeteer's key table has it. A key with text goes down as `keyDown`
|
|
127
|
+
* carrying it, so Chrome raises the character event — what makes Enter submit a focused button's
|
|
128
|
+
* form. A key with none (Tab, the arrows) goes down as `rawKeyDown`.
|
|
129
|
+
*/
|
|
130
|
+
const typedText = (key: string): string | undefined =>
|
|
131
|
+
key === 'Enter' ? '\r' : key.length === 1 ? key : undefined;
|
|
132
|
+
|
|
133
|
+
/** `KeyboardEvent.code`: `KeyA`, `Digit7`, `Space`; a named key is its own code. */
|
|
134
|
+
const keyCodeName = (key: string): string =>
|
|
135
|
+
key === ' '
|
|
136
|
+
? 'Space'
|
|
137
|
+
: /^[a-z]$/i.test(key)
|
|
138
|
+
? `Key${key.toUpperCase()}`
|
|
139
|
+
: /^[0-9]$/.test(key)
|
|
140
|
+
? `Digit${key}`
|
|
141
|
+
: key;
|
|
142
|
+
|
|
84
143
|
export interface CdpE2eTabOptions {
|
|
85
144
|
readonly connection: CdpConnection;
|
|
86
145
|
/** The attached tab's flattened session — every page call carries it. */
|
|
@@ -135,6 +194,8 @@ export function cdpE2eTab(options: CdpE2eTabOptions): E2eTab {
|
|
|
135
194
|
// url is tracked here. Seeded with the tab's own starting url rather than '' so a `reload()`
|
|
136
195
|
// before any `goto()` navigates somewhere real.
|
|
137
196
|
let current = 'about:blank';
|
|
197
|
+
// Touch emulation is per tab and stays on: switched on by the first `touchDrag`, once.
|
|
198
|
+
let touchOn = false;
|
|
138
199
|
|
|
139
200
|
const evaluateRaw = (expression: string) =>
|
|
140
201
|
send('Runtime.evaluate', { expression, returnByValue: true, awaitPromise: true }, sessionId);
|
|
@@ -304,6 +365,55 @@ export function cdpE2eTab(options: CdpE2eTabOptions): E2eTab {
|
|
|
304
365
|
);
|
|
305
366
|
}
|
|
306
367
|
},
|
|
368
|
+
async touchDrag(from: TouchPoint, to: TouchPoint, steps = 5): Promise<void> {
|
|
369
|
+
if (!Number.isInteger(steps) || steps < 1) {
|
|
370
|
+
throw new CdpCallFailedError({
|
|
371
|
+
method: `touchDrag(steps: ${String(steps)})`,
|
|
372
|
+
detail: 'steps is the number of moves, a whole number of at least 1',
|
|
373
|
+
});
|
|
374
|
+
}
|
|
375
|
+
if (!touchOn) {
|
|
376
|
+
await send(
|
|
377
|
+
'Emulation.setTouchEmulationEnabled',
|
|
378
|
+
{ enabled: true, maxTouchPoints: 1 },
|
|
379
|
+
sessionId,
|
|
380
|
+
);
|
|
381
|
+
touchOn = true;
|
|
382
|
+
}
|
|
383
|
+
const touch = (type: string, points: readonly TouchPoint[]) =>
|
|
384
|
+
send(
|
|
385
|
+
'Input.dispatchTouchEvent',
|
|
386
|
+
{ type, touchPoints: points.map((p) => ({ x: p.x, y: p.y })) },
|
|
387
|
+
sessionId,
|
|
388
|
+
);
|
|
389
|
+
await touch('touchStart', [from]);
|
|
390
|
+
for (let step = 1; step <= steps; step += 1) {
|
|
391
|
+
const at = (a: number, b: number): number => a + ((b - a) * step) / steps;
|
|
392
|
+
await touch('touchMove', [{ x: at(from.x, to.x), y: at(from.y, to.y) }]);
|
|
393
|
+
}
|
|
394
|
+
await touch('touchEnd', []);
|
|
395
|
+
},
|
|
396
|
+
async press(key: string): Promise<void> {
|
|
397
|
+
const code = (Object.hasOwn(PRESS_KEYS, key) ? PRESS_KEYS[key] : undefined) ?? charCode(key);
|
|
398
|
+
if (code === undefined) {
|
|
399
|
+
throw new CdpCallFailedError({
|
|
400
|
+
method: `press(${key})`,
|
|
401
|
+
detail: `not a key press() knows: one of ${Object.keys(PRESS_KEYS).join(', ')}, or one letter or digit`,
|
|
402
|
+
});
|
|
403
|
+
}
|
|
404
|
+
const text = typedText(key);
|
|
405
|
+
const common = { key, code: keyCodeName(key), windowsVirtualKeyCode: code };
|
|
406
|
+
await send(
|
|
407
|
+
'Input.dispatchKeyEvent',
|
|
408
|
+
{
|
|
409
|
+
type: text === undefined ? 'rawKeyDown' : 'keyDown',
|
|
410
|
+
...common,
|
|
411
|
+
...(text === undefined ? {} : { text }),
|
|
412
|
+
},
|
|
413
|
+
sessionId,
|
|
414
|
+
);
|
|
415
|
+
await send('Input.dispatchKeyEvent', { type: 'keyUp', ...common }, sessionId);
|
|
416
|
+
},
|
|
307
417
|
offline: (enabled: boolean) => options.offline(enabled),
|
|
308
418
|
async accessibilityTree(request: AxTreeRequest): Promise<readonly AxTreeNode[]> {
|
|
309
419
|
const nodes = toAxTreeNodes((await send(FULL_AX_TREE, {}, sessionId)).result);
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
// The module-scope declaration tables `registry-snapshot.ts` does not hold, put back at the file
|
|
2
|
+
// boundary to what the file's body inherited: realtime's channels and `@ultimat3/mcp`'s declared
|
|
3
|
+
// remote servers and served recipes. Each is read through the module cache, never imported — an
|
|
4
|
+
// unloaded package has nothing to restore, and `testing` does not depend on `@ultimat3/mcp`.
|
|
5
|
+
|
|
6
|
+
import type {
|
|
7
|
+
AuthenticatorOptions,
|
|
8
|
+
configureAuthenticator,
|
|
9
|
+
configuredAuthenticator,
|
|
10
|
+
configuredCredentialTtlMs,
|
|
11
|
+
resetAuthenticator,
|
|
12
|
+
} from '@ultimat3/http';
|
|
13
|
+
import type { Channel } from '@ultimat3/realtime';
|
|
14
|
+
import type { RouteSnapshot, restoreRoutes, routeSnapshot } from '@ultimat3/render';
|
|
15
|
+
import { loaded } from './per-test-reset';
|
|
16
|
+
|
|
17
|
+
/** One table: where it lives, how to read it, and the exact restore its owner publishes. */
|
|
18
|
+
export interface DeclarationTable {
|
|
19
|
+
/** `<package>/<file under src>` — the row `process-registries.test.ts` holds to the source. */
|
|
20
|
+
readonly owner: string;
|
|
21
|
+
/** `undefined` while the owner is unloaded. */
|
|
22
|
+
capture(): unknown;
|
|
23
|
+
/** Called with a defined snapshot only. */
|
|
24
|
+
restore(snapshot: unknown): void;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
interface ChannelModule {
|
|
28
|
+
readonly registeredChannels: () => readonly Channel[];
|
|
29
|
+
readonly restoreChannels: (declared: readonly Channel[]) => void;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
interface RouteModule {
|
|
33
|
+
readonly routeSnapshot: typeof routeSnapshot;
|
|
34
|
+
readonly restoreRoutes: typeof restoreRoutes;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** `@ultimat3/ai`'s catalogue, restated: `ai` is reached dynamically only, never type-imported. */
|
|
38
|
+
interface ModelModule {
|
|
39
|
+
readonly registeredModels: () => readonly unknown[];
|
|
40
|
+
readonly restoreModels: (specs: readonly unknown[]) => void;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
interface HooksModule {
|
|
44
|
+
readonly configureAuthenticator: typeof configureAuthenticator;
|
|
45
|
+
readonly configuredAuthenticator: typeof configuredAuthenticator;
|
|
46
|
+
readonly configuredCredentialTtlMs: typeof configuredCredentialTtlMs;
|
|
47
|
+
readonly resetAuthenticator: typeof resetAuthenticator;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
interface AuthenticatorSlot {
|
|
51
|
+
readonly authenticate: ReturnType<typeof configuredAuthenticator>;
|
|
52
|
+
readonly ttl: number | undefined;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** `@ultimat3/mcp`'s shapes, restated: `testing` neither depends on nor type-imports the package. */
|
|
56
|
+
interface RecipeModule {
|
|
57
|
+
readonly servedRecipes: () => ReadonlySet<string>;
|
|
58
|
+
readonly resetServedRecipes: () => void;
|
|
59
|
+
readonly noteServedRecipes: (names: readonly string[]) => void;
|
|
60
|
+
}
|
|
61
|
+
/** `@ultimat3/storage`'s registry, restated: `testing` does not depend on the package. */
|
|
62
|
+
interface StorageModule {
|
|
63
|
+
readonly definedStorage: () => unknown;
|
|
64
|
+
readonly resetStorage: () => void;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
interface RemoteModule {
|
|
68
|
+
readonly declaredMcpServers: () => ReadonlyMap<string, unknown>;
|
|
69
|
+
readonly restoreDeclaredMcpServers: (servers: ReadonlyMap<string, unknown>) => void;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const found = new Map<string, string>();
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* A loaded module whose path ends in `suffix` and that exports every name in `shape`. For a
|
|
76
|
+
* package `testing` cannot resolve (not a dependency): the cache is scanned until it is seen,
|
|
77
|
+
* then the path is kept. The shape check is what keeps an app's own `packages/mcp/src/` out.
|
|
78
|
+
*/
|
|
79
|
+
function cachedModule<M>(suffix: string, shape: readonly string[]): M | undefined {
|
|
80
|
+
const known = found.get(suffix);
|
|
81
|
+
if (known !== undefined) return require.cache[known]?.exports as M | undefined;
|
|
82
|
+
for (const [path, entry] of Object.entries(require.cache)) {
|
|
83
|
+
if (!path.replaceAll('\\', '/').endsWith(suffix)) continue;
|
|
84
|
+
const exports = entry?.exports as Record<string, unknown> | undefined;
|
|
85
|
+
if (exports === undefined || !shape.every((name) => typeof exports[name] === 'function')) {
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
88
|
+
found.set(suffix, path);
|
|
89
|
+
return exports as M;
|
|
90
|
+
}
|
|
91
|
+
return undefined;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const channelModule = (): ChannelModule | undefined => {
|
|
95
|
+
const path = loaded('@ultimat3/realtime', 'channel-registry.ts');
|
|
96
|
+
return path === undefined ? undefined : (require(path) as ChannelModule);
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
const routeModule = (): RouteModule | undefined => {
|
|
100
|
+
const path = loaded('@ultimat3/render', 'registry.ts');
|
|
101
|
+
return path === undefined ? undefined : (require(path) as RouteModule);
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
const modelModule = (): ModelModule | undefined => {
|
|
105
|
+
const path = loaded('@ultimat3/ai', 'models.ts');
|
|
106
|
+
return path === undefined ? undefined : (require(path) as ModelModule);
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
const hooksModule = (): HooksModule | undefined => {
|
|
110
|
+
const path = loaded('@ultimat3/http', 'hooks.ts');
|
|
111
|
+
return path === undefined ? undefined : (require(path) as HooksModule);
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
const STORAGE_SHAPE = ['definedStorage', 'defineStorage', 'resetStorage'] as const;
|
|
115
|
+
const storageModule = (): StorageModule | undefined =>
|
|
116
|
+
cachedModule<StorageModule>('/storage/src/storage.ts', STORAGE_SHAPE);
|
|
117
|
+
|
|
118
|
+
const RECIPE_SHAPE = ['servedRecipes', 'resetServedRecipes', 'noteServedRecipes'] as const;
|
|
119
|
+
const REMOTE_SHAPE = ['declaredMcpServers', 'restoreDeclaredMcpServers'] as const;
|
|
120
|
+
const recipeModule = (): RecipeModule | undefined =>
|
|
121
|
+
cachedModule<RecipeModule>('/mcp/src/recipe-links.ts', RECIPE_SHAPE);
|
|
122
|
+
const remoteModule = (): RemoteModule | undefined =>
|
|
123
|
+
cachedModule<RemoteModule>('/mcp/src/remote-tools.ts', REMOTE_SHAPE);
|
|
124
|
+
|
|
125
|
+
/** Every table the boundary restores. A new module-scope registry joins here, with its restore. */
|
|
126
|
+
export const DECLARATION_TABLES: readonly DeclarationTable[] = [
|
|
127
|
+
{
|
|
128
|
+
// One file's `site/` route was a later fixture app's `budgets` red (`X_STYLES_GLOBAL_MISSING`
|
|
129
|
+
// in `mcp-host-tools.test.ts`): `documentSurfaces()` reads the whole route table.
|
|
130
|
+
owner: '@ultimat3/render/registry.ts',
|
|
131
|
+
capture: () => routeModule()?.routeSnapshot(),
|
|
132
|
+
restore: (snapshot) => routeModule()?.restoreRoutes(snapshot as RouteSnapshot),
|
|
133
|
+
},
|
|
134
|
+
{
|
|
135
|
+
owner: '@ultimat3/ai/models.ts',
|
|
136
|
+
capture: () => modelModule()?.registeredModels(),
|
|
137
|
+
restore: (snapshot) => modelModule()?.restoreModels(snapshot as readonly unknown[]),
|
|
138
|
+
},
|
|
139
|
+
{
|
|
140
|
+
// A slot, not a table: one file's `configureAuthenticator` answered every later file's socket
|
|
141
|
+
// upgrade with its resolver — `role-sync-dev-origin.test.ts` read 401 where it wanted 101.
|
|
142
|
+
owner: '@ultimat3/http/hooks.ts',
|
|
143
|
+
capture: (): AuthenticatorSlot | undefined => {
|
|
144
|
+
const module = hooksModule();
|
|
145
|
+
return module === undefined
|
|
146
|
+
? undefined
|
|
147
|
+
: {
|
|
148
|
+
authenticate: module.configuredAuthenticator(),
|
|
149
|
+
ttl: module.configuredCredentialTtlMs(),
|
|
150
|
+
};
|
|
151
|
+
},
|
|
152
|
+
restore: (snapshot) => {
|
|
153
|
+
const module = hooksModule();
|
|
154
|
+
if (module === undefined) return;
|
|
155
|
+
const { authenticate, ttl } = snapshot as AuthenticatorSlot;
|
|
156
|
+
if (authenticate === undefined) return module.resetAuthenticator();
|
|
157
|
+
const options: AuthenticatorOptions = ttl === undefined ? {} : { credentialTtlMs: ttl };
|
|
158
|
+
module.configureAuthenticator(authenticate, options);
|
|
159
|
+
},
|
|
160
|
+
},
|
|
161
|
+
{
|
|
162
|
+
// A slot with a reset and no setter: a body that installed storage over NONE is undone; one
|
|
163
|
+
// that replaced an inherited registry cannot be put back and is left (no exact writer exists).
|
|
164
|
+
// One file's `defineStorage({ disks: { assets } })` was every later boot's `appDeclared()`.
|
|
165
|
+
owner: '@ultimat3/storage/storage.ts',
|
|
166
|
+
capture: () => {
|
|
167
|
+
const module = storageModule();
|
|
168
|
+
return module === undefined ? undefined : { storage: module.definedStorage() };
|
|
169
|
+
},
|
|
170
|
+
restore: (snapshot) => {
|
|
171
|
+
const module = storageModule();
|
|
172
|
+
if (module === undefined) return;
|
|
173
|
+
if ((snapshot as { readonly storage: unknown }).storage === undefined) module.resetStorage();
|
|
174
|
+
},
|
|
175
|
+
},
|
|
176
|
+
{
|
|
177
|
+
owner: '@ultimat3/realtime/channel-registry.ts',
|
|
178
|
+
capture: () => channelModule()?.registeredChannels(),
|
|
179
|
+
restore: (snapshot) => {
|
|
180
|
+
const module = channelModule();
|
|
181
|
+
if (module !== undefined) module.restoreChannels(snapshot as readonly Channel[]);
|
|
182
|
+
},
|
|
183
|
+
},
|
|
184
|
+
{
|
|
185
|
+
owner: '@ultimat3/mcp/recipe-links.ts',
|
|
186
|
+
capture: () => {
|
|
187
|
+
const served = recipeModule()?.servedRecipes();
|
|
188
|
+
return served === undefined ? undefined : [...served];
|
|
189
|
+
},
|
|
190
|
+
restore: (snapshot) => {
|
|
191
|
+
const module = recipeModule();
|
|
192
|
+
if (module === undefined) return;
|
|
193
|
+
module.resetServedRecipes();
|
|
194
|
+
module.noteServedRecipes(snapshot as readonly string[]);
|
|
195
|
+
},
|
|
196
|
+
},
|
|
197
|
+
{
|
|
198
|
+
owner: '@ultimat3/mcp/remote-tools.ts',
|
|
199
|
+
capture: () => {
|
|
200
|
+
const declared = remoteModule()?.declaredMcpServers();
|
|
201
|
+
return declared === undefined ? undefined : new Map(declared);
|
|
202
|
+
},
|
|
203
|
+
restore: (snapshot) => {
|
|
204
|
+
const module = remoteModule();
|
|
205
|
+
if (module === undefined) return;
|
|
206
|
+
module.restoreDeclaredMcpServers(snapshot as ReadonlyMap<string, unknown>);
|
|
207
|
+
},
|
|
208
|
+
},
|
|
209
|
+
];
|
|
210
|
+
|
|
211
|
+
/** Each table's contents now, in `DECLARATION_TABLES` order; `undefined` for an unloaded owner. */
|
|
212
|
+
export function captureDeclarationTables(): readonly unknown[] {
|
|
213
|
+
return DECLARATION_TABLES.map((table) => table.capture());
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* Exactly `snapshots` again. A table whose owner was not loaded at the capture is left alone: what
|
|
218
|
+
* it holds was declared by a module this file loaded lazily, at module scope — a cached module
|
|
219
|
+
* never declares again, so taking it away would cost every later file that imports it.
|
|
220
|
+
*/
|
|
221
|
+
export function restoreDeclarationTables(snapshots: readonly unknown[]): void {
|
|
222
|
+
DECLARATION_TABLES.forEach((table, index) => {
|
|
223
|
+
const snapshot = snapshots[index];
|
|
224
|
+
if (snapshot !== undefined) table.restore(snapshot);
|
|
225
|
+
});
|
|
226
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// The driver kinds `@ultimat3/entity` has noted (`driverStores()`), put back at the file boundary
|
|
2
|
+
// to what the preload had noted: the drift step reads that record to tell a Postgres app from a
|
|
3
|
+
// `defineDriver` one, and one file's custom driver made every later file's fixture app non-SQL.
|
|
4
|
+
|
|
5
|
+
import type { clearDriverStores, driverStores, noteDriverStore } from '@ultimat3/entity/adapter';
|
|
6
|
+
import { loaded } from './per-test-reset';
|
|
7
|
+
|
|
8
|
+
interface DriverRegistry {
|
|
9
|
+
readonly driverStores: typeof driverStores;
|
|
10
|
+
readonly clearDriverStores: typeof clearDriverStores;
|
|
11
|
+
readonly noteDriverStore: typeof noteDriverStore;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
type Noted = ReturnType<typeof driverStores>;
|
|
15
|
+
|
|
16
|
+
const EMPTY: Noted = { sql: [], custom: [] };
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* The registry module when something in this process loaded it, else `undefined`. Read through the
|
|
20
|
+
* `require` cache, never imported: `@ultimat3/entity` stays out of every `packages/core` graph.
|
|
21
|
+
*/
|
|
22
|
+
const registry = (): DriverRegistry | undefined => {
|
|
23
|
+
const path = loaded('@ultimat3/entity', 'driver-registry.ts');
|
|
24
|
+
return path === undefined ? undefined : (require(path) as DriverRegistry);
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
/** What is noted now; nothing when the package was never loaded. */
|
|
28
|
+
export function captureDriverStores(): Noted {
|
|
29
|
+
return registry()?.driverStores() ?? EMPTY;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** Exactly `noted` again — a REPLACE, as the permission set is. A no-op while entity is unloaded. */
|
|
33
|
+
export function restoreDriverStores(noted: Noted): void {
|
|
34
|
+
const live = registry();
|
|
35
|
+
if (live === undefined) return;
|
|
36
|
+
live.clearDriverStores();
|
|
37
|
+
for (const name of noted.sql) live.noteDriverStore('sql', name);
|
|
38
|
+
for (const name of noted.custom) live.noteDriverStore('custom', name);
|
|
39
|
+
}
|
package/src/e2e-driver.ts
CHANGED
|
@@ -35,19 +35,15 @@ const refuse =
|
|
|
35
35
|
Promise.reject(new FixtureUnavailableError({ name, needs }));
|
|
36
36
|
|
|
37
37
|
/**
|
|
38
|
-
* `offline()`/`online()` FORWARD, `As of 2026-08-27
|
|
39
|
-
*
|
|
40
|
-
* (`
|
|
41
|
-
* `
|
|
42
|
-
*
|
|
43
|
-
* exposes it as `ScrapePage.offline()`. All of that landed in **the same commit as the comment**
|
|
44
|
-
* (#351), so the refusal was never true, and it is the reason issue #390 records a real browser
|
|
45
|
-
* check as out of reach.
|
|
38
|
+
* `offline()`/`online()` FORWARD, `As of 2026-08-27`, to `ScrapePage.offline()`
|
|
39
|
+
* (`page-over-target.ts`), which reaches `CdpPageLike.setOfflineMode` — checked when the session
|
|
40
|
+
* opens (scraping's `cdp-complete.ts`), so a driver that lacks it is refused there, never at the
|
|
41
|
+
* first `offline()`. Issue #390 recorded a real browser check as out of reach on a refusal that
|
|
42
|
+
* was never true (#351).
|
|
46
43
|
*
|
|
47
|
-
* Optional on `E2eBrowserPage`
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
* rather than a capability the framework does not have.
|
|
44
|
+
* Optional on `E2eBrowserPage` all the same: this port is the shape of somebody ELSE's object, and
|
|
45
|
+
* a six-line test double must still satisfy it. Absent, the fixture refuses by name — naming the
|
|
46
|
+
* method the double is missing rather than a capability the framework does not have.
|
|
51
47
|
*/
|
|
52
48
|
const networkFixtures = (browser: E2eBrowserPage): Pick<E2eFixtures, 'offline' | 'online'> => {
|
|
53
49
|
const setOffline = browser.offline?.bind(browser);
|
package/src/e2e-page.ts
CHANGED
|
@@ -22,14 +22,14 @@ export interface E2eBrowserPage {
|
|
|
22
22
|
click(selector: string): Promise<void>;
|
|
23
23
|
/**
|
|
24
24
|
* The browser's own network condition, which `E2eFixtures.offline()`/`online()` forward to.
|
|
25
|
-
* `ScrapePage` has it (`page-over-target.ts`),
|
|
26
|
-
* `cdp-
|
|
25
|
+
* `ScrapePage` has it (`page-over-target.ts`), over `CdpPageLike.setOfflineMode` — checked when
|
|
26
|
+
* the session opens (scraping's `cdp-complete.ts`).
|
|
27
27
|
*
|
|
28
|
-
* OPTIONAL for the reason the four above are structural: this port is the shape of somebody
|
|
28
|
+
* OPTIONAL here for the reason the four above are structural: this port is the shape of somebody
|
|
29
29
|
* ELSE's object, and requiring it would cost every six-line double a type error for a capability
|
|
30
|
-
* a test that never goes offline does not need. Absent, `e2e-driver.ts`
|
|
31
|
-
*
|
|
32
|
-
*
|
|
30
|
+
* a test that never goes offline does not need. Absent, `e2e-driver.ts` refuses by name — a coded
|
|
31
|
+
* refusal, never a silent no-op, because an `offline()` that did nothing would let the app's
|
|
32
|
+
* ONLINE page pass an offline test.
|
|
33
33
|
*/
|
|
34
34
|
offline?(enabled: boolean): Promise<void>;
|
|
35
35
|
/**
|
package/src/factory-persist.ts
CHANGED
|
@@ -34,6 +34,9 @@ export function clearPersister(): void {
|
|
|
34
34
|
|
|
35
35
|
export const persisterInstalled = (): boolean => current !== undefined;
|
|
36
36
|
|
|
37
|
+
/** The installed persister itself: what the registry guard's file boundary hands back. */
|
|
38
|
+
export const installedPersister = (): Persister | undefined => current;
|
|
39
|
+
|
|
37
40
|
/** Install for one run and hand back what was there: the factory lint's own throwaway writer. */
|
|
38
41
|
export function swapPersister(next: Persister | undefined): Persister | undefined {
|
|
39
42
|
const previous = current;
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
// Every module a test file can reach by import, read from source: what a shared worker uses to
|
|
2
|
+
// tell a file's OWN environment from the declarations an earlier file's imports left behind. Bun
|
|
3
|
+
// publishes no module graph (`require.cache` entries carry no `children` for ESM), so it is scanned.
|
|
4
|
+
|
|
5
|
+
/** The closure, and whether every module in it could be read: an incomplete one filters nothing. */
|
|
6
|
+
export interface ImportGraph {
|
|
7
|
+
readonly modules: ReadonlySet<string>;
|
|
8
|
+
readonly complete: boolean;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/** Only these are scanned; a `.json` or `.css` import is a leaf that declares nothing. */
|
|
12
|
+
const CODE = /\.[cm]?[jt]sx?$/;
|
|
13
|
+
|
|
14
|
+
/** `bin.ts` opens with a shebang, which the transpiler refuses as a syntax error. */
|
|
15
|
+
const withoutShebang = (source: string): string =>
|
|
16
|
+
source.startsWith('#!') ? `//${source.slice(2)}` : source;
|
|
17
|
+
|
|
18
|
+
const transpilers = {
|
|
19
|
+
ts: new Bun.Transpiler({ loader: 'ts' }),
|
|
20
|
+
tsx: new Bun.Transpiler({ loader: 'tsx' }),
|
|
21
|
+
js: new Bun.Transpiler({ loader: 'js' }),
|
|
22
|
+
jsx: new Bun.Transpiler({ loader: 'jsx' }),
|
|
23
|
+
} as const;
|
|
24
|
+
|
|
25
|
+
const transpilerFor = (path: string): Bun.Transpiler => {
|
|
26
|
+
if (path.endsWith('.tsx')) return transpilers.tsx;
|
|
27
|
+
if (path.endsWith('.jsx')) return transpilers.jsx;
|
|
28
|
+
if (/\.[cm]?ts$/.test(path)) return transpilers.ts;
|
|
29
|
+
return transpilers.js;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const dirOf = (path: string): string => path.slice(0, Math.max(path.lastIndexOf('/'), 0)) || '/';
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* A module's direct imports, resolved, or `undefined` when its source could not be read. Third-
|
|
36
|
+
* party code under `node_modules` is a leaf: it never declares an Ultimate permission, and walking
|
|
37
|
+
* it would multiply the scan for nothing. A specifier that does not resolve statically (a template
|
|
38
|
+
* `import()`, a plugin's virtual module) is skipped — the caller keeps anything first declared
|
|
39
|
+
* during the file, so a module reached that way is not lost on its first evaluation.
|
|
40
|
+
*/
|
|
41
|
+
async function directImports(path: string): Promise<readonly string[] | undefined> {
|
|
42
|
+
if (!CODE.test(path) || path.endsWith('.d.ts') || path.includes('/node_modules/')) return [];
|
|
43
|
+
let source: string;
|
|
44
|
+
try {
|
|
45
|
+
source = await Bun.file(path).text();
|
|
46
|
+
} catch {
|
|
47
|
+
return undefined;
|
|
48
|
+
}
|
|
49
|
+
let specifiers: readonly string[];
|
|
50
|
+
try {
|
|
51
|
+
specifiers = transpilerFor(path)
|
|
52
|
+
.scanImports(withoutShebang(source))
|
|
53
|
+
.map((entry) => entry.path);
|
|
54
|
+
} catch {
|
|
55
|
+
return undefined;
|
|
56
|
+
}
|
|
57
|
+
const dir = dirOf(path);
|
|
58
|
+
const resolved: string[] = [];
|
|
59
|
+
for (const specifier of specifiers) {
|
|
60
|
+
if (specifier.startsWith('bun:') || specifier.startsWith('node:')) continue;
|
|
61
|
+
try {
|
|
62
|
+
resolved.push(Bun.resolveSync(specifier, dir));
|
|
63
|
+
} catch {
|
|
64
|
+
// Unresolvable statically: see the doc comment.
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return resolved;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** One reader per process: a module's imports are read once however many files reach it. */
|
|
71
|
+
export function importGraphReader(): (entry: string) => Promise<ImportGraph> {
|
|
72
|
+
const direct = new Map<string, Promise<readonly string[] | undefined>>();
|
|
73
|
+
const importsOf = (path: string): Promise<readonly string[] | undefined> => {
|
|
74
|
+
let pending = direct.get(path);
|
|
75
|
+
if (pending === undefined) {
|
|
76
|
+
pending = directImports(path);
|
|
77
|
+
direct.set(path, pending);
|
|
78
|
+
}
|
|
79
|
+
return pending;
|
|
80
|
+
};
|
|
81
|
+
return async (entry) => {
|
|
82
|
+
const modules = new Set<string>([entry]);
|
|
83
|
+
let complete = true;
|
|
84
|
+
let frontier = [entry];
|
|
85
|
+
while (frontier.length > 0) {
|
|
86
|
+
const next: string[] = [];
|
|
87
|
+
for (const imports of await Promise.all(frontier.map(importsOf))) {
|
|
88
|
+
if (imports === undefined) {
|
|
89
|
+
complete = false;
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
for (const module of imports) {
|
|
93
|
+
if (modules.has(module)) continue;
|
|
94
|
+
modules.add(module);
|
|
95
|
+
next.push(module);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
frontier = next;
|
|
99
|
+
}
|
|
100
|
+
return { modules, complete };
|
|
101
|
+
};
|
|
102
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -45,8 +45,8 @@ export {
|
|
|
45
45
|
} from './cdp-browser';
|
|
46
46
|
export type { E2eBrowserLease, RunEndHook } from './cdp-browser-lease';
|
|
47
47
|
export { closeE2eBrowsersAtRunEnd, leaseE2eBrowser } from './cdp-browser-lease';
|
|
48
|
-
export type { CdpE2eTabOptions, E2eTab } from './cdp-e2e-page';
|
|
49
|
-
export { cdpE2eTab } from './cdp-e2e-page';
|
|
48
|
+
export type { CdpE2eTabOptions, E2eTab, TouchPoint } from './cdp-e2e-page';
|
|
49
|
+
export { cdpE2eTab, PRESS_KEYS } from './cdp-e2e-page';
|
|
50
50
|
export type { CdpE2eSessionOptions, E2eSession } from './cdp-e2e-session';
|
|
51
51
|
export { cdpE2eSession } from './cdp-e2e-session';
|
|
52
52
|
// The exercise pass (plan 101 / 40, phase 2): an app's per-primitive overrides — 39's
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
// What every `JobDriver` records for `onSettled` (J11): a settle that ENDS a run of a job with a
|
|
2
2
|
// hook owes it, the hook's return clears the debt under that claim, and a debt a crash left is
|
|
3
|
-
// taken once per grace
|
|
3
|
+
// taken once per grace — and a row the CLAIM settles (a final-attempt burial, an expiry) owes it
|
|
4
|
+
// too, named by `ClaimOptions.settleOwed`. A driver with no `settleDebt` fails here.
|
|
5
|
+
//
|
|
4
6
|
// Type-only imports: the barrel never loads `@ultimat3/jobs`.
|
|
5
7
|
|
|
6
8
|
import { expect } from 'bun:test';
|
|
7
|
-
import type { JobDriver, SettleDebt } from '@ultimat3/jobs';
|
|
9
|
+
import type { JobDriver, JobRecord, SettleDebt } from '@ultimat3/jobs';
|
|
8
10
|
import type { JobDriverCheck } from './job-driver-checks';
|
|
9
11
|
|
|
10
12
|
let minted = 0;
|
|
@@ -93,4 +95,61 @@ export const SETTLE_DEBT_CHECKS: readonly JobDriverCheck[] = [
|
|
|
93
95
|
expect(await lost(debt, at.name)).toEqual([]);
|
|
94
96
|
},
|
|
95
97
|
},
|
|
98
|
+
{
|
|
99
|
+
name: 'a row the claim buries or expires owes onSettled when settleOwed names its job',
|
|
100
|
+
async run(driver) {
|
|
101
|
+
const debt = debtOf(driver);
|
|
102
|
+
const hooked = scope();
|
|
103
|
+
const plain = scope();
|
|
104
|
+
// A final attempt whose lease lapsed (0 ms), for each job; and an expired row of the hooked.
|
|
105
|
+
const lapsing = async (at: typeof hooked): Promise<string> => {
|
|
106
|
+
const { id } = await driver.enqueue({
|
|
107
|
+
name: at.name,
|
|
108
|
+
queue: at.queue,
|
|
109
|
+
input: {},
|
|
110
|
+
idempotencyKey: 'lapsing',
|
|
111
|
+
maxAttempts: 1,
|
|
112
|
+
});
|
|
113
|
+
const taken = await driver.claim({
|
|
114
|
+
queues: [at.queue],
|
|
115
|
+
limit: 1,
|
|
116
|
+
visibilityTimeoutMs: 0,
|
|
117
|
+
workerId: 'w-gone',
|
|
118
|
+
});
|
|
119
|
+
expect(taken.map((row) => row.id)).toEqual([id]);
|
|
120
|
+
return id;
|
|
121
|
+
};
|
|
122
|
+
const dead = await lapsing(hooked);
|
|
123
|
+
const unowed = await lapsing(plain);
|
|
124
|
+
const expired = await driver.enqueue({
|
|
125
|
+
name: hooked.name,
|
|
126
|
+
queue: hooked.queue,
|
|
127
|
+
input: {},
|
|
128
|
+
idempotencyKey: 'expired',
|
|
129
|
+
maxAttempts: 3,
|
|
130
|
+
expiresAt: 1,
|
|
131
|
+
});
|
|
132
|
+
const buried: JobRecord[] = [];
|
|
133
|
+
for (const at of [hooked, plain]) {
|
|
134
|
+
const handed = await driver.claim({
|
|
135
|
+
queues: [at.queue],
|
|
136
|
+
limit: 10,
|
|
137
|
+
visibilityTimeoutMs: 30_000,
|
|
138
|
+
workerId: 'w-burier',
|
|
139
|
+
settleOwed: [hooked.name],
|
|
140
|
+
onExhausted: (rows) => buried.push(...rows),
|
|
141
|
+
});
|
|
142
|
+
expect(handed).toEqual([]);
|
|
143
|
+
}
|
|
144
|
+
expect(buried.map((row) => row.id).sort()).toEqual([dead, expired.id, unowed].sort());
|
|
145
|
+
// Recorded by the claim's own write: a burier that dies now leaves it for the leader.
|
|
146
|
+
expect([...(await lost(debt, hooked.name))].sort()).toEqual([dead, expired.id].sort());
|
|
147
|
+
expect(await lost(debt, plain.name)).toEqual([]);
|
|
148
|
+
// Paid under the claim the buried row carries — the one the burier was handed.
|
|
149
|
+
for (const row of buried.filter((each) => each.name === hooked.name)) {
|
|
150
|
+
expect(await debt.clear(row.id, row.claim ?? 0)).toBe(true);
|
|
151
|
+
}
|
|
152
|
+
expect(await lost(debt, hooked.name)).toEqual([]);
|
|
153
|
+
},
|
|
154
|
+
},
|
|
96
155
|
];
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
// The permissions and roles a test file inherits on a shared worker: what a module in ITS import
|
|
2
|
+
// graph declared, never what a module only an earlier file imported left behind. Read from each
|
|
3
|
+
// name's declaration site; `registry-leak-guard.ts` owns WHEN, `import-graph.ts` the graph.
|
|
4
|
+
|
|
5
|
+
import type { RoleMap } from '@ultimat3/policy';
|
|
6
|
+
import type { ImportGraph } from './import-graph';
|
|
7
|
+
import type { ProcessRegistrySnapshot } from './registry-snapshot';
|
|
8
|
+
|
|
9
|
+
/** The policy half of a snapshot — the only half this narrows. */
|
|
10
|
+
export type PolicyEnvironment = Pick<
|
|
11
|
+
ProcessRegistrySnapshot,
|
|
12
|
+
'permissions' | 'permissionSites' | 'roles' | 'roleSites'
|
|
13
|
+
>;
|
|
14
|
+
|
|
15
|
+
/** Names kept whatever the graph says: the preload's, and those first declared during THIS load. */
|
|
16
|
+
export interface KeptNames {
|
|
17
|
+
readonly permissions: ReadonlySet<string>;
|
|
18
|
+
readonly roles: ReadonlySet<string>;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** `?x-reload=…` is a loader's cache key, not part of the file. */
|
|
22
|
+
const withoutQuery = (path: string): string => path.replace(/\?.*$/, '');
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* The file a stack frame names — `at /a/b.ts:5:1`, `at fn (/a/b.ts:5:1)`, `at async C:\a\b.ts:5:1`
|
|
26
|
+
* — `/`-normalised, or `undefined` for a frame that names none (`unknown site`, `<anonymous>`).
|
|
27
|
+
*/
|
|
28
|
+
export function siteFile(frame: string): string | undefined {
|
|
29
|
+
const line = frame.trim();
|
|
30
|
+
const file = (/\(([^()]+):\d+:\d+\)$/.exec(line) ??
|
|
31
|
+
/^at (?:async )?(.+):\d+:\d+$/.exec(line))?.[1];
|
|
32
|
+
if (file === undefined || file.startsWith('<') || file.startsWith('native')) return undefined;
|
|
33
|
+
return withoutQuery(file.replaceAll('\\', '/'));
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* In the graph when ANY site is, and when a site cannot be read at all: an unreadable site is
|
|
38
|
+
* provenance this cannot judge, and dropping a name a cached module really declared is the one
|
|
39
|
+
* failure a file cannot repair from inside.
|
|
40
|
+
*/
|
|
41
|
+
const reachable = (sites: readonly string[], modules: ReadonlySet<string>): boolean =>
|
|
42
|
+
sites.length === 0 ||
|
|
43
|
+
sites.some((site) => {
|
|
44
|
+
const file = siteFile(site);
|
|
45
|
+
return file === undefined || modules.has(file);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* `inherited` narrowed to the names `graph` reaches, plus `kept`. An incomplete graph narrows
|
|
50
|
+
* nothing: a module it could not read may be the one that declared.
|
|
51
|
+
*/
|
|
52
|
+
export function ownEnvironment(
|
|
53
|
+
inherited: PolicyEnvironment,
|
|
54
|
+
graph: ImportGraph,
|
|
55
|
+
kept: KeptNames,
|
|
56
|
+
): PolicyEnvironment {
|
|
57
|
+
if (!graph.complete) return inherited;
|
|
58
|
+
const modules = new Set([...graph.modules].map((path) => path.replaceAll('\\', '/')));
|
|
59
|
+
const permissions = inherited.permissions.filter(
|
|
60
|
+
(name) =>
|
|
61
|
+
kept.permissions.has(name) ||
|
|
62
|
+
reachable(
|
|
63
|
+
Object.hasOwn(inherited.permissionSites, name)
|
|
64
|
+
? (inherited.permissionSites[name] ?? [])
|
|
65
|
+
: [],
|
|
66
|
+
modules,
|
|
67
|
+
),
|
|
68
|
+
);
|
|
69
|
+
const roles: Record<string, RoleMap[string]> = {};
|
|
70
|
+
const roleSites: Record<string, string> = {};
|
|
71
|
+
for (const [name, definition] of Object.entries(inherited.roles)) {
|
|
72
|
+
const site = Object.hasOwn(inherited.roleSites, name) ? inherited.roleSites[name] : undefined;
|
|
73
|
+
if (!kept.roles.has(name) && !reachable(site === undefined ? [] : [site], modules)) continue;
|
|
74
|
+
roles[name] = definition;
|
|
75
|
+
if (site !== undefined) roleSites[name] = site;
|
|
76
|
+
}
|
|
77
|
+
const permitted = new Set(permissions);
|
|
78
|
+
const permissionSites = Object.fromEntries(
|
|
79
|
+
Object.entries(inherited.permissionSites).filter(([name]) => permitted.has(name)),
|
|
80
|
+
);
|
|
81
|
+
return { permissions, permissionSites, roles, roleSites };
|
|
82
|
+
}
|
|
@@ -5,13 +5,21 @@
|
|
|
5
5
|
|
|
6
6
|
import { afterAll } from 'bun:test';
|
|
7
7
|
import { knownTags, registeredTiers } from '@ultimat3/cache';
|
|
8
|
+
import { configureLocales } from '@ultimat3/i18n';
|
|
9
|
+
import { captureAdminMounts, restoreAdminMounts } from './admin-mount-boundary';
|
|
8
10
|
import { isAppRoot } from './app-root';
|
|
11
|
+
import { captureDeclarationTables, restoreDeclarationTables } from './declaration-boundary';
|
|
12
|
+
import { captureDriverStores, restoreDriverStores } from './driver-store-boundary';
|
|
9
13
|
import { RegistryLeakError } from './errors';
|
|
14
|
+
import { installedPersister, swapPersister } from './factory-persist';
|
|
10
15
|
import { runBoundaryHooks, runFileBoundary } from './file-boundary';
|
|
16
|
+
import { type ImportGraph, importGraphReader } from './import-graph';
|
|
17
|
+
import { ownEnvironment } from './registry-environment';
|
|
11
18
|
import type { ProcessRegistrySnapshot } from './registry-snapshot';
|
|
12
19
|
import {
|
|
13
20
|
captureProcessRegistries,
|
|
14
21
|
mergeSnapshots,
|
|
22
|
+
restorePolicyRegistries,
|
|
15
23
|
restoreProcessRegistries,
|
|
16
24
|
} from './registry-snapshot';
|
|
17
25
|
import { rerunDeclarations } from './rerun-declarations';
|
|
@@ -34,14 +42,14 @@ import { frameworkDeclarationRegistries } from './rerun-registries';
|
|
|
34
42
|
* "Idiomatic to leave filled" says nothing about a file that calls `clear*()`/`reset*()` and takes
|
|
35
43
|
* a module-scope declaration from every file after it — a module evaluates once per process, so the
|
|
36
44
|
* next file's own `import` is a cache hit that declares nothing. That is what `registry-snapshot.ts`
|
|
37
|
-
* repairs, and it repairs
|
|
45
|
+
* repairs, and it repairs SEVEN registries out of the set that has one:
|
|
38
46
|
*
|
|
39
47
|
* | registry | reset export | owner | in the snapshot? |
|
|
40
48
|
* |---|---|---|---|
|
|
41
49
|
* | locales / catalogs | `resetCatalogs` | `@ultimat3/i18n` | yes |
|
|
42
50
|
* | permissions / roles | `restorePermissions` / `restoreRoles` | `@ultimat3/policy` | yes |
|
|
43
51
|
* | routes | `clearRoutes` | `@ultimat3/render` | **no** |
|
|
44
|
-
* | jobs | `resetJobs` / `restoreJobs` | `@ultimat3/jobs` |
|
|
52
|
+
* | jobs | `resetJobs` / `restoreJobs` | `@ultimat3/jobs` | yes (2026-11) |
|
|
45
53
|
* | tasks | `restoreTasks` | `@ultimat3/jobs` | yes (22.7) |
|
|
46
54
|
* | measurement actor | `resetMeasurementActor` | `@ultimat3/core` | yes |
|
|
47
55
|
* | actions | `resetActions` | `@ultimat3/action` | **no** |
|
|
@@ -109,7 +117,10 @@ const repoRelative = (path: string): string => {
|
|
|
109
117
|
*/
|
|
110
118
|
const BASELINE_HOOK = '__ultimateRegistryLeakBaseline';
|
|
111
119
|
|
|
112
|
-
/**
|
|
120
|
+
/**
|
|
121
|
+
* Appended: the TAG baseline is the file's whole module scope, its body's declarations included.
|
|
122
|
+
* The RESTORE baseline is not — it is taken at `BODY_START_HOOK`, below.
|
|
123
|
+
*/
|
|
113
124
|
const SAMPLE_BASELINE = `\n;globalThis[${JSON.stringify(BASELINE_HOOK)}]?.();\n`;
|
|
114
125
|
|
|
115
126
|
/**
|
|
@@ -117,6 +128,14 @@ const SAMPLE_BASELINE = `\n;globalThis[${JSON.stringify(BASELINE_HOOK)}]?.();\n`
|
|
|
117
128
|
* and before its body (measured on Bun 1.4.4) — the start of the window in which the BODY declares
|
|
118
129
|
* (`rerun-declarations.ts`). On line 1 with no newline, so every line number a stack trace or a
|
|
119
130
|
* coverage report names is the file's own.
|
|
131
|
+
*
|
|
132
|
+
* It is also where the RESTORE snapshot is taken, and why there rather than after the body: the
|
|
133
|
+
* imports are the file's environment — a cached module never declares again, so what it declared
|
|
134
|
+
* has to outlive the file — but a `.test.ts` body is imported by no other file, so nothing it
|
|
135
|
+
* declared is anyone's cache hit. Sampled after the body (until 2026-11), every test file's
|
|
136
|
+
* module-scope `definePermissions()` / `defineRoles()` was folded into what each later file on the
|
|
137
|
+
* worker inherited: strict permission checking switched on for files that declared nothing, and
|
|
138
|
+
* `X_ROLE_REDEFINED` in the next file that defined the same role its own way.
|
|
120
139
|
*/
|
|
121
140
|
const BODY_START_HOOK = '__ultimateBodyStart';
|
|
122
141
|
const SAMPLE_BODY_START = `;globalThis[${JSON.stringify(BODY_START_HOOK)}]?.();`;
|
|
@@ -146,8 +165,12 @@ export function installRegistryLeakGuard(): void {
|
|
|
146
165
|
let current:
|
|
147
166
|
| {
|
|
148
167
|
readonly file: string;
|
|
149
|
-
|
|
168
|
+
/** Unset until the body ends: a body that threw is restored, never judged for tags. */
|
|
169
|
+
before: RegistrySample | undefined;
|
|
150
170
|
readonly snapshot: ProcessRegistrySnapshot;
|
|
171
|
+
readonly admins: ReturnType<typeof captureAdminMounts>;
|
|
172
|
+
readonly tables: ReturnType<typeof captureDeclarationTables>;
|
|
173
|
+
readonly persister: ReturnType<typeof installedPersister>;
|
|
151
174
|
}
|
|
152
175
|
| undefined;
|
|
153
176
|
const leaks: RegistryLeak[] = [];
|
|
@@ -157,14 +180,30 @@ export function installRegistryLeakGuard(): void {
|
|
|
157
180
|
const pristineLocales = JSON.stringify(captureProcessRegistries().locales);
|
|
158
181
|
const inApp = isAppRoot();
|
|
159
182
|
const reruns = rerunDeclarations(frameworkDeclarationRegistries);
|
|
183
|
+
// The preload's own declarations are every file's: no test file's graph reaches the preload.
|
|
184
|
+
const atPreload = captureProcessRegistries();
|
|
185
|
+
const preloadNames = {
|
|
186
|
+
permissions: new Set(atPreload.permissions),
|
|
187
|
+
roles: new Set(Object.keys(atPreload.roles)),
|
|
188
|
+
};
|
|
189
|
+
// What the last boundary put back: a name live at a body's start and absent here was declared
|
|
190
|
+
// by a module THIS file's load evaluated for the first time — its own, whatever the graph says.
|
|
191
|
+
let lastBoundary = atPreload;
|
|
192
|
+
const preloadStores = captureDriverStores();
|
|
193
|
+
const graphOf = importGraphReader();
|
|
194
|
+
let graph: ImportGraph | undefined;
|
|
160
195
|
|
|
161
196
|
const close = (): void => {
|
|
162
197
|
if (current === undefined) return;
|
|
163
|
-
const leak =
|
|
198
|
+
const leak =
|
|
199
|
+
current.before === undefined
|
|
200
|
+
? undefined
|
|
201
|
+
: leakBetween(current.file, current.before, sampleRegistries());
|
|
164
202
|
if (leak !== undefined) leaks.push(leak);
|
|
165
203
|
// The repair, at the only point it is safe: the file is over and the next one has not
|
|
166
204
|
// evaluated yet, so what goes back is exactly what that file inherited — module-scope
|
|
167
|
-
// declarations included, which is the half a plain `resetX()` in a `beforeEach` destroys
|
|
205
|
+
// declarations included, which is the half a plain `resetX()` in a `beforeEach` destroys —
|
|
206
|
+
// and the file's own BODY excluded (`BODY_START_HOOK`).
|
|
168
207
|
//
|
|
169
208
|
// In an APP, declarations are put back as a UNION with what the process holds now (22.7,
|
|
170
209
|
// shared worker): an app module a test imported lazily declared its permissions and roles once,
|
|
@@ -189,23 +228,78 @@ export function installRegistryLeakGuard(): void {
|
|
|
189
228
|
...merged,
|
|
190
229
|
locales: declaredLazily ? live.locales : current.snapshot.locales,
|
|
191
230
|
tasks: current.snapshot.tasks,
|
|
231
|
+
jobs: current.snapshot.jobs,
|
|
192
232
|
};
|
|
193
233
|
restoreProcessRegistries(restored);
|
|
234
|
+
// To the PRELOAD's notes, never the body's start: a store is noted as its driver is built,
|
|
235
|
+
// and a fixture module that builds one at import noted it for every later file on the worker —
|
|
236
|
+
// whose drift step then read its fixture app as "a store that owns its own schema".
|
|
237
|
+
restoreDriverStores(preloadStores);
|
|
238
|
+
restoreAdminMounts(current.admins);
|
|
239
|
+
// The framework repository's own suites only: in an app these tables hold what `loadApp()`
|
|
240
|
+
// registered once for the worker's life (routes, the authenticator, storage, channels), and a
|
|
241
|
+
// module the cache will not evaluate again cannot put them back for the next file.
|
|
242
|
+
if (!inApp) restoreDeclarationTables(current.tables);
|
|
243
|
+
// A preload's `usePersister` is in every body's start; a file's own `factoryWorld()` is not.
|
|
244
|
+
swapPersister(current.persister);
|
|
194
245
|
accumulated = mergeSnapshots(accumulated, restored);
|
|
246
|
+
lastBoundary = restored;
|
|
195
247
|
current = undefined;
|
|
196
248
|
};
|
|
197
249
|
|
|
198
|
-
//
|
|
199
|
-
//
|
|
200
|
-
//
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
250
|
+
// The framework repository's files, on a shared worker, start from THEIR graph's policy
|
|
251
|
+
// declarations (`registry-environment.ts`), put in place before the body runs. An app keeps the
|
|
252
|
+
// union: its tests reach app modules through `loadApp()`, which no static graph shows.
|
|
253
|
+
const narrowed = (
|
|
254
|
+
live: ProcessRegistrySnapshot,
|
|
255
|
+
inherited: ProcessRegistrySnapshot,
|
|
256
|
+
): ProcessRegistrySnapshot => {
|
|
257
|
+
if (inApp || graph === undefined) return inherited;
|
|
258
|
+
const fresh = (names: readonly string[], before: readonly string[]): Set<string> =>
|
|
259
|
+
new Set(names.filter((name) => !before.includes(name)));
|
|
260
|
+
const kept = {
|
|
261
|
+
permissions: new Set([
|
|
262
|
+
...preloadNames.permissions,
|
|
263
|
+
...fresh(live.permissions, lastBoundary.permissions),
|
|
264
|
+
]),
|
|
265
|
+
roles: new Set([
|
|
266
|
+
...preloadNames.roles,
|
|
267
|
+
...fresh(Object.keys(live.roles), Object.keys(lastBoundary.roles)),
|
|
268
|
+
]),
|
|
269
|
+
};
|
|
270
|
+
// The locale config likewise: an earlier file's import that narrowed it (an app's
|
|
271
|
+
// `defineCatalogs()`) is no environment of this one — unless THIS load moved it.
|
|
272
|
+
const movedNow = JSON.stringify(live.locales) !== JSON.stringify(lastBoundary.locales);
|
|
273
|
+
const locales = movedNow ? live.locales : atPreload.locales;
|
|
274
|
+
const own = { ...inherited, ...ownEnvironment(inherited, graph, kept), locales };
|
|
275
|
+
restorePolicyRegistries(own);
|
|
276
|
+
configureLocales(locales);
|
|
277
|
+
return own;
|
|
278
|
+
};
|
|
279
|
+
|
|
280
|
+
// Both called from the file's own source, once per test file. At the body's START everything
|
|
281
|
+
// the file's IMPORT graph registered is its environment, and is what the boundary restores to.
|
|
282
|
+
// At the body's END everything the module scope registered is the TAG baseline — importing an
|
|
283
|
+
// app module is how an app declares its tags — and everything after it is the file's to undo.
|
|
284
|
+
hookHost[BODY_START_HOOK] = () => {
|
|
285
|
+
reruns.bodyStart();
|
|
204
286
|
if (pending === undefined) return;
|
|
205
|
-
|
|
206
|
-
|
|
287
|
+
const live = captureProcessRegistries();
|
|
288
|
+
accumulated = mergeSnapshots(accumulated, live);
|
|
289
|
+
current = {
|
|
290
|
+
file: pending,
|
|
291
|
+
before: undefined,
|
|
292
|
+
snapshot: narrowed(live, accumulated),
|
|
293
|
+
admins: captureAdminMounts(),
|
|
294
|
+
tables: captureDeclarationTables(),
|
|
295
|
+
persister: installedPersister(),
|
|
296
|
+
};
|
|
207
297
|
pending = undefined;
|
|
208
298
|
};
|
|
299
|
+
hookHost[BASELINE_HOOK] = () => {
|
|
300
|
+
reruns.bodyEnd();
|
|
301
|
+
if (current !== undefined && current.before === undefined) current.before = sampleRegistries();
|
|
302
|
+
};
|
|
209
303
|
|
|
210
304
|
// The only signal Bun gives a preload for "a new test file starts": its hooks carry no file. A
|
|
211
305
|
// load handler MUST answer with contents — one that answers `undefined` makes Bun load nothing
|
|
@@ -225,6 +319,8 @@ export function installRegistryLeakGuard(): void {
|
|
|
225
319
|
runFileBoundary();
|
|
226
320
|
close();
|
|
227
321
|
pending = repoRelative(args.path);
|
|
322
|
+
// Read before the file evaluates — a body-start hook is synchronous and this is not.
|
|
323
|
+
graph = inApp ? undefined : await graphOf(args.path);
|
|
228
324
|
// `loading` closes the previous file's window first (`fileEnd`).
|
|
229
325
|
reruns.loading(args.path);
|
|
230
326
|
return {
|
package/src/registry-snapshot.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// module declares at MODULE scope evaluates once per `bun test` process — a neighbour's clear is
|
|
4
4
|
// permanent and there is no second evaluation left to redo it.
|
|
5
5
|
//
|
|
6
|
-
//
|
|
6
|
+
// SEVEN registries, out of roughly nine that publish a `clear*`/`reset*`. The missing ones and what
|
|
7
7
|
// each still needs are tabulated in `registry-leak-guard.ts` beside `RegistrySample` — every one of
|
|
8
8
|
// them needs a RESTORE in its owning package first, the way `restorePermissions` / `restoreRoles`
|
|
9
9
|
// were added to `@ultimat3/policy` for the two rows below.
|
|
@@ -25,8 +25,8 @@ import {
|
|
|
25
25
|
registeredLocales,
|
|
26
26
|
resetCatalogs,
|
|
27
27
|
} from '@ultimat3/i18n';
|
|
28
|
-
import type { TaskHandle } from '@ultimat3/jobs';
|
|
29
|
-
import { registeredTasks, restoreTasks } from '@ultimat3/jobs';
|
|
28
|
+
import type { AnyJobHandle, TaskHandle } from '@ultimat3/jobs';
|
|
29
|
+
import { registeredJobs, registeredTasks, restoreJobs, restoreTasks } from '@ultimat3/jobs';
|
|
30
30
|
import type { RoleMap } from '@ultimat3/policy';
|
|
31
31
|
import {
|
|
32
32
|
knownPermissions,
|
|
@@ -57,6 +57,13 @@ export interface ProcessRegistrySnapshot {
|
|
|
57
57
|
* fired in every later file's `appManifest` round — 14 framework failures, measured.
|
|
58
58
|
*/
|
|
59
59
|
readonly tasks: readonly TaskHandle[];
|
|
60
|
+
/**
|
|
61
|
+
* Jobs, for the tasks' reason read the other way: `job()` runs at module scope (`sendMailJob`),
|
|
62
|
+
* and `job.test.ts` `resetJobs()` in every `beforeEach` — so on a shared worker every later file
|
|
63
|
+
* lost the jobs its cached imports had declared, and a fixture app with no module of its own
|
|
64
|
+
* read as X_APP_EMPTY (`@ultimat3/cli`'s `loadApp` counts the process's registries).
|
|
65
|
+
*/
|
|
66
|
+
readonly jobs: readonly AnyJobHandle[];
|
|
60
67
|
/** `defineCatalogs()` calls so far — see `@ultimat3/i18n`'s `catalogDeclarationCount`. */
|
|
61
68
|
readonly catalogDeclarations: number;
|
|
62
69
|
/**
|
|
@@ -77,6 +84,7 @@ export function captureProcessRegistries(): ProcessRegistrySnapshot {
|
|
|
77
84
|
roles: roleDefinitions(),
|
|
78
85
|
roleSites: roleDeclarationSites(),
|
|
79
86
|
tasks: registeredTasks(),
|
|
87
|
+
jobs: registeredJobs(),
|
|
80
88
|
catalogDeclarations: catalogDeclarationCount(),
|
|
81
89
|
measurementActor: declaredMeasurementActor(),
|
|
82
90
|
};
|
|
@@ -92,13 +100,24 @@ export function restoreProcessRegistries(snapshot: ProcessRegistrySnapshot): voi
|
|
|
92
100
|
// a partial call can never widen `supported` back.
|
|
93
101
|
configureLocales(snapshot.locales);
|
|
94
102
|
restoreCatalogs(snapshot.catalogs);
|
|
95
|
-
|
|
96
|
-
restoreRoles(snapshot.roles, snapshot.roleSites);
|
|
103
|
+
restorePolicyRegistries(snapshot);
|
|
97
104
|
restoreTasks(snapshot.tasks);
|
|
105
|
+
restoreJobs(snapshot.jobs);
|
|
98
106
|
if (snapshot.measurementActor === undefined) resetMeasurementActor();
|
|
99
107
|
else defineMeasurementActor(snapshot.measurementActor);
|
|
100
108
|
}
|
|
101
109
|
|
|
110
|
+
/** The permission set and the role map alone, each with its declaration sites. */
|
|
111
|
+
export function restorePolicyRegistries(
|
|
112
|
+
snapshot: Pick<
|
|
113
|
+
ProcessRegistrySnapshot,
|
|
114
|
+
'permissions' | 'permissionSites' | 'roles' | 'roleSites'
|
|
115
|
+
>,
|
|
116
|
+
): void {
|
|
117
|
+
restorePermissions(snapshot.permissions, snapshot.permissionSites);
|
|
118
|
+
restoreRoles(snapshot.roles, snapshot.roleSites);
|
|
119
|
+
}
|
|
120
|
+
|
|
102
121
|
/**
|
|
103
122
|
* Repair a clear; never undo a registration. The catalogs are the one registry here restored by
|
|
104
123
|
* MERGE rather than by replacement, and the module cache is why.
|
|
@@ -154,6 +173,8 @@ export function mergeSnapshots(
|
|
|
154
173
|
}
|
|
155
174
|
const tasks = new Map(older.tasks.map((handle) => [handle.name, handle] as const));
|
|
156
175
|
for (const handle of newer.tasks) tasks.set(handle.name, handle);
|
|
176
|
+
const jobs = new Map(older.jobs.map((handle) => [handle.name, handle] as const));
|
|
177
|
+
for (const handle of newer.jobs) jobs.set(handle.name, handle);
|
|
157
178
|
return {
|
|
158
179
|
locales: newer.locales,
|
|
159
180
|
catalogs: [...catalogs],
|
|
@@ -162,6 +183,7 @@ export function mergeSnapshots(
|
|
|
162
183
|
roles: { ...older.roles, ...newer.roles },
|
|
163
184
|
roleSites: { ...older.roleSites, ...newer.roleSites },
|
|
164
185
|
tasks: [...tasks.values()],
|
|
186
|
+
jobs: [...jobs.values()],
|
|
165
187
|
catalogDeclarations: Math.max(older.catalogDeclarations, newer.catalogDeclarations),
|
|
166
188
|
// Last declaration wins, as `defineMeasurementActor` itself has it; "none" never erases one.
|
|
167
189
|
measurementActor: newer.measurementActor ?? older.measurementActor,
|
|
@@ -75,7 +75,7 @@ export const SCRAPE_FRAME_CHECKS: readonly ScrapeDriverCheck[] = [
|
|
|
75
75
|
},
|
|
76
76
|
},
|
|
77
77
|
{
|
|
78
|
-
name: 'accessibility() answers the computed role and name,
|
|
78
|
+
name: 'accessibility() answers the computed role and name, on every driver',
|
|
79
79
|
async run({ page }) {
|
|
80
80
|
await page.goto(SCRAPE_CONFORMANCE_URLS.search);
|
|
81
81
|
// Screened before any driver is asked, whichever kind this is.
|
|
@@ -83,12 +83,6 @@ export const SCRAPE_FRAME_CHECKS: readonly ScrapeDriverCheck[] = [
|
|
|
83
83
|
'X_INVARIANT',
|
|
84
84
|
);
|
|
85
85
|
expect(await codeOf(() => page.accessibility('#go', { max: 0 }))).toBe('X_INVARIANT');
|
|
86
|
-
const refused = await codeOf(() => page.accessibility('#go'));
|
|
87
|
-
if (refused !== undefined) {
|
|
88
|
-
// An offline driver refuses rather than reading `role=` off the markup and inventing one.
|
|
89
|
-
expect(refused).toBe('X_NOT_IMPLEMENTED');
|
|
90
|
-
return;
|
|
91
|
-
}
|
|
92
86
|
expect(await page.accessibility('#go')).toMatchObject([
|
|
93
87
|
{ role: 'button', name: 'Run search' },
|
|
94
88
|
]);
|
|
@@ -98,14 +98,10 @@ export const SCRAPE_PAGE_CHECKS: readonly ScrapeDriverCheck[] = [
|
|
|
98
98
|
},
|
|
99
99
|
},
|
|
100
100
|
{
|
|
101
|
-
name: 'offline(true) cuts the browser off
|
|
101
|
+
name: 'offline(true) cuts the browser off — answered by every driver, never a no-op',
|
|
102
102
|
async run({ page }) {
|
|
103
103
|
await page.goto(SCRAPE_CONFORMANCE_URLS.orders);
|
|
104
|
-
|
|
105
|
-
if (refused !== undefined) {
|
|
106
|
-
expect(refused).toBe('X_NOT_IMPLEMENTED');
|
|
107
|
-
return;
|
|
108
|
-
}
|
|
104
|
+
expect(await codeOf(() => page.offline(true))).toBeUndefined();
|
|
109
105
|
// Set: then the browser must actually fail a navigation, or a test proved nothing offline.
|
|
110
106
|
expect(await codeOf(() => page.goto(SCRAPE_CONFORMANCE_URLS.second))).not.toBeUndefined();
|
|
111
107
|
await page.offline(false);
|