Skip to content

Commit 9712184

Browse files
committed
prevent the same step from being mocked multiple times
1 parent be5d2ac commit 9712184

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

packages/workflows-shared/src/modifier.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ type UserEvent = {
1313
payload: unknown;
1414
};
1515

16+
export class WorkflowIntrospectorError extends Error {
17+
name = "WorkflowIntrospectorError";
18+
}
19+
1620
export class InstanceModifier extends RpcTarget {
1721
#engine: Engine;
1822
#state: DurableObjectState;
@@ -80,6 +84,13 @@ export class InstanceModifier extends RpcTarget {
8084
step.name
8185
);
8286
const valueKey = await this.#getStepCacheKey(step);
87+
88+
if (await this.#state.storage.get(`replace-result-${valueKey}`)) {
89+
throw new WorkflowIntrospectorError(
90+
"You're trying to mock the same step multiple times!"
91+
);
92+
}
93+
8394
await this.#state.storage.put(`replace-result-${valueKey}`, stepResult);
8495
}
8596

@@ -137,7 +148,6 @@ export class InstanceModifier extends RpcTarget {
137148
};
138149

139150
await this.#state.storage.put(`mockEvent-${event.type}`, true);
140-
141151
await this.#engine.receiveEvent(myEvent);
142152
}
143153

0 commit comments

Comments
 (0)