@@ -12,81 +12,103 @@ describe('CLI argument parsing', () => {
1212    fixture . cleanup ( ) ; 
1313  } ) ; 
1414
15-   it ( 'should parse zero-friction  expert commands ' ,  async  ( )  =>  { 
15+   it ( 'should require explicit  expert command ' ,  async  ( )  =>  { 
1616    createTestFiles ( fixture . dir ,  { 
1717      'src/index.ts' : 'console.log("Test");' , 
1818      'backend/auth.ts' : 'export const auth = {};' 
1919    } ) ; 
2020
21-     // These should be interpreted as expert commands (with question)  
21+     // These should now fail without explicit command  
2222    const  testCases  =  [ 
23-       {  args : [ '"Why is this slow?"' ,  'src/**/*.ts' ] ,   hasQuestion :  true  } , 
24-       {  args : [ '"Explain the auth flow"' ,  'backend/**/*.ts' ] ,   hasQuestion :  true  } , 
25-       {  args : [ "'What are the security risks?'" ,  'src/**/*.ts' ] ,   hasQuestion :  true  } , 
23+       {  args : [ '"Why is this slow?"' ,  'src/**/*.ts' ]  } , 
24+       {  args : [ '"Explain the auth flow"' ,  'backend/**/*.ts' ]  } , 
25+       {  args : [ "'What are the security risks?'" ,  'src/**/*.ts' ]  } , 
2626    ] ; 
2727
2828    for  ( const  testCase  of  testCases )  { 
29-       // We can't fully test expert without API keys, but we can verify it tries to run expert  
29+       // Should fail with invalid usage error  
3030      const  result  =  await  runCLI ( testCase . args ,  {  
31-         cwd : fixture . dir , 
32-         env : {  ...process . env ,  OPENAI_API_KEY : '' ,  ANTHROPIC_API_KEY : '' ,  GOOGLE_API_KEY : '' ,  XAI_API_KEY : '' ,  GROK_API_KEY : ''  } 
31+         cwd : fixture . dir 
3332      } ) ; 
3433
35-       // Should fail asking for API key (meaning it tried expert command)  
34+       // Should fail with error about invalid usage  
3635      expect ( result . exitCode ) . toBe ( 1 ) ; 
37-       // Error message could be on stdout or stderr 
3836      const  output  =  result . stdout  +  result . stderr ; 
39-       expect ( output ) . toContain ( 'API key ' ) ; 
37+       expect ( output . toLowerCase ( ) ) . toContain ( 'invalid usage ' ) ; 
4038    } 
39+     
40+     // Test that explicit expert command works (fails with API key error) 
41+     const  result  =  await  runCLI ( [ 'expert' ,  '"Why is this slow?"' ,  '-f' ,  'src/**/*.ts' ] ,  { 
42+       cwd : fixture . dir , 
43+       env : {  ...process . env ,  OPENAI_API_KEY : '' ,  ANTHROPIC_API_KEY : '' ,  GOOGLE_API_KEY : '' ,  XAI_API_KEY : '' ,  GROK_API_KEY : ''  } 
44+     } ) ; 
45+     expect ( result . exitCode ) . toBe ( 1 ) ; 
46+     expect ( result . stdout  +  result . stderr ) . toContain ( 'API key' ) ; 
4147  } ) ; 
4248
43-   it ( 'should parse zero-friction  generate commands ' ,  async  ( )  =>  { 
49+   it ( 'should require explicit  generate command ' ,  async  ( )  =>  { 
4450    createTestFiles ( fixture . dir ,  { 
4551      'src/index.ts' : 'console.log("Test");' , 
4652      'src/utils.ts' : 'export const util = 1;' , 
4753      'tests/test.ts' : 'describe("test", () => {});' , 
4854      'main.js' : 'console.log("js");' 
4955    } ) ; 
5056
51-     // These should be interpreted as generate commands (no question)  
57+     // These should now fail without explicit command  
5258    const  testCases  =  [ 
5359      {  args : [ 'src/**/*.ts' ]  } , 
54-       {  args : [ 'src/**/*' ,  'tests/**/*' ]  } ,    // Use glob patterns for directories 
55-       {  args : [ '*.js' ,  'src/**/*.ts' ]  } ,    // Mixed patterns 
60+       {  args : [ 'src/**/*' ,  'tests/**/*' ]  } , 
61+       {  args : [ '*.js' ,  'src/**/*.ts' ]  } , 
5662    ] ; 
5763
5864    for  ( const  testCase  of  testCases )  { 
5965      const  result  =  await  runCLI ( testCase . args ,  {  cwd : fixture . dir  } ) ; 
6066
61-       // Should succeed and output prompt 
62-       expect ( result . exitCode ) . toBe ( 0 ) ; 
63-       expect ( result . stdout ) . toContain ( 'console.log("Test")' ) ; 
67+       // Should fail with invalid usage error 
68+       expect ( result . exitCode ) . toBe ( 1 ) ; 
69+       const  output  =  result . stdout  +  result . stderr ; 
70+       expect ( output . toLowerCase ( ) ) . toContain ( 'invalid usage' ) ; 
6471    } 
72+     
73+     // Test that explicit generate command works 
74+     const  result  =  await  runCLI ( [ 'generate' ,  '-f' ,  'src/**/*.ts' ] ,  {  cwd : fixture . dir  } ) ; 
75+     expect ( result . exitCode ) . toBe ( 0 ) ; 
76+     expect ( result . stdout ) . toContain ( 'console.log("Test")' ) ; 
6577  } ) ; 
6678
67-   it ( 'should handle @ prefix in file patterns' ,  async  ( )  =>  { 
79+   it ( 'should handle @ prefix in file patterns with explicit command ' ,  async  ( )  =>  { 
6880    createTestFiles ( fixture . dir ,  { 
6981      'backend/server.ts' : 'const server = {};' , 
7082      'frontend/app.tsx' : 'const app = {};' 
7183    } ) ; 
7284
73-     // @ prefix should be stripped 
74-     const  result  =  await  runCLI ( [ '@backend/**/*.ts' ] ,  {  cwd : fixture . dir  } ) ; 
85+     // @ prefix no longer works without explicit command 
86+     const  result1  =  await  runCLI ( [ '@backend/**/*.ts' ] ,  {  cwd : fixture . dir  } ) ; 
87+     expect ( result1 . exitCode ) . toBe ( 1 ) ; 
88+     expect ( ( result1 . stdout  +  result1 . stderr ) . toLowerCase ( ) ) . toContain ( 'invalid usage' ) ; 
7589
76-     expect ( result . exitCode ) . toBe ( 0 ) ; 
77-     expect ( result . stdout ) . toContain ( 'const server' ) ; 
78-     expect ( result . stdout ) . not . toContain ( 'const app' ) ; 
90+     // @ prefix should be stripped with explicit command 
91+     const  result2  =  await  runCLI ( [ 'generate' ,  '-f' ,  '@backend/*.ts' ] ,  {  cwd : fixture . dir  } ) ; 
92+     expect ( result2 . exitCode ) . toBe ( 0 ) ; 
93+     expect ( result2 . stdout ) . toContain ( 'const server' ) ; 
94+     expect ( result2 . stdout ) . not . toContain ( 'const app' ) ; 
7995  } ) ; 
8096
81-   it ( 'should save preset  with zero-friction syntax ' ,  async  ( )  =>  { 
97+   it ( 'should require explicit command even  with --save-preset ' ,  async  ( )  =>  { 
8298    createTestFiles ( fixture . dir ,  { 
8399      'src/index.ts' : 'console.log("Test");' 
84100    } ) ; 
85101
102+     // Should fail without explicit command 
86103    const  result  =  await  runCLI ( [ 'src/**/*.ts' ,  '--save-preset' ,  'my-files' ] ,  {  cwd : fixture . dir  } ) ; 
104+     expect ( result . exitCode ) . toBe ( 1 ) ; 
105+     expect ( ( result . stdout  +  result . stderr ) . toLowerCase ( ) ) . toContain ( 'invalid usage' ) ; 
87106
88-     expect ( result . exitCode ) . toBe ( 0 ) ; 
89-     expect ( result . stdout ) . toContain ( 'Saved file patterns to preset: my-files' ) ; 
107+     // Test that explicit generate command with --save-preset works 
108+     const  result2  =  await  runCLI ( [ 'generate' ,  '-f' ,  'src/**/*.ts' ,  '--save-preset' ,  'my-files' ] ,  {  cwd : fixture . dir  } ) ; 
109+     expect ( result2 . exitCode ) . toBe ( 0 ) ; 
110+     // Should generate the prompt output 
111+     expect ( result2 . stdout ) . toContain ( 'console.log("Test")' ) ; 
90112  } ) ; 
91113
92114  it ( 'should show help when no arguments provided' ,  async  ( )  =>  { 
0 commit comments