@@ -1344,54 +1344,60 @@ test("ctrl+c dismisses autocomplete and shell mode before exiting", async () =>
13441344 expect ( setup . renderer . isDestroyed ) . toBe ( false )
13451345} )
13461346
1347- test ( "enter submits a prompt ending in a path when no slash command matches" , async ( ) => {
1348- const location = { directory, project : { id : "project" , directory, canonical : directory } }
1349- const submitted = Promise . withResolvers < unknown > ( )
1350- let session : unknown
1351- await using setup = await createAppFixture ( {
1352- config : { animations : false , tabs : { mode : "off" } } ,
1353- fetch : async ( url , request ) => {
1354- if ( url . pathname === "/api/location" ) return json ( location )
1355- if ( url . pathname === "/api/agent" )
1356- return json ( { location, data : [ { id : "build" , mode : "primary" , hidden : false , permissions : [ ] } ] } )
1357- if ( url . pathname === "/api/model" )
1358- return json ( { location, data : [ { id : "model" , providerID : "provider" , name : "Remote Model" , variants : [ ] } ] } )
1359- if ( url . pathname === "/api/provider" ) return json ( { location, data : [ { id : "provider" , name : "Provider" } ] } )
1360- if ( url . pathname === "/api/session" && request . method === "POST" ) {
1361- session = {
1362- ...( await request . json ( ) ) ,
1363- projectID : "project" ,
1364- cost : 0 ,
1365- tokens : { input : 0 , output : 0 , reasoning : 0 , cache : { read : 0 , write : 0 } } ,
1366- time : { created : 0 , updated : 0 } ,
1347+ test . each ( [
1348+ [ "submits a prompt ending in a path" , "list files in /tmp" , true ] ,
1349+ [ "keeps a mistyped leading command blocked" , "/zzzz" , false ] ,
1350+ ] as const ) (
1351+ "enter %s when no slash command matches" ,
1352+ async ( _ , text , submits ) => {
1353+ const location = { directory, project : { id : "project" , directory, canonical : directory } }
1354+ const submitted = Promise . withResolvers < unknown > ( )
1355+ let session : unknown
1356+ await using setup = await createAppFixture ( {
1357+ config : { animations : false , tabs : { mode : "off" } } ,
1358+ fetch : async ( url , request ) => {
1359+ if ( url . pathname === "/api/location" ) return json ( location )
1360+ if ( url . pathname === "/api/agent" )
1361+ return json ( { location, data : [ { id : "build" , mode : "primary" , hidden : false , permissions : [ ] } ] } )
1362+ if ( url . pathname === "/api/model" )
1363+ return json ( { location, data : [ { id : "model" , providerID : "provider" , name : "Remote Model" , variants : [ ] } ] } )
1364+ if ( url . pathname === "/api/provider" ) return json ( { location, data : [ { id : "provider" , name : "Provider" } ] } )
1365+ if ( url . pathname === "/api/session" && request . method === "POST" ) {
1366+ session = {
1367+ ...( await request . json ( ) ) ,
1368+ projectID : "project" ,
1369+ cost : 0 ,
1370+ tokens : { input : 0 , output : 0 , reasoning : 0 , cache : { read : 0 , write : 0 } } ,
1371+ time : { created : 0 , updated : 0 } ,
1372+ }
1373+ return json ( { data : session } )
13671374 }
1368- return json ( { data : session } )
1369- }
1370- if ( / ^ \/ a p i \/ s e s s i o n \/ [ ^ / ] + \/ p r o m p t $ / . test ( url . pathname ) ) {
1371- submitted . resolve ( await request . json ( ) )
1372- return json ( { data : { } } )
1373- }
1374- if ( / ^ \/ a p i \/ s e s s i o n \/ [ ^ / ] + \/ ( m e s s a g e | i n b o x | p e r m i s s i o n ) $ / . test ( url . pathname ) )
1375- return json ( { data : [ ] , cursor : { } } )
1376- if ( session && / ^ \/ a p i \/ s e s s i o n \/ [ ^ / ] + $ / . test ( url . pathname ) ) return json ( { data : session } )
1377- return undefined
1378- } ,
1379- } )
1375+ if ( / ^ \/ a p i \/ s e s s i o n \/ [ ^ / ] + \/ p r o m p t $ / . test ( url . pathname ) ) {
1376+ submitted . resolve ( await request . json ( ) )
1377+ return json ( { data : { } } )
1378+ }
1379+ if ( / ^ \/ a p i \/ s e s s i o n \/ [ ^ / ] + \/ ( m e s s a g e | i n b o x | p e r m i s s i o n ) $ / . test ( url . pathname ) )
1380+ return json ( { data : [ ] , cursor : { } } )
1381+ if ( session && / ^ \/ a p i \/ s e s s i o n \/ [ ^ / ] + $ / . test ( url . pathname ) ) return json ( { data : session } )
1382+ return undefined
1383+ } ,
1384+ } )
13801385
1381- await setup . ready
1382- await setup . waitForFrame ( ( frame ) => frame . includes ( "Build · Remote Model Provider" ) )
1383- await setup . mockInput . typeText ( "list files in /tmp" )
1384- await setup . waitForFrame ( ( frame ) => frame . includes ( "No matching commands" ) )
1385- setup . mockInput . pressEnter ( )
1386- expect (
1387- await Promise . race ( [
1388- submitted . promise ,
1389- Bun . sleep ( 2_000 ) . then ( ( ) => {
1390- throw new Error ( "prompt was not submitted" )
1391- } ) ,
1392- ] ) ,
1393- ) . toMatchObject ( { text : "list files in /tmp" } )
1394- } , 10_000 )
1386+ await setup . ready
1387+ await setup . waitForFrame ( ( frame ) => frame . includes ( "Build · Remote Model Provider" ) )
1388+ await setup . mockInput . typeText ( text )
1389+ await setup . waitForFrame ( ( frame ) => frame . includes ( "No matching commands" ) )
1390+ setup . mockInput . pressEnter ( )
1391+ const result = await Promise . race ( [ submitted . promise , Bun . sleep ( 2_000 ) . then ( ( ) => undefined ) ] )
1392+ if ( ! submits ) {
1393+ expect ( result ) . toBeUndefined ( )
1394+ expect ( setup . captureCharFrame ( ) ) . toContain ( "No matching commands" )
1395+ return
1396+ }
1397+ expect ( result ) . toMatchObject ( { text } )
1398+ } ,
1399+ 10_000 ,
1400+ )
13951401
13961402test . skipIf ( process . platform === "win32" ) . each ( [ "manual" , "select" ] as const ) (
13971403 "selection copy and pane management respect %s mode in the prompt and terminal pane" ,
0 commit comments