From aedb1f23ce969970365808f72344a93d475ada83 Mon Sep 17 00:00:00 2001 From: milymarkovic Date: Thu, 16 Jul 2026 19:11:02 +0300 Subject: [PATCH] fix(cli): set agent type when updating autopilot --- server/cmd/multica/cmd_autopilot.go | 1 + server/cmd/multica/cmd_autopilot_test.go | 50 ++++++++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/server/cmd/multica/cmd_autopilot.go b/server/cmd/multica/cmd_autopilot.go index c10c2b93f76..d4db16a0279 100644 --- a/server/cmd/multica/cmd_autopilot.go +++ b/server/cmd/multica/cmd_autopilot.go @@ -366,6 +366,7 @@ func runAutopilotUpdate(cmd *cobra.Command, args []string) error { if resolveErr != nil { return fmt.Errorf("resolve agent: %w", resolveErr) } + body["assignee_type"] = "agent" body["assignee_id"] = agentID } if cmd.Flags().Changed("project") { diff --git a/server/cmd/multica/cmd_autopilot_test.go b/server/cmd/multica/cmd_autopilot_test.go index 4a230a16546..c31fa3a2ba7 100644 --- a/server/cmd/multica/cmd_autopilot_test.go +++ b/server/cmd/multica/cmd_autopilot_test.go @@ -281,6 +281,56 @@ func TestRunAutopilotUpdateSendsProjectIDChanges(t *testing.T) { }) } +func TestRunAutopilotUpdateAgentSwitchesAssigneeType(t *testing.T) { + const ( + autopilotID = "33333333-3333-3333-3333-333333333333" + agentID = "11111111-1111-1111-1111-111111111111" + ) + + var body map[string]any + srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + switch r.URL.Path { + case "/api/agents": + json.NewEncoder(w).Encode([]map[string]any{{"id": agentID, "name": "Codex Agent"}}) + case "/api/autopilots/" + autopilotID: + if r.Method != http.MethodPatch { + t.Errorf("method = %s, want PATCH", r.Method) + } + if err := json.NewDecoder(r.Body).Decode(&body); err != nil { + t.Errorf("decode body: %v", err) + } + if body["assignee_type"] != "agent" { + http.Error(w, "squad not found", http.StatusBadRequest) + return + } + json.NewEncoder(w).Encode(map[string]any{ + "id": autopilotID, + "assignee_type": body["assignee_type"], + "assignee_id": body["assignee_id"], + }) + default: + http.NotFound(w, r) + } + })) + defer srv.Close() + + t.Setenv("MULTICA_SERVER_URL", srv.URL) + t.Setenv("MULTICA_WORKSPACE_ID", "ws-1") + t.Setenv("MULTICA_TOKEN", "mat_test-token") + + cmd := newAutopilotUpdateTestCmd() + _ = cmd.Flags().Set("agent", "Codex Agent") + if err := runAutopilotUpdate(cmd, []string{autopilotID}); err != nil { + t.Fatalf("runAutopilotUpdate: %v", err) + } + if got := body["assignee_id"]; got != agentID { + t.Fatalf("assignee_id = %#v, want %q", got, agentID) + } + if got := body["assignee_type"]; got != "agent" { + t.Fatalf("assignee_type = %#v, want agent", got) + } +} + func TestRunAutopilotUpdateSendsSubscriberReplacement(t *testing.T) { const ( autopilotID = "33333333-3333-3333-3333-333333333333"