@fluidgrids/workflows 2026.1028.2 → 2026.1029.1

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 (118) hide show
  1. package/README.md +72 -10
  2. package/dist/{activation-DnhG7SmF.d.ts → activation-BnVQMv9y.d.ts} +1 -1
  3. package/dist/{activation-BBh1p82z.d.cts → activation-CESehfYi.d.cts} +1 -1
  4. package/dist/{chunk-XHXIDVEC.js → chunk-25BKWR2O.js} +1 -1
  5. package/dist/{chunk-UK3WM7YZ.cjs → chunk-2B37XAFQ.cjs} +44 -8
  6. package/dist/{chunk-DJYMDLV5.js → chunk-2DDULZFM.js} +93 -1
  7. package/dist/{chunk-623FVQSN.cjs → chunk-3FIDHONL.cjs} +104 -0
  8. package/dist/chunk-6QPOJZT6.cjs +1180 -0
  9. package/dist/chunk-7ILGCUI6.js +154 -0
  10. package/dist/chunk-A2OHX3UQ.js +1156 -0
  11. package/dist/{chunk-VOKMAAJP.js → chunk-A36CCOWS.js} +188 -19
  12. package/dist/{chunk-FMSW2HDF.cjs → chunk-ELL2RBML.cjs} +0 -14
  13. package/dist/{chunk-JD2VQIDZ.cjs → chunk-EWYADREB.cjs} +2 -2
  14. package/dist/{chunk-HWJZVOG7.js → chunk-FQSJI5NV.js} +1 -1
  15. package/dist/{chunk-ABFZWYHT.js → chunk-FWBRQWRX.js} +156 -48
  16. package/dist/{chunk-PZCVF76Q.cjs → chunk-I47EENR4.cjs} +209 -40
  17. package/dist/chunk-J3PYFGKA.cjs +166 -0
  18. package/dist/{chunk-C5OLWZ42.js → chunk-KXJDRQ6G.js} +1 -13
  19. package/dist/chunk-M272AHEX.js +25 -0
  20. package/dist/{chunk-VRHHBPT6.js → chunk-MJ5TGYVG.js} +333 -65
  21. package/dist/{chunk-SAOBPYYJ.cjs → chunk-NXFBVDOI.cjs} +3 -3
  22. package/dist/{chunk-XKJA7KX3.js → chunk-OIX4O6UR.js} +38 -2
  23. package/dist/{chunk-FEW3JBYA.cjs → chunk-OKX3FYIM.cjs} +3 -3
  24. package/dist/{chunk-M4BBAERY.cjs → chunk-OMY3CKUZ.cjs} +404 -136
  25. package/dist/chunk-PWIUEWC3.js +81 -0
  26. package/dist/chunk-Q4MWQNJK.cjs +28 -0
  27. package/dist/{chunk-P6TA5EZT.cjs → chunk-RUQIMTN5.cjs} +171 -57
  28. package/dist/{chunk-IISBRUWJ.js → chunk-WXXNCHUY.js} +1 -1
  29. package/dist/chunk-YHBVMOMK.cjs +87 -0
  30. package/dist/codegen/index.d.cts +2 -2
  31. package/dist/codegen/index.d.ts +2 -2
  32. package/dist/collect-BTHjQaSp.d.ts +86 -0
  33. package/dist/collect-CSyOg5XC.d.cts +86 -0
  34. package/dist/{file-BOoHZgoQ.d.cts → file-cgL9l9l8.d.cts} +765 -14
  35. package/dist/{file-yuPCFU5b.d.ts → file-olQudcx5.d.ts} +765 -14
  36. package/dist/history/index.cjs +198 -86
  37. package/dist/history/index.d.cts +49 -10
  38. package/dist/history/index.d.ts +49 -10
  39. package/dist/history/index.js +49 -4
  40. package/dist/index.cjs +64 -51
  41. package/dist/index.d.cts +9 -53
  42. package/dist/index.d.ts +9 -53
  43. package/dist/index.js +5 -4
  44. package/dist/ir/index.cjs +24 -3
  45. package/dist/ir/index.d.cts +43 -4
  46. package/dist/ir/index.d.ts +43 -4
  47. package/dist/ir/index.js +24 -3
  48. package/dist/{lower-BzmUz0sq.d.cts → lower-3S6PsqjJ.d.cts} +40 -6
  49. package/dist/{lower-_-iT4HYs.d.ts → lower-DmZpQ8hJ.d.ts} +40 -6
  50. package/dist/{manifest-C8N6HDYl.d.ts → manifest-BJjrQt77.d.ts} +1 -1
  51. package/dist/{manifest-0OLw0i7k.d.cts → manifest-gRI2Q5Fj.d.cts} +1 -1
  52. package/dist/node-evaluator-SOADN23V.js +14 -0
  53. package/dist/node-evaluator-YGDEXK4U.cjs +24 -0
  54. package/dist/quickjs/index.cjs +25 -24
  55. package/dist/quickjs/index.d.cts +6 -6
  56. package/dist/quickjs/index.d.ts +6 -6
  57. package/dist/quickjs/index.js +8 -7
  58. package/dist/roundtrip/index.cjs +245 -43
  59. package/dist/roundtrip/index.d.cts +86 -9
  60. package/dist/roundtrip/index.d.ts +86 -9
  61. package/dist/roundtrip/index.js +172 -8
  62. package/dist/runtime/index.cjs +21 -20
  63. package/dist/runtime/index.d.cts +49 -7
  64. package/dist/runtime/index.d.ts +49 -7
  65. package/dist/runtime/index.js +8 -7
  66. package/dist/testing/index.cjs +514 -74
  67. package/dist/testing/index.d.cts +127 -10
  68. package/dist/testing/index.d.ts +127 -10
  69. package/dist/testing/index.js +480 -42
  70. package/dist/{types-BGoPzgcl.d.ts → types-Bb2wRnJ5.d.cts} +20 -1
  71. package/dist/{types-BGoPzgcl.d.cts → types-Bb2wRnJ5.d.ts} +20 -1
  72. package/dist/{types-DV-HX_Gt.d.ts → types-CQKOhPTa.d.cts} +122 -14
  73. package/dist/{types-CpBBjaGX.d.cts → types-CnIOinoz.d.ts} +122 -14
  74. package/dist/{workflow-Bpr3vnA_.d.ts → workflow-8uRU9rhL.d.ts} +2 -2
  75. package/dist/{workflow-FXUkpIBc.d.cts → workflow-CZOXUlQ5.d.cts} +2 -2
  76. package/dist/{workflow-C2a05WUJ.d.ts → workflow-DWTPHFbt.d.ts} +124 -12
  77. package/dist/{workflow-J-yYixny.d.cts → workflow-O6e64ZcG.d.cts} +124 -12
  78. package/fixtures/histories/auto-upgrade-patched.history.json +276 -0
  79. package/fixtures/histories/benign-failure.history.json +146 -0
  80. package/fixtures/histories/cancel-activity-try-cancel.history.json +150 -0
  81. package/fixtures/histories/child-cancel-wait-requested.history.json +217 -0
  82. package/fixtures/histories/child-options-roundtrip.history.json +192 -0
  83. package/fixtures/histories/continue-as-new-last-result.history.json +86 -0
  84. package/fixtures/histories/continue-as-new-options.history.json +99 -0
  85. package/fixtures/histories/continue-as-new-r1-long-task-queue.history.json +78 -0
  86. package/fixtures/histories/continue-as-new-r1-retry-options.history.json +83 -0
  87. package/fixtures/histories/execution-timeout-chain.history.json +98 -0
  88. package/fixtures/histories/external-cancel-resolved.history.json +123 -0
  89. package/fixtures/histories/external-cancel-unknown-target.history.json +127 -0
  90. package/fixtures/histories/failure-error-types-fails-run.history.json +144 -0
  91. package/fixtures/histories/handler-drain-warn.history.json +222 -0
  92. package/fixtures/histories/heartbeat-details-on-retry.history.json +145 -0
  93. package/fixtures/histories/local-activity-abandoned-at-completion.history.json +73 -0
  94. package/fixtures/histories/local-activity-cancelled-in-scope.history.json +118 -0
  95. package/fixtures/histories/local-activity-completed.history.json +157 -0
  96. package/fixtures/histories/local-activity-failed.history.json +93 -0
  97. package/fixtures/histories/local-activity-retry-in-task.history.json +88 -0
  98. package/fixtures/histories/run-retry-last-failure.history.json +90 -0
  99. package/fixtures/histories/run-timeout.history.json +159 -0
  100. package/fixtures/histories/schedule-to-start-timeout.history.json +132 -0
  101. package/fixtures/histories/start-delay-signal-ends-delay.history.json +155 -0
  102. package/fixtures/histories/typeerror-task-retry-100.history.json +137 -0
  103. package/package.json +1 -1
  104. package/schema/history-file.schema.json +283 -2
  105. package/schema/ir-v2.schema.json +45 -0
  106. package/schema/run-event.schema.json +264 -2
  107. package/schema/workflow-command.schema.json +178 -1
  108. package/schema/workflow-task.schema.json +392 -4
  109. package/dist/assemble-BLqQ8lSu.d.cts +0 -39
  110. package/dist/assemble-DWgaXHd-.d.ts +0 -39
  111. package/dist/chunk-2J6TF7YI.cjs +0 -86
  112. package/dist/chunk-BO6OVILK.js +0 -79
  113. package/dist/chunk-DHTLALBL.cjs +0 -80
  114. package/dist/chunk-I5LR3D2K.js +0 -869
  115. package/dist/chunk-N23SKIG4.js +0 -73
  116. package/dist/chunk-QQ6ULXHI.cjs +0 -885
  117. package/dist/node-evaluator-4MSDKWOG.cjs +0 -22
  118. package/dist/node-evaluator-SX4LEYQC.js +0 -12
@@ -1,12 +1,12 @@
1
- import { h as DurableWorkflow, O as Operation, j as Duration, l as SignalDefinition } from '../workflow-J-yYixny.cjs';
2
- import { i as HistoryFile, m as RunState } from '../file-BOoHZgoQ.cjs';
3
- import { a6 as WorkflowInfoSnapshot, a7 as WorkflowTaskRequest, a8 as WorkflowTaskResult, U as RunEventRecord, F as Failure, V as RunEventType } from '../types-CpBBjaGX.cjs';
4
- import { a as Json, b as WorkflowDefinition, m as WorkflowNode } from '../types-BGoPzgcl.cjs';
5
- import { x as Tier1Workflow } from '../workflow-FXUkpIBc.cjs';
1
+ import { j as Duration, t as WorkflowRetryOptions, h as DurableWorkflow, O as Operation, n as SignalDefinition } from '../workflow-O6e64ZcG.cjs';
2
+ import { C as CommandGate, o as HistoryFile, t as RunState } from '../file-cgL9l9l8.cjs';
3
+ import { ai as WorkflowInfoSnapshot, ah as WorkflowIdReusePolicy, ag as WorkflowIdConflictPolicy, ac as VersioningBehavior, aj as WorkflowTaskRequest, ak as WorkflowTaskResult, Z as RunEventRecord, a8 as UnfinishedHandler, F as Failure, _ as RunEventType } from '../types-CQKOhPTa.cjs';
4
+ import { J as Json, a as JsonObject, W as WorkflowDefinition, m as WorkflowNode } from '../types-Bb2wRnJ5.cjs';
5
+ import { x as Tier1Workflow } from '../workflow-CZOXUlQ5.cjs';
6
6
  import { E as EsbuildApi } from '../lower-types-DQNBfWQn.cjs';
7
7
  import { WorkflowRegistry } from '../runtime/index.cjs';
8
8
  import 'esbuild';
9
- import '../activation-BBh1p82z.cjs';
9
+ import '../activation-CESehfYi.cjs';
10
10
 
11
11
  /**
12
12
  * `TestWorkflowEnvironment` (spec 10 §1): an in-process engine for tier-2
@@ -18,24 +18,41 @@ import '../activation-BBh1p82z.cjs';
18
18
  * the conformance fixtures are recorded with it and then replayed in QuickJS
19
19
  * and in `vm`.
20
20
  *
21
+ * R2 adds local activities (run through `mock`, retried inside the task),
22
+ * start delay, run and execution timeouts and run-level retry on the fake
23
+ * clock, workflow-id policies and workflow-id targets, held activity queues
24
+ * for schedule-to-start timeouts, heartbeat details on retry, and the handler
25
+ * drain check (`failOnUnfinishedHandlers`, default true).
26
+ *
21
27
  * Divergences from the service (documented, accepted for Phase B):
22
28
  * - Workflow tasks run in this process without the determinism shims.
23
29
  * - A failed workflow task is not retried forever: the run stops, and
24
30
  * `result()` rejects with {@link WorkflowTaskFailedError}.
25
31
  * - Every task is a first attempt (no transient attempts), and activity
26
32
  * start-to-close and heartbeat timeouts are not timed; a mock may throw a
27
- * `TimeoutFailure` to simulate one. Schedule-to-close is honoured.
33
+ * `TimeoutFailure` to simulate one. Schedule-to-close is honoured, and
34
+ * schedule-to-start while a node type is held (`holdActivities`).
35
+ * - Local-activity retries do not wait for their backoff: the task's clock
36
+ * is its start time, as in the worker, and the fake clock does not move.
37
+ * - The workflow-task timeout is recorded, not enforced.
28
38
  * - Graph child runs are mocks (`mockChild`).
29
39
  */
30
40
 
31
41
  /** What a mock receives besides the activity's args. */
32
42
  interface ActivityMockInfo {
33
43
  runId: string;
44
+ /** `a<n>` for an activity, `l<n>` for a local activity. */
34
45
  activityId: string;
35
46
  attempt: number;
36
47
  nodeType: string;
37
48
  operation: string;
38
49
  connection?: string;
50
+ /** True when the call is a local activity (`ctx.localActivity`). */
51
+ local?: boolean;
52
+ /** Details the previous attempt recorded with `heartbeat` (11 §2.4); activities only. */
53
+ heartbeatDetails?: Json;
54
+ /** Record heartbeat details for the next attempt (activities only). */
55
+ heartbeat?: (details?: unknown) => void;
39
56
  }
40
57
  type ActivityMock = (args: Json, info: ActivityMockInfo) => unknown;
41
58
  type ChildMock = (input: Json, info: {
@@ -49,8 +66,21 @@ interface TestEnvironmentOptions {
49
66
  startTime?: number | string | Date;
50
67
  /** Tier-2 functions by export name, for `ctx.child(fn)` and by-name starts. */
51
68
  workflows?: Readonly<Record<string, DurableWorkflow<never, unknown>>>;
52
- /** Command set the environment accepts; default `parity`. */
53
- enabled?: 'core' | 'parity';
69
+ /** Command set the environment accepts: a feature set or a release level; default `parity`. */
70
+ enabled?: CommandGate;
71
+ /**
72
+ * Turn the drain warning (a workflow that finishes while a signal handler
73
+ * with policy `WARN_AND_ABANDON` still runs, 11 §2.18) into a failure of
74
+ * `result()` (`UnfinishedHandlersError`). Default true.
75
+ */
76
+ failOnUnfinishedHandlers?: boolean;
77
+ /**
78
+ * The runtime release whose history fields the environment writes (default
79
+ * {@link RUNTIME_RELEASE}). Release 1 omits the R2 start fields that the
80
+ * Phase B core service never wrote (`lastCompletionResult` on a
81
+ * continue-as-new), so R1 conformance histories record unchanged.
82
+ */
83
+ historyRelease?: number;
54
84
  /** Workspace id written into run info. */
55
85
  workspaceId?: string;
56
86
  /**
@@ -71,6 +101,43 @@ interface StartOptions {
71
101
  payload?: unknown;
72
102
  }>;
73
103
  info?: Partial<WorkflowInfoSnapshot>;
104
+ /** The workflow key for workflow-id policies and targets; default the declaration's name. */
105
+ workflowKey?: string;
106
+ /** The business id (11 §2.1); unique among the open runs of the workflow key. */
107
+ workflowId?: string;
108
+ /** Default `ALLOW_DUPLICATE`. */
109
+ idReusePolicy?: WorkflowIdReusePolicy;
110
+ /** Default `FAIL`. */
111
+ idConflictPolicy?: WorkflowIdConflictPolicy;
112
+ /** Delay the first workflow task (11 §2.23); a signal ends the delay. */
113
+ startDelay?: Duration;
114
+ /** Bounds the whole chain; default the declaration's `executionTimeout`. */
115
+ executionTimeout?: Duration;
116
+ /** Bounds one run; default the declaration's `runTimeout`. */
117
+ runTimeout?: Duration;
118
+ /** Recorded only; default the declaration's `workflowTaskTimeout`. */
119
+ workflowTaskTimeout?: Duration;
120
+ /** Run-level retry; default the declaration's `retry`. */
121
+ retry?: WorkflowRetryOptions;
122
+ summary?: string;
123
+ details?: string;
124
+ /** The run's memo (`ctx.info.context`). */
125
+ memo?: JsonObject;
126
+ /** Default the declaration's `versioningBehavior`. */
127
+ versioningBehavior?: VersioningBehavior;
128
+ }
129
+ /** A start found an open run with the same workflow id (`idConflictPolicy: FAIL`) or a refused closed one. */
130
+ declare class WorkflowAlreadyStartedError extends Error {
131
+ readonly workflowKey: string;
132
+ readonly workflowId: string;
133
+ readonly existingRunId: string;
134
+ constructor(workflowKey: string, workflowId: string, existingRunId: string);
135
+ }
136
+ /** The workflow finished while signal handlers still ran (`failOnUnfinishedHandlers`). */
137
+ declare class UnfinishedHandlersError extends Error {
138
+ readonly runId: string;
139
+ readonly handlers: UnfinishedHandler[];
140
+ constructor(runId: string, handlers: UnfinishedHandler[]);
74
141
  }
75
142
  /** A run's workflow failed (`WORKFLOW_FAILED`). */
76
143
  declare class WorkflowFailedError extends Error {
@@ -114,6 +181,10 @@ declare class TestWorkflowEnvironment {
114
181
  private clock;
115
182
  private readonly timeSkipping;
116
183
  private readonly enabled;
184
+ private readonly failOnUnfinishedHandlers;
185
+ private readonly historyRelease;
186
+ private dues;
187
+ private readonly held;
117
188
  private readonly workspaceId;
118
189
  private readonly runs;
119
190
  private readonly runOrder;
@@ -134,10 +205,26 @@ declare class TestWorkflowEnvironment {
134
205
  now(): number;
135
206
  /** Mock a node operation (by node type, and operation when given). */
136
207
  mock<In, Out>(operation: Operation<In, Out> | string, impl: (args: In, info: ActivityMockInfo) => Out | Promise<Out>, operationName?: string): void;
208
+ /**
209
+ * Hold the activity queue of a node type (every node type when omitted):
210
+ * attempts wait instead of starting, and a `scheduleToStartTimeout` expires
211
+ * (`ACTIVITY_TIMED_OUT { timeoutType: SCHEDULE_TO_START }`, not retried).
212
+ */
213
+ holdActivities(nodeType?: string): void;
214
+ /** Release held activity queues (all when no node type is given). */
215
+ releaseActivities(nodeType?: string): void;
216
+ private isHeld;
137
217
  /** Mock a child workflow started by key (graph or durable). */
138
218
  mockChild(workflowKey: string, impl: ChildMock): void;
139
219
  /** Start a run of a tier-2 function (by declaration, or by export name with a task executor). */
140
220
  start<In, Out>(definition: DurableWorkflow<In, Out> | string, options?: StartOptions): Promise<TestRunHandle<Out>>;
221
+ private durationConfig;
222
+ /**
223
+ * The workflow-id policies of a start (11 §2.1): the open run to use, or
224
+ * undefined to start a new run (after terminating the open one for
225
+ * `TERMINATE_EXISTING`). Throws {@link WorkflowAlreadyStartedError}.
226
+ */
227
+ private useExisting;
141
228
  /** Advance the clock by `duration`, firing timers and running work as it comes due. */
142
229
  sleep(duration: Duration): Promise<void>;
143
230
  /** Every run, in start order. */
@@ -150,20 +237,50 @@ declare class TestWorkflowEnvironment {
150
237
  private ensureRegistered;
151
238
  private run;
152
239
  private createRun;
240
+ /** The R2 fields of `WORKFLOW_STARTED`, each written only when it is set. */
241
+ private startedFields;
153
242
  private append;
243
+ /** End a start delay: the first workflow task is scheduled now. */
244
+ private endDelay;
154
245
  deliverSignal(runId: string, name: string, payload: unknown): boolean;
155
246
  requestCancel(runId: string, reason?: string): boolean;
156
247
  terminate(runId: string, reason: string): void;
157
248
  /** Run every runnable task and activity; skip time when allowed and idle. */
158
249
  runUntilIdle(skipTime: boolean): Promise<void>;
250
+ /** When a held attempt's schedule-to-start timeout expires, if it has one. */
251
+ private heldDeadline;
159
252
  private nextDue;
253
+ /** Expire held attempts whose schedule-to-start timeout passed (not retried, 11 §2.3). */
254
+ private expireHeld;
255
+ /** Fire run-level deadlines: the end of a start delay, run and execution timeouts. */
256
+ private fireRunDues;
160
257
  private fireDue;
161
258
  private runTask;
259
+ private execute;
260
+ /**
261
+ * Run a workflow task as the worker does (11 §2.12): while it asks for
262
+ * local activities, run each through its mock and run the same task again
263
+ * with the outcomes, up to 1,000 rounds.
264
+ */
265
+ private executeWithLocalActivities;
266
+ private runLocalActivity;
162
267
  private afterCommand;
268
+ /** What a successor of a run inherits (continue-as-new, run retry). */
269
+ private chainConfig;
270
+ /** Start the next run of a chain; the closed run's parent and handles follow it. */
271
+ private startSuccessor;
163
272
  private resolveTarget;
273
+ /** The open run of a workflow id, else its latest run (11 §2.1). */
274
+ private resolveWorkflowId;
164
275
  private startChild;
165
276
  private runMockedChild;
166
277
  private runAttempt;
278
+ /**
279
+ * Run-level retry (11 §2.17): a failed or run-timed-out run whose policy
280
+ * allows another attempt is followed by a new run of the chain after the
281
+ * backoff, with `runAttempt + 1` and the failure as `lastFailure`.
282
+ */
283
+ private retryRun;
167
284
  private onClosed;
168
285
  resultOf(runId: string): Promise<Json>;
169
286
  /** Every tier-2 function registered, by export name. */
@@ -302,4 +419,4 @@ declare function registryOf(workflows: Readonly<Record<string, DurableWorkflow<n
302
419
  /** Run one workflow task in process. */
303
420
  declare function runWorkflowTaskInProcess(registry: WorkflowRegistry, request: WorkflowTaskRequest): Promise<WorkflowTaskResult>;
304
421
 
305
- export { type ActivityMock, type ActivityMockInfo, type ChildMock, type ExpectedEvent, HistoryAssertionError, type IRSnapshot, type NodeMock, type NodeMockResult, ReplayError, type ReplayInput, RunBlockedError, type SimulateOptions, type SimulatedStep, type SimulationResult, type StartOptions, type TestEnvironmentOptions, TestRunHandle, TestWorkflowEnvironment, WorkflowFailedError, WorkflowTaskFailedError, assertHistory, bundleToScript, drainJobs, expectIR, jsonCopy, registryOf, replay, replayRequest, runWorkflowTaskInProcess, runWorkflowTaskInVm, simulate };
422
+ export { type ActivityMock, type ActivityMockInfo, type ChildMock, type ExpectedEvent, HistoryAssertionError, type IRSnapshot, type NodeMock, type NodeMockResult, ReplayError, type ReplayInput, RunBlockedError, type SimulateOptions, type SimulatedStep, type SimulationResult, type StartOptions, type TestEnvironmentOptions, TestRunHandle, TestWorkflowEnvironment, UnfinishedHandlersError, WorkflowAlreadyStartedError, WorkflowFailedError, WorkflowTaskFailedError, assertHistory, bundleToScript, drainJobs, expectIR, jsonCopy, registryOf, replay, replayRequest, runWorkflowTaskInProcess, runWorkflowTaskInVm, simulate };
@@ -1,12 +1,12 @@
1
- import { h as DurableWorkflow, O as Operation, j as Duration, l as SignalDefinition } from '../workflow-C2a05WUJ.js';
2
- import { i as HistoryFile, m as RunState } from '../file-yuPCFU5b.js';
3
- import { a6 as WorkflowInfoSnapshot, a7 as WorkflowTaskRequest, a8 as WorkflowTaskResult, U as RunEventRecord, F as Failure, V as RunEventType } from '../types-DV-HX_Gt.js';
4
- import { a as Json, b as WorkflowDefinition, m as WorkflowNode } from '../types-BGoPzgcl.js';
5
- import { x as Tier1Workflow } from '../workflow-Bpr3vnA_.js';
1
+ import { j as Duration, t as WorkflowRetryOptions, h as DurableWorkflow, O as Operation, n as SignalDefinition } from '../workflow-DWTPHFbt.js';
2
+ import { C as CommandGate, o as HistoryFile, t as RunState } from '../file-olQudcx5.js';
3
+ import { ai as WorkflowInfoSnapshot, ah as WorkflowIdReusePolicy, ag as WorkflowIdConflictPolicy, ac as VersioningBehavior, aj as WorkflowTaskRequest, ak as WorkflowTaskResult, Z as RunEventRecord, a8 as UnfinishedHandler, F as Failure, _ as RunEventType } from '../types-CnIOinoz.js';
4
+ import { J as Json, a as JsonObject, W as WorkflowDefinition, m as WorkflowNode } from '../types-Bb2wRnJ5.js';
5
+ import { x as Tier1Workflow } from '../workflow-8uRU9rhL.js';
6
6
  import { E as EsbuildApi } from '../lower-types-DQNBfWQn.js';
7
7
  import { WorkflowRegistry } from '../runtime/index.js';
8
8
  import 'esbuild';
9
- import '../activation-DnhG7SmF.js';
9
+ import '../activation-BnVQMv9y.js';
10
10
 
11
11
  /**
12
12
  * `TestWorkflowEnvironment` (spec 10 §1): an in-process engine for tier-2
@@ -18,24 +18,41 @@ import '../activation-DnhG7SmF.js';
18
18
  * the conformance fixtures are recorded with it and then replayed in QuickJS
19
19
  * and in `vm`.
20
20
  *
21
+ * R2 adds local activities (run through `mock`, retried inside the task),
22
+ * start delay, run and execution timeouts and run-level retry on the fake
23
+ * clock, workflow-id policies and workflow-id targets, held activity queues
24
+ * for schedule-to-start timeouts, heartbeat details on retry, and the handler
25
+ * drain check (`failOnUnfinishedHandlers`, default true).
26
+ *
21
27
  * Divergences from the service (documented, accepted for Phase B):
22
28
  * - Workflow tasks run in this process without the determinism shims.
23
29
  * - A failed workflow task is not retried forever: the run stops, and
24
30
  * `result()` rejects with {@link WorkflowTaskFailedError}.
25
31
  * - Every task is a first attempt (no transient attempts), and activity
26
32
  * start-to-close and heartbeat timeouts are not timed; a mock may throw a
27
- * `TimeoutFailure` to simulate one. Schedule-to-close is honoured.
33
+ * `TimeoutFailure` to simulate one. Schedule-to-close is honoured, and
34
+ * schedule-to-start while a node type is held (`holdActivities`).
35
+ * - Local-activity retries do not wait for their backoff: the task's clock
36
+ * is its start time, as in the worker, and the fake clock does not move.
37
+ * - The workflow-task timeout is recorded, not enforced.
28
38
  * - Graph child runs are mocks (`mockChild`).
29
39
  */
30
40
 
31
41
  /** What a mock receives besides the activity's args. */
32
42
  interface ActivityMockInfo {
33
43
  runId: string;
44
+ /** `a<n>` for an activity, `l<n>` for a local activity. */
34
45
  activityId: string;
35
46
  attempt: number;
36
47
  nodeType: string;
37
48
  operation: string;
38
49
  connection?: string;
50
+ /** True when the call is a local activity (`ctx.localActivity`). */
51
+ local?: boolean;
52
+ /** Details the previous attempt recorded with `heartbeat` (11 §2.4); activities only. */
53
+ heartbeatDetails?: Json;
54
+ /** Record heartbeat details for the next attempt (activities only). */
55
+ heartbeat?: (details?: unknown) => void;
39
56
  }
40
57
  type ActivityMock = (args: Json, info: ActivityMockInfo) => unknown;
41
58
  type ChildMock = (input: Json, info: {
@@ -49,8 +66,21 @@ interface TestEnvironmentOptions {
49
66
  startTime?: number | string | Date;
50
67
  /** Tier-2 functions by export name, for `ctx.child(fn)` and by-name starts. */
51
68
  workflows?: Readonly<Record<string, DurableWorkflow<never, unknown>>>;
52
- /** Command set the environment accepts; default `parity`. */
53
- enabled?: 'core' | 'parity';
69
+ /** Command set the environment accepts: a feature set or a release level; default `parity`. */
70
+ enabled?: CommandGate;
71
+ /**
72
+ * Turn the drain warning (a workflow that finishes while a signal handler
73
+ * with policy `WARN_AND_ABANDON` still runs, 11 §2.18) into a failure of
74
+ * `result()` (`UnfinishedHandlersError`). Default true.
75
+ */
76
+ failOnUnfinishedHandlers?: boolean;
77
+ /**
78
+ * The runtime release whose history fields the environment writes (default
79
+ * {@link RUNTIME_RELEASE}). Release 1 omits the R2 start fields that the
80
+ * Phase B core service never wrote (`lastCompletionResult` on a
81
+ * continue-as-new), so R1 conformance histories record unchanged.
82
+ */
83
+ historyRelease?: number;
54
84
  /** Workspace id written into run info. */
55
85
  workspaceId?: string;
56
86
  /**
@@ -71,6 +101,43 @@ interface StartOptions {
71
101
  payload?: unknown;
72
102
  }>;
73
103
  info?: Partial<WorkflowInfoSnapshot>;
104
+ /** The workflow key for workflow-id policies and targets; default the declaration's name. */
105
+ workflowKey?: string;
106
+ /** The business id (11 §2.1); unique among the open runs of the workflow key. */
107
+ workflowId?: string;
108
+ /** Default `ALLOW_DUPLICATE`. */
109
+ idReusePolicy?: WorkflowIdReusePolicy;
110
+ /** Default `FAIL`. */
111
+ idConflictPolicy?: WorkflowIdConflictPolicy;
112
+ /** Delay the first workflow task (11 §2.23); a signal ends the delay. */
113
+ startDelay?: Duration;
114
+ /** Bounds the whole chain; default the declaration's `executionTimeout`. */
115
+ executionTimeout?: Duration;
116
+ /** Bounds one run; default the declaration's `runTimeout`. */
117
+ runTimeout?: Duration;
118
+ /** Recorded only; default the declaration's `workflowTaskTimeout`. */
119
+ workflowTaskTimeout?: Duration;
120
+ /** Run-level retry; default the declaration's `retry`. */
121
+ retry?: WorkflowRetryOptions;
122
+ summary?: string;
123
+ details?: string;
124
+ /** The run's memo (`ctx.info.context`). */
125
+ memo?: JsonObject;
126
+ /** Default the declaration's `versioningBehavior`. */
127
+ versioningBehavior?: VersioningBehavior;
128
+ }
129
+ /** A start found an open run with the same workflow id (`idConflictPolicy: FAIL`) or a refused closed one. */
130
+ declare class WorkflowAlreadyStartedError extends Error {
131
+ readonly workflowKey: string;
132
+ readonly workflowId: string;
133
+ readonly existingRunId: string;
134
+ constructor(workflowKey: string, workflowId: string, existingRunId: string);
135
+ }
136
+ /** The workflow finished while signal handlers still ran (`failOnUnfinishedHandlers`). */
137
+ declare class UnfinishedHandlersError extends Error {
138
+ readonly runId: string;
139
+ readonly handlers: UnfinishedHandler[];
140
+ constructor(runId: string, handlers: UnfinishedHandler[]);
74
141
  }
75
142
  /** A run's workflow failed (`WORKFLOW_FAILED`). */
76
143
  declare class WorkflowFailedError extends Error {
@@ -114,6 +181,10 @@ declare class TestWorkflowEnvironment {
114
181
  private clock;
115
182
  private readonly timeSkipping;
116
183
  private readonly enabled;
184
+ private readonly failOnUnfinishedHandlers;
185
+ private readonly historyRelease;
186
+ private dues;
187
+ private readonly held;
117
188
  private readonly workspaceId;
118
189
  private readonly runs;
119
190
  private readonly runOrder;
@@ -134,10 +205,26 @@ declare class TestWorkflowEnvironment {
134
205
  now(): number;
135
206
  /** Mock a node operation (by node type, and operation when given). */
136
207
  mock<In, Out>(operation: Operation<In, Out> | string, impl: (args: In, info: ActivityMockInfo) => Out | Promise<Out>, operationName?: string): void;
208
+ /**
209
+ * Hold the activity queue of a node type (every node type when omitted):
210
+ * attempts wait instead of starting, and a `scheduleToStartTimeout` expires
211
+ * (`ACTIVITY_TIMED_OUT { timeoutType: SCHEDULE_TO_START }`, not retried).
212
+ */
213
+ holdActivities(nodeType?: string): void;
214
+ /** Release held activity queues (all when no node type is given). */
215
+ releaseActivities(nodeType?: string): void;
216
+ private isHeld;
137
217
  /** Mock a child workflow started by key (graph or durable). */
138
218
  mockChild(workflowKey: string, impl: ChildMock): void;
139
219
  /** Start a run of a tier-2 function (by declaration, or by export name with a task executor). */
140
220
  start<In, Out>(definition: DurableWorkflow<In, Out> | string, options?: StartOptions): Promise<TestRunHandle<Out>>;
221
+ private durationConfig;
222
+ /**
223
+ * The workflow-id policies of a start (11 §2.1): the open run to use, or
224
+ * undefined to start a new run (after terminating the open one for
225
+ * `TERMINATE_EXISTING`). Throws {@link WorkflowAlreadyStartedError}.
226
+ */
227
+ private useExisting;
141
228
  /** Advance the clock by `duration`, firing timers and running work as it comes due. */
142
229
  sleep(duration: Duration): Promise<void>;
143
230
  /** Every run, in start order. */
@@ -150,20 +237,50 @@ declare class TestWorkflowEnvironment {
150
237
  private ensureRegistered;
151
238
  private run;
152
239
  private createRun;
240
+ /** The R2 fields of `WORKFLOW_STARTED`, each written only when it is set. */
241
+ private startedFields;
153
242
  private append;
243
+ /** End a start delay: the first workflow task is scheduled now. */
244
+ private endDelay;
154
245
  deliverSignal(runId: string, name: string, payload: unknown): boolean;
155
246
  requestCancel(runId: string, reason?: string): boolean;
156
247
  terminate(runId: string, reason: string): void;
157
248
  /** Run every runnable task and activity; skip time when allowed and idle. */
158
249
  runUntilIdle(skipTime: boolean): Promise<void>;
250
+ /** When a held attempt's schedule-to-start timeout expires, if it has one. */
251
+ private heldDeadline;
159
252
  private nextDue;
253
+ /** Expire held attempts whose schedule-to-start timeout passed (not retried, 11 §2.3). */
254
+ private expireHeld;
255
+ /** Fire run-level deadlines: the end of a start delay, run and execution timeouts. */
256
+ private fireRunDues;
160
257
  private fireDue;
161
258
  private runTask;
259
+ private execute;
260
+ /**
261
+ * Run a workflow task as the worker does (11 §2.12): while it asks for
262
+ * local activities, run each through its mock and run the same task again
263
+ * with the outcomes, up to 1,000 rounds.
264
+ */
265
+ private executeWithLocalActivities;
266
+ private runLocalActivity;
162
267
  private afterCommand;
268
+ /** What a successor of a run inherits (continue-as-new, run retry). */
269
+ private chainConfig;
270
+ /** Start the next run of a chain; the closed run's parent and handles follow it. */
271
+ private startSuccessor;
163
272
  private resolveTarget;
273
+ /** The open run of a workflow id, else its latest run (11 §2.1). */
274
+ private resolveWorkflowId;
164
275
  private startChild;
165
276
  private runMockedChild;
166
277
  private runAttempt;
278
+ /**
279
+ * Run-level retry (11 §2.17): a failed or run-timed-out run whose policy
280
+ * allows another attempt is followed by a new run of the chain after the
281
+ * backoff, with `runAttempt + 1` and the failure as `lastFailure`.
282
+ */
283
+ private retryRun;
167
284
  private onClosed;
168
285
  resultOf(runId: string): Promise<Json>;
169
286
  /** Every tier-2 function registered, by export name. */
@@ -302,4 +419,4 @@ declare function registryOf(workflows: Readonly<Record<string, DurableWorkflow<n
302
419
  /** Run one workflow task in process. */
303
420
  declare function runWorkflowTaskInProcess(registry: WorkflowRegistry, request: WorkflowTaskRequest): Promise<WorkflowTaskResult>;
304
421
 
305
- export { type ActivityMock, type ActivityMockInfo, type ChildMock, type ExpectedEvent, HistoryAssertionError, type IRSnapshot, type NodeMock, type NodeMockResult, ReplayError, type ReplayInput, RunBlockedError, type SimulateOptions, type SimulatedStep, type SimulationResult, type StartOptions, type TestEnvironmentOptions, TestRunHandle, TestWorkflowEnvironment, WorkflowFailedError, WorkflowTaskFailedError, assertHistory, bundleToScript, drainJobs, expectIR, jsonCopy, registryOf, replay, replayRequest, runWorkflowTaskInProcess, runWorkflowTaskInVm, simulate };
422
+ export { type ActivityMock, type ActivityMockInfo, type ChildMock, type ExpectedEvent, HistoryAssertionError, type IRSnapshot, type NodeMock, type NodeMockResult, ReplayError, type ReplayInput, RunBlockedError, type SimulateOptions, type SimulatedStep, type SimulationResult, type StartOptions, type TestEnvironmentOptions, TestRunHandle, TestWorkflowEnvironment, UnfinishedHandlersError, WorkflowAlreadyStartedError, WorkflowFailedError, WorkflowTaskFailedError, assertHistory, bundleToScript, drainJobs, expectIR, jsonCopy, registryOf, replay, replayRequest, runWorkflowTaskInProcess, runWorkflowTaskInVm, simulate };