3148fdfa92
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
48 lines
1.3 KiB
Go
48 lines
1.3 KiB
Go
package ai
|
|
|
|
import (
|
|
"slices"
|
|
"testing"
|
|
)
|
|
|
|
func TestNewBackendSelector(t *testing.T) {
|
|
for _, name := range []string{"", "claude"} {
|
|
b, err := NewBackend(name)
|
|
if err != nil {
|
|
t.Fatalf("NewBackend(%q): %v", name, err)
|
|
}
|
|
if b.Name() != "claude" {
|
|
t.Fatalf("NewBackend(%q) name = %q", name, b.Name())
|
|
}
|
|
}
|
|
b, err := NewBackend("codex")
|
|
if err != nil || b.Name() != "codex" {
|
|
t.Fatalf("codex backend: %v / %q", err, b.Name())
|
|
}
|
|
if _, err := NewBackend("bogus"); err == nil {
|
|
t.Fatal("unknown backend should error")
|
|
}
|
|
}
|
|
|
|
func TestClaudeArgs(t *testing.T) {
|
|
want := []string{"--print", "--tools", "", "--no-session-persistence", "--output-format", "text"}
|
|
if got := newClaudeBackend().args; !slices.Equal(got, want) {
|
|
t.Fatalf("claude args = %v want %v", got, want)
|
|
}
|
|
}
|
|
|
|
func TestCodexArgsCarryOutfileAndStdinMarker(t *testing.T) {
|
|
got := newCodexBackend().args("/tmp/out.txt")
|
|
if got[len(got)-1] != "-" {
|
|
t.Fatalf("codex args must end with stdin marker '-', got %v", got)
|
|
}
|
|
if !slices.Contains(got, "-o") || !slices.Contains(got, "/tmp/out.txt") {
|
|
t.Fatalf("codex args must include -o /tmp/out.txt, got %v", got)
|
|
}
|
|
for _, want := range []string{"exec", "--ignore-user-config", "--ignore-rules", "read-only", "never"} {
|
|
if !slices.Contains(got, want) {
|
|
t.Fatalf("codex args missing %q, got %v", want, got)
|
|
}
|
|
}
|
|
}
|