Files
boshu2__agentops/cli/internal/runtimecmd/runtimecmd_test.go
boshu 377d9048fe fix(rpi): complete the runtimecmd extraction — add the files dropped from bacf15d99
bacf15d99 landed INCOMPLETE: it deleted rpi/stream.go + added the cmd/ao test, but
the new internal/runtimecmd package and the two consumer repoints (eval/runtime.go,
cmd/ao/engine_shared.go) were not in the commit, leaving main build-broken
(undefined: rpilib.RuntimeDirectCommandArgs / cliRPI.SplitRuntimeCommand). This
commit adds exactly those dropped files. Build/vet/eval+cmd-ao+runtimecmd green.

Part of age-tlj6.
2026-06-22 03:20:21 -04:00

69 lines
2.0 KiB
Go

// practices: [design-by-contract, ai-assisted-dev]
package runtimecmd
import (
"reflect"
"testing"
)
func TestSplit(t *testing.T) {
tests := []struct {
name string
command string
wantExec string
wantArgs []string
}{
{"simple", "codex", "codex", []string{}},
{"with prefix args", "env -i claude", "env", []string{"-i", "claude"}},
{"extra whitespace", " codex exec ", "codex", []string{"exec"}},
{"empty", "", "", nil},
{"whitespace only", " ", "", nil},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
gotExec, gotArgs := Split(tt.command)
if gotExec != tt.wantExec {
t.Errorf("Split(%q) exec = %q, want %q", tt.command, gotExec, tt.wantExec)
}
if len(gotArgs) != 0 || len(tt.wantArgs) != 0 {
if !reflect.DeepEqual(gotArgs, tt.wantArgs) {
t.Errorf("Split(%q) args = %v, want %v", tt.command, gotArgs, tt.wantArgs)
}
}
})
}
}
func TestBinaryName(t *testing.T) {
tests := []struct {
command string
want string
}{
{"codex", "codex"},
{"/usr/local/bin/Codex", "codex"},
{"claude.exe", "claude"},
{"env -i codex exec", "env"}, // base name of the FIRST token
{"", ""},
}
for _, tt := range tests {
if got := BinaryName(tt.command); got != tt.want {
t.Errorf("BinaryName(%q) = %q, want %q", tt.command, got, tt.want)
}
}
}
func TestDirectArgs(t *testing.T) {
// codex uses `exec <prompt>`; everything else uses `-p <prompt>`.
if got := DirectArgs("codex", "hello"); !reflect.DeepEqual(got, []string{"exec", "hello"}) {
t.Errorf("DirectArgs codex = %v, want [exec hello]", got)
}
if got := DirectArgs("claude", "hello"); !reflect.DeepEqual(got, []string{"-p", "hello"}) {
t.Errorf("DirectArgs claude = %v, want [-p hello]", got)
}
// prefix args are preserved; binary name is the FIRST token ("env" here, not
// "codex"), so this takes the non-codex -p path.
if got := DirectArgs("env -i codex", "hi"); !reflect.DeepEqual(got, []string{"-i", "codex", "-p", "hi"}) {
t.Errorf("DirectArgs with prefix = %v, want [-i codex -p hi]", got)
}
}