@@ -8,8 +8,9 @@ import assert from 'assert'
88import sinon from 'sinon'
99import { DocPrepareCodeGenState } from '../../../amazonqDoc'
1010import { createMockSessionStateAction } from '../../amazonq/utils'
11-
1211import { createTestContext , setupTestHooks } from '../../amazonq/session/testSetup'
12+ import * as filesModule from '../../../amazonq/util/files'
13+ import { CodeGenBase as CodeGenBaseClass } from '../../../amazonq/session/sessionState'
1314
1415describe ( '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