summaryrefslogtreecommitdiff
path: root/internal/api
diff options
context:
space:
mode:
Diffstat (limited to 'internal/api')
-rw-r--r--internal/api/scripts.go8
-rw-r--r--internal/api/server.go7
-rw-r--r--internal/api/server_test.go17
3 files changed, 31 insertions, 1 deletions
diff --git a/internal/api/scripts.go b/internal/api/scripts.go
index 822bd32..8db937b 100644
--- a/internal/api/scripts.go
+++ b/internal/api/scripts.go
@@ -4,7 +4,9 @@ import (
"bytes"
"context"
"net/http"
+ "os"
"os/exec"
+ "strings"
"time"
)
@@ -33,6 +35,12 @@ func (s *Server) handleScript(w http.ResponseWriter, r *http.Request) {
defer cancel()
cmd := exec.CommandContext(ctx, scriptPath)
+ cmd.Env = os.Environ()
+ for k, v := range r.URL.Query() {
+ if len(v) > 0 {
+ cmd.Env = append(cmd.Env, "CLAUDOMATOR_"+strings.ToUpper(k)+"="+v[0])
+ }
+ }
var stdout, stderr bytes.Buffer
cmd.Stdout = &stdout
diff --git a/internal/api/server.go b/internal/api/server.go
index df35536..163f2b8 100644
--- a/internal/api/server.go
+++ b/internal/api/server.go
@@ -488,9 +488,10 @@ func (s *Server) handleGetTask(w http.ResponseWriter, r *http.Request) {
}
writeJSON(w, http.StatusOK, t)
}
-
func (s *Server) handleRunTask(w http.ResponseWriter, r *http.Request) {
id := r.PathValue("id")
+ agent := r.URL.Query().Get("agent")
+
t, err := s.store.ResetTaskForRetry(id)
if err != nil {
if strings.Contains(err.Error(), "not found") {
@@ -505,6 +506,10 @@ func (s *Server) handleRunTask(w http.ResponseWriter, r *http.Request) {
return
}
+ if agent != "" && agent != "auto" {
+ t.Agent.Type = agent
+ }
+
if err := s.pool.Submit(context.Background(), t); err != nil {
writeJSON(w, http.StatusServiceUnavailable, map[string]string{"error": fmt.Sprintf("executor pool: %v", err)})
return
diff --git a/internal/api/server_test.go b/internal/api/server_test.go
index c90e3b3..2209a69 100644
--- a/internal/api/server_test.go
+++ b/internal/api/server_test.go
@@ -384,6 +384,23 @@ func TestRunTask_TimedOutTask_Returns202(t *testing.T) {
}
}
+func TestRunTask_WithAgentParam(t *testing.T) {
+ srv, store := testServer(t)
+ createTaskWithState(t, store, "run-agent-param", task.StatePending)
+
+ // Request run with agent=gemini.
+ req := httptest.NewRequest("POST", "/api/tasks/run-agent-param/run?agent=gemini", nil)
+ w := httptest.NewRecorder()
+ srv.Handler().ServeHTTP(w, req)
+
+ if w.Code != http.StatusAccepted {
+ t.Fatalf("status: want 202, got %d; body: %s", w.Code, w.Body.String())
+ }
+
+ // Wait for the task to complete via the mock runner.
+ pollState(t, store, "run-agent-param", task.StateReady, 2*time.Second)
+}
+
func TestRunTask_CompletedTask_Returns409(t *testing.T) {
srv, store := testServer(t)
createTaskWithState(t, store, "run-completed", task.StateCompleted)