-
Notifications
You must be signed in to change notification settings - Fork 11
Fix falsy values (0, empty string, false, null) silently dropped during serialization #138
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
torosent
merged 5 commits into
main
from
copilot-finds/bug/fix-falsy-input-serialization
Mar 6, 2026
+401
−6
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
0e4a2bc
Fix falsy input values silently dropped in activity, sub-orchestratio…
Copilot ca52b66
Update packages/durabletask-js/test/falsy-input-serialization.spec.ts
YunchuWang 37e5907
Update packages/durabletask-js/test/falsy-input-serialization.spec.ts
YunchuWang 27b36f0
Fix TypeScript error in continueAsNew test: async return type must be…
YunchuWang 4c3d5ef
Fix activity output falsy serialization and add e2e tests
YunchuWang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
188 changes: 188 additions & 0 deletions
188
packages/durabletask-js/test/falsy-input-serialization.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,188 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| import { OrchestrationContext } from "../src/task/context/orchestration-context"; | ||
| import { | ||
| newExecutionStartedEvent, | ||
| newOrchestratorStartedEvent, | ||
| } from "../src/utils/pb-helper.util"; | ||
| import { OrchestrationExecutor } from "../src/worker/orchestration-executor"; | ||
| import * as pb from "../src/proto/orchestrator_service_pb"; | ||
| import { Registry } from "../src/worker/registry"; | ||
| import { TOrchestrator } from "../src/types/orchestrator.type"; | ||
| import { NoOpLogger } from "../src/types/logger.type"; | ||
| import { ActivityContext } from "../src/task/context/activity-context"; | ||
|
|
||
| const testLogger = new NoOpLogger(); | ||
| const TEST_INSTANCE_ID = "falsy-test-instance"; | ||
|
|
||
| describe("Falsy input serialization", () => { | ||
| describe("callActivity with falsy inputs", () => { | ||
| it.each([ | ||
| { input: 0, label: "zero" }, | ||
| { input: "", label: "empty string" }, | ||
| { input: false, label: "false" }, | ||
| { input: null, label: "null" }, | ||
| ])("should correctly serialize $label as activity input", async ({ input }) => { | ||
| const myActivity = async (_ctx: ActivityContext, actInput: any) => actInput; | ||
|
|
||
| const orchestrator: TOrchestrator = async function* (ctx: OrchestrationContext): any { | ||
| const result = yield ctx.callActivity(myActivity, input as any); | ||
| return result; | ||
| }; | ||
|
|
||
| const registry = new Registry(); | ||
| const orchestratorName = registry.addOrchestrator(orchestrator); | ||
| registry.addActivity(myActivity); | ||
|
|
||
| const newEvents = [ | ||
| newOrchestratorStartedEvent(new Date()), | ||
| newExecutionStartedEvent(orchestratorName, TEST_INSTANCE_ID), | ||
| ]; | ||
|
|
||
| const executor = new OrchestrationExecutor(registry, testLogger); | ||
| const result = await executor.execute(TEST_INSTANCE_ID, [], newEvents); | ||
|
|
||
| // Should have a ScheduleTask action with the serialized input | ||
| const scheduleAction = result.actions.find((a) => a.hasScheduletask()); | ||
| expect(scheduleAction).toBeDefined(); | ||
| const inputValue = scheduleAction!.getScheduletask()!.getInput(); | ||
| expect(inputValue).toBeDefined(); | ||
| expect(inputValue!.getValue()).toEqual(JSON.stringify(input)); | ||
| }); | ||
| }); | ||
|
|
||
| describe("callSubOrchestrator with falsy inputs", () => { | ||
| it.each([ | ||
| { input: 0, label: "zero" }, | ||
| { input: "", label: "empty string" }, | ||
| { input: false, label: "false" }, | ||
| { input: null, label: "null" }, | ||
| ])("should correctly serialize $label as sub-orchestration input", async ({ input }) => { | ||
| const subOrchestrator: TOrchestrator = async (_ctx: OrchestrationContext, subInput: any) => { | ||
| return subInput; | ||
| }; | ||
|
|
||
| const orchestrator: TOrchestrator = async function* (ctx: OrchestrationContext): any { | ||
| const result = yield ctx.callSubOrchestrator(subOrchestrator, input as any); | ||
| return result; | ||
| }; | ||
|
|
||
| const registry = new Registry(); | ||
| const orchestratorName = registry.addOrchestrator(orchestrator); | ||
| registry.addOrchestrator(subOrchestrator); | ||
|
|
||
| const newEvents = [ | ||
| newOrchestratorStartedEvent(new Date()), | ||
| newExecutionStartedEvent(orchestratorName, TEST_INSTANCE_ID), | ||
| ]; | ||
|
|
||
| const executor = new OrchestrationExecutor(registry, testLogger); | ||
| const result = await executor.execute(TEST_INSTANCE_ID, [], newEvents); | ||
|
|
||
| // Should have a CreateSubOrchestration action with the serialized input | ||
| const subOrchAction = result.actions.find((a) => a.hasCreatesuborchestration()); | ||
| expect(subOrchAction).toBeDefined(); | ||
| const inputValue = subOrchAction!.getCreatesuborchestration()!.getInput(); | ||
| expect(inputValue).toBeDefined(); | ||
| expect(inputValue!.getValue()).toEqual(JSON.stringify(input)); | ||
| }); | ||
| }); | ||
|
|
||
| describe("orchestration completion with falsy results", () => { | ||
| it.each([ | ||
| { result: 0, label: "zero" }, | ||
| { result: "", label: "empty string" }, | ||
| { result: false, label: "false" }, | ||
| { result: null, label: "null" }, | ||
| ])("should correctly serialize $label as orchestration result", async ({ result }) => { | ||
| const orchestrator: TOrchestrator = async (_ctx: OrchestrationContext) => { | ||
| return result; | ||
| }; | ||
|
|
||
| const registry = new Registry(); | ||
| const orchestratorName = registry.addOrchestrator(orchestrator); | ||
|
|
||
| const newEvents = [ | ||
| newOrchestratorStartedEvent(new Date()), | ||
| newExecutionStartedEvent(orchestratorName, TEST_INSTANCE_ID), | ||
| ]; | ||
|
|
||
| const executor = new OrchestrationExecutor(registry, testLogger); | ||
| const execResult = await executor.execute(TEST_INSTANCE_ID, [], newEvents); | ||
|
|
||
| expect(execResult.actions.length).toEqual(1); | ||
| const completeAction = execResult.actions[0].getCompleteorchestration(); | ||
| expect(completeAction).toBeDefined(); | ||
| expect(completeAction!.getOrchestrationstatus()).toEqual( | ||
| pb.OrchestrationStatus.ORCHESTRATION_STATUS_COMPLETED, | ||
| ); | ||
| const resultValue = completeAction!.getResult(); | ||
| expect(resultValue).toBeDefined(); | ||
| expect(resultValue!.getValue()).toEqual(JSON.stringify(result)); | ||
| }); | ||
| }); | ||
|
|
||
| describe("continueAsNew with falsy input", () => { | ||
| it("should correctly serialize zero as continue-as-new input", async () => { | ||
| const orchestrator: TOrchestrator = async function* (ctx: OrchestrationContext, input: any): any { | ||
| if (input === 0) { | ||
| ctx.continueAsNew(0, false); | ||
| yield ctx.createTimer(1); // yield to avoid require-yield lint error | ||
| return; | ||
| } | ||
| return input; | ||
| }; | ||
|
|
||
| const registry = new Registry(); | ||
| const orchestratorName = registry.addOrchestrator(orchestrator); | ||
|
|
||
| const newEvents = [ | ||
| newOrchestratorStartedEvent(new Date()), | ||
| newExecutionStartedEvent(orchestratorName, TEST_INSTANCE_ID, JSON.stringify(0)), | ||
| ]; | ||
|
|
||
| const executor = new OrchestrationExecutor(registry, testLogger); | ||
| const result = await executor.execute(TEST_INSTANCE_ID, [], newEvents); | ||
|
|
||
| expect(result.actions.length).toEqual(1); | ||
| const completeAction = result.actions[0].getCompleteorchestration(); | ||
| expect(completeAction).toBeDefined(); | ||
| expect(completeAction!.getOrchestrationstatus()).toEqual( | ||
| pb.OrchestrationStatus.ORCHESTRATION_STATUS_CONTINUED_AS_NEW, | ||
| ); | ||
| const resultValue = completeAction!.getResult(); | ||
| expect(resultValue).toBeDefined(); | ||
| expect(resultValue!.getValue()).toEqual(JSON.stringify(0)); | ||
| }); | ||
| }); | ||
|
|
||
| describe("undefined inputs are still treated as no input", () => { | ||
| it("should not set input when activity input is undefined", async () => { | ||
| const myActivity = async (_ctx: ActivityContext) => "done"; | ||
|
|
||
| const orchestrator: TOrchestrator = async function* (ctx: OrchestrationContext): any { | ||
| const result = yield ctx.callActivity(myActivity); | ||
| return result; | ||
| }; | ||
|
|
||
| const registry = new Registry(); | ||
| const orchestratorName = registry.addOrchestrator(orchestrator); | ||
| registry.addActivity(myActivity); | ||
|
|
||
| const newEvents = [ | ||
| newOrchestratorStartedEvent(new Date()), | ||
| newExecutionStartedEvent(orchestratorName, TEST_INSTANCE_ID), | ||
| ]; | ||
|
|
||
| const executor = new OrchestrationExecutor(registry, testLogger); | ||
| const result = await executor.execute(TEST_INSTANCE_ID, [], newEvents); | ||
|
|
||
| const scheduleAction = result.actions.find((a) => a.hasScheduletask()); | ||
| expect(scheduleAction).toBeDefined(); | ||
| // Input should be undefined/null when not provided | ||
|
YunchuWang marked this conversation as resolved.
Outdated
|
||
| const inputValue = scheduleAction!.getScheduletask()!.getInput(); | ||
| expect(inputValue).toBeUndefined(); | ||
| }); | ||
| }); | ||
| }); | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.