@fluidgrids/workflows 2026.1029.1 → 2026.1030.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 +112 -4
  2. package/dist/{activation-CESehfYi.d.cts → activation-DqUfpHzk.d.cts} +1 -1
  3. package/dist/{activation-BnVQMv9y.d.ts → activation-xpx1oWuo.d.ts} +1 -1
  4. package/dist/{chunk-MJ5TGYVG.js → chunk-2D3MYIIF.js} +969 -153
  5. package/dist/{chunk-2B37XAFQ.cjs → chunk-3U2NU7YC.cjs} +24 -11
  6. package/dist/{chunk-NEIUQASE.cjs → chunk-4QKB4ARC.cjs} +3 -3
  7. package/dist/{chunk-GBQ33SIZ.cjs → chunk-54FLQNUM.cjs} +12 -1
  8. package/dist/{chunk-2DDULZFM.js → chunk-5HIVIV53.js} +86 -75
  9. package/dist/chunk-5MFVJM76.js +1222 -0
  10. package/dist/{chunk-EWYADREB.cjs → chunk-672KMMBK.cjs} +2 -2
  11. package/dist/{chunk-KXJDRQ6G.js → chunk-6A2FGSUS.js} +22 -2
  12. package/dist/{chunk-OIX4O6UR.js → chunk-6OLN6BMB.js} +16 -3
  13. package/dist/{chunk-6FSHT5IL.js → chunk-7EZIANC7.js} +1 -1
  14. package/dist/chunk-A5SXCA62.cjs +93 -0
  15. package/dist/chunk-AC6ZEXVR.js +85 -0
  16. package/dist/{chunk-FWBRQWRX.js → chunk-AE5Q6ZAJ.js} +167 -10
  17. package/dist/{chunk-7ILGCUI6.js → chunk-C4F5KJTI.js} +142 -3
  18. package/dist/{chunk-WXXNCHUY.js → chunk-G5H32GIG.js} +1 -1
  19. package/dist/{chunk-OMY3CKUZ.cjs → chunk-GEQDGUGB.cjs} +1042 -226
  20. package/dist/{chunk-25BKWR2O.js → chunk-HCM7ZC7Q.js} +1 -1
  21. package/dist/{chunk-I47EENR4.cjs → chunk-HMZUGSMU.cjs} +673 -156
  22. package/dist/{chunk-NXFBVDOI.cjs → chunk-IQPXHQQQ.cjs} +8 -4
  23. package/dist/{chunk-RUQIMTN5.cjs → chunk-ISOIA7NV.cjs} +178 -15
  24. package/dist/chunk-JSC75O5C.cjs +167 -0
  25. package/dist/{chunk-BD7ZPG53.js → chunk-NWQ5WRLE.js} +10 -2
  26. package/dist/chunk-ODZ2IAR2.cjs +1247 -0
  27. package/dist/{chunk-FQSJI5NV.js → chunk-SR7TR5KX.js} +6 -2
  28. package/dist/{chunk-OKX3FYIM.cjs → chunk-TCTE7DX5.cjs} +3 -3
  29. package/dist/{chunk-3FIDHONL.cjs → chunk-TYF56RGB.cjs} +99 -80
  30. package/dist/{chunk-J3PYFGKA.cjs → chunk-VA4OFR72.cjs} +162 -4
  31. package/dist/chunk-VU5S5A7V.js +150 -0
  32. package/dist/{chunk-A36CCOWS.js → chunk-YEHR4NNE.js} +633 -128
  33. package/dist/{chunk-ELL2RBML.cjs → chunk-ZCGKGDCL.cjs} +23 -1
  34. package/dist/codegen/index.d.cts +2 -2
  35. package/dist/codegen/index.d.ts +2 -2
  36. package/dist/{collect-BTHjQaSp.d.ts → collect-6NIEufHd.d.ts} +20 -3
  37. package/dist/{collect-CSyOg5XC.d.cts → collect-CcTCKqx6.d.cts} +20 -3
  38. package/dist/{file-cgL9l9l8.d.cts → file-BxYpwjRQ.d.cts} +250 -15
  39. package/dist/{file-olQudcx5.d.ts → file-CFdPQJI9.d.ts} +250 -15
  40. package/dist/history/index.cjs +283 -106
  41. package/dist/history/index.d.cts +549 -10
  42. package/dist/history/index.d.ts +549 -10
  43. package/dist/history/index.js +5 -4
  44. package/dist/index.cjs +146 -53
  45. package/dist/index.d.cts +38 -14
  46. package/dist/index.d.ts +38 -14
  47. package/dist/index.js +6 -5
  48. package/dist/interceptors-CNcr2dlk.d.ts +159 -0
  49. package/dist/interceptors-CqkNZVfI.d.cts +159 -0
  50. package/dist/ir/index.cjs +339 -36
  51. package/dist/ir/index.d.cts +244 -8
  52. package/dist/ir/index.d.ts +244 -8
  53. package/dist/ir/index.js +306 -21
  54. package/dist/{lower-3S6PsqjJ.d.cts → lower-BtRfIW2A.d.cts} +23 -9
  55. package/dist/{lower-DmZpQ8hJ.d.ts → lower-CpsMFOFX.d.ts} +23 -9
  56. package/dist/{manifest-BJjrQt77.d.ts → manifest-D-I_twys.d.ts} +1 -1
  57. package/dist/{manifest-gRI2Q5Fj.d.cts → manifest-DahBQVM8.d.cts} +1 -1
  58. package/dist/node-evaluator-DGQDPSPI.cjs +24 -0
  59. package/dist/node-evaluator-LEEVD7H7.js +14 -0
  60. package/dist/payload-fields-BVRQn2yH.d.cts +122 -0
  61. package/dist/payload-fields-oOBWxDiG.d.ts +122 -0
  62. package/dist/quickjs/index.cjs +27 -27
  63. package/dist/quickjs/index.d.cts +6 -6
  64. package/dist/quickjs/index.d.ts +6 -6
  65. package/dist/quickjs/index.js +9 -9
  66. package/dist/roundtrip/index.cjs +72 -66
  67. package/dist/roundtrip/index.d.cts +25 -11
  68. package/dist/roundtrip/index.d.ts +25 -11
  69. package/dist/roundtrip/index.js +13 -11
  70. package/dist/runtime/index.cjs +19 -19
  71. package/dist/runtime/index.d.cts +139 -12
  72. package/dist/runtime/index.d.ts +139 -12
  73. package/dist/runtime/index.js +6 -6
  74. package/dist/testing/index.cjs +688 -121
  75. package/dist/testing/index.d.cts +174 -10
  76. package/dist/testing/index.d.ts +174 -10
  77. package/dist/testing/index.js +646 -82
  78. package/dist/{types-CnIOinoz.d.ts → types-Bv2i4cBX.d.cts} +126 -23
  79. package/dist/{types-CQKOhPTa.d.cts → types-DGx-b9eq.d.ts} +126 -23
  80. package/dist/{types-Bb2wRnJ5.d.cts → types-V7jEEUaL.d.cts} +1 -1
  81. package/dist/{types-Bb2wRnJ5.d.ts → types-V7jEEUaL.d.ts} +1 -1
  82. package/dist/{workflow-8uRU9rhL.d.ts → workflow-B18OeF7g.d.ts} +2 -2
  83. package/dist/{workflow-DWTPHFbt.d.ts → workflow-BGnv8SS6.d.ts} +261 -14
  84. package/dist/{workflow-CZOXUlQ5.d.cts → workflow-BJPFv3cp.d.cts} +2 -2
  85. package/dist/{workflow-O6e64ZcG.d.cts → workflow-DS32Gtws.d.cts} +261 -14
  86. package/fixtures/histories/activity-options-updated.history.json +159 -0
  87. package/fixtures/histories/activity-paused-unpaused.history.json +160 -0
  88. package/fixtures/histories/codec-opaque.history.json +229 -0
  89. package/fixtures/histories/dynamic-workflow.history.json +150 -0
  90. package/fixtures/histories/interceptor-headers.history.json +339 -0
  91. package/fixtures/histories/query-custom.history.json +213 -0
  92. package/fixtures/histories/query-default-handler.history.json +120 -0
  93. package/fixtures/histories/reset-forked-reapplied-signals.history.json +239 -0
  94. package/fixtures/histories/reset-reapplied-update-admitted.history.json +228 -0
  95. package/fixtures/histories/search-attributes-upserted.history.json +177 -0
  96. package/fixtures/histories/update-accepted-completed.history.json +45 -30
  97. package/fixtures/histories/update-default-handler.history.json +246 -0
  98. package/fixtures/histories/update-handler-awaits-activity.history.json +196 -0
  99. package/fixtures/histories/update-not-handled.history.json +138 -0
  100. package/fixtures/histories/update-rejected-no-event.history.json +190 -0
  101. package/fixtures/histories/update-with-start-admitted.history.json +150 -0
  102. package/fixtures/histories/user-activity-cancel.history.json +149 -0
  103. package/fixtures/histories/user-activity-retry.history.json +143 -0
  104. package/fixtures/histories/user-activity.history.json +149 -0
  105. package/package.json +1 -1
  106. package/schema/bridge-v2.schema.json +1062 -0
  107. package/schema/history-file.schema.json +255 -81
  108. package/schema/ir-v2.schema.json +246 -1
  109. package/schema/payload-fields.json +162 -0
  110. package/schema/run-event.schema.json +239 -80
  111. package/schema/workflow-command.schema.json +210 -84
  112. package/schema/workflow-task.schema.json +532 -167
  113. package/dist/chunk-6QPOJZT6.cjs +0 -1180
  114. package/dist/chunk-A2OHX3UQ.js +0 -1156
  115. package/dist/chunk-PWIUEWC3.js +0 -81
  116. package/dist/chunk-YHBVMOMK.cjs +0 -87
  117. package/dist/node-evaluator-SOADN23V.js +0 -14
  118. package/dist/node-evaluator-YGDEXK4U.cjs +0 -24
@@ -1,12 +1,13 @@
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';
1
+ import { x as Duration, X as WorkflowRetryOptions, v as DurableWorkflow, h as ActivityImplementation, i as ActivityInboundInterceptor, e as ActivityDefinition, c as ActivityContext, O as Operation, U as UpdateDefinition, Q as QueryDefinition, G as SignalDefinition } from '../workflow-DS32Gtws.cjs';
2
+ import { k as WorkflowInterceptorsFactory, M as MarkedInterceptorsFactory } from '../interceptors-CqkNZVfI.cjs';
3
+ import { C as CommandGate, p as HistoryFile, x as RunState } from '../file-BxYpwjRQ.cjs';
4
+ import { b as WorkflowInfoSnapshot, ay as WorkflowIdReusePolicy, ax as WorkflowIdConflictPolicy, at as VersioningBehavior, M as Headers, az as WorkflowTaskRequest, aA as WorkflowTaskResult, F as Failure, aj as SinkCall, R as RunEventRecord, U as UnfinishedHandler, ac as RunEventType } from '../types-Bv2i4cBX.cjs';
5
+ import { a as Json, J as JsonObject, W as WorkflowDefinition, m as WorkflowNode } from '../types-V7jEEUaL.cjs';
6
+ import { x as Tier1Workflow } from '../workflow-BJPFv3cp.cjs';
6
7
  import { E as EsbuildApi } from '../lower-types-DQNBfWQn.cjs';
7
8
  import { WorkflowRegistry } from '../runtime/index.cjs';
8
9
  import 'esbuild';
9
- import '../activation-CESehfYi.cjs';
10
+ import '../activation-DqUfpHzk.cjs';
10
11
 
11
12
  /**
12
13
  * `TestWorkflowEnvironment` (spec 10 §1): an in-process engine for tier-2
@@ -24,6 +25,12 @@ import '../activation-CESehfYi.cjs';
24
25
  * for schedule-to-start timeouts, heartbeat details on retry, and the handler
25
26
  * drain check (`failOnUnfinishedHandlers`, default true).
26
27
  *
28
+ * C-R1 (Phase C) adds updates (`update`, update-with-start), custom queries
29
+ * (`query`), reset (`reset`, a forked run with signals and updates
30
+ * re-applied), user activities (`registerActivity`, `mockActivity`, async
31
+ * completion), search attributes and headers at the start, workflow
32
+ * interceptors, activity interceptors and sinks.
33
+ *
27
34
  * Divergences from the service (documented, accepted for Phase B):
28
35
  * - Workflow tasks run in this process without the determinism shims.
29
36
  * - A failed workflow task is not retried forever: the run stops, and
@@ -36,6 +43,9 @@ import '../activation-CESehfYi.cjs';
36
43
  * is its start time, as in the worker, and the fake clock does not move.
37
44
  * - The workflow-task timeout is recorded, not enforced.
38
45
  * - Graph child runs are mocks (`mockChild`).
46
+ * - Task queues are not checked: a user activity runs on any queue (the
47
+ * service refuses one on `managed`), and paused activities, pause rules
48
+ * and activity options updates are service operations without a test form.
39
49
  */
40
50
 
41
51
  /** What a mock receives besides the activity's args. */
@@ -91,6 +101,61 @@ interface TestEnvironmentOptions {
91
101
  taskExecutor?: (request: WorkflowTaskRequest) => Promise<WorkflowTaskResult> | WorkflowTaskResult;
92
102
  /** Workflow keys of tier-2 functions (key -> export name), for `ctx.child('<key>')` with a task executor. */
93
103
  workflowKeys?: Readonly<Record<string, string>>;
104
+ /** Workflow interceptors, as a bundle would export them as `interceptors` (in-process tasks only). */
105
+ interceptors?: WorkflowInterceptorsFactory | MarkedInterceptorsFactory;
106
+ /** User-activity implementations (`implementActivity`, `defineActivity`, `dynamicActivity`). */
107
+ activities?: ReadonlyArray<ActivityImplementation<never, unknown>>;
108
+ /** Activity inbound interceptors around every user activity, first outermost. */
109
+ activityInterceptors?: readonly ActivityInboundInterceptor[];
110
+ /** Connections `ActivityContext.connection(name)` returns. */
111
+ connections?: Readonly<Record<string, Record<string, Json>>>;
112
+ /** Sink implementations called with each task's sink calls after the task completes. */
113
+ sinks?: Readonly<Record<string, Readonly<Record<string, (...args: Json[]) => void>>>>;
114
+ }
115
+ /** The state of an update (Phase C, 05 §6). */
116
+ type UpdateStatus = 'PENDING' | 'ACCEPTED' | 'REJECTED' | 'COMPLETED';
117
+ /** What `update` returns (`UpdateResult` of `updateWorkflowRun`). */
118
+ interface UpdateResult {
119
+ updateId: string;
120
+ status: UpdateStatus;
121
+ result?: Json;
122
+ failure?: Failure;
123
+ }
124
+ /** Options of `update`. */
125
+ interface UpdateOptions {
126
+ /** Idempotency: a repeat with the same id returns the first result. Default `u<n>`. */
127
+ updateId?: string;
128
+ /** `COMPLETED` (default) runs until idle, `ACCEPTED` returns once the update is accepted. */
129
+ waitFor?: 'ACCEPTED' | 'COMPLETED';
130
+ headers?: Headers;
131
+ }
132
+ /** Options of `reset` (11 §2.7). */
133
+ interface ResetOptions {
134
+ /** The last `WORKFLOW_TASK_COMPLETED` at or before this seq is the reset point. */
135
+ toSeq?: number;
136
+ /** `FIRST_TASK` or `LAST_TASK` (default) instead of a seq. */
137
+ to?: 'FIRST_TASK' | 'LAST_TASK';
138
+ reason?: string;
139
+ /** Re-append signals received after the reset point (default true). */
140
+ reapplySignals?: boolean;
141
+ /** Re-append updates accepted after the reset point as `UPDATE_ADMITTED` (default true). */
142
+ reapplyUpdates?: boolean;
143
+ }
144
+ /** A query found no handler (`rejected`, `VALIDATION`). */
145
+ declare class QueryRejectedError extends Error {
146
+ readonly runId: string;
147
+ readonly queryName: string;
148
+ constructor(runId: string, queryName: string, message: string);
149
+ }
150
+ /** A query handler threw, or the replay failed. */
151
+ declare class QueryFailedError extends Error {
152
+ readonly runId: string;
153
+ readonly queryName: string;
154
+ constructor(runId: string, queryName: string, message: string);
155
+ }
156
+ /** An update to a run that is not open, or an update-with-start on a delayed start. */
157
+ declare class UpdateRefusedError extends Error {
158
+ constructor(message: string);
94
159
  }
95
160
  interface StartOptions {
96
161
  input?: unknown;
@@ -125,6 +190,20 @@ interface StartOptions {
125
190
  memo?: JsonObject;
126
191
  /** Default the declaration's `versioningBehavior`. */
127
192
  versioningBehavior?: VersioningBehavior;
193
+ /** Headers of the start (`WORKFLOW_STARTED.headers`, interceptors). */
194
+ headers?: Headers;
195
+ /** Search attributes at the start (Phase C). */
196
+ searchAttributes?: JsonObject;
197
+ /** Fairness of the run's tasks (Phase C). */
198
+ fairnessKey?: string;
199
+ fairnessWeight?: number;
200
+ /** Update-with-start (11 §2.6): admitted right after `WORKFLOW_STARTED`. */
201
+ update?: {
202
+ name: string;
203
+ args?: unknown;
204
+ updateId?: string;
205
+ headers?: Headers;
206
+ };
128
207
  }
129
208
  /** A start found an open run with the same workflow id (`idConflictPolicy: FAIL`) or a refused closed one. */
130
209
  declare class WorkflowAlreadyStartedError extends Error {
@@ -171,6 +250,14 @@ declare class TestRunHandle<Out = Json> {
171
250
  cancel(reason?: string): Promise<void>;
172
251
  /** Terminate the run without running code. */
173
252
  terminate(reason?: string): Promise<void>;
253
+ /** Send an update and run until idle (Phase C). */
254
+ update<Args, Result>(update: UpdateDefinition<Args, Result> | string, args?: Args, options?: UpdateOptions): Promise<UpdateResult>;
255
+ /** Answer a query from the run's history (Phase C custom queries and the built-ins). */
256
+ query<Result, Args>(query: QueryDefinition<Result, Args> | string, args?: Args): Promise<Result>;
257
+ /** Reset the run (11 §2.7): a new run forked at a completed task; this one is terminated. */
258
+ reset(options?: ResetOptions): Promise<TestRunHandle<Out>>;
259
+ /** Sink calls the run's tasks made (Phase C). */
260
+ sinkCalls(): SinkCall[];
174
261
  /** Run until this run (or the last run of its continue-as-new chain) ends; its output. */
175
262
  result(): Promise<Out>;
176
263
  /** The projected state of the run. */
@@ -181,6 +268,8 @@ declare class TestWorkflowEnvironment {
181
268
  private clock;
182
269
  private readonly timeSkipping;
183
270
  private readonly enabled;
271
+ /** The bundle features the gate's flags enable, sent with every task (`request.features`). */
272
+ private readonly codeFeatures;
184
273
  private readonly failOnUnfinishedHandlers;
185
274
  private readonly historyRelease;
186
275
  private dues;
@@ -196,9 +285,21 @@ declare class TestWorkflowEnvironment {
196
285
  private timers;
197
286
  private mockedChildren;
198
287
  private runCounter;
288
+ private updateCounter;
199
289
  private readonly executor;
200
290
  private readonly workflowKeys;
291
+ private readonly interceptors;
292
+ private readonly activityImpls;
293
+ private readonly activityInterceptors;
294
+ private readonly connections;
295
+ private readonly sinks;
296
+ /** Attempts that handed their completion to an outside system (`completeAsync`), by token. */
297
+ private readonly asyncAttempts;
201
298
  private constructor();
299
+ /** Register a user-activity implementation (Phase C). A later one replaces an earlier of the same name. */
300
+ registerActivity(implementation: ActivityImplementation<never, unknown>): void;
301
+ /** Mock a user activity by name or declaration (Phase C). */
302
+ mockActivity<In, Out>(activity: ActivityDefinition<In, Out> | string, fn: (args: In, ctx: ActivityContext) => Out | Promise<Out>): void;
202
303
  /** Create an environment. */
203
304
  static create(options?: TestEnvironmentOptions): Promise<TestWorkflowEnvironment>;
204
305
  /** The fake clock, in epoch milliseconds. */
@@ -213,11 +314,53 @@ declare class TestWorkflowEnvironment {
213
314
  holdActivities(nodeType?: string): void;
214
315
  /** Release held activity queues (all when no node type is given). */
215
316
  releaseActivities(nodeType?: string): void;
317
+ /** The hold key of an attempt: its node type, or the task queue of a user activity. */
318
+ private holdKeyOf;
216
319
  private isHeld;
217
320
  /** Mock a child workflow started by key (graph or durable). */
218
321
  mockChild(workflowKey: string, impl: ChildMock): void;
219
322
  /** Start a run of a tier-2 function (by declaration, or by export name with a task executor). */
220
323
  start<In, Out>(definition: DurableWorkflow<In, Out> | string, options?: StartOptions): Promise<TestRunHandle<Out>>;
324
+ /**
325
+ * Update-with-start (11 §2.6): start the run (or, with
326
+ * `idConflictPolicy: USE_EXISTING`, reach the open one) and deliver the
327
+ * update before any other task runs.
328
+ */
329
+ startWithUpdate<In, Out>(definition: DurableWorkflow<In, Out> | string, options: StartOptions & {
330
+ update: NonNullable<StartOptions['update']>;
331
+ }): Promise<{
332
+ handle: TestRunHandle<Out>;
333
+ update: UpdateResult;
334
+ }>;
335
+ private nextUpdateId;
336
+ /** A new update row (not attached to a run yet). */
337
+ private newUpdate;
338
+ /** Record an update on a run: pending (delivered by the next task) or admitted into history. */
339
+ private addUpdate;
340
+ /** Schedule a workflow task for a run that has none (an update needs no input event). */
341
+ private scheduleTask;
342
+ /**
343
+ * Send an update to a run and run until idle (Phase C, 05 §6). The result
344
+ * is `REJECTED` (the validator refused it or no handler took it; nothing is
345
+ * written to history), `COMPLETED`, or `ACCEPTED` while its handler still
346
+ * waits (for a timer without time skipping, or with `waitFor: ACCEPTED`).
347
+ */
348
+ update<Args, Result>(runId: string, update: UpdateDefinition<Args, Result> | string, args?: Args, options?: UpdateOptions): Promise<UpdateResult>;
349
+ /** The current result of an update. */
350
+ updateResultOf(runId: string, updateId: string): UpdateResult;
351
+ /** Answer a query from the run's history (a replay-only `query` task). */
352
+ query(runId: string, query: QueryDefinition<unknown, unknown> | string, args?: unknown): Promise<Json>;
353
+ /** Sink calls the run's tasks made. */
354
+ sinkCallsOf(runId: string): SinkCall[];
355
+ /**
356
+ * Reset a run (11 §2.7): a new run whose history is the original's up to
357
+ * and including the chosen completed workflow task (with its commands),
358
+ * then `WORKFLOW_RESET`, then the signals (and, as `UPDATE_ADMITTED`, the
359
+ * accepted updates) received after that point. The original is terminated
360
+ * with reason `RESET`; children it started before the point follow the new
361
+ * run, the others get their parent-close policy. Returns the new run id.
362
+ */
363
+ reset(runId: string, options?: ResetOptions): Promise<string>;
221
364
  private durationConfig;
222
365
  /**
223
366
  * The workflow-id policies of a start (11 §2.1): the open run to use, or
@@ -242,7 +385,7 @@ declare class TestWorkflowEnvironment {
242
385
  private append;
243
386
  /** End a start delay: the first workflow task is scheduled now. */
244
387
  private endDelay;
245
- deliverSignal(runId: string, name: string, payload: unknown): boolean;
388
+ deliverSignal(runId: string, name: string, payload: unknown, headers?: Headers): boolean;
246
389
  requestCancel(runId: string, reason?: string): boolean;
247
390
  terminate(runId: string, reason: string): void;
248
391
  /** Run every runnable task and activity; skip time when allowed and idle. */
@@ -256,6 +399,10 @@ declare class TestWorkflowEnvironment {
256
399
  private fireRunDues;
257
400
  private fireDue;
258
401
  private runTask;
402
+ /** What a task's update replies mean for the run's update rows. */
403
+ private recordUpdateReplies;
404
+ /** Keep a task's sink calls and call the configured sinks with them. */
405
+ private runSinks;
259
406
  private execute;
260
407
  /**
261
408
  * Run a workflow task as the worker does (11 §2.12): while it asks for
@@ -275,12 +422,26 @@ declare class TestWorkflowEnvironment {
275
422
  private startChild;
276
423
  private runMockedChild;
277
424
  private runAttempt;
425
+ /** The `ActivityContext` of one user-activity attempt. */
426
+ private activityContext;
427
+ /** Complete an activity that called `completeAsync()` (`completeActivityAsync`). */
428
+ completeActivityAsync(token: string, result?: unknown): Promise<void>;
429
+ /** Fail an activity that called `completeAsync()` (`failActivityAsync`); the retry policy applies. */
430
+ failActivityAsync(token: string, error: unknown): Promise<void>;
431
+ private takeAsync;
432
+ /** Record an attempt's outcome: completion, a final failure or timeout, or the next attempt. */
433
+ private finishAttempt;
278
434
  /**
279
435
  * Run-level retry (11 §2.17): a failed or run-timed-out run whose policy
280
436
  * allows another attempt is followed by a new run of the chain after the
281
437
  * backoff, with `runAttempt + 1` and the failure as `lastFailure`.
282
438
  */
283
439
  private retryRun;
440
+ /**
441
+ * A run closed: drop its pending work, retry it, apply the parent-close
442
+ * policy to its children (except `keptChildren`, which follow a reset
443
+ * fork), settle its open updates and notify its parent.
444
+ */
284
445
  private onClosed;
285
446
  resultOf(runId: string): Promise<Json>;
286
447
  /** Every tier-2 function registered, by export name. */
@@ -414,9 +575,12 @@ declare function runWorkflowTaskInVm(script: string, request: WorkflowTaskReques
414
575
 
415
576
  /** Let every queued promise job run. */
416
577
  declare function drainJobs(): Promise<void>;
417
- /** A registry from export names to workflow functions. */
418
- declare function registryOf(workflows: Readonly<Record<string, DurableWorkflow<never, unknown>>>): WorkflowRegistry;
578
+ /**
579
+ * A registry from export names to workflow functions, with the workflow
580
+ * interceptors a bundle would export as `interceptors`.
581
+ */
582
+ declare function registryOf(workflows: Readonly<Record<string, DurableWorkflow<never, unknown>>>, interceptors?: WorkflowInterceptorsFactory | MarkedInterceptorsFactory): WorkflowRegistry;
419
583
  /** Run one workflow task in process. */
420
584
  declare function runWorkflowTaskInProcess(registry: WorkflowRegistry, request: WorkflowTaskRequest): Promise<WorkflowTaskResult>;
421
585
 
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 };
586
+ export { type ActivityMock, type ActivityMockInfo, type ChildMock, type ExpectedEvent, HistoryAssertionError, type IRSnapshot, type NodeMock, type NodeMockResult, QueryFailedError, QueryRejectedError, ReplayError, type ReplayInput, type ResetOptions, RunBlockedError, type SimulateOptions, type SimulatedStep, type SimulationResult, type StartOptions, type TestEnvironmentOptions, TestRunHandle, TestWorkflowEnvironment, UnfinishedHandlersError, type UpdateOptions, UpdateRefusedError, type UpdateResult, type UpdateStatus, WorkflowAlreadyStartedError, WorkflowFailedError, WorkflowTaskFailedError, assertHistory, bundleToScript, drainJobs, expectIR, jsonCopy, registryOf, replay, replayRequest, runWorkflowTaskInProcess, runWorkflowTaskInVm, simulate };
@@ -1,12 +1,13 @@
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';
1
+ import { x as Duration, X as WorkflowRetryOptions, v as DurableWorkflow, h as ActivityImplementation, i as ActivityInboundInterceptor, e as ActivityDefinition, c as ActivityContext, O as Operation, U as UpdateDefinition, Q as QueryDefinition, G as SignalDefinition } from '../workflow-BGnv8SS6.js';
2
+ import { k as WorkflowInterceptorsFactory, M as MarkedInterceptorsFactory } from '../interceptors-CNcr2dlk.js';
3
+ import { C as CommandGate, p as HistoryFile, x as RunState } from '../file-CFdPQJI9.js';
4
+ import { b as WorkflowInfoSnapshot, ay as WorkflowIdReusePolicy, ax as WorkflowIdConflictPolicy, at as VersioningBehavior, M as Headers, az as WorkflowTaskRequest, aA as WorkflowTaskResult, F as Failure, aj as SinkCall, R as RunEventRecord, U as UnfinishedHandler, ac as RunEventType } from '../types-DGx-b9eq.js';
5
+ import { a as Json, J as JsonObject, W as WorkflowDefinition, m as WorkflowNode } from '../types-V7jEEUaL.js';
6
+ import { x as Tier1Workflow } from '../workflow-B18OeF7g.js';
6
7
  import { E as EsbuildApi } from '../lower-types-DQNBfWQn.js';
7
8
  import { WorkflowRegistry } from '../runtime/index.js';
8
9
  import 'esbuild';
9
- import '../activation-BnVQMv9y.js';
10
+ import '../activation-xpx1oWuo.js';
10
11
 
11
12
  /**
12
13
  * `TestWorkflowEnvironment` (spec 10 §1): an in-process engine for tier-2
@@ -24,6 +25,12 @@ import '../activation-BnVQMv9y.js';
24
25
  * for schedule-to-start timeouts, heartbeat details on retry, and the handler
25
26
  * drain check (`failOnUnfinishedHandlers`, default true).
26
27
  *
28
+ * C-R1 (Phase C) adds updates (`update`, update-with-start), custom queries
29
+ * (`query`), reset (`reset`, a forked run with signals and updates
30
+ * re-applied), user activities (`registerActivity`, `mockActivity`, async
31
+ * completion), search attributes and headers at the start, workflow
32
+ * interceptors, activity interceptors and sinks.
33
+ *
27
34
  * Divergences from the service (documented, accepted for Phase B):
28
35
  * - Workflow tasks run in this process without the determinism shims.
29
36
  * - A failed workflow task is not retried forever: the run stops, and
@@ -36,6 +43,9 @@ import '../activation-BnVQMv9y.js';
36
43
  * is its start time, as in the worker, and the fake clock does not move.
37
44
  * - The workflow-task timeout is recorded, not enforced.
38
45
  * - Graph child runs are mocks (`mockChild`).
46
+ * - Task queues are not checked: a user activity runs on any queue (the
47
+ * service refuses one on `managed`), and paused activities, pause rules
48
+ * and activity options updates are service operations without a test form.
39
49
  */
40
50
 
41
51
  /** What a mock receives besides the activity's args. */
@@ -91,6 +101,61 @@ interface TestEnvironmentOptions {
91
101
  taskExecutor?: (request: WorkflowTaskRequest) => Promise<WorkflowTaskResult> | WorkflowTaskResult;
92
102
  /** Workflow keys of tier-2 functions (key -> export name), for `ctx.child('<key>')` with a task executor. */
93
103
  workflowKeys?: Readonly<Record<string, string>>;
104
+ /** Workflow interceptors, as a bundle would export them as `interceptors` (in-process tasks only). */
105
+ interceptors?: WorkflowInterceptorsFactory | MarkedInterceptorsFactory;
106
+ /** User-activity implementations (`implementActivity`, `defineActivity`, `dynamicActivity`). */
107
+ activities?: ReadonlyArray<ActivityImplementation<never, unknown>>;
108
+ /** Activity inbound interceptors around every user activity, first outermost. */
109
+ activityInterceptors?: readonly ActivityInboundInterceptor[];
110
+ /** Connections `ActivityContext.connection(name)` returns. */
111
+ connections?: Readonly<Record<string, Record<string, Json>>>;
112
+ /** Sink implementations called with each task's sink calls after the task completes. */
113
+ sinks?: Readonly<Record<string, Readonly<Record<string, (...args: Json[]) => void>>>>;
114
+ }
115
+ /** The state of an update (Phase C, 05 §6). */
116
+ type UpdateStatus = 'PENDING' | 'ACCEPTED' | 'REJECTED' | 'COMPLETED';
117
+ /** What `update` returns (`UpdateResult` of `updateWorkflowRun`). */
118
+ interface UpdateResult {
119
+ updateId: string;
120
+ status: UpdateStatus;
121
+ result?: Json;
122
+ failure?: Failure;
123
+ }
124
+ /** Options of `update`. */
125
+ interface UpdateOptions {
126
+ /** Idempotency: a repeat with the same id returns the first result. Default `u<n>`. */
127
+ updateId?: string;
128
+ /** `COMPLETED` (default) runs until idle, `ACCEPTED` returns once the update is accepted. */
129
+ waitFor?: 'ACCEPTED' | 'COMPLETED';
130
+ headers?: Headers;
131
+ }
132
+ /** Options of `reset` (11 §2.7). */
133
+ interface ResetOptions {
134
+ /** The last `WORKFLOW_TASK_COMPLETED` at or before this seq is the reset point. */
135
+ toSeq?: number;
136
+ /** `FIRST_TASK` or `LAST_TASK` (default) instead of a seq. */
137
+ to?: 'FIRST_TASK' | 'LAST_TASK';
138
+ reason?: string;
139
+ /** Re-append signals received after the reset point (default true). */
140
+ reapplySignals?: boolean;
141
+ /** Re-append updates accepted after the reset point as `UPDATE_ADMITTED` (default true). */
142
+ reapplyUpdates?: boolean;
143
+ }
144
+ /** A query found no handler (`rejected`, `VALIDATION`). */
145
+ declare class QueryRejectedError extends Error {
146
+ readonly runId: string;
147
+ readonly queryName: string;
148
+ constructor(runId: string, queryName: string, message: string);
149
+ }
150
+ /** A query handler threw, or the replay failed. */
151
+ declare class QueryFailedError extends Error {
152
+ readonly runId: string;
153
+ readonly queryName: string;
154
+ constructor(runId: string, queryName: string, message: string);
155
+ }
156
+ /** An update to a run that is not open, or an update-with-start on a delayed start. */
157
+ declare class UpdateRefusedError extends Error {
158
+ constructor(message: string);
94
159
  }
95
160
  interface StartOptions {
96
161
  input?: unknown;
@@ -125,6 +190,20 @@ interface StartOptions {
125
190
  memo?: JsonObject;
126
191
  /** Default the declaration's `versioningBehavior`. */
127
192
  versioningBehavior?: VersioningBehavior;
193
+ /** Headers of the start (`WORKFLOW_STARTED.headers`, interceptors). */
194
+ headers?: Headers;
195
+ /** Search attributes at the start (Phase C). */
196
+ searchAttributes?: JsonObject;
197
+ /** Fairness of the run's tasks (Phase C). */
198
+ fairnessKey?: string;
199
+ fairnessWeight?: number;
200
+ /** Update-with-start (11 §2.6): admitted right after `WORKFLOW_STARTED`. */
201
+ update?: {
202
+ name: string;
203
+ args?: unknown;
204
+ updateId?: string;
205
+ headers?: Headers;
206
+ };
128
207
  }
129
208
  /** A start found an open run with the same workflow id (`idConflictPolicy: FAIL`) or a refused closed one. */
130
209
  declare class WorkflowAlreadyStartedError extends Error {
@@ -171,6 +250,14 @@ declare class TestRunHandle<Out = Json> {
171
250
  cancel(reason?: string): Promise<void>;
172
251
  /** Terminate the run without running code. */
173
252
  terminate(reason?: string): Promise<void>;
253
+ /** Send an update and run until idle (Phase C). */
254
+ update<Args, Result>(update: UpdateDefinition<Args, Result> | string, args?: Args, options?: UpdateOptions): Promise<UpdateResult>;
255
+ /** Answer a query from the run's history (Phase C custom queries and the built-ins). */
256
+ query<Result, Args>(query: QueryDefinition<Result, Args> | string, args?: Args): Promise<Result>;
257
+ /** Reset the run (11 §2.7): a new run forked at a completed task; this one is terminated. */
258
+ reset(options?: ResetOptions): Promise<TestRunHandle<Out>>;
259
+ /** Sink calls the run's tasks made (Phase C). */
260
+ sinkCalls(): SinkCall[];
174
261
  /** Run until this run (or the last run of its continue-as-new chain) ends; its output. */
175
262
  result(): Promise<Out>;
176
263
  /** The projected state of the run. */
@@ -181,6 +268,8 @@ declare class TestWorkflowEnvironment {
181
268
  private clock;
182
269
  private readonly timeSkipping;
183
270
  private readonly enabled;
271
+ /** The bundle features the gate's flags enable, sent with every task (`request.features`). */
272
+ private readonly codeFeatures;
184
273
  private readonly failOnUnfinishedHandlers;
185
274
  private readonly historyRelease;
186
275
  private dues;
@@ -196,9 +285,21 @@ declare class TestWorkflowEnvironment {
196
285
  private timers;
197
286
  private mockedChildren;
198
287
  private runCounter;
288
+ private updateCounter;
199
289
  private readonly executor;
200
290
  private readonly workflowKeys;
291
+ private readonly interceptors;
292
+ private readonly activityImpls;
293
+ private readonly activityInterceptors;
294
+ private readonly connections;
295
+ private readonly sinks;
296
+ /** Attempts that handed their completion to an outside system (`completeAsync`), by token. */
297
+ private readonly asyncAttempts;
201
298
  private constructor();
299
+ /** Register a user-activity implementation (Phase C). A later one replaces an earlier of the same name. */
300
+ registerActivity(implementation: ActivityImplementation<never, unknown>): void;
301
+ /** Mock a user activity by name or declaration (Phase C). */
302
+ mockActivity<In, Out>(activity: ActivityDefinition<In, Out> | string, fn: (args: In, ctx: ActivityContext) => Out | Promise<Out>): void;
202
303
  /** Create an environment. */
203
304
  static create(options?: TestEnvironmentOptions): Promise<TestWorkflowEnvironment>;
204
305
  /** The fake clock, in epoch milliseconds. */
@@ -213,11 +314,53 @@ declare class TestWorkflowEnvironment {
213
314
  holdActivities(nodeType?: string): void;
214
315
  /** Release held activity queues (all when no node type is given). */
215
316
  releaseActivities(nodeType?: string): void;
317
+ /** The hold key of an attempt: its node type, or the task queue of a user activity. */
318
+ private holdKeyOf;
216
319
  private isHeld;
217
320
  /** Mock a child workflow started by key (graph or durable). */
218
321
  mockChild(workflowKey: string, impl: ChildMock): void;
219
322
  /** Start a run of a tier-2 function (by declaration, or by export name with a task executor). */
220
323
  start<In, Out>(definition: DurableWorkflow<In, Out> | string, options?: StartOptions): Promise<TestRunHandle<Out>>;
324
+ /**
325
+ * Update-with-start (11 §2.6): start the run (or, with
326
+ * `idConflictPolicy: USE_EXISTING`, reach the open one) and deliver the
327
+ * update before any other task runs.
328
+ */
329
+ startWithUpdate<In, Out>(definition: DurableWorkflow<In, Out> | string, options: StartOptions & {
330
+ update: NonNullable<StartOptions['update']>;
331
+ }): Promise<{
332
+ handle: TestRunHandle<Out>;
333
+ update: UpdateResult;
334
+ }>;
335
+ private nextUpdateId;
336
+ /** A new update row (not attached to a run yet). */
337
+ private newUpdate;
338
+ /** Record an update on a run: pending (delivered by the next task) or admitted into history. */
339
+ private addUpdate;
340
+ /** Schedule a workflow task for a run that has none (an update needs no input event). */
341
+ private scheduleTask;
342
+ /**
343
+ * Send an update to a run and run until idle (Phase C, 05 §6). The result
344
+ * is `REJECTED` (the validator refused it or no handler took it; nothing is
345
+ * written to history), `COMPLETED`, or `ACCEPTED` while its handler still
346
+ * waits (for a timer without time skipping, or with `waitFor: ACCEPTED`).
347
+ */
348
+ update<Args, Result>(runId: string, update: UpdateDefinition<Args, Result> | string, args?: Args, options?: UpdateOptions): Promise<UpdateResult>;
349
+ /** The current result of an update. */
350
+ updateResultOf(runId: string, updateId: string): UpdateResult;
351
+ /** Answer a query from the run's history (a replay-only `query` task). */
352
+ query(runId: string, query: QueryDefinition<unknown, unknown> | string, args?: unknown): Promise<Json>;
353
+ /** Sink calls the run's tasks made. */
354
+ sinkCallsOf(runId: string): SinkCall[];
355
+ /**
356
+ * Reset a run (11 §2.7): a new run whose history is the original's up to
357
+ * and including the chosen completed workflow task (with its commands),
358
+ * then `WORKFLOW_RESET`, then the signals (and, as `UPDATE_ADMITTED`, the
359
+ * accepted updates) received after that point. The original is terminated
360
+ * with reason `RESET`; children it started before the point follow the new
361
+ * run, the others get their parent-close policy. Returns the new run id.
362
+ */
363
+ reset(runId: string, options?: ResetOptions): Promise<string>;
221
364
  private durationConfig;
222
365
  /**
223
366
  * The workflow-id policies of a start (11 §2.1): the open run to use, or
@@ -242,7 +385,7 @@ declare class TestWorkflowEnvironment {
242
385
  private append;
243
386
  /** End a start delay: the first workflow task is scheduled now. */
244
387
  private endDelay;
245
- deliverSignal(runId: string, name: string, payload: unknown): boolean;
388
+ deliverSignal(runId: string, name: string, payload: unknown, headers?: Headers): boolean;
246
389
  requestCancel(runId: string, reason?: string): boolean;
247
390
  terminate(runId: string, reason: string): void;
248
391
  /** Run every runnable task and activity; skip time when allowed and idle. */
@@ -256,6 +399,10 @@ declare class TestWorkflowEnvironment {
256
399
  private fireRunDues;
257
400
  private fireDue;
258
401
  private runTask;
402
+ /** What a task's update replies mean for the run's update rows. */
403
+ private recordUpdateReplies;
404
+ /** Keep a task's sink calls and call the configured sinks with them. */
405
+ private runSinks;
259
406
  private execute;
260
407
  /**
261
408
  * Run a workflow task as the worker does (11 §2.12): while it asks for
@@ -275,12 +422,26 @@ declare class TestWorkflowEnvironment {
275
422
  private startChild;
276
423
  private runMockedChild;
277
424
  private runAttempt;
425
+ /** The `ActivityContext` of one user-activity attempt. */
426
+ private activityContext;
427
+ /** Complete an activity that called `completeAsync()` (`completeActivityAsync`). */
428
+ completeActivityAsync(token: string, result?: unknown): Promise<void>;
429
+ /** Fail an activity that called `completeAsync()` (`failActivityAsync`); the retry policy applies. */
430
+ failActivityAsync(token: string, error: unknown): Promise<void>;
431
+ private takeAsync;
432
+ /** Record an attempt's outcome: completion, a final failure or timeout, or the next attempt. */
433
+ private finishAttempt;
278
434
  /**
279
435
  * Run-level retry (11 §2.17): a failed or run-timed-out run whose policy
280
436
  * allows another attempt is followed by a new run of the chain after the
281
437
  * backoff, with `runAttempt + 1` and the failure as `lastFailure`.
282
438
  */
283
439
  private retryRun;
440
+ /**
441
+ * A run closed: drop its pending work, retry it, apply the parent-close
442
+ * policy to its children (except `keptChildren`, which follow a reset
443
+ * fork), settle its open updates and notify its parent.
444
+ */
284
445
  private onClosed;
285
446
  resultOf(runId: string): Promise<Json>;
286
447
  /** Every tier-2 function registered, by export name. */
@@ -414,9 +575,12 @@ declare function runWorkflowTaskInVm(script: string, request: WorkflowTaskReques
414
575
 
415
576
  /** Let every queued promise job run. */
416
577
  declare function drainJobs(): Promise<void>;
417
- /** A registry from export names to workflow functions. */
418
- declare function registryOf(workflows: Readonly<Record<string, DurableWorkflow<never, unknown>>>): WorkflowRegistry;
578
+ /**
579
+ * A registry from export names to workflow functions, with the workflow
580
+ * interceptors a bundle would export as `interceptors`.
581
+ */
582
+ declare function registryOf(workflows: Readonly<Record<string, DurableWorkflow<never, unknown>>>, interceptors?: WorkflowInterceptorsFactory | MarkedInterceptorsFactory): WorkflowRegistry;
419
583
  /** Run one workflow task in process. */
420
584
  declare function runWorkflowTaskInProcess(registry: WorkflowRegistry, request: WorkflowTaskRequest): Promise<WorkflowTaskResult>;
421
585
 
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 };
586
+ export { type ActivityMock, type ActivityMockInfo, type ChildMock, type ExpectedEvent, HistoryAssertionError, type IRSnapshot, type NodeMock, type NodeMockResult, QueryFailedError, QueryRejectedError, ReplayError, type ReplayInput, type ResetOptions, RunBlockedError, type SimulateOptions, type SimulatedStep, type SimulationResult, type StartOptions, type TestEnvironmentOptions, TestRunHandle, TestWorkflowEnvironment, UnfinishedHandlersError, type UpdateOptions, UpdateRefusedError, type UpdateResult, type UpdateStatus, WorkflowAlreadyStartedError, WorkflowFailedError, WorkflowTaskFailedError, assertHistory, bundleToScript, drainJobs, expectIR, jsonCopy, registryOf, replay, replayRequest, runWorkflowTaskInProcess, runWorkflowTaskInVm, simulate };