Skip to content

Commit 6ad8b0f

Browse files
swap handles on config
1 parent 9de331f commit 6ad8b0f

4 files changed

Lines changed: 28 additions & 9 deletions

File tree

packages/core/workflows-sdk/src/utils/composer/__tests__/compose.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1413,16 +1413,34 @@ describe("Workflow composer", function () {
14131413
return new StepResponse(input)
14141414
})
14151415

1416-
const fakeStepWorkflow = createWorkflow("fake-workflow", () => {
1416+
const sameStepWorkflow = createWorkflow("fake-workflow", () => {
14171417
const a = log(1).config({ name: "aaaa" })
14181418
const b = log(2) // without config on purpose
14191419
const c = log(3).config({ name: "cccc" })
14201420
return new WorkflowResponse([a, b, c])
14211421
})
14221422

1423-
const { result } = await fakeStepWorkflow().run()
1423+
const sameStepWorkflow2 = createWorkflow("fake-workflow-2", () => {
1424+
const a = log(1)
1425+
const b = log(2).config({ name: "bbbb" })
1426+
const c = log(3).config({ name: "cccc" })
1427+
return new WorkflowResponse([a, b, c])
1428+
})
1429+
1430+
const sameStepWorkflow3 = createWorkflow("fake-workflow-3", () => {
1431+
const a = log(1).config({ name: "aaaa" })
1432+
const b = log(2).config({ name: "bbbb" })
1433+
const c = log(3)
1434+
return new WorkflowResponse([a, b, c])
1435+
})
1436+
1437+
const { result } = await sameStepWorkflow().run()
1438+
const { result: result2 } = await sameStepWorkflow2().run()
1439+
const { result: result3 } = await sameStepWorkflow3().run()
14241440

14251441
expect(result).toEqual([1, 2, 3])
1442+
expect(result2).toEqual([1, 2, 3])
1443+
expect(result3).toEqual([1, 2, 3])
14261444
})
14271445

14281446
it("should skip steps until the named step in case of permanent failure", async () => {

packages/core/workflows-sdk/src/utils/composer/create-step.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,9 @@ export function applyStep<
143143

144144
this.isAsync ||= !!(stepConfig.async || stepConfig.compensateAsync)
145145

146-
if (!this.canOverrideHandlers.has(stepName)) {
147-
this.canOverrideHandlers.add(stepName)
148-
this.handlers.set(stepName, handler)
149-
}
146+
this.overriddenHandler.set(stepName, this.handlers.get(stepName)!)
147+
148+
this.handlers.set(stepName, handler)
150149

151150
const ret = {
152151
__type: OrchestrationUtils.SymbolWorkflowStep,
@@ -179,7 +178,6 @@ export function applyStep<
179178
}
180179

181180
delete newConfig.name
182-
this.canOverrideHandlers.delete(stepName)
183181

184182
const handler = createStepHandler.bind(this)({
185183
stepName: newStepName,
@@ -190,6 +188,9 @@ export function applyStep<
190188

191189
wrapAsyncHandler(newConfig, handler)
192190

191+
this.handlers.set(stepName, this.overriddenHandler.get(stepName)!)
192+
this.overriddenHandler.delete(stepName)
193+
193194
this.handlers.set(newStepName, handler)
194195

195196
this.flow.replaceAction(stepConfig.uuid!, newStepName, newConfig)

packages/core/workflows-sdk/src/utils/composer/create-workflow.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ export function createWorkflow<TData, TResult, THooks extends any[]>(
117117
flow: WorkflowManager.getEmptyTransactionDefinition(),
118118
isAsync: false,
119119
handlers,
120-
canOverrideHandlers: new Set(),
120+
overriddenHandler: new Map(),
121121
hooks_: {
122122
declared: [],
123123
registered: [],

packages/core/workflows-sdk/src/utils/composer/type.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ export type CreateWorkflowComposerContext = {
113113
flow: OrchestratorBuilder
114114
isAsync: boolean
115115
handlers: WorkflowHandler
116-
canOverrideHandlers: Set<string>
116+
overriddenHandler: WorkflowHandler
117117
stepBinder: <TOutput = unknown>(
118118
fn: StepFunctionResult
119119
) => WorkflowData<TOutput>

0 commit comments

Comments
 (0)