Skip to content

Commit 6d5fbf7

Browse files
committed
feat(amazonq): skip registering run command log file
1 parent c3ea31d commit 6d5fbf7

File tree

5 files changed

+159
-2
lines changed

5 files changed

+159
-2
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"type": "Feature",
3+
"description": "The logs emitted by the Agent during user command execution will be accepted and written to .amazonq/dev/run_command.log file in the user's local repository."
4+
}

packages/core/src/amazonq/session/sessionState.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import { prepareRepoData, getDeletedFileInfos, registerNewFiles, PrepareRepoData
2929
import { uploadCode } from '../util/upload'
3030

3131
export const EmptyCodeGenID = 'EMPTY_CURRENT_CODE_GENERATION_ID'
32+
export const RunCommandLogFileName = '.amazonq/dev/run_command.log'
3233

3334
export interface BaseMessenger {
3435
sendAnswer(params: any): void
@@ -103,6 +104,16 @@ export abstract class CodeGenBase {
103104
case CodeGenerationStatus.COMPLETE: {
104105
const { newFileContents, deletedFiles, references } =
105106
await this.config.proxyClient.exportResultArchive(this.conversationId)
107+
108+
const logFileInfo = newFileContents.find(
109+
(file: { zipFilePath: string; fileContent: string }) =>
110+
file.zipFilePath === RunCommandLogFileName
111+
)
112+
if (logFileInfo) {
113+
getLogger().info(`Run Command logs: \n ${logFileInfo.fileContent}`)
114+
newFileContents.splice(newFileContents.indexOf(logFileInfo), 1)
115+
}
116+
106117
const newFileInfo = registerNewFiles(
107118
fs,
108119
newFileContents,

packages/core/src/shared/virtualFilesystem.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ export class VirtualFileSystem implements vscode.FileSystemProvider {
4646
if (this.fileProviders[key] !== undefined) {
4747
throw new Error('Cannot re-register a provider for the same URI')
4848
}
49-
5049
this.fileProviders[key] = provider
5150
const onDidChange = provider.onDidChange(() => {
5251
this._onDidChangeFile.fire([{ uri, type: vscode.FileChangeType.Changed }])
Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
/*!
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
import sinon from 'sinon'
7+
import { CodeGenBase } from '../../../amazonq/session/sessionState'
8+
import { RunCommandLogFileName } from '../../../amazonq/session/sessionState'
9+
import assert from 'assert'
10+
11+
describe('CodeGenBase generateCode log file handling', () => {
12+
class TestCodeGen extends CodeGenBase {
13+
public generatedFiles: any[] = []
14+
constructor(config: any, tabID: string) {
15+
super(config, tabID)
16+
}
17+
protected handleProgress(_messenger: any): void {
18+
// No-op for test.
19+
}
20+
protected getScheme(): string {
21+
return 'file'
22+
}
23+
protected getTimeoutErrorCode(): string {
24+
return 'test_timeout'
25+
}
26+
protected handleGenerationComplete(_messenger: any, newFileInfo: any[]): void {
27+
this.generatedFiles = newFileInfo
28+
}
29+
protected handleError(_messenger: any, _codegenResult: any): Error {
30+
throw new Error('handleError called')
31+
}
32+
}
33+
34+
let fakeProxyClient: any
35+
let testConfig: any
36+
let fsMock: any
37+
let messengerMock: any
38+
let telemetryMock: any
39+
let loggerMock: any
40+
let testAction: any
41+
42+
beforeEach(() => {
43+
fakeProxyClient = {
44+
getCodeGeneration: sinon.stub().resolves({
45+
codeGenerationStatus: { status: 'Complete' },
46+
codeGenerationRemainingIterationCount: 0,
47+
codeGenerationTotalIterationCount: 1,
48+
}),
49+
exportResultArchive: sinon.stub(),
50+
}
51+
52+
testConfig = {
53+
conversationId: 'conv_test',
54+
uploadId: 'upload_test',
55+
workspaceRoots: ['/workspace'],
56+
proxyClient: fakeProxyClient,
57+
}
58+
59+
fsMock = {
60+
writeFile: sinon.stub().resolves(),
61+
}
62+
63+
messengerMock = { sendAnswer: sinon.spy() }
64+
65+
telemetryMock = {
66+
setCodeGenerationResult: sinon.spy(),
67+
setNumberOfFilesGenerated: sinon.spy(),
68+
setAmazonqNumberOfReferences: sinon.spy(),
69+
setGenerateCodeIteration: sinon.spy(),
70+
setGenerateCodeLastInvocationTime: sinon.spy(),
71+
recordUserCodeGenerationTelemetry: sinon.spy(),
72+
}
73+
74+
loggerMock = {
75+
// addContent: sinon.spy(),
76+
info: sinon.spy(),
77+
}
78+
79+
testAction = {
80+
fs: fsMock,
81+
messenger: messengerMock,
82+
logger: loggerMock,
83+
tokenSource: { token: { isCancellationRequested: false, onCancellationRequested: () => {} } },
84+
}
85+
})
86+
87+
afterEach(() => {
88+
sinon.restore()
89+
})
90+
91+
it('adds the log content to logger if present and excludes it from new files', async () => {
92+
const logFileInfo = {
93+
zipFilePath: RunCommandLogFileName,
94+
fileContent: 'newLog',
95+
}
96+
const otherFile = { zipFilePath: 'other.ts', fileContent: 'other content' }
97+
fakeProxyClient.exportResultArchive.resolves({
98+
newFileContents: [logFileInfo, otherFile],
99+
deletedFiles: [],
100+
references: [],
101+
})
102+
103+
const testCodeGen = new TestCodeGen(testConfig, 'tab1')
104+
105+
const result = await testCodeGen.generateCode({
106+
messenger: messengerMock,
107+
fs: fsMock,
108+
codeGenerationId: 'codegen1',
109+
telemetry: telemetryMock,
110+
workspaceFolders: [] as any,
111+
action: testAction,
112+
})
113+
114+
sinon.assert.calledWith(loggerMock.info, `Run Command logs: \n ${logFileInfo.fileContent}`)
115+
116+
sinon.assert.calledWith(fsMock, [otherFile], testConfig.uploadId, [] as any, testConfig.conversationId, 'file')
117+
118+
assert.deepStrictEqual(result.newFiles, [otherFile])
119+
})
120+
121+
it('skips log file handling if log file is not present', async () => {
122+
const file1 = { zipFilePath: 'file1.ts', fileContent: 'content1' }
123+
fakeProxyClient.exportResultArchive.resolves({
124+
newFileContents: [file1],
125+
deletedFiles: [],
126+
references: [],
127+
})
128+
129+
const testCodeGen = new TestCodeGen(testConfig, 'tab1')
130+
131+
const result = await testCodeGen.generateCode({
132+
messenger: messengerMock,
133+
fs: fsMock,
134+
codeGenerationId: 'codegen2',
135+
telemetry: telemetryMock,
136+
workspaceFolders: [] as any,
137+
action: testAction,
138+
})
139+
140+
sinon.assert.notCalled(loggerMock.info)
141+
sinon.assert.calledWith(fsMock, [file1], testConfig.uploadId, [] as any, testConfig.conversationId, 'file')
142+
assert.deepStrictEqual(result.newFiles, [file1])
143+
})
144+
})

packages/core/src/test/amazonqDoc/session/sessionState.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import assert from 'assert'
88
import sinon from 'sinon'
99
import { DocPrepareCodeGenState } from '../../../amazonqDoc'
1010
import { createMockSessionStateAction } from '../../amazonq/utils'
11-
1211
import { createTestContext, setupTestHooks } from '../../amazonq/session/testSetup'
1312

1413
describe('sessionStateDoc', () => {

0 commit comments

Comments
 (0)