-
Notifications
You must be signed in to change notification settings - Fork 65
feat(amazonq): inline unit test generation #1406
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 all commits
Commits
Show all changes
42 commits
Select commit
Hold shift + click to select a range
7fe0b1f
feat(amazonq): enhanced utg
Will-ShaoHua 1750496
test(amazonq): isTestFile
Will-ShaoHua 848a50b
test(amazonq): javaTestIntent
Will-ShaoHua c54e63a
test(amazonq): py ts js TestIntent
Will-ShaoHua b1be159
chore(amazonq): chore
Will-ShaoHua 1d33836
test(amazonq): inferFocalFilename
Will-ShaoHua c6918ed
test(amazonq): inferFocalFilename
Will-ShaoHua 0d6c098
test(amazonq): extractImportedPaths - 1
Will-ShaoHua 69441fd
test(amazonq): extractImportedPaths - 2
Will-ShaoHua 5190fe1
test(amazonq): extractImportedPaths - 3
Will-ShaoHua abfc86b
test(amazonq): extractExportedSymbolsFromFile
Will-ShaoHua a450339
test(amazonq): extractExportedSymbolsFromFile - 2
Will-ShaoHua d88cf49
feat(amazonq): walk implementation
Will-ShaoHua 2dc1bd5
feat(amazonq): fix java test intent regex
Will-ShaoHua 80ce2ca
feat(amazonq): add more test intent detection test cases
Will-ShaoHua 0a2f577
chore(amazonq): jsTsTestIntent
Will-ShaoHua bc4d7bb
feat(amazonq): utg hookup
Will-ShaoHua 029ed6b
feat(amazonq): utg hookup
Will-ShaoHua d78c71b
fix(amazonq): bugfix
Will-ShaoHua 3da31b7
chore(amazonq): nit
Will-ShaoHua cd123b9
chore(amazonq): logging
Will-ShaoHua 517ec28
Merge remote-tracking branch 'upstream/main' into utg-2
Will-ShaoHua fca2737
feat(amazonq): loose test intent detection criteria
Will-ShaoHua 7aecdf6
test(amazonq): fix failing test case
Will-ShaoHua 1874992
fix(amazonq): sup context should has len <= 10240
Will-ShaoHua 6cd8d92
test(amazonq): fix TestsFoo.java not detected correctly for utg
Will-ShaoHua d872700
fix(amazonq): focalfileResolution.extractImportedPaths, continue shou…
Will-ShaoHua d25cbfc
fix(amazonq): utg test intent not using file basename to check isTest…
Will-ShaoHua fd5a6f4
fix(amazonq): nit
Will-ShaoHua 2cd3b2f
feat(amazonq): expand python/java test file keyword regex
Will-ShaoHua c9a47cb
test(amazonq): temporarily disable test
Will-ShaoHua 0f3f6e8
test(amazonq): temporarily disable test
Will-ShaoHua a8db632
test(amazonq): try fix test failure on windows
Will-ShaoHua b10b601
test(amazonq): nit
Will-ShaoHua 6373449
test(amazonq): attempt to dianost windows test failure
Will-ShaoHua 8a33f2c
test(amazonq): attempt fix test failure on windows
Will-ShaoHua 12d0f85
fix(amazonq): remove console.log
Will-ShaoHua 4ca6239
fix(amazonq): remove console.log
Will-ShaoHua 0c3f2a5
Merge remote-tracking branch 'upstream/main' into utg-2
Will-ShaoHua 1d2eaed
fix(amazonq): todo
Will-ShaoHua 7c60ba1
fix(amazonq): todo
Will-ShaoHua 1f87cfc
fix(amazonq): revert
Will-ShaoHua 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
281 changes: 281 additions & 0 deletions
281
server/aws-lsp-codewhisperer/src/shared/supplementalContextUtil/focalFileResolution.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,281 @@ | ||
/*! | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import * as assert from 'assert' | ||
import * as fs from 'fs' | ||
import * as path from 'path' | ||
import * as os from 'os' | ||
import { FocalFileResolver } from './focalFileResolution' | ||
|
||
describe('focalFileResolver', function () { | ||
let sut: FocalFileResolver | ||
let tmpProjectRoot: string | ||
|
||
beforeEach(() => { | ||
sut = new FocalFileResolver() | ||
tmpProjectRoot = fs.mkdtempSync(path.join(os.tmpdir(), 'focalFileResolutionTest-')) | ||
}) | ||
|
||
afterEach(() => { | ||
fs.rmSync(tmpProjectRoot, { recursive: true, force: true }) | ||
}) | ||
|
||
describe('inferFocalFilename', function () { | ||
describe('java', function () { | ||
const testCases = ['FooTest.java', 'FooTests.java', 'TestFoo.java', 'TestsFoo.java'] | ||
|
||
for (let i = 0; i < testCases.length; i++) { | ||
const testCase = testCases[i] | ||
it(`should infer and return correct source focal file name case ${i}`, () => { | ||
const result = sut.inferFocalFilename(testCase, 'java') | ||
assert.strictEqual(result, 'Foo.java') | ||
}) | ||
} | ||
}) | ||
|
||
describe('python', function () { | ||
const testCases = ['test_py_class.py', 'py_class_test.py'] | ||
|
||
for (let i = 0; i < testCases.length; i++) { | ||
const testCase = testCases[i] | ||
it(`should infer and return correct source focal file name case ${i}`, () => { | ||
const result = sut.inferFocalFilename(testCase, 'python') | ||
assert.strictEqual(result, 'py_class.py') | ||
}) | ||
} | ||
}) | ||
|
||
describe('js', function () { | ||
const testCases = ['foo.test.js', 'foo.spec.js'] | ||
|
||
for (let i = 0; i < testCases.length; i++) { | ||
const testCase = testCases[i] | ||
it(`should infer and return correct source focal file name case ${i}`, () => { | ||
const result = sut.inferFocalFilename(testCase, 'javascript') | ||
assert.strictEqual(result, 'foo.js') | ||
}) | ||
} | ||
}) | ||
|
||
describe('ts', function () { | ||
const testCases = ['foo.test.ts', 'foo.spec.ts'] | ||
|
||
for (let i = 0; i < testCases.length; i++) { | ||
const testCase = testCases[i] | ||
it(`should infer and return correct source focal file name case ${i}`, () => { | ||
const result = sut.inferFocalFilename(testCase, 'typescript') | ||
assert.strictEqual(result, 'foo.ts') | ||
}) | ||
} | ||
}) | ||
}) | ||
|
||
describe('extractImportedPaths', function () { | ||
describe('java', function () { | ||
it('case1', function () { | ||
const p = path.join(tmpProjectRoot, 'FooTest.java') | ||
fs.writeFileSync( | ||
p, | ||
` | ||
package com.amazon.q.service; | ||
|
||
import com.amazon.q.foo.FooClass; | ||
import com.amazon.q.bar.BarClass; | ||
import com.amazon.q.baz1.baz2.BazClass; | ||
|
||
public class TestClass {} | ||
` | ||
) | ||
|
||
const actual = sut.extractImportedPaths(p, 'java', tmpProjectRoot) | ||
assert.strictEqual(actual.size, 1) | ||
assert.ok(actual.has(path.join('com', 'amazon', 'q', 'service'))) | ||
}) | ||
}) | ||
|
||
describe('python', function () { | ||
it('case1', function () { | ||
const p = path.join(tmpProjectRoot, 'test_py_class.py') | ||
fs.writeFileSync( | ||
p, | ||
` | ||
import pytest | ||
import sys | ||
import os | ||
from py_class import PyClass | ||
from util import (foo,bar,baz) | ||
|
||
def test_py_class(): | ||
assert True | ||
` | ||
) | ||
|
||
const actual = sut.extractImportedPaths(p, 'python', tmpProjectRoot) | ||
assert.strictEqual(actual.size, 5) | ||
assert.ok(actual.has('py_class')) | ||
assert.ok(actual.has('pytest')) | ||
assert.ok(actual.has('sys')) | ||
assert.ok(actual.has('os')) | ||
assert.ok(actual.has('util')) | ||
}) | ||
}) | ||
|
||
describe('ts', function () { | ||
it('case1', function () { | ||
const p = path.join(tmpProjectRoot, 'src', 'test', 'foo.test.ts') | ||
fs.mkdirSync(path.join(tmpProjectRoot, 'src', 'test'), { recursive: true }) | ||
fs.writeFileSync( | ||
p, | ||
` | ||
import { foo } from '../foo'; | ||
import baz from '../baz'; | ||
import * as util from '../utils/util'; | ||
|
||
test('foo', () => { | ||
expect(foo()).toBe('foo'); | ||
}); | ||
` | ||
) | ||
|
||
const actual = sut.extractImportedPaths(p, 'typescript', tmpProjectRoot) | ||
assert.strictEqual(actual.size, 3) | ||
assert.ok(actual.has(path.join(tmpProjectRoot, 'src', 'foo'))) | ||
assert.ok(actual.has(path.join(tmpProjectRoot, 'src', 'baz'))) | ||
assert.ok(actual.has(path.join(tmpProjectRoot, 'src', 'utils', 'util'))) | ||
}) | ||
}) | ||
|
||
describe('js', function () {}) | ||
}) | ||
|
||
describe('extractImportedSymbols', function () { | ||
it('case1', function () { | ||
const p = path.join(tmpProjectRoot, 'foo.js') | ||
fs.writeFileSync( | ||
p, | ||
` | ||
import { foo, bar } from '../src/sample'; | ||
import baz from '../src/sample';` | ||
) | ||
|
||
const actual = sut.extractImportedSymbols(p) | ||
assert.strictEqual(actual.size, 3) | ||
assert.ok(actual.has('foo')) | ||
assert.ok(actual.has('bar')) | ||
assert.ok(actual.has('baz')) | ||
}) | ||
}) | ||
|
||
describe('extractExportedSymbolsFromFile', function () { | ||
it('', function () { | ||
fs.mkdirSync(path.join(tmpProjectRoot, 'src', 'test'), { recursive: true }) | ||
const p = path.join(tmpProjectRoot, 'src', 'test', 'sample.js') | ||
fs.writeFileSync( | ||
p, | ||
` | ||
export function foo() {} | ||
export const bar = 1; | ||
export default baz; | ||
export { alpha, beta };` | ||
) | ||
|
||
const actual = sut.extractExportedSymbolsFromFile(p) | ||
assert.strictEqual(actual.size, 5) | ||
assert.ok(actual.has('foo')) | ||
assert.ok(actual.has('bar')) | ||
assert.ok(actual.has('baz')) | ||
assert.ok(actual.has('alpha')) | ||
assert.ok(actual.has('beta')) | ||
}) | ||
}) | ||
|
||
describe('resolveImportToAbsPath', function () { | ||
it('', function () { | ||
fs.mkdirSync(path.join(tmpProjectRoot, 'src', 'test'), { recursive: true }) | ||
const p = path.join(tmpProjectRoot, 'src', 'test', 'foo.test.ts') | ||
const actual = sut.resolveImportToAbsPath(p, '../helper', tmpProjectRoot, 'typescript') | ||
assert.strictEqual(actual, path.join(tmpProjectRoot, 'src', 'helper')) | ||
}) | ||
|
||
it('alias', function () { | ||
fs.mkdirSync(path.join(tmpProjectRoot, 'src', 'test'), { recursive: true }) | ||
const p = path.join(tmpProjectRoot, 'src', 'test', 'foo.test.ts') | ||
const actual = sut.resolveImportToAbsPath('foo.test.ts', '@src/utils', tmpProjectRoot, 'typescript') | ||
assert.strictEqual(actual, path.join(tmpProjectRoot, 'src', 'utils')) | ||
}) | ||
}) | ||
|
||
describe('resolvePackageToPath', function () { | ||
it('dot', function () { | ||
const actual = sut.resolvePackageToPath('com.amazon.q.service', '.') | ||
assert.strictEqual(actual, path.join('com', 'amazon', 'q', 'service')) | ||
}) | ||
|
||
it('slash', function () { | ||
const actual = sut.resolvePackageToPath('com/amazon/q/service', '/') | ||
assert.strictEqual(actual, path.join('com', 'amazon', 'q', 'service')) | ||
}) | ||
}) | ||
|
||
describe('walk should exclude hidden files and only include files with correct extensions', function () { | ||
/** | ||
* - root/ | ||
* - src/ | ||
* - foo.ts | ||
* - bar.ts | ||
* - ui/ | ||
* - frontend.vue | ||
* - ui.html | ||
* - theme.css | ||
* - test/ | ||
* - foo.test.ts | ||
* - bar.test.ts | ||
* - .github/ | ||
* - workflows/ | ||
* - foo.yml | ||
* - pull_request_template.md | ||
* - .idea | ||
* - aws.xml | ||
* - package.json | ||
* - package-lock.json | ||
* - webpack.config | ||
*/ | ||
it('case 1', async function () { | ||
fs.mkdirSync(path.join(tmpProjectRoot, 'src'), { recursive: true }) | ||
fs.writeFileSync(path.join(tmpProjectRoot, 'src', 'foo.ts'), 'class Foo') | ||
fs.writeFileSync(path.join(tmpProjectRoot, 'src', 'bar.ts'), 'class Bar') | ||
|
||
fs.mkdirSync(path.join(tmpProjectRoot, 'src', 'ui'), { recursive: true }) | ||
fs.writeFileSync(path.join(tmpProjectRoot, 'src', 'ui', 'frontend.vue'), '') | ||
fs.writeFileSync(path.join(tmpProjectRoot, 'src', 'ui', 'ui.html'), '') | ||
fs.writeFileSync(path.join(tmpProjectRoot, 'src', 'ui', 'theme.css'), '') | ||
|
||
fs.mkdirSync(path.join(tmpProjectRoot, 'src', 'test'), { recursive: true }) | ||
fs.writeFileSync(path.join(tmpProjectRoot, 'src', 'test', 'foo.test.ts'), 'class FooTest') | ||
fs.writeFileSync(path.join(tmpProjectRoot, 'src', 'test', 'bar.test.ts'), 'class BarTest') | ||
|
||
fs.mkdirSync(path.join(tmpProjectRoot, '.github'), { recursive: true }) | ||
fs.mkdirSync(path.join(tmpProjectRoot, '.github', 'workflows'), { recursive: true }) | ||
fs.writeFileSync(path.join(tmpProjectRoot, '.github', 'workflows', 'foo.yml'), '') | ||
fs.writeFileSync(path.join(tmpProjectRoot, '.github', 'pull_request_template.md'), '') | ||
|
||
fs.mkdirSync(path.join(tmpProjectRoot, '.idea'), { recursive: true }) | ||
fs.writeFileSync(path.join(tmpProjectRoot, '.idea', 'aws.xml'), '') | ||
|
||
fs.writeFileSync(path.join(tmpProjectRoot, 'package.json'), '') | ||
fs.writeFileSync(path.join(tmpProjectRoot, 'package-lock.json'), '') | ||
fs.writeFileSync(path.join(tmpProjectRoot, 'webpack.config'), '') | ||
|
||
const files = await sut.walk(tmpProjectRoot, 'typescript') | ||
const basenames = files.map(it => path.basename(it)) | ||
|
||
assert.ok(files.length === 4) | ||
assert.ok(basenames.includes('foo.ts')) | ||
assert.ok(basenames.includes('bar.ts')) | ||
assert.ok(basenames.includes('foo.test.ts')) | ||
assert.ok(basenames.includes('bar.test.ts')) | ||
}) | ||
}) | ||
}) |
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.
Uh oh!
There was an error while loading. Please reload this page.