@@ -24,7 +24,7 @@ describe('TemplateManager', () => {
2424 } ) ;
2525
2626 describe ( 'setupSingleEnvironment' , ( ) => {
27- it ( 'should copy context file when it exists ' , async ( ) => {
27+ it ( 'should not copy context files ' , async ( ) => {
2828 const env : EnvironmentDefinition = {
2929 code : 'test-env' ,
3030 name : 'Test Environment' ,
@@ -33,24 +33,17 @@ describe('TemplateManager', () => {
3333 isCustomCommandPath : false
3434 } ;
3535
36- ( mockFs . pathExists as any )
37- . mockResolvedValueOnce ( true )
38- . mockResolvedValueOnce ( true ) ;
36+ ( mockFs . pathExists as any ) . mockResolvedValueOnce ( true ) ;
3937
4038 ( mockFs . readdir as any ) . mockResolvedValue ( [ 'command1.md' , 'command2.toml' ] ) ;
4139
4240 const result = await ( templateManager as any ) . setupSingleEnvironment ( env ) ;
4341
44- expect ( mockFs . copy ) . toHaveBeenCalledWith (
45- path . join ( templateManager [ 'templatesDir' ] , 'env' , 'base.md' ) ,
46- path . join ( templateManager [ 'targetDir' ] , env . contextFileName )
47- ) ;
48- expect ( result ) . toContain ( path . join ( templateManager [ 'targetDir' ] , env . contextFileName ) ) ;
42+ expect ( mockFs . copy ) . toHaveBeenCalledTimes ( 1 ) ;
43+ expect ( result ) . toEqual ( [ path . join ( templateManager [ 'targetDir' ] , env . commandPath , 'command1.md' ) ] ) ;
4944 } ) ;
5045
51- it ( 'should warn when context file does not exist' , async ( ) => {
52- const consoleWarnSpy = jest . spyOn ( console , 'warn' ) . mockImplementation ( ) ;
53-
46+ it ( 'should not warn for missing context file' , async ( ) => {
5447 const env : EnvironmentDefinition = {
5548 code : 'test-env' ,
5649 name : 'Test Environment' ,
@@ -59,17 +52,14 @@ describe('TemplateManager', () => {
5952 isCustomCommandPath : false
6053 } ;
6154
62- ( mockFs . pathExists as any )
63- . mockResolvedValueOnce ( false )
64- . mockResolvedValueOnce ( true ) ;
55+ const consoleWarnSpy = jest . spyOn ( console , 'warn' ) . mockImplementation ( ) ;
56+ ( mockFs . pathExists as any ) . mockResolvedValueOnce ( true ) ;
6557
6658 ( mockFs . readdir as any ) . mockResolvedValue ( [ 'command1.md' ] ) ;
6759
6860 const result = await ( templateManager as any ) . setupSingleEnvironment ( env ) ;
6961
70- expect ( consoleWarnSpy ) . toHaveBeenCalledWith (
71- expect . stringContaining ( 'Warning: Context file not found' )
72- ) ;
62+ expect ( consoleWarnSpy ) . not . toHaveBeenCalled ( ) ;
7363 expect ( result ) . toEqual ( [ path . join ( templateManager [ 'targetDir' ] , env . commandPath , 'command1.md' ) ] ) ;
7464
7565 consoleWarnSpy . mockRestore ( ) ;
@@ -86,9 +76,7 @@ describe('TemplateManager', () => {
8676
8777 const mockCommandFiles = [ 'command1.md' , 'command2.toml' , 'command3.md' ] ;
8878
89- ( mockFs . pathExists as any )
90- . mockResolvedValueOnce ( true ) // context file exists
91- . mockResolvedValueOnce ( true ) ; // commands directory exists
79+ ( mockFs . pathExists as any ) . mockResolvedValueOnce ( true ) ; // commands directory exists
9280
9381 ( mockFs . readdir as any ) . mockResolvedValue ( mockCommandFiles ) ;
9482
@@ -121,13 +109,11 @@ describe('TemplateManager', () => {
121109 isCustomCommandPath : true
122110 } ;
123111
124- ( mockFs . pathExists as any ) . mockResolvedValueOnce ( true ) ;
125-
126112 const result = await ( templateManager as any ) . setupSingleEnvironment ( env ) ;
127113
128114 expect ( mockFs . ensureDir ) . not . toHaveBeenCalled ( ) ;
129- expect ( mockFs . copy ) . toHaveBeenCalledTimes ( 1 ) ;
130- expect ( result ) . toContain ( path . join ( templateManager [ 'targetDir' ] , env . contextFileName ) ) ;
115+ expect ( mockFs . copy ) . not . toHaveBeenCalled ( ) ;
116+ expect ( result ) . toEqual ( [ ] ) ;
131117 } ) ;
132118
133119 it ( 'should handle cursor environment with special files' , async ( ) => {
@@ -142,7 +128,6 @@ describe('TemplateManager', () => {
142128 const mockRuleFiles = [ 'rule1.md' , 'rule2.toml' ] ;
143129
144130 ( mockFs . pathExists as any )
145- . mockResolvedValueOnce ( true )
146131 . mockResolvedValueOnce ( true ) . mockResolvedValueOnce ( true ) ;
147132
148133 ( mockFs . readdir as any )
@@ -180,7 +165,6 @@ description: Test command description
180165This is the prompt content.` ;
181166
182167 ( mockFs . pathExists as any )
183- . mockResolvedValueOnce ( true )
184168 . mockResolvedValueOnce ( true )
185169 . mockResolvedValueOnce ( true ) ;
186170
@@ -219,7 +203,8 @@ This is the prompt content.`;
219203 } ;
220204
221205 const testError = new Error ( 'Test error' ) ;
222- ( mockFs . pathExists as any ) . mockRejectedValue ( testError ) ;
206+ ( mockFs . pathExists as any ) . mockResolvedValueOnce ( true ) ;
207+ ( mockFs . readdir as any ) . mockRejectedValue ( testError ) ;
223208
224209 await expect ( ( templateManager as any ) . setupSingleEnvironment ( env ) ) . rejects . toThrow ( 'Test error' ) ;
225210
@@ -400,7 +385,7 @@ This is the prompt content.`;
400385 expect ( result ) . toBe ( false ) ;
401386 } ) ;
402387
403- it ( 'should return true when context file exists' , async ( ) => {
388+ it ( 'should return false when only context file exists' , async ( ) => {
404389 const envId : EnvironmentCode = 'cursor' ;
405390 const env = {
406391 code : 'cursor' ,
@@ -411,19 +396,14 @@ This is the prompt content.`;
411396
412397 mockGetEnvironment . mockReturnValue ( env ) ;
413398
414- ( mockFs . pathExists as any )
415- . mockResolvedValueOnce ( true ) // context file exists
416- . mockResolvedValueOnce ( false ) ; // command dir doesn't exist
399+ ( mockFs . pathExists as any ) . mockResolvedValueOnce ( false ) ; // command dir doesn't exist
417400
418401 const result = await templateManager . checkEnvironmentExists ( envId ) ;
419402
420- expect ( mockFs . pathExists ) . toHaveBeenCalledWith (
421- path . join ( templateManager [ 'targetDir' ] , env . contextFileName )
422- ) ;
423403 expect ( mockFs . pathExists ) . toHaveBeenCalledWith (
424404 path . join ( templateManager [ 'targetDir' ] , env . commandPath )
425405 ) ;
426- expect ( result ) . toBe ( true ) ;
406+ expect ( result ) . toBe ( false ) ;
427407 } ) ;
428408
429409 it ( 'should return true when command directory exists' , async ( ) => {
@@ -437,16 +417,14 @@ This is the prompt content.`;
437417
438418 mockGetEnvironment . mockReturnValue ( env ) ;
439419
440- ( mockFs . pathExists as any )
441- . mockResolvedValueOnce ( false ) // context file doesn't exist
442- . mockResolvedValueOnce ( true ) ; // command dir exists
420+ ( mockFs . pathExists as any ) . mockResolvedValueOnce ( true ) ; // command dir exists
443421
444422 const result = await templateManager . checkEnvironmentExists ( envId ) ;
445423
446424 expect ( result ) . toBe ( true ) ;
447425 } ) ;
448426
449- it ( 'should return false when neither context file nor command directory exists ' , async ( ) => {
427+ it ( 'should return false when command directory does not exist ' , async ( ) => {
450428 const envId : EnvironmentCode = 'cursor' ;
451429 const env = {
452430 code : 'cursor' ,
@@ -457,9 +435,7 @@ This is the prompt content.`;
457435
458436 mockGetEnvironment . mockReturnValue ( env ) ;
459437
460- ( mockFs . pathExists as any )
461- . mockResolvedValueOnce ( false ) // context file doesn't exist
462- . mockResolvedValueOnce ( false ) ; // command dir doesn't exist
438+ ( mockFs . pathExists as any ) . mockResolvedValueOnce ( false ) ; // command dir doesn't exist
463439
464440 const result = await templateManager . checkEnvironmentExists ( envId ) ;
465441
0 commit comments