133 lines
3.7 KiB
Go
133 lines
3.7 KiB
Go
package transport
|
|
|
|
import (
|
|
"testing"
|
|
|
|
toki "git.toki-labs.com/toki/common-proto-socket/go"
|
|
"google.golang.org/protobuf/proto"
|
|
|
|
edgenode "iop/apps/edge/internal/node"
|
|
"iop/packages/config"
|
|
iop "iop/proto/gen/iop"
|
|
)
|
|
|
|
func TestEdgeParserMap_NodeCommandResponse(t *testing.T) {
|
|
parsers := edgeParserMap()
|
|
original := &iop.NodeCommandResponse{
|
|
Type: iop.NodeCommandType_NODE_COMMAND_TYPE_USAGE_STATUS,
|
|
Adapter: "cli",
|
|
Model: "codex",
|
|
SessionId: "default",
|
|
UsageStatus: &iop.AgentUsageStatus{
|
|
RawOutput: "test",
|
|
},
|
|
}
|
|
payload, err := proto.Marshal(original)
|
|
if err != nil {
|
|
t.Fatalf("marshal: %v", err)
|
|
}
|
|
|
|
key := toki.TypeNameOf(original)
|
|
parser, ok := parsers[key]
|
|
if !ok {
|
|
t.Fatalf("parser not found for key: %s", key)
|
|
}
|
|
|
|
parsed, err := parser(payload)
|
|
if err != nil {
|
|
t.Fatalf("parse: %v", err)
|
|
}
|
|
got := parsed.(*iop.NodeCommandResponse)
|
|
if got.GetType() != original.GetType() ||
|
|
got.GetAdapter() != original.GetAdapter() ||
|
|
got.GetModel() != original.GetModel() ||
|
|
got.GetSessionId() != original.GetSessionId() ||
|
|
got.GetUsageStatus().GetRawOutput() != original.GetUsageStatus().GetRawOutput() {
|
|
t.Fatalf("unexpected node command response: %+v", got)
|
|
}
|
|
}
|
|
|
|
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,
|
|
OutputFormat: "codex-json",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
}
|
|
|
|
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"])
|
|
}
|
|
if got, ok := profile["output_format"].(string); !ok || got != "codex-json" {
|
|
t.Fatalf("expected output_format=%q, got %v", "codex-json", profile["output_format"])
|
|
}
|
|
}
|