|
| 1 | +package codexcli |
| 2 | + |
| 3 | +import ( |
| 4 | + "strings" |
| 5 | + "testing" |
| 6 | +) |
| 7 | + |
| 8 | +func TestWindowsBatchAppServerCommandLine(t *testing.T) { |
| 9 | + path := `C:\Users\Jane Doe\AppData\Roaming\npm & tools\codex.cmd` |
| 10 | + got, err := windowsBatchAppServerCommandLine(path) |
| 11 | + if err != nil { |
| 12 | + t.Fatalf("windowsBatchAppServerCommandLine() error = %v", err) |
| 13 | + } |
| 14 | + want := `/d /s /v:off /c ""C:\Users\Jane Doe\AppData\Roaming\npm & tools\codex.cmd" app-server --listen stdio://"` |
| 15 | + if got != want { |
| 16 | + t.Fatalf("windowsBatchAppServerCommandLine() = %q, want %q", got, want) |
| 17 | + } |
| 18 | +} |
| 19 | + |
| 20 | +func TestWindowsBatchAppServerCommandLineRejectsUnsafePath(t *testing.T) { |
| 21 | + for _, path := range []string{"", `C:\npm\%USER%\codex.cmd`, "C:\\npm\\codex.cmd\r\nwhoami"} { |
| 22 | + t.Run(strings.ReplaceAll(path, "\\", "_"), func(t *testing.T) { |
| 23 | + if _, err := windowsBatchAppServerCommandLine(path); err == nil { |
| 24 | + t.Fatalf("windowsBatchAppServerCommandLine(%q) error = nil, want error", path) |
| 25 | + } |
| 26 | + }) |
| 27 | + } |
| 28 | +} |
| 29 | + |
| 30 | +func TestIsWindowsCommandShimPath(t *testing.T) { |
| 31 | + for _, path := range []string{`C:\npm\codex.cmd`, `C:\npm\CODEX.BAT`} { |
| 32 | + if !isWindowsCommandShimPath(path) { |
| 33 | + t.Fatalf("isWindowsCommandShimPath(%q) = false, want true", path) |
| 34 | + } |
| 35 | + } |
| 36 | + for _, path := range []string{`C:\npm\codex.exe`, `C:\npm\codex.ps1`, "/usr/bin/codex"} { |
| 37 | + if isWindowsCommandShimPath(path) { |
| 38 | + t.Fatalf("isWindowsCommandShimPath(%q) = true, want false", path) |
| 39 | + } |
| 40 | + } |
| 41 | +} |
0 commit comments