@dreamboard-games/sdk 0.4.0-alpha.8 → 0.5.0-alpha.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 (121) hide show
  1. package/README.md +49 -11
  2. package/dist/authoring/index.d.ts +6 -14
  3. package/dist/authoring/index.js +11 -547
  4. package/dist/authoring/index.js.map +1 -1
  5. package/dist/authoring-compiler.d.ts +27 -0
  6. package/dist/authoring-compiler.js +11 -0
  7. package/dist/authoring-compiler.js.map +1 -0
  8. package/dist/authoring-materialize-cli.d.ts +1 -0
  9. package/dist/authoring-materialize-cli.js +45 -0
  10. package/dist/authoring-materialize-cli.js.map +1 -0
  11. package/dist/browser-interaction.d.ts +22 -22
  12. package/dist/{chunk-3BLN5POZ.js → chunk-2GQIALJL.js} +51 -15
  13. package/dist/chunk-2GQIALJL.js.map +1 -0
  14. package/dist/chunk-533O7C4L.js +7095 -0
  15. package/dist/chunk-533O7C4L.js.map +1 -0
  16. package/dist/{chunk-44N3T2A5.js → chunk-6LMESVGT.js} +9 -28
  17. package/dist/chunk-6LMESVGT.js.map +1 -0
  18. package/dist/{chunk-ZYONCTZ2.js → chunk-DQS2EG5E.js} +3 -3
  19. package/dist/{chunk-ZYONCTZ2.js.map → chunk-DQS2EG5E.js.map} +1 -1
  20. package/dist/chunk-EOEA3I64.js +1864 -0
  21. package/dist/chunk-EOEA3I64.js.map +1 -0
  22. package/dist/{chunk-B2YBS3SG.js → chunk-FL67RDID.js} +41 -13
  23. package/dist/chunk-FL67RDID.js.map +1 -0
  24. package/dist/{chunk-2TAKLJJD.js → chunk-HIH6Y4FA.js} +222 -1267
  25. package/dist/chunk-HIH6Y4FA.js.map +1 -0
  26. package/dist/chunk-HUK4234C.js +166 -0
  27. package/dist/chunk-HUK4234C.js.map +1 -0
  28. package/dist/chunk-KGV2EUNN.js +532 -0
  29. package/dist/chunk-KGV2EUNN.js.map +1 -0
  30. package/dist/{chunk-VTK4TIXC.js → chunk-KRJPRYEA.js} +49 -4
  31. package/dist/chunk-KRJPRYEA.js.map +1 -0
  32. package/dist/chunk-KWHOFBDM.js +9 -0
  33. package/dist/chunk-KWHOFBDM.js.map +1 -0
  34. package/dist/{chunk-UC2UXAC6.js → chunk-LMHCGCA6.js} +2 -2
  35. package/dist/{chunk-XV27IQHA.js → chunk-N33CGX2F.js} +15 -85
  36. package/dist/chunk-N33CGX2F.js.map +1 -0
  37. package/dist/chunk-TXELBVTG.js +32 -0
  38. package/dist/chunk-TXELBVTG.js.map +1 -0
  39. package/dist/{chunk-2TRZSZGD.js → chunk-VRRR6QZT.js} +9 -12
  40. package/dist/chunk-VRRR6QZT.js.map +1 -0
  41. package/dist/chunk-VWTKGIYF.js +90 -0
  42. package/dist/chunk-VWTKGIYF.js.map +1 -0
  43. package/dist/{chunk-IYX5OO2K.js → chunk-XFMSLL3P.js} +133 -61
  44. package/dist/chunk-XFMSLL3P.js.map +1 -0
  45. package/dist/{chunk-YGQTL63W.js → chunk-ZSTCUJKZ.js} +4 -4
  46. package/dist/chunk-ZSTCUJKZ.js.map +1 -0
  47. package/dist/codegen.js +1 -1
  48. package/dist/{components-BTwSIjXj.d.ts → components-CNAt5J1p.d.ts} +1 -1
  49. package/dist/definitions-bZSBaPjj.d.ts +300 -0
  50. package/dist/{diagnostics-1BWjRo6-.d.ts → diagnostics-DIi3ina7.d.ts} +2 -1
  51. package/dist/digest.d.ts +8 -0
  52. package/dist/{index-CFTjJIXd.d.ts → index-CR69MyWr.d.ts} +2 -2
  53. package/dist/{index.d-C0PKOVbh.d.ts → index.d-Bw8AOcgp.d.ts} +532 -225
  54. package/dist/index.js +2 -2
  55. package/dist/package-set.d.ts +2 -2
  56. package/dist/package-set.js +2 -2
  57. package/dist/plugin-runtime-contract.d.ts +17 -0
  58. package/dist/plugin-runtime-contract.js +94 -0
  59. package/dist/plugin-runtime-contract.js.map +1 -0
  60. package/dist/{protocol-nS2ojsGr.d.ts → protocol-CVaSqPgX.d.ts} +54 -47
  61. package/dist/reducer/advanced.d.ts +5 -4
  62. package/dist/reducer/advanced.js +14 -108
  63. package/dist/reducer/advanced.js.map +1 -1
  64. package/dist/reducer-contract.d.ts +1 -1
  65. package/dist/reducer-contract.js +6 -4
  66. package/dist/reducer.d.ts +20 -98
  67. package/dist/reducer.js +28 -6050
  68. package/dist/reducer.js.map +1 -1
  69. package/dist/reference-games/index.d.ts +6 -198
  70. package/dist/reference-games/index.js +18 -200
  71. package/dist/reference-games/index.js.map +1 -1
  72. package/dist/runtime/primitives.d.ts +3 -3
  73. package/dist/runtime/primitives.js +5 -5
  74. package/dist/runtime/runtime-api.d.ts +1 -1
  75. package/dist/runtime/workspace-contract.d.ts +343 -11
  76. package/dist/runtime/workspace-contract.js +12 -6
  77. package/dist/{runtime-Dkfm1x2r.d.ts → runtime-C7Z2acNU.d.ts} +67 -31
  78. package/dist/{runtime-api-C6aWo9c0.d.ts → runtime-api-CgPuEVeF.d.ts} +4 -13
  79. package/dist/runtime.d.ts +7 -7
  80. package/dist/runtime.js +15 -11
  81. package/dist/runtime.js.map +1 -1
  82. package/dist/schema.d.ts +405 -0
  83. package/dist/{stale-contract-artifact-error-C5AaZPJ8.d.ts → stale-contract-artifact-error-XLaweZtF.d.ts} +1 -1
  84. package/dist/testing-compiler.d.ts +37 -0
  85. package/dist/testing-compiler.js +272 -0
  86. package/dist/testing-compiler.js.map +1 -0
  87. package/dist/testing-runtime.d.ts +98 -21
  88. package/dist/testing-runtime.js +154 -95
  89. package/dist/testing-runtime.js.map +1 -1
  90. package/dist/testing.d.ts +197 -156
  91. package/dist/testing.js +660 -372
  92. package/dist/testing.js.map +1 -1
  93. package/dist/types-DN4O7kH_.d.ts +122 -0
  94. package/dist/{types-CTeN_QAk.d.ts → types-q1Guidm5.d.ts} +4 -5
  95. package/dist/types.d.ts +0 -1
  96. package/dist/ui/components.d.ts +3 -2
  97. package/dist/ui/components.js +1 -1
  98. package/dist/ui/plugin-styles.css +1 -1
  99. package/dist/{ui-contract-Ue6SywvO.d.ts → ui-contract-BC4JpysE.d.ts} +2 -6
  100. package/dist/ui.d.ts +4 -3
  101. package/dist/ui.js +2 -2
  102. package/dist/{views-Qx-EHBP8.d.ts → views-D2Cfzr3h.d.ts} +17 -5
  103. package/package.json +41 -22
  104. package/REFERENCE.md +0 -22884
  105. package/dist/chunk-2TAKLJJD.js.map +0 -1
  106. package/dist/chunk-2TRZSZGD.js.map +0 -1
  107. package/dist/chunk-3BLN5POZ.js.map +0 -1
  108. package/dist/chunk-3OZMHZK3.js +0 -40
  109. package/dist/chunk-3OZMHZK3.js.map +0 -1
  110. package/dist/chunk-44N3T2A5.js.map +0 -1
  111. package/dist/chunk-5CQIJHGF.js +0 -663
  112. package/dist/chunk-5CQIJHGF.js.map +0 -1
  113. package/dist/chunk-B2YBS3SG.js.map +0 -1
  114. package/dist/chunk-IYX5OO2K.js.map +0 -1
  115. package/dist/chunk-VTK4TIXC.js.map +0 -1
  116. package/dist/chunk-VTNEWMWJ.js +0 -12
  117. package/dist/chunk-VTNEWMWJ.js.map +0 -1
  118. package/dist/chunk-XV27IQHA.js.map +0 -1
  119. package/dist/chunk-YGQTL63W.js.map +0 -1
  120. package/dist/types-B_3pObUV.d.ts +0 -192
  121. /package/dist/{chunk-UC2UXAC6.js.map → chunk-LMHCGCA6.js.map} +0 -0
package/dist/testing.js CHANGED
@@ -1,8 +1,32 @@
1
1
  import {
2
2
  PluginRuntimeBoundary,
3
3
  createPluginRuntimeClient
4
- } from "./chunk-XV27IQHA.js";
5
- import "./chunk-ZYONCTZ2.js";
4
+ } from "./chunk-N33CGX2F.js";
5
+ import "./chunk-DQS2EG5E.js";
6
+ import {
7
+ ScenarioAssertionError,
8
+ ScenarioDefinitionValidationError,
9
+ ScenarioReplayError,
10
+ advanceScenarioReplay,
11
+ assertScenario,
12
+ compareCanonicalScenarioJson,
13
+ createExpectApi,
14
+ createScenarioAuthoring,
15
+ digestScenarioJson,
16
+ enumerateScenarioInteractionParams,
17
+ inspectScenarioReplayAuthority,
18
+ probeScenarioCommand,
19
+ projectScenarioCommandParams,
20
+ replayScenario,
21
+ resolveScenarioCheckpoint,
22
+ toScenarioReplayDefinition
23
+ } from "./chunk-EOEA3I64.js";
24
+ import {
25
+ StaleContractArtifactError,
26
+ isStaleContractArtifactError
27
+ } from "./chunk-533O7C4L.js";
28
+ import "./chunk-TXELBVTG.js";
29
+ import "./chunk-FL67RDID.js";
6
30
  import {
7
31
  BROWSER_INTERACTION_ACTUATOR_KINDS,
8
32
  DREAMBOARD_BROWSER_INTERACTION_PROTOCOL_VERSION,
@@ -11,14 +35,6 @@ import {
11
35
  import {
12
36
  RuntimeJsonSchema
13
37
  } from "./chunk-PF7L4BMG.js";
14
- import {
15
- createExpectApi,
16
- createTestRuntime
17
- } from "./chunk-5CQIJHGF.js";
18
- import {
19
- StaleContractArtifactError,
20
- isStaleContractArtifactError
21
- } from "./chunk-3OZMHZK3.js";
22
38
  import {
23
39
  DREAMBOARD_PLUGIN_PROTOCOL,
24
40
  DREAMBOARD_PLUGIN_PROTOCOL_VERSION,
@@ -26,21 +42,614 @@ import {
26
42
  PluginProtocolStepSchema,
27
43
  PluginProtocolTapeSchema,
28
44
  computePluginActionSetVersion,
45
+ digestPluginRuntimeJson,
29
46
  materializePluginGameplayFrame
30
- } from "./chunk-IYX5OO2K.js";
47
+ } from "./chunk-XFMSLL3P.js";
48
+ import "./chunk-2GQIALJL.js";
31
49
  import "./chunk-PZ5AY32C.js";
32
50
 
33
- // src/testing/definitions.ts
34
- function defineBase(definition) {
35
- return definition;
51
+ // src/testing/inspection/flow-diagnostic.ts
52
+ function createFlowDiagnostic(options) {
53
+ const actor = (playerId) => {
54
+ const seat = options.playerIds.indexOf(playerId);
55
+ return seat < 0 ? null : { seat, playerId };
56
+ };
57
+ const actors = (playerIds) => [...new Set(playerIds)].flatMap((playerId) => {
58
+ const resolved = actor(playerId);
59
+ return resolved ? [resolved] : [];
60
+ }).sort((left, right) => left.seat - right.seat);
61
+ const blockedBy = (options.scheduler.continuationDependencies ?? []).flatMap((dependency) => {
62
+ const waiter = actor(dependency.waiterPlayerId);
63
+ const blockers = actors(dependency.blockerPlayerIds);
64
+ return waiter && blockers.length > 0 ? [
65
+ {
66
+ actor: waiter,
67
+ blockers,
68
+ source: "scheduler"
69
+ }
70
+ ] : [];
71
+ }).sort((left, right) => left.actor.seat - right.actor.seat);
72
+ return {
73
+ phase: options.scheduler.phase,
74
+ step: options.scheduler.step,
75
+ activeActors: actors(options.scheduler.activePlayerIds),
76
+ pendingActors: actors(options.scheduler.pendingPlayerIds),
77
+ continuationWaiters: actors(
78
+ blockedBy.map((dependency) => dependency.actor.playerId)
79
+ ),
80
+ blockedBy
81
+ };
82
+ }
83
+
84
+ // src/testing/inspection/inspect-scenario.ts
85
+ var ScenarioInspectionError = class extends Error {
86
+ code;
87
+ context;
88
+ constructor(options) {
89
+ super(options.message);
90
+ this.name = "ScenarioInspectionError";
91
+ this.code = options.code;
92
+ this.context = options.context ?? {};
93
+ }
94
+ };
95
+ async function inspectScenario(options) {
96
+ assertScenarioIdentity(options.identity, options.scenario);
97
+ assertSeed(options.seed);
98
+ const selectedScenario = options.seed === void 0 ? options.scenario : {
99
+ ...options.scenario,
100
+ setup: { ...options.scenario.setup, seed: options.seed }
101
+ };
102
+ const checkpoint = options.at ?? {
103
+ segment: "given",
104
+ completed: selectedScenario.given.length
105
+ };
106
+ const replay = await replayScenario({
107
+ game: options.game,
108
+ scenario: selectedScenario,
109
+ at: checkpoint
110
+ });
111
+ const node = inspectScenarioReplayNode({
112
+ replay,
113
+ perspective: options.perspective
114
+ });
115
+ return {
116
+ schemaVersion: 1,
117
+ scenario: structuredClone(options.identity),
118
+ node,
119
+ seedSource: options.seed === void 0 ? "scenario" : "override"
120
+ };
121
+ }
122
+ function inspectScenarioReplayNode(options) {
123
+ const baseAuthority = inspectScenarioReplayAuthority({
124
+ replay: options.replay,
125
+ perspective: { kind: "spectator" }
126
+ });
127
+ const perspective = resolvePerspective(
128
+ options.perspective,
129
+ baseAuthority.scenario.setup.players,
130
+ baseAuthority.playerIds
131
+ );
132
+ const authority = inspectScenarioReplayAuthority({
133
+ replay: options.replay,
134
+ perspective: perspective.kind === "spectator" ? perspective : { kind: "player", seat: perspective.actor.seat }
135
+ });
136
+ const actor = perspective.kind === "player" ? perspective.actor : null;
137
+ const interactions = actor ? authority.interactions.map(
138
+ ({ descriptor, explanation }) => inspectInteraction(actor, descriptor, explanation)
139
+ ) : [];
140
+ const actions = actor ? authority.interactions.flatMap(
141
+ ({ explanation, actionability }) => {
142
+ if (!actionability.found || !actionability.visible || actionability.descriptor.availability.status !== "available" || actionability.inputSatisfiability?.status !== "yes") {
143
+ return [];
144
+ }
145
+ return [
146
+ {
147
+ actor,
148
+ interactionId: actionability.descriptor.interactionId,
149
+ inputs: explanation.inputs,
150
+ explanation,
151
+ hasConcreteCommand: true
152
+ }
153
+ ];
154
+ }
155
+ ) : [];
156
+ const node = {
157
+ checkpoint: authority.checkpoint,
158
+ checkpointDigest: authority.checkpointDigest,
159
+ setup: structuredClone(authority.scenario.setup),
160
+ flow: createFlowDiagnostic({
161
+ playerIds: authority.playerIds,
162
+ scheduler: authority.scheduler
163
+ }),
164
+ perspective,
165
+ publicState: authority.publicState,
166
+ view: authority.view,
167
+ interactions,
168
+ actions,
169
+ entropy: {
170
+ seed: authority.entropy.seed ?? authority.scenario.setup.seed,
171
+ draws: structuredClone(authority.entropy.draws)
172
+ },
173
+ dispatchTrace: projectDispatchTrace(
174
+ authority.commandTrace,
175
+ authority.playerIds,
176
+ perspective
177
+ )
178
+ };
179
+ return node;
180
+ }
181
+ function resolvePerspective(selector, playerCount, declaredPlayerIds) {
182
+ if (selector.kind === "spectator") return { kind: "spectator" };
183
+ const seat = selector.seat;
184
+ if (!Number.isSafeInteger(seat) || seat < 0 || seat >= playerCount) {
185
+ throw new ScenarioInspectionError({
186
+ code: "TEST_PERSPECTIVE_INVALID",
187
+ message: `Perspective seat ${String(seat)} is outside this ${playerCount}-player scenario.`,
188
+ context: {
189
+ requestedSeat: seat,
190
+ minimumSeat: 0,
191
+ maximumSeat: Math.max(0, playerCount - 1)
192
+ }
193
+ });
194
+ }
195
+ return {
196
+ kind: "player",
197
+ actor: {
198
+ seat,
199
+ playerId: declaredPlayerIds[seat] ?? `player-${seat + 1}`
200
+ }
201
+ };
202
+ }
203
+ function inspectInteraction(actor, descriptor, explanation) {
204
+ const availability = descriptor.availability ?? {
205
+ status: "blocked",
206
+ reason: "Interaction descriptor has no availability."
207
+ };
208
+ return {
209
+ actor,
210
+ interactionId: String(descriptor.interactionId ?? ""),
211
+ availability: {
212
+ status: availability.status,
213
+ ..."code" in availability && typeof availability.code === "string" ? { code: availability.code } : {},
214
+ ..."reason" in availability && typeof availability.reason === "string" ? { reason: availability.reason } : {}
215
+ },
216
+ inputs: explanation.inputs,
217
+ explanation
218
+ };
219
+ }
220
+ function projectDispatchTrace(commandTrace, playerIds, perspective) {
221
+ if (perspective.kind === "spectator") return [];
222
+ const selectedSeat = perspective.actor.seat;
223
+ return commandTrace.flatMap((entry) => {
224
+ if (entry.command.actor.seat !== selectedSeat) return [];
225
+ return entry.trace.flatMap((trace) => {
226
+ switch (trace.kind) {
227
+ case "acceptedClientInput": {
228
+ const seat = playerIds.indexOf(trace.playerId);
229
+ return seat < 0 ? [] : [
230
+ {
231
+ kind: "acceptedCommand",
232
+ actor: { seat, playerId: trace.playerId },
233
+ interactionId: trace.interactionId
234
+ }
235
+ ];
236
+ }
237
+ case "appliedInstruction":
238
+ return [
239
+ {
240
+ kind: "appliedInstruction",
241
+ instructionKind: trace.instruction
242
+ }
243
+ ];
244
+ case "rngConsumption":
245
+ return [{ kind: "entropyDraw", drawIndex: trace.drawIndex }];
246
+ }
247
+ });
248
+ });
249
+ }
250
+ function assertScenarioIdentity(identity, scenario) {
251
+ if (identity.id !== scenario.id) {
252
+ throw new ScenarioInspectionError({
253
+ code: "TEST_SCENARIO_INVALID",
254
+ message: "Scenario identity does not match the authored default export.",
255
+ context: { identityId: identity.id, scenarioId: scenario.id }
256
+ });
257
+ }
258
+ }
259
+ function assertSeed(seed) {
260
+ if (seed !== void 0 && !Number.isSafeInteger(seed)) {
261
+ throw new ScenarioInspectionError({
262
+ code: "TEST_SEED_RANGE_INVALID",
263
+ message: "Seed override must be a safe integer.",
264
+ context: { requestedSeed: seed }
265
+ });
266
+ }
267
+ }
268
+
269
+ // src/testing/exploration/cursor.ts
270
+ import { Buffer } from "buffer";
271
+ var CURSOR_VERSION = 1;
272
+ var ExploreCursorError = class extends Error {
273
+ code = "TEST_EXPLORE_CURSOR_STALE";
274
+ scenarioSourceDigest;
275
+ checkpointDigest;
276
+ constructor(options) {
277
+ super("The exploration cursor no longer matches scenario authority.");
278
+ this.name = "ExploreCursorError";
279
+ this.scenarioSourceDigest = options.scenarioSourceDigest;
280
+ this.checkpointDigest = options.checkpointDigest;
281
+ }
282
+ };
283
+ function createExploreCursor(options) {
284
+ assertOrdinal(options.nextOrdinal);
285
+ const payload = {
286
+ version: CURSOR_VERSION,
287
+ scenarioSourceDigest: options.scenario.sourceDigest,
288
+ checkpointDigest: options.checkpointDigest,
289
+ perspective: options.perspective,
290
+ seedOverride: options.seedOverride ?? null,
291
+ nextOrdinal: options.nextOrdinal
292
+ };
293
+ const encoded = Buffer.from(JSON.stringify(payload), "utf8").toString(
294
+ "base64url"
295
+ );
296
+ const digest = digestPluginRuntimeJson(payload).slice("sha256:".length);
297
+ return `dbx1.${encoded}.${digest}`;
298
+ }
299
+ function readExploreCursor(options) {
300
+ const stale = () => {
301
+ throw new ExploreCursorError({
302
+ scenarioSourceDigest: options.scenario.sourceDigest,
303
+ checkpointDigest: options.checkpointDigest
304
+ });
305
+ };
306
+ const [prefix, encoded, digest, extra] = options.cursor.split(".");
307
+ if (prefix !== "dbx1" || !encoded || !digest || extra !== void 0) stale();
308
+ let payload;
309
+ try {
310
+ payload = JSON.parse(
311
+ Buffer.from(encoded, "base64url").toString("utf8")
312
+ );
313
+ } catch {
314
+ return stale();
315
+ }
316
+ if (digestPluginRuntimeJson(payload).slice("sha256:".length) !== digest || payload.version !== CURSOR_VERSION || payload.scenarioSourceDigest !== options.scenario.sourceDigest || payload.checkpointDigest !== options.checkpointDigest || payload.seedOverride !== (options.seedOverride ?? null) || JSON.stringify(payload.perspective) !== JSON.stringify(options.perspective)) {
317
+ return stale();
318
+ }
319
+ assertOrdinal(payload.nextOrdinal);
320
+ return payload.nextOrdinal;
36
321
  }
37
- function defineScenario(definition) {
38
- return definition;
322
+ function assertOrdinal(value) {
323
+ if (!Number.isSafeInteger(value) || value < 0) {
324
+ throw new RangeError(
325
+ "Explore cursor ordinal must be a non-negative safe integer."
326
+ );
327
+ }
328
+ }
329
+
330
+ // src/testing/exploration/explore-scenario.ts
331
+ var DEFAULT_EXPLORE_LIMIT = 50;
332
+ var MAX_EXPLORE_LIMIT = 200;
333
+ var DEFAULT_EXPLORE_EVALUATIONS = 5e3;
334
+ var MAX_EXPLORE_EVALUATIONS = 1e5;
335
+ var MAX_EXPLORE_SEEDS = 64;
336
+ var ScenarioExploreError = class extends Error {
337
+ code;
338
+ context;
339
+ constructor(options) {
340
+ super(options.message);
341
+ this.name = "ScenarioExploreError";
342
+ this.code = options.code;
343
+ this.context = options.context;
344
+ }
345
+ };
346
+ async function exploreScenario(options) {
347
+ if (options.seedRange) {
348
+ if (options.seed !== void 0 || options.cursor !== void 0 || options.limit !== void 0) {
349
+ throw new ScenarioExploreError({
350
+ code: "TEST_SEED_RANGE_INVALID",
351
+ message: "Seed-range exploration cannot be combined with a seed override, cursor, or transition-page limit.",
352
+ context: { start: options.seedRange.start, end: options.seedRange.end }
353
+ });
354
+ }
355
+ return exploreSeeds(options, options.seedRange);
356
+ }
357
+ return exploreTransitions(options);
358
+ }
359
+ async function exploreTransitions(options) {
360
+ const limit = options.limit ?? DEFAULT_EXPLORE_LIMIT;
361
+ const maxEvaluations = options.maxEvaluations ?? DEFAULT_EXPLORE_EVALUATIONS;
362
+ assertTransitionLimits(limit, maxEvaluations);
363
+ const selectedScenario = scenarioWithSeed(options.scenario, options.seed);
364
+ const checkpoint = defaultCheckpoint(selectedScenario, options.at);
365
+ const replay = await replayScenario({
366
+ game: options.game,
367
+ scenario: selectedScenario,
368
+ at: checkpoint
369
+ });
370
+ const node = inspectScenarioReplayNode({
371
+ replay,
372
+ perspective: options.perspective
373
+ });
374
+ const startOrdinal = options.cursor ? readExploreCursor({
375
+ cursor: options.cursor,
376
+ scenario: options.identity,
377
+ checkpointDigest: node.checkpointDigest,
378
+ perspective: node.perspective,
379
+ seedOverride: options.seed
380
+ }) : 0;
381
+ if (node.perspective.kind === "spectator") {
382
+ return {
383
+ schemaVersion: 1,
384
+ mode: "transitions",
385
+ scenario: options.identity,
386
+ perspective: node.perspective,
387
+ node,
388
+ candidates: [],
389
+ omissions: [],
390
+ page: {
391
+ limit,
392
+ evaluated: 0,
393
+ truncated: false,
394
+ nextCursor: null
395
+ }
396
+ };
397
+ }
398
+ const accepted = [];
399
+ const omissions = [];
400
+ let evaluated = 0;
401
+ for (const action of node.actions) {
402
+ const remaining = maxEvaluations - evaluated;
403
+ if (remaining <= 0) {
404
+ omissions.push({
405
+ actor: action.actor,
406
+ interactionId: action.interactionId,
407
+ code: "INPUT_DOMAIN_BUDGET"
408
+ });
409
+ continue;
410
+ }
411
+ const enumeration = enumerateScenarioInteractionParams({
412
+ replay,
413
+ seat: action.actor.seat,
414
+ interactionId: action.interactionId,
415
+ maxEvaluations: remaining
416
+ });
417
+ if (!enumeration.found || !enumeration.visible || !enumeration.enumeration) {
418
+ continue;
419
+ }
420
+ evaluated += enumeration.enumeration.evaluated;
421
+ if (enumeration.enumeration.status !== "enumerated") {
422
+ omissions.push({
423
+ actor: action.actor,
424
+ interactionId: action.interactionId,
425
+ code: enumeration.enumeration.status === "budget" ? "INPUT_DOMAIN_BUDGET" : "INPUT_DOMAIN_NOT_ENUMERABLE",
426
+ ...enumeration.enumeration.inputKey ? { inputKey: enumeration.enumeration.inputKey } : {}
427
+ });
428
+ continue;
429
+ }
430
+ const assignments = [...enumeration.enumeration.assignments].sort(
431
+ compareCanonicalScenarioJson
432
+ );
433
+ for (const assignment of assignments) {
434
+ const command = {
435
+ actor: { seat: action.actor.seat },
436
+ interactionId: action.interactionId,
437
+ params: projectScenarioCommandParams({
438
+ game: options.game,
439
+ phase: node.flow.phase,
440
+ interactionId: action.interactionId,
441
+ params: assignment,
442
+ playerIds: node.setup.players ? Array.from(
443
+ { length: node.setup.players },
444
+ (_, seat) => options.game.contract.manifest.literals.playerIds[seat] ?? `player-${seat + 1}`
445
+ ) : [],
446
+ path: `explore.${action.interactionId}`
447
+ })
448
+ };
449
+ const advanced = await advanceScenarioReplay({
450
+ replay,
451
+ command
452
+ });
453
+ if (advanced.kind !== "accepted") continue;
454
+ const afterNode = inspectScenarioReplayNode({
455
+ replay: advanced.replay,
456
+ perspective: options.perspective
457
+ });
458
+ accepted.push({
459
+ ordinal: accepted.length,
460
+ command,
461
+ after: {
462
+ checkpointDigest: afterNode.checkpointDigest,
463
+ flow: afterNode.flow,
464
+ publicStateDigest: digestScenarioJson(
465
+ afterNode.publicState
466
+ ),
467
+ viewDigest: digestScenarioJson(afterNode.view),
468
+ actions: afterNode.actions.map(({ actor, interactionId }) => ({
469
+ actor,
470
+ interactionId
471
+ })),
472
+ entropy: afterNode.entropy,
473
+ dispatchTrace: afterNode.dispatchTrace
474
+ }
475
+ });
476
+ }
477
+ }
478
+ const candidates = accepted.slice(startOrdinal, startOrdinal + limit);
479
+ const nextOrdinal = startOrdinal + candidates.length;
480
+ const truncated = nextOrdinal < accepted.length;
481
+ return {
482
+ schemaVersion: 1,
483
+ mode: "transitions",
484
+ scenario: structuredClone(options.identity),
485
+ perspective: node.perspective,
486
+ node,
487
+ candidates,
488
+ omissions,
489
+ page: {
490
+ limit,
491
+ evaluated,
492
+ truncated,
493
+ nextCursor: truncated ? createExploreCursor({
494
+ scenario: options.identity,
495
+ checkpointDigest: node.checkpointDigest,
496
+ perspective: node.perspective,
497
+ seedOverride: options.seed,
498
+ nextOrdinal
499
+ }) : null
500
+ }
501
+ };
502
+ }
503
+ async function exploreSeeds(options, range) {
504
+ assertSeedRange(range);
505
+ const checkpoint = defaultCheckpoint(options.scenario, options.at);
506
+ const variants = [];
507
+ for (let seed = range.start; seed <= range.end; seed += 1) {
508
+ try {
509
+ const inspected = await inspectScenario({
510
+ game: options.game,
511
+ scenario: options.scenario,
512
+ identity: options.identity,
513
+ perspective: options.perspective,
514
+ at: checkpoint,
515
+ seed
516
+ });
517
+ const replay = await replayScenario({
518
+ game: options.game,
519
+ scenario: scenarioWithSeed(options.scenario, seed),
520
+ at: checkpoint
521
+ });
522
+ const counts = await concreteOptionCounts({
523
+ replay,
524
+ node: inspected.node,
525
+ maxEvaluations: options.maxEvaluations ?? DEFAULT_EXPLORE_EVALUATIONS
526
+ });
527
+ variants.push({
528
+ seed,
529
+ status: "replayed",
530
+ checkpointDigest: inspected.node.checkpointDigest,
531
+ entropy: inspected.node.entropy,
532
+ observable: {
533
+ publicState: inspected.node.publicState,
534
+ view: inspected.node.view
535
+ },
536
+ signature: {
537
+ phase: inspected.node.flow.phase,
538
+ step: inspected.node.flow.step,
539
+ actions: inspected.node.actions.map(({ actor, interactionId }) => ({
540
+ seat: actor.seat,
541
+ interactionId,
542
+ concreteOptionCount: counts.get(`${actor.seat}:${interactionId}`) ?? "lazy"
543
+ }))
544
+ }
545
+ });
546
+ } catch (error) {
547
+ if (!(error instanceof ScenarioReplayError)) throw error;
548
+ variants.push({
549
+ seed,
550
+ status: "rejected",
551
+ rejection: {
552
+ segment: error.segment,
553
+ sourceIndex: error.index,
554
+ interactionId: error.interactionId,
555
+ errorCode: error.errorCode
556
+ }
557
+ });
558
+ }
559
+ }
560
+ return {
561
+ schemaVersion: 1,
562
+ mode: "seeds",
563
+ scenario: structuredClone(options.identity),
564
+ perspective: (await inspectSeedPerspective(options)).node.perspective,
565
+ checkpoint,
566
+ variants
567
+ };
568
+ }
569
+ async function inspectSeedPerspective(options) {
570
+ return inspectScenario({
571
+ game: options.game,
572
+ scenario: options.scenario,
573
+ identity: options.identity,
574
+ perspective: options.perspective,
575
+ at: { segment: "setup", completed: 0 }
576
+ });
577
+ }
578
+ async function concreteOptionCounts(options) {
579
+ assertTransitionLimits(DEFAULT_EXPLORE_LIMIT, options.maxEvaluations);
580
+ const counts = /* @__PURE__ */ new Map();
581
+ let evaluated = 0;
582
+ for (const action of options.node.actions) {
583
+ const remaining = options.maxEvaluations - evaluated;
584
+ if (remaining <= 0) {
585
+ counts.set(`${action.actor.seat}:${action.interactionId}`, "lazy");
586
+ continue;
587
+ }
588
+ const result = enumerateScenarioInteractionParams({
589
+ replay: options.replay,
590
+ seat: action.actor.seat,
591
+ interactionId: action.interactionId,
592
+ maxEvaluations: remaining
593
+ });
594
+ if (!result.found || !result.visible || !result.enumeration) continue;
595
+ evaluated += result.enumeration.evaluated;
596
+ counts.set(
597
+ `${action.actor.seat}:${action.interactionId}`,
598
+ result.enumeration.status === "enumerated" ? result.enumeration.assignments.length : "lazy"
599
+ );
600
+ }
601
+ return counts;
602
+ }
603
+ function scenarioWithSeed(scenario, seed) {
604
+ return seed === void 0 ? scenario : { ...scenario, setup: { ...scenario.setup, seed } };
605
+ }
606
+ function defaultCheckpoint(scenario, at) {
607
+ return at ?? {
608
+ segment: "given",
609
+ completed: scenario.given.length
610
+ };
611
+ }
612
+ function assertTransitionLimits(limit, maxEvaluations) {
613
+ if (!Number.isSafeInteger(limit) || limit < 1 || limit > MAX_EXPLORE_LIMIT) {
614
+ throw new ScenarioExploreError({
615
+ code: "TEST_EXPLORE_LIMIT_INVALID",
616
+ message: `Explore limit must be between 1 and ${MAX_EXPLORE_LIMIT}.`,
617
+ context: { requested: limit, minimum: 1, maximum: MAX_EXPLORE_LIMIT }
618
+ });
619
+ }
620
+ if (!Number.isSafeInteger(maxEvaluations) || maxEvaluations < 1 || maxEvaluations > MAX_EXPLORE_EVALUATIONS) {
621
+ throw new ScenarioExploreError({
622
+ code: "TEST_EXPLORE_LIMIT_INVALID",
623
+ message: `Explore max evaluations must be between 1 and ${MAX_EXPLORE_EVALUATIONS}.`,
624
+ context: {
625
+ requested: maxEvaluations,
626
+ minimum: 1,
627
+ maximum: MAX_EXPLORE_EVALUATIONS
628
+ }
629
+ });
630
+ }
631
+ }
632
+ function assertSeedRange(range) {
633
+ const width = range.end - range.start + 1;
634
+ if (!Number.isSafeInteger(range.start) || !Number.isSafeInteger(range.end) || range.start > range.end || !Number.isSafeInteger(width) || width < 1 || width > MAX_EXPLORE_SEEDS) {
635
+ throw new ScenarioExploreError({
636
+ code: "TEST_SEED_RANGE_INVALID",
637
+ message: `Seed range must contain 1 through ${MAX_EXPLORE_SEEDS} inclusive safe-integer seeds.`,
638
+ context: {
639
+ start: range.start,
640
+ end: range.end,
641
+ maximumWidth: MAX_EXPLORE_SEEDS
642
+ }
643
+ });
644
+ }
39
645
  }
40
646
 
41
647
  // src/testing/ui-fixture/canonical.ts
42
648
  import { createHash } from "crypto";
43
649
  var sha256DigestPattern = /^sha256:[a-f0-9]{64}$/;
650
+ function compareCanonicalStrings(left, right) {
651
+ return left === right ? 0 : left < right ? -1 : 1;
652
+ }
44
653
  function isSha256Digest(value) {
45
654
  return sha256DigestPattern.test(value);
46
655
  }
@@ -66,7 +675,7 @@ function canonicalizeUIFixtureJson(value) {
66
675
  }
67
676
  const entries = Object.entries(value);
68
677
  return Object.fromEntries(
69
- entries.filter(([, item]) => item !== void 0).sort(([left], [right]) => left.localeCompare(right)).map(([key, item]) => [key, canonicalizeUIFixtureJson(item)])
678
+ entries.filter(([, item]) => item !== void 0).sort(([left], [right]) => compareCanonicalStrings(left, right)).map(([key, item]) => [key, canonicalizeUIFixtureJson(item)])
70
679
  );
71
680
  }
72
681
  }
@@ -88,7 +697,7 @@ function digestUIFixtureRequest(request) {
88
697
  }
89
698
  function digestUIFixtureTransportRequest(request) {
90
699
  return digestUIFixtureJson({
91
- digestVersion: "ui-fixture-runtime-command@2",
700
+ digestVersion: "ui-fixture-runtime-command@3",
92
701
  request
93
702
  });
94
703
  }
@@ -128,11 +737,11 @@ function createReducerScenarioRunner(options) {
128
737
  const frames = [];
129
738
  const exchanges = [];
130
739
  const appendFrame = (id) => {
131
- const dynamicProjection = options.bundle.projectSeatsDynamic({
740
+ const dynamicProjection = options.bundle.project({
132
741
  state,
133
742
  playerIds: [options.viewer.playerId]
134
743
  });
135
- const staticProjection = options.bundle.projectStatic?.() ?? null;
744
+ const staticProjection = options.bundle.boardStatic();
136
745
  const flow = readFlowState(state);
137
746
  const materialized = materializePluginGameplayFrame({
138
747
  currentPhase: flow.currentPhase,
@@ -140,11 +749,11 @@ function createReducerScenarioRunner(options) {
140
749
  dynamicProjection,
141
750
  staticProjection,
142
751
  perspectivePlayerId: options.viewer.playerId,
143
- gameVersion,
752
+ version: gameVersion,
144
753
  actionSetVersion: "pending"
145
754
  });
146
755
  const actionSetVersion = computePluginActionSetVersion({
147
- gameVersion,
756
+ version: gameVersion,
148
757
  availableInteractions: materialized.availableInteractions
149
758
  });
150
759
  const frame = {
@@ -174,10 +783,15 @@ function createReducerScenarioRunner(options) {
174
783
  throw new Error("Reducer scenario runner lost its initial frame.");
175
784
  }
176
785
  if (operation.operation === "validate") {
177
- const result2 = await options.bundle.validateInput({
178
- state,
786
+ const dispatched = await options.bundle.dispatch({
787
+ state: structuredClone(state),
179
788
  input: operation.input
180
789
  });
790
+ const result2 = dispatched.kind === "accept" ? { valid: true } : {
791
+ valid: false,
792
+ errorCode: dispatched.errorCode,
793
+ message: dispatched.message
794
+ };
181
795
  exchanges.push({
182
796
  id: operation.id,
183
797
  operation: "validate",
@@ -245,304 +859,6 @@ function defineUIScenario(scenario) {
245
859
  return Object.freeze(scenario);
246
860
  }
247
861
 
248
- // src/testing/ui-fixture/parity.ts
249
- var topLevelComparisons = [
250
- { path: "scenarioId", code: "fixture-source-mismatch" },
251
- { path: "fixtureDigest", code: "candidate-mismatch" },
252
- { path: "sdkCandidateDigest", code: "candidate-mismatch" },
253
- { path: "pluginRuntimeProtocol", code: "protocol-mismatch" },
254
- { path: "browserInteractionProtocol", code: "protocol-mismatch" },
255
- { path: "environment.project", code: "host-setup-failure" },
256
- { path: "environment.viewport.width", code: "host-setup-failure" },
257
- { path: "environment.viewport.height", code: "host-setup-failure" }
258
- ];
259
- var checkpointComparisons = [
260
- { path: "stepId", code: "interaction-resolution-mismatch" },
261
- { path: "interactionKey", code: "interaction-resolution-mismatch" },
262
- { path: "interactionId", code: "interaction-resolution-mismatch" },
263
- { path: "actuatorId", code: "interaction-resolution-mismatch" },
264
- { path: "descriptorDigest", code: "interaction-resolution-mismatch" },
265
- { path: "gameVersion", code: "projection-mismatch" },
266
- { path: "actionSetVersion", code: "projection-mismatch" },
267
- { path: "perspectivePlayerId", code: "projection-mismatch" },
268
- { path: "projectionDigest", code: "projection-mismatch" },
269
- { path: "semanticDigest", code: "semantic-snapshot-mismatch" },
270
- { path: "draftDigest", code: "draft-mismatch" },
271
- { path: "submissionDigest", code: "submission-mismatch" },
272
- { path: "screenshot", code: "visual-mismatch" }
273
- ];
274
- function createUIParityObservationFromFixture({
275
- fixture,
276
- sdkCandidateDigest,
277
- environment,
278
- fixtureDigest = digestUIScenarioFixture(fixture),
279
- screenshotsByStepId = {},
280
- diagnostics = []
281
- }) {
282
- const frameById = new Map(
283
- fixture.protocol.frames.map((frame) => [frame.id, frame])
284
- );
285
- const firstFrame = fixture.protocol.frames[0];
286
- if (!firstFrame) {
287
- throw new Error(
288
- `Fixture '${fixture.id}' does not contain protocol frames.`
289
- );
290
- }
291
- const checkpoints = fixture.replay.map((step, index) => {
292
- const expectedFrameId = step.expect.frameId ?? firstFrame.id;
293
- const frame = frameById.get(expectedFrameId);
294
- if (!frame) {
295
- throw new Error(
296
- `Fixture '${fixture.id}' replay step '${step.stepId}' references missing frame '${expectedFrameId}'.`
297
- );
298
- }
299
- const identity = "expectedIdentity" in step ? step.expectedIdentity : null;
300
- const projectionDigest = step.expect.projectionDigest ?? frame.projectionDigest;
301
- const isFinal = index === fixture.replay.length - 1;
302
- const semanticDigest = step.expect.semanticDigest ?? (isFinal ? fixture.expected.finalSemanticDigest : digestUIFixtureJson({
303
- scenarioId: fixture.id,
304
- stepId: step.stepId,
305
- frameId: frame.id,
306
- projectionDigest
307
- }));
308
- const submissionDigest = step.expect.submissionDigest ?? (isFinal ? fixture.expected.submissionDigest : void 0);
309
- return {
310
- stepId: step.stepId,
311
- interactionKey: identity?.interactionKey,
312
- interactionId: identity?.interactionId,
313
- actuatorId: identity?.actuatorId,
314
- descriptorDigest: identity?.descriptorDigest,
315
- draftDigest: step.expect.draftDigest ?? identity?.draftDigest,
316
- gameVersion: frame.frame.gameVersion,
317
- actionSetVersion: frame.frame.actionSetVersion,
318
- perspectivePlayerId: frame.frame.perspectivePlayerId,
319
- projectionDigest,
320
- semanticDigest,
321
- submissionDigest,
322
- screenshot: screenshotsByStepId[step.stepId]
323
- };
324
- });
325
- return {
326
- schemaVersion: 1,
327
- scenarioId: fixture.id,
328
- fixtureDigest,
329
- sdkCandidateDigest,
330
- pluginRuntimeProtocol: fixture.pluginRuntimeProtocol,
331
- browserInteractionProtocol: fixture.browserInteractionProtocol,
332
- environment,
333
- provenance: {
334
- kind: "fixture-expectation"
335
- },
336
- checkpoints,
337
- diagnostics
338
- };
339
- }
340
- function parseUIParityObservationV1(value) {
341
- const observation = assertRecord(value, "observation");
342
- if (observation.schemaVersion !== 1) {
343
- throw new Error("UI parity observation schemaVersion must be 1.");
344
- }
345
- assertString(observation.scenarioId, "scenarioId");
346
- assertString(observation.fixtureDigest, "fixtureDigest");
347
- assertString(observation.sdkCandidateDigest, "sdkCandidateDigest");
348
- if (observation.pluginRuntimeProtocol !== 3) {
349
- throw new Error("UI parity observation pluginRuntimeProtocol must be 3.");
350
- }
351
- assertString(
352
- observation.browserInteractionProtocol,
353
- "browserInteractionProtocol"
354
- );
355
- const environment = assertRecord(observation.environment, "environment");
356
- assertString(environment.project, "environment.project");
357
- const viewport = assertRecord(environment.viewport, "environment.viewport");
358
- assertNumber(viewport.width, "environment.viewport.width");
359
- assertNumber(viewport.height, "environment.viewport.height");
360
- const provenance = assertRecord(
361
- observation.provenance,
362
- "observation.provenance"
363
- );
364
- if (provenance.kind !== "fixture-expectation" && provenance.kind !== "source-workbench" && provenance.kind !== "packed-real-host") {
365
- throw new Error(
366
- "observation.provenance.kind must identify fixture, source Workbench, or packed real-host measurement."
367
- );
368
- }
369
- assertOptionalString(provenance.evidence, "observation.provenance.evidence");
370
- const checkpoints = assertArray(observation.checkpoints, "checkpoints");
371
- for (let index = 0; index < checkpoints.length; index += 1) {
372
- const checkpoint = assertRecord(
373
- checkpoints[index],
374
- `checkpoints[${index}]`
375
- );
376
- assertString(checkpoint.stepId, `checkpoints[${index}].stepId`);
377
- assertOptionalString(
378
- checkpoint.interactionKey,
379
- `checkpoints[${index}].interactionKey`
380
- );
381
- assertOptionalString(
382
- checkpoint.interactionId,
383
- `checkpoints[${index}].interactionId`
384
- );
385
- assertOptionalString(
386
- checkpoint.actuatorId,
387
- `checkpoints[${index}].actuatorId`
388
- );
389
- assertOptionalString(
390
- checkpoint.descriptorDigest,
391
- `checkpoints[${index}].descriptorDigest`
392
- );
393
- assertOptionalString(
394
- checkpoint.draftDigest,
395
- `checkpoints[${index}].draftDigest`
396
- );
397
- assertNumber(checkpoint.gameVersion, `checkpoints[${index}].gameVersion`);
398
- assertString(
399
- checkpoint.actionSetVersion,
400
- `checkpoints[${index}].actionSetVersion`
401
- );
402
- if (checkpoint.perspectivePlayerId !== null && typeof checkpoint.perspectivePlayerId !== "string") {
403
- throw new Error(
404
- `checkpoints[${index}].perspectivePlayerId must be a string or null.`
405
- );
406
- }
407
- assertString(
408
- checkpoint.projectionDigest,
409
- `checkpoints[${index}].projectionDigest`
410
- );
411
- assertString(
412
- checkpoint.semanticDigest,
413
- `checkpoints[${index}].semanticDigest`
414
- );
415
- assertOptionalString(
416
- checkpoint.submissionDigest,
417
- `checkpoints[${index}].submissionDigest`
418
- );
419
- assertOptionalString(
420
- checkpoint.screenshot,
421
- `checkpoints[${index}].screenshot`
422
- );
423
- }
424
- const diagnostics = assertArray(observation.diagnostics, "diagnostics");
425
- for (let index = 0; index < diagnostics.length; index += 1) {
426
- const diagnostic = assertRecord(
427
- diagnostics[index],
428
- `diagnostics[${index}]`
429
- );
430
- assertString(diagnostic.code, `diagnostics[${index}].code`);
431
- assertString(diagnostic.message, `diagnostics[${index}].message`);
432
- }
433
- return observation;
434
- }
435
- function compareUIParityObservations(expected, actual) {
436
- for (const comparison of topLevelComparisons) {
437
- const result = comparePath(expected, actual, comparison);
438
- if (result) {
439
- return result;
440
- }
441
- }
442
- if (expected.checkpoints.length !== actual.checkpoints.length) {
443
- return mismatch({
444
- code: "interaction-resolution-mismatch",
445
- path: "checkpoints.length",
446
- expected: expected.checkpoints.length,
447
- actual: actual.checkpoints.length
448
- });
449
- }
450
- for (let index = 0; index < expected.checkpoints.length; index += 1) {
451
- const expectedCheckpoint = expected.checkpoints[index];
452
- const actualCheckpoint = actual.checkpoints[index];
453
- for (const comparison of checkpointComparisons) {
454
- const result = comparePath(
455
- expectedCheckpoint,
456
- actualCheckpoint,
457
- comparison,
458
- {
459
- prefix: `checkpoints[${index}]`,
460
- checkpointIndex: index,
461
- stepId: expectedCheckpoint.stepId
462
- }
463
- );
464
- if (result) {
465
- return result;
466
- }
467
- }
468
- }
469
- if (!sameValue(expected.diagnostics, actual.diagnostics)) {
470
- return mismatch({
471
- code: "host-setup-failure",
472
- path: "diagnostics",
473
- expected: expected.diagnostics,
474
- actual: actual.diagnostics
475
- });
476
- }
477
- return { ok: true };
478
- }
479
- function comparePath(expected, actual, comparison, options = {}) {
480
- const expectedValue = getPath(expected, comparison.path);
481
- const actualValue = getPath(actual, comparison.path);
482
- if (sameValue(expectedValue, actualValue)) {
483
- return null;
484
- }
485
- const path = options.prefix ? `${options.prefix}.${comparison.path}` : comparison.path;
486
- return mismatch({
487
- code: comparison.code,
488
- path,
489
- expected: expectedValue,
490
- actual: actualValue,
491
- checkpointIndex: options.checkpointIndex,
492
- stepId: options.stepId
493
- });
494
- }
495
- function mismatch(input) {
496
- return {
497
- ok: false,
498
- failure: {
499
- ...input,
500
- message: `${input.code} at ${input.path}`
501
- }
502
- };
503
- }
504
- function sameValue(left, right) {
505
- if (left === void 0 || right === void 0) {
506
- return left === right;
507
- }
508
- return canonicalUIFixtureJson(left) === canonicalUIFixtureJson(right);
509
- }
510
- function getPath(value, path) {
511
- return path.split(".").reduce((current, key) => {
512
- if (current === null || typeof current !== "object") {
513
- return void 0;
514
- }
515
- return current[key];
516
- }, value);
517
- }
518
- function assertRecord(value, path) {
519
- if (typeof value !== "object" || value === null || Array.isArray(value)) {
520
- throw new Error(`${path} must be an object.`);
521
- }
522
- return value;
523
- }
524
- function assertArray(value, path) {
525
- if (!Array.isArray(value)) {
526
- throw new Error(`${path} must be an array.`);
527
- }
528
- return value;
529
- }
530
- function assertString(value, path) {
531
- if (typeof value !== "string" || value.length === 0) {
532
- throw new Error(`${path} must be a non-empty string.`);
533
- }
534
- }
535
- function assertOptionalString(value, path) {
536
- if (value !== void 0 && (typeof value !== "string" || value.length === 0)) {
537
- throw new Error(`${path} must be a non-empty string when present.`);
538
- }
539
- }
540
- function assertNumber(value, path) {
541
- if (typeof value !== "number" || !Number.isFinite(value)) {
542
- throw new Error(`${path} must be a finite number.`);
543
- }
544
- }
545
-
546
862
  // src/testing/ui-fixture/create-fixture-host-harness.ts
547
863
  var DEFAULT_CHANNEL_ID = "fixture-channel";
548
864
  function createFixtureHostHarness(options) {
@@ -679,26 +995,6 @@ function createFixtureHostHarness(options) {
679
995
  stepCursor += 1;
680
996
  return step;
681
997
  };
682
- const handleValidate = async (command) => {
683
- const requestDigest = digestUIFixtureTransportRequest({
684
- operation: "validate",
685
- basis: command.basis,
686
- interactionId: command.interactionId,
687
- payload: command.params
688
- });
689
- const step = consumeExpectedStep("client.validate", requestDigest);
690
- record({
691
- kind: "validate-received",
692
- requestDigest,
693
- result: step.response.valid ? "accepted" : "rejected"
694
- });
695
- await waitForConfiguredLatency();
696
- sendHostPayload({
697
- type: "interaction.validation-result",
698
- requestId: command.requestId,
699
- result: step.response
700
- });
701
- };
702
998
  const handleSubmit = async (command) => {
703
999
  const requestDigest = digestUIFixtureTransportRequest({
704
1000
  operation: "submit",
@@ -714,9 +1010,8 @@ function createFixtureHostHarness(options) {
714
1010
  });
715
1011
  await waitForConfiguredLatency();
716
1012
  sendHostPayload({
717
- type: "interaction.submit-result",
718
- requestId: command.requestId,
719
- result: step.response
1013
+ ...step.response,
1014
+ clientActionId: command.clientActionId
720
1015
  });
721
1016
  if (step.response.accepted) {
722
1017
  await waitForConfiguredLatency();
@@ -739,9 +1034,6 @@ function createFixtureHostHarness(options) {
739
1034
  case "runtime.ack":
740
1035
  record({ kind: "ack-received" });
741
1036
  break;
742
- case "interaction.validate":
743
- trackHandler(handleValidate(payload));
744
- break;
745
1037
  case "interaction.submit":
746
1038
  trackHandler(handleSubmit(payload));
747
1039
  break;
@@ -863,17 +1155,6 @@ function compilePluginProtocolTape(options) {
863
1155
  );
864
1156
  }
865
1157
  if (exchange.operation === "validate") {
866
- steps.push({
867
- id: exchange.id,
868
- kind: "client.validate",
869
- fromFrameId: exchange.fromFrameId,
870
- requestDigest: digestRuntimeCommand(exchange, fromFrame),
871
- response: {
872
- valid: exchange.result.valid,
873
- errorCode: exchange.result.errorCode,
874
- message: exchange.result.message
875
- }
876
- });
877
1158
  continue;
878
1159
  }
879
1160
  steps.push({
@@ -881,7 +1162,13 @@ function compilePluginProtocolTape(options) {
881
1162
  kind: "client.submit",
882
1163
  fromFrameId: exchange.fromFrameId,
883
1164
  requestDigest: digestRuntimeCommand(exchange, fromFrame),
884
- response: exchange.result.kind === "accepted" ? { accepted: true } : {
1165
+ response: exchange.result.kind === "accepted" ? {
1166
+ type: "interaction.result",
1167
+ clientActionId: exchange.id,
1168
+ accepted: true
1169
+ } : {
1170
+ type: "interaction.result",
1171
+ clientActionId: exchange.id,
885
1172
  accepted: false,
886
1173
  errorCode: exchange.result.diagnostics[0]?.code ?? "fixture-rejected",
887
1174
  message: exchange.result.diagnostics[0]?.message
@@ -916,7 +1203,7 @@ function materializeTraceFrame(frame, perspectivePlayerId) {
916
1203
  dynamicProjection: frame.dynamicProjection,
917
1204
  staticProjection: frame.staticProjection,
918
1205
  perspectivePlayerId,
919
- gameVersion: frame.gameVersion,
1206
+ version: frame.gameVersion,
920
1207
  actionSetVersion: frame.actionSetVersion
921
1208
  }),
922
1209
  projectionDigest: frame.projectionDigest
@@ -925,11 +1212,7 @@ function materializeTraceFrame(frame, perspectivePlayerId) {
925
1212
  function digestRuntimeCommand(exchange, frame) {
926
1213
  return digestUIFixtureTransportRequest({
927
1214
  operation: exchange.operation === "validate" ? "validate" : "submit",
928
- basis: {
929
- gameVersion: frame.frame.gameVersion,
930
- actionSetVersion: frame.frame.actionSetVersion,
931
- perspectivePlayerId: frame.frame.perspectivePlayerId
932
- },
1215
+ basis: frame.frame.basis,
933
1216
  interactionId: exchange.input.interactionId,
934
1217
  payload: exchange.input.params
935
1218
  });
@@ -1357,6 +1640,9 @@ function assertStep(stepId, expect) {
1357
1640
  }
1358
1641
  export {
1359
1642
  FixturePluginRuntime,
1643
+ ScenarioAssertionError,
1644
+ ScenarioDefinitionValidationError,
1645
+ ScenarioReplayError,
1360
1646
  StaleContractArtifactError,
1361
1647
  UI_SCENARIO_FIXTURE_BUNDLE_SCHEMA_VERSION,
1362
1648
  UI_SCENARIO_FIXTURE_PLUGIN_RUNTIME_PROTOCOL,
@@ -1364,6 +1650,7 @@ export {
1364
1650
  UI_SCENARIO_FIXTURE_SUPPORTED_BROWSER_PROTOCOL_MAJOR,
1365
1651
  activate,
1366
1652
  assertDeterministicUIScenarioFixture,
1653
+ assertScenario,
1367
1654
  assertStep,
1368
1655
  assertSupportedBrowserInteractionProtocol,
1369
1656
  assertUIStepExpectationSatisfied,
@@ -1371,18 +1658,14 @@ export {
1371
1658
  canonicalUIFixtureJson,
1372
1659
  canonicalizeUIFixtureJson,
1373
1660
  canonicalizeUIScenarioFixture,
1374
- compareUIParityObservations,
1375
1661
  compilePluginProtocolTape,
1376
1662
  compileUIScenarioFixture,
1377
1663
  createDeterministicIdFactory,
1378
1664
  createExpectApi,
1379
1665
  createFixtureHostHarness,
1380
1666
  createReducerScenarioRunner,
1381
- createTestRuntime,
1382
- createUIParityObservationFromFixture,
1667
+ createScenarioAuthoring,
1383
1668
  defaultFixtureEnvironmentInit,
1384
- defineBase,
1385
- defineScenario,
1386
1669
  defineUIScenario,
1387
1670
  digestPluginProtocolTape,
1388
1671
  digestUIFixtureJson,
@@ -1390,18 +1673,23 @@ export {
1390
1673
  digestUIFixtureTransportRequest,
1391
1674
  digestUIScenarioFixture,
1392
1675
  drag,
1676
+ exploreScenario,
1393
1677
  fill,
1394
1678
  fixtureEnvironmentInitFor,
1679
+ inspectScenario,
1395
1680
  isSha256Digest,
1396
1681
  isStaleContractArtifactError,
1397
- parseUIParityObservationV1,
1398
1682
  parseUIScenarioFixture,
1399
1683
  parseUIScenarioFixtureBundleIndex,
1400
1684
  pluginProtocolTapeSchema,
1401
1685
  portableSemanticReplayStepSchema,
1402
1686
  press,
1687
+ probeScenarioCommand,
1688
+ replayScenario,
1689
+ resolveScenarioCheckpoint,
1403
1690
  serializeUIScenarioFixture,
1404
1691
  submit,
1692
+ toScenarioReplayDefinition,
1405
1693
  uiFixtureFrameSchema,
1406
1694
  uiFixtureProtocolStepSchema,
1407
1695
  uiReplayExecutionSchema,