M2: ai claude and codex CLI backends with selector
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user