Skip to content

Commit

Permalink
test: update /dev prepareRepoData unit test to include devfile filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
willyyhuang committed Nov 14, 2024
1 parent ea5dae5 commit 38771f8
Showing 1 changed file with 44 additions and 1 deletion.
45 changes: 44 additions & 1 deletion packages/amazonq/test/unit/amazonqFeatureDev/util/files.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,25 @@ import {
ContentLengthError,
maxRepoSizeBytes,
} from 'aws-core-vscode/amazonqFeatureDev'
import { assertTelemetry, createTestWorkspace } from 'aws-core-vscode/test'
import { assertTelemetry, createTestWorkspace, getWorkspaceFolder, TestFolder } from 'aws-core-vscode/test'
import { fs, AmazonqCreateUpload } from 'aws-core-vscode/shared'
import { Span } from 'aws-core-vscode/telemetry'
import sinon from 'sinon'
import { CodeWhispererSettings } from 'aws-core-vscode/codewhisperer'

const getWorkspaceWithDevFile = async () => {
const folder = await TestFolder.create()
await folder.write('devfile.yaml', 'test')
await folder.write('file.md', 'test content')
return getWorkspaceFolder(folder.path)
}

describe('file utils', () => {
describe('prepareRepoData', function () {
afterEach(() => {
sinon.restore()
})

it('returns files in the workspace as a zip', async function () {
// these variables are a manual selection of settings for the test in order to test the collectFiles function
const fileAmount = 2
Expand Down Expand Up @@ -56,6 +68,37 @@ describe('file utils', () => {
assertTelemetry('amazonq_bundleExtensionIgnored', { filenameExt: 'mp4', count: 1 })
})

it('should ignore devfile.yaml when setting is disabled', async function () {
const workspace = await getWorkspaceWithDevFile()
sinon.stub(CodeWhispererSettings.instance, 'getDevCommandWorkspaceConfigurations').returns({})

const telemetry = new TelemetryHelper()
const result = await prepareRepoData([workspace.uri.fsPath], [workspace], telemetry, {
record: () => {},
} as unknown as Span<AmazonqCreateUpload>)
assert.strictEqual(Buffer.isBuffer(result.zipFileBuffer), true)
// checksum is not the same across different test executions because some unique random folder names are generated
assert.strictEqual(result.zipFileChecksum.length, 44)
assert.strictEqual(telemetry.repositorySize, 12)
sinon.reset()
})

it('should include devfile.yaml when setting is enabled', async function () {
const workspace = await getWorkspaceWithDevFile()
sinon.stub(CodeWhispererSettings.instance, 'getDevCommandWorkspaceConfigurations').returns({
[workspace.uri.fsPath]: true,
})

const telemetry = new TelemetryHelper()
const result = await prepareRepoData([workspace.uri.fsPath], [workspace], telemetry, {
record: () => {},
} as unknown as Span<AmazonqCreateUpload>)
assert.strictEqual(Buffer.isBuffer(result.zipFileBuffer), true)
// checksum is not the same across different test executions because some unique random folder names are generated
assert.strictEqual(result.zipFileChecksum.length, 44)
assert.strictEqual(telemetry.repositorySize, 16)
})

// Test the logic that allows the customer to modify root source folder
it('prepareRepoData throws a ContentLengthError code when repo is too big', async function () {
const workspace = await createTestWorkspace(1, {})
Expand Down

0 comments on commit 38771f8

Please sign in to comment.