|
| 1 | +/*! |
| 2 | + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 3 | + * SPDX-License-Identifier: Apache-2.0 |
| 4 | + */ |
| 5 | + |
| 6 | +import assert from 'assert' |
| 7 | +import * as vscode from 'vscode' |
| 8 | +import * as sinon from 'sinon' |
| 9 | +import * as crossFile from 'aws-core-vscode/codewhisperer' |
| 10 | +import { TestFolder } from 'aws-core-vscode/test' |
| 11 | +import { FeatureConfigProvider } from 'aws-core-vscode/codewhisperer' |
| 12 | +import { toTextEditor } from 'aws-core-vscode/test' |
| 13 | + |
| 14 | +describe('supplementalContextUtil', function () { |
| 15 | + let testFolder: TestFolder |
| 16 | + |
| 17 | + const fakeCancellationToken: vscode.CancellationToken = { |
| 18 | + isCancellationRequested: false, |
| 19 | + onCancellationRequested: sinon.spy(), |
| 20 | + } |
| 21 | + |
| 22 | + beforeEach(async function () { |
| 23 | + testFolder = await TestFolder.create() |
| 24 | + sinon.stub(FeatureConfigProvider.instance, 'isNewProjectContextGroup').alwaysReturned(false) |
| 25 | + }) |
| 26 | + |
| 27 | + afterEach(function () { |
| 28 | + sinon.restore() |
| 29 | + }) |
| 30 | + |
| 31 | + describe('fetchSupplementalContext', function () { |
| 32 | + describe('openTabsContext', function () { |
| 33 | + it('opentabContext should include chunks if non empty', async function () { |
| 34 | + await toTextEditor('class Foo', 'Foo.java', testFolder.path, { preview: false }) |
| 35 | + await toTextEditor('class Bar', 'Bar.java', testFolder.path, { preview: false }) |
| 36 | + await toTextEditor('class Baz', 'Baz.java', testFolder.path, { preview: false }) |
| 37 | + |
| 38 | + const editor = await toTextEditor('public class Foo {}', 'Query.java', testFolder.path, { |
| 39 | + preview: false, |
| 40 | + }) |
| 41 | + |
| 42 | + const actual = await crossFile.fetchSupplementalContext(editor, fakeCancellationToken) |
| 43 | + assert.ok(actual?.supplementalContextItems.length === 3) |
| 44 | + }) |
| 45 | + |
| 46 | + it('opentabsContext should filter out empty chunks', async function () { |
| 47 | + // open 3 files as supplemental context candidate files but none of them have contents |
| 48 | + await toTextEditor('', 'Foo.java', testFolder.path, { preview: false }) |
| 49 | + await toTextEditor('', 'Bar.java', testFolder.path, { preview: false }) |
| 50 | + await toTextEditor('', 'Baz.java', testFolder.path, { preview: false }) |
| 51 | + |
| 52 | + const editor = await toTextEditor('public class Foo {}', 'Query.java', testFolder.path, { |
| 53 | + preview: false, |
| 54 | + }) |
| 55 | + |
| 56 | + const actual = await crossFile.fetchSupplementalContext(editor, fakeCancellationToken) |
| 57 | + assert.ok(actual?.supplementalContextItems.length === 0) |
| 58 | + }) |
| 59 | + }) |
| 60 | + }) |
| 61 | +}) |
0 commit comments