fix: read protobuf StringValue activity input with getValue#280
Open
YunchuWang wants to merge 1 commit into
Open
fix: read protobuf StringValue activity input with getValue#280YunchuWang wants to merge 1 commit into
YunchuWang wants to merge 1 commit into
Conversation
…activity execution Replace incorrect .toString() call on protobuf StringValue with the correct .getValue() API in _executeActivityInternal. The toString() method on protobuf Message objects calls the base class implementation which relies on internal array representation, not the documented field accessor. Also remove redundant .toString() on the activity result (already a string). Add tests verifying activity input extraction and result serialization. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes activity input extraction in the gRPC worker by using the documented protobuf StringValue.getValue() accessor instead of relying on toString()’s incidental behavior, aligning the worker with stable protobuf APIs and the rest of the SDK’s wrapper usage. It also updates the activity result handling to avoid redundant string coercion and adds tests around input/output behavior.
Changes:
- Read
ActivityRequest.inputviareq.getInput()?.getValue()instead oftoString(). - Remove redundant
.toString()when setting the activity resultStringValue. - Add worker-level tests for activity input deserialization and result serialization.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| packages/durabletask-js/src/worker/task-hub-grpc-worker.ts | Uses StringValue.getValue() for activity input and avoids redundant output string coercion. |
| packages/durabletask-js/test/worker-activity-response.spec.ts | Adds tests for activity input extraction and ActivityResponse result encoding/empty-result behavior. |
Comment on lines
+114
to
+125
| const mockStub = createMockStub(); | ||
| const testInput = { key: "value", nested: { arr: [1, 2, 3] } }; | ||
| const req = createActivityRequest("inputCapturingActivity", JSON.stringify(testInput)); | ||
|
|
||
| // Act | ||
| await (worker as any)._executeActivityInternal(req, COMPLETION_TOKEN, mockStub.stub); | ||
|
|
||
| // Assert — the activity must receive the deserialized input object | ||
| expect(receivedInput).toEqual(testInput); | ||
| expect(mockStub.capturedResponse).not.toBeNull(); | ||
| expect(mockStub.capturedResponse!.getResult()?.getValue()).toBe(JSON.stringify("done")); | ||
| }); |
Comment on lines
+127
to
+150
| it("should pass empty string as input when protobuf StringValue is not set", async () => { | ||
| // Arrange | ||
| const worker = new TaskHubGrpcWorker({ | ||
| logger: new NoOpLogger(), | ||
| }); | ||
|
|
||
| let receivedInput: unknown = "sentinel"; | ||
| const inputCapturingActivity = (_ctx: ActivityContext, input: unknown) => { | ||
| receivedInput = input; | ||
| return "done"; | ||
| }; | ||
|
|
||
| worker.addActivity(inputCapturingActivity); | ||
|
|
||
| const mockStub = createMockStub(); | ||
| // Create request WITHOUT setting input — simulates no input from sidecar | ||
| const req = createActivityRequest("inputCapturingActivity"); | ||
|
|
||
| // Act | ||
| await (worker as any)._executeActivityInternal(req, COMPLETION_TOKEN, mockStub.stub); | ||
|
|
||
| // Assert — no input means the activity receives undefined (empty string is parsed as falsy by executor) | ||
| expect(receivedInput).toBeUndefined(); | ||
| }); |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Fixes #223