-
-
Notifications
You must be signed in to change notification settings - Fork 990
Fix run.taskIdentifier being reported as "unknown" for batch triggers #2974
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
Open
bharathkumar39293
wants to merge
4
commits into
triggerdotdev:main
Choose a base branch
from
bharathkumar39293:fix/batch-trigger-task-identifier
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+191
−31
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
c6c4ce7
fix(core): propagate taskIdentifier for batch triggers
bharathkumar39293 99192b6
chore(test): remove mocks
bharathkumar39293 7727737
Merge branch 'main' into fix/batch-trigger-task-identifier
bharathkumar39293 7af5dd6
Merge branch 'main' into fix/batch-trigger-task-identifier
bharathkumar39293 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
121 changes: 121 additions & 0 deletions
121
packages/core/src/v3/runtime/sharedRuntimeManager.test.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,121 @@ | ||
| import { describe, expect, it } from "vitest"; | ||
| import { SharedRuntimeManager } from "./sharedRuntimeManager.js"; | ||
| import { CompletedWaitpoint } from "../schemas/index.js"; | ||
|
|
||
| describe("SharedRuntimeManager", () => { | ||
| const mockIpc = { | ||
| send: () => { }, | ||
| } as any; | ||
|
|
||
| const manager = new SharedRuntimeManager(mockIpc, false); | ||
|
|
||
| // Access private method | ||
| const waitpointToResult = (manager as any).waitpointToTaskRunExecutionResult.bind(manager); | ||
|
|
||
| describe("waitpointToTaskRunExecutionResult", () => { | ||
| it("should use the taskIdentifier from the waitpoint if present (success)", () => { | ||
| const waitpoint: CompletedWaitpoint = { | ||
| id: "wp_1", | ||
| friendlyId: "wp_1", | ||
| type: "RUN", | ||
| completedAt: new Date(), | ||
| outputIsError: false, | ||
| output: JSON.stringify({ foo: "bar" }), | ||
| outputType: "application/json", | ||
| completedByTaskRun: { | ||
| id: "run_1", | ||
| friendlyId: "run_1", | ||
| taskIdentifier: "my-task", | ||
| }, | ||
| }; | ||
|
|
||
| const result = waitpointToResult(waitpoint); | ||
|
|
||
| expect(result).toEqual({ | ||
| ok: true, | ||
| id: "run_1", | ||
| taskIdentifier: "my-task", | ||
| output: JSON.stringify({ foo: "bar" }), | ||
| outputType: "application/json", | ||
| }); | ||
| }); | ||
|
|
||
| it("should default taskIdentifier to 'unknown' if missing (success)", () => { | ||
| const waitpoint: CompletedWaitpoint = { | ||
| id: "wp_2", | ||
| friendlyId: "wp_2", | ||
| type: "RUN", | ||
| completedAt: new Date(), | ||
| outputIsError: false, | ||
| output: JSON.stringify({ foo: "bar" }), | ||
| outputType: "application/json", | ||
| completedByTaskRun: { | ||
| id: "run_2", | ||
| friendlyId: "run_2", | ||
| // database/legacy object missing taskIdentifier | ||
| } as any, | ||
| }; | ||
|
|
||
| const result = waitpointToResult(waitpoint); | ||
|
|
||
| expect(result).toEqual({ | ||
| ok: true, | ||
| id: "run_2", | ||
| taskIdentifier: "unknown", | ||
| output: JSON.stringify({ foo: "bar" }), | ||
| outputType: "application/json", | ||
| }); | ||
| }); | ||
|
|
||
| it("should use the taskIdentifier from the waitpoint if present (failure)", () => { | ||
| const waitpoint: CompletedWaitpoint = { | ||
| id: "wp_3", | ||
| friendlyId: "wp_3", | ||
| type: "RUN", | ||
| completedAt: new Date(), | ||
| outputIsError: true, | ||
| output: JSON.stringify({ message: "Boom" }), | ||
| outputType: "application/json", | ||
| completedByTaskRun: { | ||
| id: "run_3", | ||
| friendlyId: "run_3", | ||
| taskIdentifier: "my-failed-task", | ||
| }, | ||
| }; | ||
|
|
||
| const result = waitpointToResult(waitpoint); | ||
|
|
||
| expect(result).toEqual({ | ||
| ok: false, | ||
| id: "run_3", | ||
| taskIdentifier: "my-failed-task", | ||
| error: { message: "Boom" }, | ||
| }); | ||
| }); | ||
|
|
||
| it("should default taskIdentifier to 'unknown' if missing (failure)", () => { | ||
| const waitpoint: CompletedWaitpoint = { | ||
| id: "wp_4", | ||
| friendlyId: "wp_4", | ||
| type: "RUN", | ||
| completedAt: new Date(), | ||
| outputIsError: true, | ||
| output: JSON.stringify({ message: "Boom" }), | ||
| outputType: "application/json", | ||
| completedByTaskRun: { | ||
| id: "run_4", | ||
| friendlyId: "run_4", | ||
| } as any, | ||
| }; | ||
|
|
||
| const result = waitpointToResult(waitpoint); | ||
|
|
||
| expect(result).toEqual({ | ||
| ok: false, | ||
| id: "run_4", | ||
| taskIdentifier: "unknown", | ||
| error: { message: "Boom" }, | ||
| }); | ||
| }); | ||
| }); | ||
| }); |
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
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟡 Missing
thisbinding when passing method to map() causes runtime error in waitForBatchIn
waitForBatch, the methodwaitpointToTaskRunExecutionResultis passed directly tomap()without bindingthis, causing the method to lose its context and fail at runtime.Click to expand
The Problem
On line 116, the code uses:
When a method is passed as a callback to
map()without binding,thisinside the method becomesundefined(in strict mode). ThewaitpointToTaskRunExecutionResultmethod doesn't accessthisdirectly in its implementation atpackages/core/src/v3/runtime/sharedRuntimeManager.ts:289-312, but this pattern is still incorrect and error-prone.Comparison with waitForTask
In
waitForTask(line 68), the method is called correctly with properthiscontext:Actual vs Expected
waitpoints.map(this.waitpointToTaskRunExecutionResult)waitpoints.map((wp) => this.waitpointToTaskRunExecutionResult(wp))Impact
This affects the
batch.triggerAndWaitandbatch.triggerByTaskAndWaitfunctionality that this PR is trying to fix. While the current implementation ofwaitpointToTaskRunExecutionResultdoesn't accessthis, this is fragile - any future modification that addsthisusage will cause silent failures.(Refers to line 116)
Recommendation: Change line 116 to use an arrow function to preserve
thiscontext:Was this helpful? React with 👍 or 👎 to provide feedback.