93 lines
2.3 KiB
Go
93 lines
2.3 KiB
Go
package main
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"runtime"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestRunRequiresRedaction(t *testing.T) {
|
|
if code := run([]string{"-config", "catalog.yaml", "-profile", "profile"}); code != 2 {
|
|
t.Fatalf("run code = %d, want 2", code)
|
|
}
|
|
}
|
|
|
|
func TestRunLifecycleWithFakeCatalogProvider(t *testing.T) {
|
|
if runtime.GOOS == "windows" {
|
|
t.Skip("shell fixture requires Unix")
|
|
}
|
|
dir := t.TempDir()
|
|
command := filepath.Join(dir, "fake-codex")
|
|
script := `#!/bin/sh
|
|
case "$1" in
|
|
--version)
|
|
echo "fake-codex 1.0"
|
|
exit 0
|
|
;;
|
|
login)
|
|
echo "authenticated"
|
|
exit 0
|
|
;;
|
|
exec)
|
|
if [ "$2" = "resume" ]; then
|
|
shift 2
|
|
session=""
|
|
prompt=""
|
|
for arg in "$@"; do
|
|
case "$arg" in --*) continue ;; esac
|
|
if [ -z "$session" ]; then session="$arg"; else prompt="$arg"; fi
|
|
done
|
|
printf '{"type":"thread.started","thread_id":"%s"}\n' "$session"
|
|
printf '{"type":"item.completed","item":{"type":"agent_message","text":"resume:%s"}}\n' "$prompt"
|
|
exit 0
|
|
fi
|
|
last=""
|
|
for arg in "$@"; do last="$arg"; done
|
|
printf '{"type":"thread.started","thread_id":"native-session"}\n'
|
|
printf '{"type":"item.completed","item":{"type":"agent_message","text":"run:%s"}}\n' "$last"
|
|
exit 0
|
|
;;
|
|
esac
|
|
exit 2
|
|
`
|
|
if err := os.WriteFile(command, []byte(script), 0o755); err != nil {
|
|
t.Fatalf("write fake command: %v", err)
|
|
}
|
|
configPath := filepath.Join(dir, "catalog.yaml")
|
|
config := strings.ReplaceAll(`
|
|
version: "1"
|
|
providers:
|
|
- id: codex
|
|
command: COMMAND
|
|
version_probe: {args: ["--version"]}
|
|
authentication: {args: ["login", "status"]}
|
|
capabilities: [cancel, resume, run, status]
|
|
models:
|
|
- {id: model, provider: codex, target: native-model}
|
|
profiles:
|
|
- id: profile
|
|
provider: codex
|
|
model: model
|
|
args: ["exec", "--json"]
|
|
resume_args: ["exec", "resume", "--json"]
|
|
mode: codex-exec
|
|
output_format: codex-json
|
|
persistent: true
|
|
capabilities: [cancel, resume, run, status]
|
|
`, "COMMAND", command)
|
|
if err := os.WriteFile(configPath, []byte(config), 0o600); err != nil {
|
|
t.Fatalf("write catalog: %v", err)
|
|
}
|
|
|
|
code := run([]string{
|
|
"-config", configPath,
|
|
"-profile", "profile",
|
|
"-operations", "status,run,resume,cancel",
|
|
"-redact",
|
|
})
|
|
if code != 0 {
|
|
t.Fatalf("run code = %d, want 0", code)
|
|
}
|
|
}
|