@ultimat3/testing 30.9.0 → 31.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (151) hide show
  1. package/CLAUDE.md +46 -55
  2. package/README.md +179 -39
  3. package/package.json +23 -17
  4. package/src/ai-conformance-answer.ts +67 -0
  5. package/src/ai-gateway-conformance.ts +105 -0
  6. package/src/ai-provider-conformance.ts +69 -0
  7. package/src/ai-provider-transport-conformance.ts +170 -0
  8. package/src/audit-sink-conformance.ts +204 -0
  9. package/src/auth-adapter-conformance-credentials.ts +124 -0
  10. package/src/auth-adapter-conformance-mfa.ts +70 -0
  11. package/src/auth-adapter-conformance-passkeys.ts +133 -0
  12. package/src/auth-adapter-conformance-sessions.ts +115 -0
  13. package/src/auth-adapter-conformance-support.ts +71 -0
  14. package/src/auth-adapter-conformance-users.ts +128 -0
  15. package/src/auth-adapter-conformance.ts +34 -0
  16. package/src/auth-limiter-factory-conformance.ts +224 -0
  17. package/src/auth-server-store-conformance-records.ts +69 -0
  18. package/src/auth-server-store-conformance.ts +208 -0
  19. package/src/cache-tier-conformance-checks.ts +142 -0
  20. package/src/cache-tier-conformance.ts +24 -0
  21. package/src/cassette-format.ts +8 -13
  22. package/src/cassette-record.ts +1 -1
  23. package/src/cdp-browser.ts +10 -11
  24. package/src/cdp-e2e-page.ts +2 -2
  25. package/src/cdp-e2e-session.ts +2 -2
  26. package/src/cdp-network-probe.ts +1 -1
  27. package/src/cdp-offline-script.ts +2 -2
  28. package/src/clock-conformance.ts +126 -0
  29. package/src/conformance.ts +239 -0
  30. package/src/e2e-browser-handle.ts +1 -2
  31. package/src/e2e-error-codes.ts +17 -16
  32. package/src/e2e-run.ts +4 -3
  33. package/src/embedder-conformance.ts +101 -0
  34. package/src/entity-conformance-aggregates.ts +210 -0
  35. package/src/entity-conformance-batches.ts +216 -0
  36. package/src/entity-conformance-bulk.ts +379 -0
  37. package/src/entity-conformance-checks.ts +27 -0
  38. package/src/entity-conformance-entities.ts +52 -0
  39. package/src/entity-conformance-locks.ts +286 -0
  40. package/src/entity-conformance-matrix.ts +397 -0
  41. package/src/entity-conformance-reads.ts +241 -0
  42. package/src/entity-conformance-support.ts +56 -0
  43. package/src/entity-conformance-tenancy.ts +296 -0
  44. package/src/entity-conformance-values.ts +305 -0
  45. package/src/entity-conformance-versions.ts +60 -0
  46. package/src/entity-conformance-writes.ts +348 -0
  47. package/src/entity-driver-conformance.ts +103 -0
  48. package/src/error-groups-store-conformance.ts +198 -0
  49. package/src/error-reporter-conformance.ts +119 -0
  50. package/src/errors.ts +20 -2
  51. package/src/event-bus-conformance.ts +161 -0
  52. package/src/exercise-drift-hint.ts +4 -1
  53. package/src/exercise-judge.ts +5 -3
  54. package/src/exercise-override-line.ts +98 -0
  55. package/src/exercise-report.ts +138 -115
  56. package/src/exercise-room-mail.ts +40 -0
  57. package/src/exercise.ts +33 -29
  58. package/src/factories.ts +192 -179
  59. package/src/factory-api.ts +131 -0
  60. package/src/factory-associations.ts +67 -0
  61. package/src/factory-errors.ts +38 -0
  62. package/src/factory-lint.ts +92 -0
  63. package/src/factory-persist.ts +74 -16
  64. package/src/factory-pipeline.ts +191 -0
  65. package/src/factory-registry.ts +2 -1
  66. package/src/factory-types.ts +131 -0
  67. package/src/failure-store-conformance.ts +137 -0
  68. package/src/fixture-jobs.ts +27 -11
  69. package/src/fixture-mail.ts +7 -7
  70. package/src/fixture-seed.ts +111 -0
  71. package/src/fixture-statements.ts +68 -52
  72. package/src/framework-fixtures.ts +1 -1
  73. package/src/idempotency-store-conformance.ts +186 -0
  74. package/src/idempotency-store-replay-conformance.ts +140 -0
  75. package/src/idempotency-store-tx-conformance.ts +132 -0
  76. package/src/idempotency-store-world-conformance.ts +82 -0
  77. package/src/identity-provider-conformance.ts +144 -0
  78. package/src/image-transform-conformance.ts +89 -0
  79. package/src/index.ts +68 -157
  80. package/src/isr-store-conformance.ts +113 -0
  81. package/src/job-sim-effects.ts +19 -31
  82. package/src/job-sim-world.ts +6 -15
  83. package/src/lease-store-conformance.ts +195 -0
  84. package/src/mail-driver-conformance.ts +108 -0
  85. package/src/matcher-doubles.ts +104 -0
  86. package/src/matcher-stub.ts +78 -0
  87. package/src/matcher-surface.ts +21 -0
  88. package/src/matchers.ts +19 -1
  89. package/src/mcp-confirmation-store-conformance.ts +262 -0
  90. package/src/meter-store-conformance.ts +135 -0
  91. package/src/notify-digest-conformance.ts +133 -0
  92. package/src/notify-inbox-conformance.ts +130 -0
  93. package/src/notify-ledger-conformance.ts +134 -0
  94. package/src/notify-preference-conformance.ts +49 -0
  95. package/src/notify-stores-conformance.ts +73 -0
  96. package/src/outbox-store-conformance-claims.ts +112 -0
  97. package/src/outbox-store-conformance-subject.ts +65 -0
  98. package/src/outbox-store-conformance.ts +71 -0
  99. package/src/per-test-reset.ts +55 -20
  100. package/src/preload.ts +4 -2
  101. package/src/purge-conformance.ts +79 -0
  102. package/src/push-device-conformance.ts +124 -0
  103. package/src/push-subscription-conformance.ts +123 -0
  104. package/src/quiet-logs.ts +4 -4
  105. package/src/rate-limit-store-conformance.ts +178 -0
  106. package/src/registry-leak-error.ts +8 -1
  107. package/src/scale-sweep-run.ts +6 -9
  108. package/src/scrape-driver-conformance-frame-checks.ts +97 -0
  109. package/src/scrape-driver-conformance-page-checks.ts +114 -0
  110. package/src/scrape-driver-conformance-site.ts +84 -0
  111. package/src/scrape-driver-conformance.ts +34 -0
  112. package/src/sealed-network.ts +20 -2
  113. package/src/search-index-conformance-list.ts +76 -0
  114. package/src/search-index-conformance-support.ts +69 -0
  115. package/src/search-index-conformance-versions.ts +66 -0
  116. package/src/search-index-conformance.ts +126 -0
  117. package/src/secret-source-conformance.ts +91 -0
  118. package/src/seed-factories.ts +57 -0
  119. package/src/seed-writer.ts +8 -19
  120. package/src/semantic-cache-factory-conformance.ts +86 -0
  121. package/src/sms-transport-conformance.ts +102 -0
  122. package/src/step-store-conformance.ts +171 -0
  123. package/src/storage-conformance-read-checks.ts +132 -0
  124. package/src/storage-conformance-shape.ts +121 -0
  125. package/src/storage-conformance-stream-checks.ts +226 -0
  126. package/src/storage-conformance.ts +34 -0
  127. package/src/stub-action.ts +24 -0
  128. package/src/stub-errors.ts +86 -0
  129. package/src/stub-job.ts +30 -0
  130. package/src/stub-query.ts +25 -0
  131. package/src/stub-script.ts +76 -0
  132. package/src/stub-stack.ts +29 -0
  133. package/src/stub.ts +73 -0
  134. package/src/swap-adapter.ts +135 -0
  135. package/src/test-scope.ts +96 -0
  136. package/src/test-types.ts +1 -1
  137. package/src/totp-replay-guard-conformance.ts +76 -0
  138. package/src/transport-conformance.ts +179 -0
  139. package/src/upload-scanner-conformance.ts +112 -0
  140. package/src/vector-store-conformance-checks.ts +174 -0
  141. package/src/vector-store-conformance.ts +21 -0
  142. package/src/cdp-connection.ts +0 -291
  143. package/src/cdp-errors.ts +0 -179
  144. package/src/cdp-launch-attempt.ts +0 -224
  145. package/src/cdp-launch-candidates.ts +0 -62
  146. package/src/cdp-launch-profile.ts +0 -106
  147. package/src/cdp-launch-reap.ts +0 -68
  148. package/src/cdp-launch-wire.ts +0 -171
  149. package/src/cdp-launch.ts +0 -175
  150. package/src/cdp-pipe.ts +0 -77
  151. package/src/cdp-wire-watch.ts +0 -113
@@ -1,26 +1,22 @@
1
1
  // What one primitive did in the exercise pass, and the room it did it in: the network sealed with
2
2
  // every allow and mock cleared, the mail fixture, the clock frozen, statements and committed rows
3
- // observed. Every seam is process-global, so the room hands back exactly what it found.
3
+ // observed. Every seam is process-global, so the room keeps only what the observed call's own
4
+ // async context did — a timer's or another request's work in the same window is not the call's.
4
5
 
5
- import { isSelfOrigin, peerAddressClass } from '@ultimat3/core';
6
- import type { StatementObserver } from '@ultimat3/db';
7
- import {
8
- expectedSeqScanReason,
9
- setStatementObserver,
10
- statementFingerprint,
11
- statementObserver,
12
- } from '@ultimat3/db';
13
- import type { RowObserver } from '@ultimat3/entity';
6
+ import type { DbStatementEvent } from '@ultimat3/core';
7
+ import { asyncContext, isSelfOrigin, peerAddressClass, subscribe } from '@ultimat3/core';
8
+ import { expectedSeqScanReason, statementFingerprint } from '@ultimat3/db';
14
9
  import { captureDeterminism, installDeterminism, restoreCapturedDeterminism } from './determinism';
15
10
  import type { ExerciseDefect } from './exercise-defect';
16
- import { testMail } from './fixture-mail';
11
+ import { roomMail } from './exercise-room-mail';
17
12
  import { routeMatches } from './mock-route';
18
13
  import type { PlanProof, SentStatement } from './plan-sweep';
14
+ import type { LoggedRequest } from './request-log';
19
15
  import type { ScaleProof, StatementTally } from './scale-sweep';
20
16
  import {
21
17
  captureNetwork,
22
18
  isNetworkSealed,
23
- requestLog,
19
+ onDial,
24
20
  resetNetwork,
25
21
  restoreCapturedNetwork,
26
22
  sealNetwork,
@@ -168,17 +164,6 @@ export interface EffectPayload {
168
164
  readonly value: unknown;
169
165
  }
170
166
 
171
- const IDENTIFIER = /^[A-Za-z_$][\w$]*$/;
172
-
173
- /** `publishPost: { actor, input: (drawn) => ({ ...drawn, postId: '<…>' }) },` — valid TS to paste. */
174
- export function overrideLine(name: string, idFields: readonly string[]): string {
175
- const key = IDENTIFIER.test(name) ? name : JSON.stringify(name);
176
- const bound = idFields
177
- .map((field) => `, ${IDENTIFIER.test(field) ? field : JSON.stringify(field)}: '<a real id>'`)
178
- .join('');
179
- return `${key}: { actor: <an actor its policy permits>, input: (drawn) => ({ ...drawn${bound} }) },`;
180
- }
181
-
182
167
  const hostOf = (url: string): string => (URL.canParse(url) ? new URL(url).host : url);
183
168
 
184
169
  /** `sealed-network.ts`'s own exemption: this machine and a server this process booted. */
@@ -197,7 +182,7 @@ const tally = (keys: readonly string[]): ReadonlyMap<string, number> => {
197
182
  return counts;
198
183
  };
199
184
 
200
- /** What happened between `begin()` and `end()`. */
185
+ /** What the observed call did — it and the work it started, never a neighbour in its window. */
201
186
  export interface Observed {
202
187
  readonly statements: number;
203
188
  readonly effects: readonly ExerciseEffect[];
@@ -209,16 +194,33 @@ export interface Observed {
209
194
  readonly shapes: readonly StatementTally[];
210
195
  }
211
196
 
197
+ /** What `observe` hands back: what the call did, and its value or what it threw. */
198
+ export type Observation<T> =
199
+ | { readonly observed: Observed; readonly value: T }
200
+ | { readonly observed: Observed; readonly error: unknown };
201
+
212
202
  export interface ExerciseRoom extends AsyncDisposable {
213
- /** `subject`: the primitive the statements until `end()` are sent for — what the plan sweep reads. */
214
- begin(subject?: string): void;
215
- end(): Observed;
216
- /** Every distinct statement text sent between a `begin(subject)` and its `end()`, so far. */
203
+ /**
204
+ * Run `fn` — one primitive's call — and hand back what it did. Attributed by async context, never
205
+ * by time: `fn` runs under a marker of this call's own, and a statement, row, mail or dial counts
206
+ * only when it is made under it. Work `fn` starts and does not await carries the marker too, until
207
+ * `observe` returns. `subject`: the primitive the statements are sent for — what the plan sweep
208
+ * reads; none, and they are tallied but not planned.
209
+ */
210
+ observe<T>(subject: string | undefined, fn: () => Promise<T>): Promise<Observation<T>>;
211
+ /** Whether the caller is inside the call being observed — for a seam the room does not own. */
212
+ owns(): boolean;
213
+ /** Every distinct statement text an `observe(subject, …)` call sent, so far. */
217
214
  sent(): ReadonlyMap<string, SentStatement>;
218
215
  }
219
216
 
217
+ /**
218
+ * The room's marker in flight — an identity object, never a credential. Never `ctx.requestId`: a job subject runs under the worker's own
219
+ * context, and a request the call did not make has one too.
220
+ */
221
+ const scope = asyncContext<object>('the exercise room');
222
+
220
223
  export async function openExerciseRoom(): Promise<ExerciseRoom> {
221
- const { setRowObserver } = await import('@ultimat3/entity');
222
224
  const clock = captureDeterminism();
223
225
  if (!clock.installed) installDeterminism();
224
226
  const network = captureNetwork();
@@ -227,108 +229,129 @@ export async function openExerciseRoom(): Promise<ExerciseRoom> {
227
229
  // a refusal by definition.
228
230
  resetNetwork();
229
231
  sealNetwork();
230
- const mail = await testMail();
232
+ // The call in flight: a fresh object per `observe`, so a straggler of the call before is not it.
233
+ let marker: object | undefined;
234
+ const owns = (): boolean => marker !== undefined && scope.get() === marker;
235
+ const mail = await roomMail(owns);
231
236
  let statements = 0;
232
- let logFrom = 0;
237
+ const calls: LoggedRequest[] = [];
233
238
  let subject: string | undefined;
234
239
  const rows: string[] = [];
235
240
  const shapes = new Map<string, { count: number; unexpected: number; expected?: string }>();
236
241
  const sent = new Map<string, { primitives: Set<string>; scan?: string }>();
237
- const previousStatements = statementObserver();
238
- const counting: StatementObserver = {
239
- onStatement: (event) => {
240
- statements += 1;
241
- const fingerprint = statementFingerprint(event);
242
- const shape = shapes.get(fingerprint) ?? { count: 0, unexpected: 0 };
243
- shape.count += 1;
244
- if (event.expected === undefined) shape.unexpected += 1;
245
- else shape.expected = event.expected;
246
- shapes.set(fingerprint, shape);
247
- if (subject === undefined) return;
248
- // Whitespace collapsed, so one builder's two indentations are one statement to plan.
249
- const text = event.text.replace(/\s+/g, ' ').trim();
250
- const one = sent.get(text) ?? { primitives: new Set<string>() };
251
- one.primitives.add(subject);
252
- // Read here, in the sender's own async context: the scope is the statement's, not the room's.
253
- const scan = expectedSeqScanReason();
254
- if (scan !== undefined) one.scan = scan;
255
- sent.set(text, one);
256
- },
242
+ // Every observer below returns at once unless the sender is the observed call: the bus delivers
243
+ // synchronously in the sender's context (`instrument`), so `owns()` reads the sender's marker.
244
+ const counting = (event: DbStatementEvent): void => {
245
+ if (!owns()) return;
246
+ statements += 1;
247
+ const fingerprint = statementFingerprint(event);
248
+ const shape = shapes.get(fingerprint) ?? { count: 0, unexpected: 0 };
249
+ shape.count += 1;
250
+ if (event.expected === undefined) shape.unexpected += 1;
251
+ else shape.expected = event.expected;
252
+ shapes.set(fingerprint, shape);
253
+ if (subject === undefined) return;
254
+ // Whitespace collapsed, so one builder's two indentations are one statement to plan.
255
+ const text = event.text.replace(/\s+/g, ' ').trim();
256
+ const one = sent.get(text) ?? { primitives: new Set<string>() };
257
+ one.primitives.add(subject);
258
+ // Read here, in the sender's own async context: the scope is the statement's, not the room's.
259
+ const scan = expectedSeqScanReason();
260
+ if (scan !== undefined) one.scan = scan;
261
+ sent.set(text, one);
257
262
  };
258
- setStatementObserver(counting);
259
- const rowObserver: RowObserver = {
260
- onChange: (change) => rows.push(`${change.entity}\u0000${change.op}`),
261
- onBulk: (change) => {
262
- for (let i = 0; i < change.rows; i += 1) rows.push(`${change.entity}\u0000${change.op}`);
263
- },
263
+ // Subscribers on the bus, beside any outer one — released at dispose, never displacing it.
264
+ const offStatements = subscribe('db.statement', (event) => counting(event.payload));
265
+ const offRows = subscribe('entity', (event) => {
266
+ if (!owns()) return;
267
+ if (event.name === 'entity.row') rows.push(`${event.payload.entity}\u0000${event.payload.op}`);
268
+ if (event.name !== 'entity.bulk') return;
269
+ const { entity, op } = event.payload;
270
+ for (let i = 0; i < event.payload.rows; i += 1) rows.push(`${entity}\u0000${op}`);
271
+ });
272
+ const offDials = onDial((call) => {
273
+ if (owns()) calls.push(call);
274
+ });
275
+
276
+ const begin = (name: string | undefined): object => {
277
+ subject = name;
278
+ statements = 0;
279
+ shapes.clear();
280
+ rows.length = 0;
281
+ calls.length = 0;
282
+ mail.clear();
283
+ marker = {};
284
+ return marker;
285
+ };
286
+ const end = (): Observed => {
287
+ marker = undefined;
288
+ // A call a route answered never left the process: the app's `setup` installed it.
289
+ const { mocks } = captureNetwork();
290
+ const refused = (call: (typeof calls)[number]): boolean =>
291
+ !local(call.url) && !mocks.some((route) => routeMatches(route, call));
292
+ const effects: ExerciseEffect[] = [
293
+ ...[...tally(rows)].map(([key, count]): ExerciseEffect => {
294
+ const [entity = '', op = ''] = key.split('\u0000');
295
+ return { kind: 'row', entity, op, rows: count };
296
+ }),
297
+ ...[...tally(mail.sent().map((message) => message.mailId))].map(
298
+ ([id, count]): ExerciseEffect => ({ kind: 'mail', mail: id, count }),
299
+ ),
300
+ ...calls.map(
301
+ (call): ExerciseEffect => ({
302
+ kind: 'network',
303
+ method: call.method,
304
+ host: hostOf(call.url),
305
+ refused: refused(call),
306
+ }),
307
+ ),
308
+ ];
309
+ const refusedHosts = calls.filter(refused).map((c) => hostOf(c.url));
310
+ const payloads: EffectPayload[] = [
311
+ ...mail.sent().map((message, i) => ({
312
+ path: `effect.mail[${i}]`,
313
+ value: {
314
+ to: message.to,
315
+ cc: message.cc,
316
+ bcc: message.bcc,
317
+ replyTo: message.replyTo,
318
+ subject: message.subject,
319
+ text: message.text,
320
+ html: message.html,
321
+ unsubscribeUrl: message.unsubscribeUrl,
322
+ },
323
+ })),
324
+ // Headers left out: a bearer token is not A's row, and a header is no row's text.
325
+ ...calls.map((call, i) => ({
326
+ path: `effect.network[${i}]`,
327
+ value: { url: call.url, body: call.body },
328
+ })),
329
+ ];
330
+ subject = undefined;
331
+ const tallies = [...shapes].map(([fingerprint, shape]) => ({ fingerprint, ...shape }));
332
+ return { statements, effects, refusedHosts, payloads, shapes: tallies };
264
333
  };
265
- const previousRows = setRowObserver(rowObserver);
266
334
 
267
335
  return {
268
- begin: (name) => {
269
- subject = name;
270
- statements = 0;
271
- shapes.clear();
272
- rows.length = 0;
273
- mail.clear();
274
- logFrom = requestLog().length;
275
- },
276
- end: (): Observed => {
277
- const calls = requestLog().slice(logFrom);
278
- // A call a route answered never left the process: the app's `setup` installed it.
279
- const { mocks } = captureNetwork();
280
- const refused = (call: (typeof calls)[number]): boolean =>
281
- !local(call.url) && !mocks.some((route) => routeMatches(route, call));
282
- const effects: ExerciseEffect[] = [
283
- ...[...tally(rows)].map(([key, count]): ExerciseEffect => {
284
- const [entity = '', op = ''] = key.split('\u0000');
285
- return { kind: 'row', entity, op, rows: count };
286
- }),
287
- ...[...tally(mail.outbox().map((sent) => sent.message.mailId))].map(
288
- ([id, count]): ExerciseEffect => ({ kind: 'mail', mail: id, count }),
289
- ),
290
- ...calls.map(
291
- (call): ExerciseEffect => ({
292
- kind: 'network',
293
- method: call.method,
294
- host: hostOf(call.url),
295
- refused: refused(call),
296
- }),
297
- ),
298
- ];
299
- const refusedHosts = calls.filter(refused).map((c) => hostOf(c.url));
300
- const payloads: EffectPayload[] = [
301
- ...mail.outbox().map(({ message }, i) => ({
302
- path: `effect.mail[${i}]`,
303
- value: {
304
- to: message.to,
305
- cc: message.cc,
306
- bcc: message.bcc,
307
- replyTo: message.replyTo,
308
- subject: message.subject,
309
- text: message.text,
310
- html: message.html,
311
- unsubscribeUrl: message.unsubscribeUrl,
312
- },
313
- })),
314
- // Headers left out: a bearer token is not A's row, and a header is no row's text.
315
- ...calls.map((call, i) => ({
316
- path: `effect.network[${i}]`,
317
- value: { url: call.url, body: call.body },
318
- })),
319
- ];
320
- subject = undefined;
321
- const tallies = [...shapes].map(([fingerprint, shape]) => ({ fingerprint, ...shape }));
322
- return { statements, effects, refusedHosts, payloads, shapes: tallies };
336
+ observe: async <T>(name: string | undefined, fn: () => Promise<T>): Promise<Observation<T>> => {
337
+ const mine = begin(name);
338
+ try {
339
+ const value = await scope.run(mine, fn);
340
+ return { observed: end(), value };
341
+ } catch (error) {
342
+ return { observed: end(), error };
343
+ }
323
344
  },
345
+ owns,
324
346
  sent: () => sent,
325
347
  [Symbol.asyncDispose]: async (): Promise<void> => {
326
348
  // Each restore runs whatever the one before it did: a throw must not strand a seam.
327
349
  try {
328
350
  mail[Symbol.dispose]();
329
351
  } finally {
330
- setRowObserver(previousRows);
331
- setStatementObserver(previousStatements);
352
+ offDials();
353
+ offRows();
354
+ offStatements();
332
355
  restoreCapturedNetwork(network);
333
356
  if (!sealedBefore) unsealNetwork();
334
357
  restoreCapturedDeterminism(clock);
@@ -0,0 +1,40 @@
1
+ // The exercise room's mail seam: every send delivered to memory, and only the observed call's
2
+ // kept. Asked at the send, in the sender's own async context — a timer's or another request's
3
+ // mail sent while the call awaits is somebody else's effect, never the primitive's.
4
+
5
+ import type { MailMessage } from '@ultimat3/mail';
6
+
7
+ export interface RoomMail extends Disposable {
8
+ /** The observed call's messages since `clear()`, newest first — the `outbox()` order. */
9
+ sent(): readonly MailMessage[];
10
+ clear(): void;
11
+ }
12
+
13
+ /** Install a driver frame whose kept messages are those sent while `owns()` answers true. */
14
+ export async function roomMail(owns: () => boolean): Promise<RoomMail> {
15
+ const { memoryMailDriver } = await import('@ultimat3/mail');
16
+ // The installer is the `./adapter` subpath's, never the barrel's (slice 21).
17
+ const { installMailDriver } = await import('@ultimat3/mail/adapter');
18
+ const memory = memoryMailDriver();
19
+ const kept: MailMessage[] = [];
20
+ const release = installMailDriver({
21
+ name: 'test',
22
+ send: async (message) => {
23
+ // Read before the first await: the send's own context, not whatever resumes it.
24
+ const mine = owns();
25
+ const result = await memory.send(message);
26
+ if (mine) kept.unshift(message);
27
+ return result;
28
+ },
29
+ });
30
+ return {
31
+ sent: () => [...kept],
32
+ clear: () => {
33
+ kept.length = 0;
34
+ memory.clear();
35
+ },
36
+ [Symbol.dispose]: (): void => {
37
+ release();
38
+ },
39
+ };
40
+ }
package/src/exercise.ts CHANGED
@@ -10,7 +10,7 @@
10
10
  // what the input sent is never the call's, and a name two kinds share has an entry per kind.
11
11
 
12
12
  import type { Actor, ExerciseAttempt, ExerciseVerdict } from '@ultimat3/core';
13
- import { runExercise } from '@ultimat3/core';
13
+ import { runExercise, subscribe } from '@ultimat3/core';
14
14
  import { LIVE_STATES, registeredJobs } from '@ultimat3/jobs';
15
15
  import type { ExerciseOverride, ExerciseOverrides } from './define-exercise';
16
16
  import { assertOverridesKnown, overrideFor, unknownDeclaration } from './define-exercise';
@@ -26,6 +26,7 @@ import { judged, labelFor } from './exercise-judge';
26
26
  import { mergeObserved } from './exercise-observed';
27
27
  import type { OverrideInput } from './exercise-override-input';
28
28
  import { inputThrew, overrideInput } from './exercise-override-input';
29
+ import { actorHintOf, type OverrideHint, seededIn } from './exercise-override-line';
29
30
  import type {
30
31
  EffectPayload,
31
32
  ExerciseEffect,
@@ -117,6 +118,8 @@ interface Prepared {
117
118
  readonly declaredRuns: number | undefined;
118
119
  readonly lookups: readonly [IdLookup, IdLookup];
119
120
  readonly bindInput: OverrideInput | undefined;
121
+ /** The actor the pass picked, as the paste line spells it (`exercise-override-line.ts`). */
122
+ readonly actorHint: OverrideHint['actor'];
120
123
  }
121
124
 
122
125
  /** Thrown out of 39's loop by a bind that failed: the record is the entry's, never the loop's. */
@@ -168,23 +171,21 @@ async function control(
168
171
  (await subject.input['~standard'].validate(input)).issues === undefined,
169
172
  attempt: async (input): Promise<ExerciseAttempt> => {
170
173
  const before = await queuedIds();
171
- room.begin(key);
172
- try {
173
- const answer = await subject.call(input, actor, tenant, jobs);
174
- if ('failure' in answer) {
175
- lastError = answer.failure;
176
- return { ok: false, reached: true, error: answer.failure };
177
- }
178
- answered = true;
179
- output = answer.output;
180
- return { ok: true, reached: true };
181
- } catch (error) {
182
- lastError = error;
183
- return { ok: false, reached: false, error };
184
- } finally {
185
- segments.push(room.end());
186
- for (const id of await queuedIds()) if (!before.has(id)) mine.add(id);
174
+ const seen = await room.observe(key, () => subject.call(input, actor, tenant, jobs));
175
+ segments.push(seen.observed);
176
+ for (const id of await queuedIds()) if (!before.has(id)) mine.add(id);
177
+ if ('error' in seen) {
178
+ lastError = seen.error;
179
+ return { ok: false, reached: false, error: seen.error };
187
180
  }
181
+ const answer = seen.value;
182
+ if ('failure' in answer) {
183
+ lastError = answer.failure;
184
+ return { ok: false, reached: true, error: answer.failure };
185
+ }
186
+ answered = true;
187
+ output = answer.output;
188
+ return { ok: true, reached: true };
188
189
  },
189
190
  statusOf: (await import('@ultimat3/http')).statusFor,
190
191
  });
@@ -204,7 +205,8 @@ async function control(
204
205
  const ms = Math.round(performance.now() - started);
205
206
  const observed = mergeObserved(segments);
206
207
  const effects = [...observed.effects, ...(await enqueued(subject, mine))];
207
- const outcome = { verdict, answered, lastError, lastInput };
208
+ const hint = { actor: run.actorHint, ids: seededIn(lastInput, lookups) };
209
+ const outcome = { verdict, answered, lastError, lastInput, hint };
208
210
  const verdictOf = judged(subject, key, outcome, observed, sampler);
209
211
  // A 5xx's cause, statement and fields: the code alone sent the author to reproduce it by hand.
210
212
  const defect =
@@ -233,26 +235,27 @@ async function attack(
233
235
  room: ExerciseRoom,
234
236
  ): Promise<LegAnswer> {
235
237
  await using jobs = await testJobs();
236
- room.begin(key);
237
238
  let output: unknown;
238
239
  // A job's org is re-seated in B's: B cannot enqueue a payload naming A (refused at the enqueue,
239
240
  // which proves nothing), so the attack that matters is a job of B's carrying A's ids.
240
241
  const sent = seatIn(subject, input, tenant);
241
242
  // Every `crossTenant()` B's call opened: a job's declared sweep is told from a leak by it alone.
242
- // Loaded here, never at the top: the barrel stays entity-free (`seed-writer.ts`'s rule).
243
- const { setCrossTenantObserver } = await import('@ultimat3/entity');
243
+ // On the bus, so the barrel stays entity-free (`seed-writer.ts`'s rule) with no import at all.
244
244
  const crossings: string[] = [];
245
- setCrossTenantObserver((reason) => crossings.push(reason));
245
+ // B's own: a scope another context opened in the window excuses nothing of B's.
246
+ const offCrossings = subscribe('entity.cross_tenant', (event) => {
247
+ if (room.owns()) crossings.push(event.payload.reason);
248
+ });
249
+ let observed: Observed;
246
250
  try {
247
- const answer = await subject.call(sent, actor, tenant, jobs);
248
- output = answer.output;
249
- } catch {
250
- // B's refusal is the answer a scoped primitive gives: only what B got back, and what B's call
251
- // did to A's rows, is judged — never whether B was refused.
251
+ // A throw is B's refusal, the answer a scoped primitive gives: only what B got back, and what
252
+ // B's call did to A's rows, is judged — never whether B was refused.
253
+ const seen = await room.observe(key, () => subject.call(sent, actor, tenant, jobs));
254
+ observed = seen.observed;
255
+ if ('value' in seen) output = seen.value.output;
252
256
  } finally {
253
- setCrossTenantObserver(undefined);
257
+ offCrossings();
254
258
  }
255
- const observed = room.end();
256
259
  const payloads = [...observed.payloads, ...(await queuedPayloads(subject))];
257
260
  return { output, payloads, crossings };
258
261
  }
@@ -308,6 +311,7 @@ async function exerciseOne(
308
311
  declaredRuns,
309
312
  lookups,
310
313
  bindInput,
314
+ actorHint: actorHintOf(chosen, override),
311
315
  };
312
316
  // A's own first input, A's ids in it: B sends exactly what A legitimately would.
313
317
  const drawn = bindIds(drawInput(sampler, subject.input, 0, 0), lookups[0]);