iop/apps/edge/internal/transport/server_test.go

89 lines
2.4 KiB
Go

package transport
import (
"testing"
edgenode "iop/apps/edge/internal/node"
"iop/packages/config"
)
func TestBuildConfigPayload_CLIArgsRoundtrip(t *testing.T) {
rec := &edgenode.NodeRecord{
ID: "node-local",
Alias: "local",
Adapters: config.AdaptersConf{
CLI: config.CLIConf{
Enabled: true,
Profiles: map[string]config.CLIProfileConf{
"codex": {
Command: "codex",
Args: []string{"--foo", "--bar"},
Env: []string{"KEY=val"},
Persistent: true,
Terminal: true,
ResponseIdleTimeoutMS: 1500,
StartupIdleTimeoutMS: 300,
},
},
},
},
}
payload, err := buildConfigPayload(rec)
if err != nil {
t.Fatalf("build config payload: %v", err)
}
var cliSettings map[string]any
for _, adapter := range payload.GetAdapters() {
if adapter.GetType() == "cli" {
cliSettings = adapter.GetSettings().AsMap()
break
}
}
if cliSettings == nil {
t.Fatal("expected cli adapter settings")
}
profiles, ok := cliSettings["profiles"].(map[string]any)
if !ok {
t.Fatalf("expected profiles map, got %T", cliSettings["profiles"])
}
profile, ok := profiles["codex"].(map[string]any)
if !ok {
t.Fatalf("expected codex profile map, got %T", profiles["codex"])
}
if got := profile["command"]; got != "codex" {
t.Fatalf("expected command %q, got %v", "codex", got)
}
args, ok := profile["args"].([]any)
if !ok {
t.Fatalf("expected args []any, got %T", profile["args"])
}
if len(args) != 2 || args[0] != "--foo" || args[1] != "--bar" {
t.Fatalf("unexpected args: %#v", args)
}
env, ok := profile["env"].([]any)
if !ok {
t.Fatalf("expected env []any, got %T", profile["env"])
}
if len(env) != 1 || env[0] != "KEY=val" {
t.Fatalf("unexpected env: %#v", env)
}
if got, ok := profile["persistent"].(bool); !ok || !got {
t.Fatalf("expected persistent=true, got %v", profile["persistent"])
}
if got, ok := profile["terminal"].(bool); !ok || !got {
t.Fatalf("expected terminal=true, got %v", profile["terminal"])
}
// structpb encodes numbers as float64
if got, ok := profile["response_idle_timeout_ms"].(float64); !ok || got != 1500 {
t.Fatalf("expected response_idle_timeout_ms=1500, got %v", profile["response_idle_timeout_ms"])
}
if got, ok := profile["startup_idle_timeout_ms"].(float64); !ok || got != 300 {
t.Fatalf("expected startup_idle_timeout_ms=300, got %v", profile["startup_idle_timeout_ms"])
}
}