Skip to content

Commit 7ebe0e9

Browse files
committed
feat(amazonq): skip registering run command log file
1 parent e01574f commit 7ebe0e9

File tree

3 files changed

+122
-1
lines changed

3 files changed

+122
-1
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: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*/
55

66
import * as vscode from 'vscode'
7+
import * as path from 'path'
78
import { ToolkitError } from '../../shared/errors'
89
import globals from '../../shared/extensionGlobals'
910
import { getLogger } from '../../shared/logger/logger'
@@ -29,6 +30,7 @@ import { prepareRepoData, getDeletedFileInfos, registerNewFiles, PrepareRepoData
2930
import { uploadCode } from '../util/upload'
3031

3132
export const EmptyCodeGenID = 'EMPTY_CURRENT_CODE_GENERATION_ID'
33+
const RunCommandLogFileName = '.amazonq/dev/run_command.log'
3234

3335
export interface BaseMessenger {
3436
sendAnswer(params: any): void
@@ -103,6 +105,22 @@ export abstract class CodeGenBase {
103105
case CodeGenerationStatus.COMPLETE: {
104106
const { newFileContents, deletedFiles, references } =
105107
await this.config.proxyClient.exportResultArchive(this.conversationId)
108+
109+
const logFileInfo = newFileContents.find(
110+
(file: { zipFilePath: string; fileContent: string }) =>
111+
file.zipFilePath === RunCommandLogFileName
112+
)
113+
if (logFileInfo) {
114+
const filePath = path.join(this.config.workspaceRoots[0], RunCommandLogFileName)
115+
const fileUri = vscode.Uri.file(filePath)
116+
117+
await fs.writeFile(fileUri, new TextEncoder().encode(logFileInfo.fileContent), {
118+
create: true,
119+
overwrite: true,
120+
})
121+
newFileContents.splice(newFileContents.indexOf(logFileInfo), 1)
122+
}
123+
106124
const newFileInfo = registerNewFiles(
107125
fs,
108126
newFileContents,

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

Lines changed: 100 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ 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'
12+
import * as filesModule from '../../../amazonq/util/files'
13+
import { CodeGenBase as CodeGenBaseClass } from '../../../amazonq/session/sessionState'
1314

1415
describe('sessionStateDoc', () => {
1516
const context = createTestContext()
@@ -26,4 +27,102 @@ describe('sessionStateDoc', () => {
2627
})
2728
})
2829
})
30+
31+
describe('CodeGenBase generateCode log file handling', () => {
32+
const RunCommandLogFileName = '.amazonq/dev/run_command.log'
33+
34+
class TestCodeGen extends CodeGenBaseClass {
35+
public generatedFiles: any[] = []
36+
constructor(config: any, tabID: string) {
37+
super(config, tabID)
38+
}
39+
protected handleProgress(_messenger: any): void {}
40+
protected getScheme(): string {
41+
return 'file'
42+
}
43+
protected getTimeoutErrorCode(): string {
44+
return 'test_timeout'
45+
}
46+
protected handleGenerationComplete(_messenger: any, newFileInfo: any[]): void {
47+
this.generatedFiles = newFileInfo
48+
}
49+
protected handleError(_messenger: any, _codegenResult: any): Error {
50+
throw new Error('handleError called')
51+
}
52+
}
53+
54+
let testConfig: any, fakeProxyClient: any, fsMock: any, messengerMock: any, testAction: any
55+
56+
beforeEach(() => {
57+
fakeProxyClient = {
58+
getCodeGeneration: sinon.stub().resolves({
59+
codeGenerationStatus: { status: 'Complete' },
60+
codeGenerationRemainingIterationCount: 0,
61+
codeGenerationTotalIterationCount: 1,
62+
}),
63+
exportResultArchive: sinon.stub(),
64+
}
65+
66+
testConfig = {
67+
conversationId: 'conv1',
68+
uploadId: 'upload1',
69+
workspaceRoots: ['/workspace'],
70+
proxyClient: fakeProxyClient,
71+
}
72+
73+
fsMock = {
74+
writeFile: sinon.stub().resolves(),
75+
}
76+
77+
messengerMock = { sendAnswer: sinon.spy() }
78+
79+
testAction = {
80+
fs: fsMock,
81+
messenger: messengerMock,
82+
tokenSource: { token: { isCancellationRequested: false, onCancellationRequested: () => {} } },
83+
}
84+
})
85+
86+
afterEach(() => {
87+
sinon.restore()
88+
})
89+
90+
it('writes to the log file, present or not', async () => {
91+
const logFileInfo = {
92+
zipFilePath: RunCommandLogFileName,
93+
fileContent: 'newLog',
94+
}
95+
const otherFile = { zipFilePath: 'other.ts', fileContent: 'other' }
96+
97+
fakeProxyClient.exportResultArchive.resolves({
98+
newFileContents: [logFileInfo, otherFile],
99+
deletedFiles: [],
100+
references: [],
101+
})
102+
103+
// Minimal stubs to simulate file processing behavior.
104+
sinon.stub(filesModule, 'registerNewFiles').callsFake((_, newFileContents: any[]) => newFileContents)
105+
sinon.stub(filesModule, 'getDeletedFileInfos').callsFake(() => [])
106+
107+
const testCodeGen = new TestCodeGen(testConfig, 'tab1')
108+
109+
await testCodeGen.generateCode({
110+
messenger: messengerMock,
111+
fs: fsMock,
112+
codeGenerationId: 'codegen2',
113+
telemetry: {} as any,
114+
workspaceFolders: {} as any,
115+
action: testAction,
116+
})
117+
118+
const expectedFilePath = `${testConfig.workspaceRoots[0]}/${RunCommandLogFileName}`
119+
const fileUri = vscode.Uri.file(expectedFilePath)
120+
sinon.assert.calledWith(fsMock.writeFile, fileUri, new TextEncoder().encode('newLog'), {
121+
create: true,
122+
overwrite: true,
123+
})
124+
125+
assert.deepStrictEqual(testCodeGen.generatedFiles, [otherFile])
126+
})
127+
})
29128
})

0 commit comments

Comments
 (0)