@@ -2,111 +2,30 @@ import { describe, expect, it } from "bun:test"
22import { ParseCommand } from "../../src/acp/parse-command"
33
44describe ( "ParseCommand" , ( ) => {
5- describe ( "parse" , ( ) => {
6- it ( "parses ls as list command" , ( ) => {
7- const result = ParseCommand . parse ( "ls" )
8- expect ( result ) . toEqual ( { type : "list" , cmd : "ls" , path : undefined } )
9- } )
10-
11- it ( "parses ls with path as list command" , ( ) => {
12- const result = ParseCommand . parse ( "ls /some/path" )
13- expect ( result ) . toEqual ( { type : "list" , cmd : "ls" , path : "/some/path" } )
14- } )
15-
16- it ( "parses ls with flags correctly" , ( ) => {
17- const result = ParseCommand . parse ( "ls -la /some/path" )
18- expect ( result ) . toEqual ( { type : "list" , cmd : "ls" , path : "/some/path" } )
19- } )
20-
21- it ( "parses cat as read command" , ( ) => {
22- const result = ParseCommand . parse ( "cat file.txt" )
23- expect ( result ) . toEqual ( { type : "read" , cmd : "cat" , name : "file.txt" , path : "file.txt" } )
24- } )
25-
26- it ( "parses cat with path as read command" , ( ) => {
27- const result = ParseCommand . parse ( "cat /some/path/file.txt" )
28- expect ( result ) . toEqual ( { type : "read" , cmd : "cat" , name : "file.txt" , path : "/some/path/file.txt" } )
29- } )
30-
31- it ( "parses grep as search command" , ( ) => {
32- const result = ParseCommand . parse ( "grep pattern" )
33- expect ( result ) . toEqual ( { type : "search" , cmd : "grep" , query : "pattern" , path : undefined } )
34- } )
35-
36- it ( "parses grep with path as search command" , ( ) => {
37- const result = ParseCommand . parse ( "grep pattern /some/path" )
38- expect ( result ) . toEqual ( { type : "search" , cmd : "grep" , query : "pattern" , path : "/some/path" } )
39- } )
40-
41- it ( "parses rg as search command" , ( ) => {
42- const result = ParseCommand . parse ( "rg pattern" )
43- expect ( result ) . toEqual ( { type : "search" , cmd : "rg" , query : "pattern" , path : undefined } )
44- } )
45-
46- it ( "parses unknown command" , ( ) => {
47- const result = ParseCommand . parse ( "npm install" )
48- expect ( result ) . toEqual ( { type : "unknown" , cmd : "npm install" } )
49- } )
50-
51- it ( "parses cat without args as unknown" , ( ) => {
52- const result = ParseCommand . parse ( "cat" )
53- expect ( result ) . toEqual ( { type : "unknown" , cmd : "cat" } )
54- } )
55- } )
56-
575 describe ( "format" , ( ) => {
58- it ( "formats list command with cwd" , ( ) => {
59- const parsed = ParseCommand . parse ( "ls" )
60- const result = ParseCommand . format ( parsed , "/home/user" )
61- expect ( result . kind ) . toBe ( "search" )
62- expect ( result . title ) . toBe ( "List /home/user" )
63- expect ( result . locations ) . toEqual ( [ { path : "/home/user" } ] )
64- } )
65-
66- it ( "formats list command with explicit path" , ( ) => {
67- const parsed = ParseCommand . parse ( "ls /some/path" )
68- const result = ParseCommand . format ( parsed , "/home/user" )
69- expect ( result . kind ) . toBe ( "search" )
70- expect ( result . title ) . toBe ( "List /some/path" )
71- expect ( result . locations ) . toEqual ( [ { path : "/some/path" } ] )
6+ it ( "uses description as title when provided" , ( ) => {
7+ const result = ParseCommand . format ( "ls" , "List files in current directory" , "/home/user" )
8+ expect ( result . title ) . toBe ( "List files in current directory" )
9+ expect ( result . kind ) . toBe ( "other" )
7210 } )
7311
74- it ( "formats list command with relative path" , ( ) => {
75- const parsed = ParseCommand . parse ( "ls subdir" )
76- const result = ParseCommand . format ( parsed , "/home/user" )
77- expect ( result . kind ) . toBe ( "search" )
78- expect ( result . title ) . toBe ( "List /home/user/subdir" )
79- expect ( result . locations ) . toEqual ( [ { path : "/home/user/subdir" } ] )
12+ it ( "falls back to command when no description" , ( ) => {
13+ const result = ParseCommand . format ( "ls -la" , "" , "/home/user" )
14+ expect ( result . title ) . toBe ( "ls -la" )
8015 } )
8116
82- it ( "formats read command" , ( ) => {
83- const parsed = ParseCommand . parse ( "cat /some/file.txt" )
84- const result = ParseCommand . format ( parsed , "/home/user" )
85- expect ( result . kind ) . toBe ( "read" )
86- expect ( result . title ) . toBe ( "Read file.txt" )
87- expect ( result . locations ) . toEqual ( [ { path : "/some/file.txt" } ] )
88- } )
89-
90- it ( "formats search command with query" , ( ) => {
91- const parsed = ParseCommand . parse ( "grep pattern" )
92- const result = ParseCommand . format ( parsed , "/home/user" )
93- expect ( result . kind ) . toBe ( "search" )
94- expect ( result . title ) . toBe ( "Search pattern" )
17+ it ( "includes cwd in locations" , ( ) => {
18+ const result = ParseCommand . format ( "ls" , "List files" , "/home/user" )
19+ expect ( result . locations ) . toEqual ( [ { path : "/home/user" } ] )
9520 } )
9621
97- it ( "formats search command with query and path" , ( ) => {
98- const parsed = ParseCommand . parse ( "grep pattern /some/path" )
99- const result = ParseCommand . format ( parsed , "/home/user" )
100- expect ( result . kind ) . toBe ( "search" )
101- expect ( result . title ) . toBe ( "Search pattern in /some/path" )
102- expect ( result . locations ) . toEqual ( [ { path : "/some/path" } ] )
22+ it ( "handles empty cwd" , ( ) => {
23+ const result = ParseCommand . format ( "ls" , "List files" , "" )
24+ expect ( result . locations ) . toEqual ( [ ] )
10325 } )
10426
105- it ( "formats unknown command as execute" , ( ) => {
106- const parsed = ParseCommand . parse ( "npm install" )
107- const result = ParseCommand . format ( parsed , "/home/user" )
108- expect ( result . kind ) . toBe ( "execute" )
109- expect ( result . title ) . toBe ( "Run npm install" )
27+ it ( "sets terminalOutput to true" , ( ) => {
28+ const result = ParseCommand . format ( "npm install" , "Install dependencies" , "/home/user" )
11029 expect ( result . terminalOutput ) . toBe ( true )
11130 } )
11231 } )
0 commit comments