-
Notifications
You must be signed in to change notification settings - Fork 440
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
fix(amazonq): validationException if empty supplemental context chunk is sent to the service #5920
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
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
4 changes: 4 additions & 0 deletions
4
packages/amazonq/.changes/next-release/Bug Fix-9f5467f7-da28-455c-9471-a5799055ddb7.json
This file contains 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,4 @@ | ||
{ | ||
"type": "Bug Fix", | ||
"description": "Fix empty chunks being sent to service and get validationException" | ||
} |
This file contains 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
61 changes: 61 additions & 0 deletions
61
packages/amazonq/test/unit/codewhisperer/util/supplemetalContextUtil.test.ts
This file contains 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,61 @@ | ||
/*! | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import assert from 'assert' | ||
import * as vscode from 'vscode' | ||
import * as sinon from 'sinon' | ||
import * as crossFile from 'aws-core-vscode/codewhisperer' | ||
import { TestFolder } from 'aws-core-vscode/test' | ||
import { FeatureConfigProvider } from 'aws-core-vscode/codewhisperer' | ||
import { toTextEditor } from 'aws-core-vscode/test' | ||
|
||
describe('supplementalContextUtil', function () { | ||
let testFolder: TestFolder | ||
|
||
const fakeCancellationToken: vscode.CancellationToken = { | ||
isCancellationRequested: false, | ||
onCancellationRequested: sinon.spy(), | ||
} | ||
|
||
beforeEach(async function () { | ||
testFolder = await TestFolder.create() | ||
sinon.stub(FeatureConfigProvider.instance, 'isNewProjectContextGroup').alwaysReturned(false) | ||
}) | ||
|
||
afterEach(function () { | ||
sinon.restore() | ||
}) | ||
|
||
describe('fetchSupplementalContext', function () { | ||
describe('openTabsContext', function () { | ||
it('opentabContext should include chunks if non empty', async function () { | ||
await toTextEditor('class Foo', 'Foo.java', testFolder.path, { preview: false }) | ||
await toTextEditor('class Bar', 'Bar.java', testFolder.path, { preview: false }) | ||
await toTextEditor('class Baz', 'Baz.java', testFolder.path, { preview: false }) | ||
|
||
const editor = await toTextEditor('public class Foo {}', 'Query.java', testFolder.path, { | ||
preview: false, | ||
}) | ||
|
||
const actual = await crossFile.fetchSupplementalContext(editor, fakeCancellationToken) | ||
assert.ok(actual?.supplementalContextItems.length === 3) | ||
}) | ||
|
||
it('opentabsContext should filter out empty chunks', async function () { | ||
// open 3 files as supplemental context candidate files but none of them have contents | ||
await toTextEditor('', 'Foo.java', testFolder.path, { preview: false }) | ||
await toTextEditor('', 'Bar.java', testFolder.path, { preview: false }) | ||
await toTextEditor('', 'Baz.java', testFolder.path, { preview: false }) | ||
|
||
const editor = await toTextEditor('public class Foo {}', 'Query.java', testFolder.path, { | ||
preview: false, | ||
}) | ||
|
||
const actual = await crossFile.fetchSupplementalContext(editor, fakeCancellationToken) | ||
assert.ok(actual?.supplementalContextItems.length === 0) | ||
}) | ||
}) | ||
}) | ||
}) |
This file contains 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 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 |
---|---|---|
|
@@ -152,7 +152,7 @@ export async function fetchSupplementalContextForSrcV1( | |
// DO NOT send code chunk with empty content | ||
getLogger().debug(`CodeWhisperer finished fetching crossfile context out of ${relevantCrossFilePaths.length} files`) | ||
return { | ||
supplementalContextItems: supplementalContexts.filter((item) => item.content.trim().length !== 0), | ||
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. moved to upstream caller |
||
supplementalContextItems: supplementalContexts, | ||
strategy: 'OpenTabs_BM25', | ||
} | ||
} | ||
|
This file contains 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.
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.
Nice! Thanks for thinking about the log format, that helps with troubleshooting for both users and devs.