Skip to content

Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.

Go

fix(autopilots): reject the values on edit that create rejects (#11541)

pseudoyu78d581ab06f0
diff --git a/server/internal/handler/autopilot.go b/server/internal/handler/autopilot.go
index 0fed992a02..21840b5ce2 100644
--- a/server/internal/handler/autopilot.go
+++ b/server/internal/handler/autopilot.go
@@ -840,7 +840,7 @@ func (h *Handler) CreateAutopilot(w http.ResponseWriter, r *http.Request) {
writeError(w, http.StatusBadRequest, "invalid request body")
return
}
- if req.Title == "" {
+ if strings.TrimSpace(req.Title) == "" {
writeError(w, http.StatusBadRequest, "title is required")
return
}
@@ -1106,12 +1106,24 @@ func (h *Handler) UpdateAutopilot(w http.ResponseWriter, r *http.Request) {
ProjectID: prev.ProjectID,
}
if req.Title != nil {
+ if strings.TrimSpace(*req.Title) == "" {
+ writeError(w, http.StatusBadRequest, "title is required")
+ return
+ }
params.Title = pgtype.Text{String: *req.Title, Valid: true}
}
if req.Status != nil {
+ if s := *req.Status; s != "active" && s != "paused" && s != "archived" {
+ writeError(w, http.StatusBadRequest, "status must be active, paused or archived")
+ return
+ }
params.Status = pgtype.Text{String: *req.Status, Valid: true}
}
if req.ExecutionMode != nil {
+ if m := *req.ExecutionMode; m != "create_issue" && m != "run_only" {
+ writeError(w, http.StatusBadRequest, "execution_mode must be create_issue or run_only")
+ return
+ }
params.ExecutionMode = pgtype.Text{String: *req.ExecutionMode, Valid: true}
}
if _, ok := rawFields["description"]; ok {
@@ -2007,6 +2019,10 @@ func (h *Handler) UpdateAutopilotTrigger(w http.ResponseWriter, r *http.Request)
params.Enabled = pgtype.Bool{Bool: *req.Enabled, Valid: true}
}
if req.CronExpression != nil {
+ if prev.Kind == "schedule" && *req.CronExpression == "" {
+ writeError(w, http.StatusBadRequest, "cron_expression is required for schedule triggers")
+ return
+ }
params.CronExpression = pgtype.Text{String: *req.CronExpression, Valid: true}
}
if req.Timezone != nil {
diff --git a/server/internal/handler/autopilot_update_validation_test.go b/server/internal/handler/autopilot_update_validation_test.go
new file mode 100644
index 0000000000..d4cc31ecba
--- /dev/null
+++ b/server/internal/handler/autopilot_update_validation_test.go
@@ -0,0 +1,66 @@
+package handler
+
+import (
+ "context"
+ "net/http"
+ "strings"
+ "testing"
+
+ "github.com/multica-ai/multica/server/internal/testutil"
+)
+
+// An edit must reject the values a create rejects. Unchecked status and
+// execution_mode values only failed at the table's CHECK constraint (500),
+// and a blank title was stored as an autopilot with no name.
+func TestUpdateAutopilot_RejectsInvalidFields(t *testing.T) {
+ agentID := createWebhookTestAgent(t, "UpdateValidation Agent")
+ apID := createWebhookTestAutopilot(t, agentID, "active", "run_only")
+
+ for name, body := range map[string]map[string]any{
+ "unknown status": {"status": "pause"},
+ "unknown execution mode": {"execution_mode": "bogus"},
+ "empty title": {"title": ""},
+ "blank title": {"title": " "},
+ } {
+ t.Run(name, func(t *testing.T) {
+ req := newRequest("PATCH", "/api/autopilots/"+apID+"?workspace_id="+testWorkspaceID, body)
+ testutil.Call(t, testHandler.UpdateAutopilot, withURLParam(req, "id", apID)).Want(http.StatusBadRequest)
+ })
+ }
+
+ var title, status, mode string
+ if err := testPool.QueryRow(context.Background(),
+ `SELECT title, status, execution_mode FROM autopilot WHERE id = $1`, apID).Scan(&title, &status, &mode); err != nil {
+ t.Fatalf("read autopilot: %v", err)
+ }
+ if strings.TrimSpace(title) == "" || status != "active" || mode != "run_only" {
+ t.Fatalf("autopilot changed by rejected edits: title=%q status=%q mode=%q", title, status, mode)
+ }
+}
+
+func TestCreateAutopilot_RejectsBlankTitle(t *testing.T) {
+ agentID := createWebhookTestAgent(t, "CreateBlankTitle Agent")
+ req := newRequest("POST", "/api/autopilots?workspace_id="+testWorkspaceID, map[string]any{
+ "title": " ",
+ "assignee_id": agentID,
+ "execution_mode": "run_only",
+ })
+ testutil.Call(t, testHandler.CreateAutopilot, req).Want(http.StatusBadRequest)
+}
+
+// Clearing a schedule trigger's cron left it enabled with its old
+// next_run_at: the list kept showing a next run the scheduler would never
+// pick up, since it skips triggers without a cron.
+func TestUpdateAutopilotTrigger_RejectsEmptyCronOnSchedule(t *testing.T) {
+ agentID := createWebhookTestAgent(t, "EmptyCron Agent")
+ apID := createWebhookTestAutopilot(t, agentID, "active", "run_only")
+ trig := createScheduleTriggerViaHandler(t, apID, "0 * * * *")
+
+ req := newRequest("PATCH", "/api/autopilots/"+apID+"/triggers/"+trig.ID, map[string]any{"cron_expression": ""})
+ req = withURLParams(req, "id", apID, "triggerId", trig.ID)
+ testutil.Call(t, testHandler.UpdateAutopilotTrigger, req).Want(http.StatusBadRequest)
+
+ if storedTriggerNextRunIsNull(t, trig.ID) {
+ t.Fatal("rejected edit cleared the trigger's next run")
+ }
+}