package cli_test import ( "context" "strings" "testing" "go.uber.org/zap" "iop/apps/node/internal/adapters/cli" "iop/apps/node/internal/adapters/cli/status" "iop/apps/node/internal/runtime" "iop/packages/config" ) func TestCLIHandleCommandUsageStatusUsesSelectedAgent(t *testing.T) { c := cli.New(config.CLIConf{ Enabled: true, Profiles: map[string]config.CLIProfileConf{ "codex": { Command: "/tmp/fake-codex", }, "cline-m1": { Command: "cline-m1", }, }, }, zap.NewNop()) // Inject fake checker c.StatusChecker = func(ctx context.Context, agent string, profile config.CLIProfileConf) (*status.UsageStatus, error) { if agent == "codex" { if profile.Command != "/tmp/fake-codex" { t.Errorf("expected command /tmp/fake-codex, got %q", profile.Command) } return &status.UsageStatus{RawOutput: "fake-codex-status"}, nil } return nil, nil } // Test missing agent _, err := c.HandleCommand(context.Background(), runtime.CommandRequest{ Type: runtime.CommandTypeUsageStatus, Model: "unknown", }) if err == nil || !strings.Contains(err.Error(), "unknown agent") { t.Errorf("expected unknown agent error, got %v", err) } // Test codex resp, err := c.HandleCommand(context.Background(), runtime.CommandRequest{ RequestID: "req-123", Type: runtime.CommandTypeUsageStatus, Model: "codex", SessionID: "sess-456", Adapter: "cli", }) if err != nil { t.Fatalf("HandleCommand failed: %v", err) } if resp.UsageStatus == nil || resp.UsageStatus.RawOutput != "fake-codex-status" { t.Errorf("unexpected usage status: %+v", resp.UsageStatus) } if resp.RequestID != "req-123" { t.Errorf("expected RequestID req-123, got %s", resp.RequestID) } if resp.SessionID != "sess-456" { t.Errorf("expected SessionID sess-456, got %s", resp.SessionID) } // Test unsupported command type _, err = c.HandleCommand(context.Background(), runtime.CommandRequest{ Type: runtime.CommandType("invalid"), Model: "codex", }) if err == nil || !strings.Contains(err.Error(), "unsupported command") { t.Errorf("expected unsupported command error, got %v", err) } }