Skip to content
Snippets Groups Projects
Unverified Commit 17f9022d authored by Alex Yang's avatar Alex Yang Committed by GitHub
Browse files

fix: output event check (#1475)

parent 14792cd8
No related branches found
No related tags found
No related merge requests found
...@@ -397,10 +397,11 @@ export class WorkflowContext<Start = string, Stop = string, Data = unknown> ...@@ -397,10 +397,11 @@ export class WorkflowContext<Start = string, Stop = string, Data = unknown>
); );
} }
const outputs = outputsMap.get(step) ?? []; const outputs = outputsMap.get(step) ?? [];
const outputEvents = flattenEvents(outputs, [ if (
nextEvent, !outputs.some(
]); (output) => nextEvent.constructor === output,
if (outputEvents.length !== outputs.length) { )
) {
if (this.#strict) { if (this.#strict) {
const error = Error( const error = Error(
`Step ${step.name} returned an unexpected output event ${nextEvent}`, `Step ${step.name} returned an unexpected output event ${nextEvent}`,
......
...@@ -794,6 +794,21 @@ describe("workflow event loop", () => { ...@@ -794,6 +794,21 @@ describe("workflow event loop", () => {
} }
`); `);
}); });
test("workflow multiple output", async () => {
const myFlow = new Workflow<unknown, string, string>({ verbose: true });
myFlow.addStep(
{
inputs: [StartEvent<string>],
outputs: [StopEvent<string>, StopEvent<string>],
},
async (_context, ev) => {
return new StopEvent(`Hello ${ev.data}!`);
},
);
const result = await myFlow.run("world").strict();
expect(result.data).toBe("Hello world!");
});
}); });
describe("snapshot", async () => { describe("snapshot", async () => {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment