-
Notifications
You must be signed in to change notification settings - Fork 13k
Disallow unsafe type assertions #18688
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
Merged
Changes from 2 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
b43203f
Disallow unsafe type assertions.
gundermanc 88c842c
Blanket suppress unsafe cast lints.
gundermanc 26d2814
Fix build.
gundermanc 4355df8
Fix build.
gundermanc 5f89d9e
Fix build.
gundermanc 312a4b7
Merge remote-tracking branch 'origin/main' into gundermanc/work-around
gundermanc bfb4156
Merge remote-tracking branch 'origin/main' into gundermanc/work-around
gundermanc 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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -378,6 +378,7 @@ export class Task { | |
| if (tc.status === 'awaiting_approval' && tc.confirmationDetails) { | ||
| this.pendingToolConfirmationDetails.set( | ||
| tc.request.callId, | ||
| // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion | ||
| tc.confirmationDetails as ToolCallConfirmationDetails, | ||
| ); | ||
| } | ||
|
|
@@ -411,7 +412,7 @@ export class Task { | |
| ); | ||
| toolCalls.forEach((tc: ToolCall) => { | ||
| if (tc.status === 'awaiting_approval' && tc.confirmationDetails) { | ||
| // eslint-disable-next-line @typescript-eslint/no-floating-promises | ||
| // eslint-disable-next-line @typescript-eslint/no-floating-promises, @typescript-eslint/no-unsafe-type-assertion | ||
| (tc.confirmationDetails as ToolCallConfirmationDetails).onConfirm( | ||
| ToolConfirmationOutcome.ProceedOnce, | ||
| ); | ||
|
|
@@ -465,12 +466,14 @@ export class Task { | |
| T extends ToolCall | AnyDeclarativeTool, | ||
| K extends UnionKeys<T>, | ||
| >(from: T, ...fields: K[]): Partial<T> { | ||
| // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion | ||
| const ret = {} as Pick<T, K>; | ||
| for (const field of fields) { | ||
| if (field in from) { | ||
| ret[field] = from[field]; | ||
| } | ||
| } | ||
| // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion | ||
| return ret as Partial<T>; | ||
| } | ||
|
Comment on lines
468
to
478
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This function uses two unsafe type assertions. It can be refactored to be fully type-safe by correctly typing the return object from the start. >(from: T, ...fields: K[]): Partial<T> {
const ret: Partial<T> = {};
for (const field of fields) {
if (field in from) {
ret[field] = from[field];
}
}
return ret;
} |
||
|
|
||
|
|
@@ -493,6 +496,7 @@ export class Task { | |
| ); | ||
|
|
||
| if (tc.tool) { | ||
| // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion | ||
| serializableToolCall.tool = this._pickFields( | ||
| tc.tool, | ||
| 'name', | ||
|
|
@@ -622,8 +626,11 @@ export class Task { | |
| request.args['new_string'] | ||
| ) { | ||
| const newContent = await this.getProposedContent( | ||
| // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion | ||
| request.args['file_path'] as string, | ||
| // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion | ||
| request.args['old_string'] as string, | ||
| // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion | ||
| request.args['new_string'] as string, | ||
| ); | ||
| return { ...request, args: { ...request.args, newContent } }; | ||
|
|
@@ -719,6 +726,7 @@ export class Task { | |
| case GeminiEventType.Error: | ||
| default: { | ||
| // Block scope for lexical declaration | ||
| // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion | ||
| const errorEvent = event as ServerGeminiErrorEvent; // Type assertion | ||
| const errorMessage = | ||
| errorEvent.value?.error.message ?? 'Unknown error from LLM stream'; | ||
|
|
@@ -807,6 +815,7 @@ export class Task { | |
| if (confirmationDetails.type === 'edit') { | ||
| const payload = part.data['newContent'] | ||
| ? ({ | ||
| // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion | ||
| newContent: part.data['newContent'] as string, | ||
| } as ToolConfirmationPayload) | ||
| : undefined; | ||
|
|
||
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
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
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
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
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
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
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
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
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
Oops, something went wrong.
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.
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.
This type assertion is critically unsafe. Casting an empty object
{}toAgentSettingscreates an object that does not conform to the interface, as it will be missing required properties likekindandworkspacePath. While the current implementation might handle this gracefully due to checks insetTargetDir, it creates a fragile contract and can lead to runtime errors ifgetConfigor its dependencies ever rely on other properties ofAgentSettings.Instead of suppressing this error, it's better to refactor
getConfigto accept aPartial<AgentSettings>and handle the optional properties safely. This would make the contract explicit and prevent future bugs.