summaryrefslogtreecommitdiff
path: root/internal/executor/container_test.go
blob: b1513ea7d117a3ec83248e2717fd8680d68a3050 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package executor

import (
	"strings"
	"testing"

	"github.com/thepeterstone/claudomator/internal/task"
)

func TestContainerRunner_BuildDockerArgs(t *testing.T) {
	runner := &ContainerRunner{
		APIURL:   "http://localhost:8484",
		DropsDir: "/data/drops",
	}
	workspace := "/tmp/ws"
	taskID := "task-123"

	args := runner.buildDockerArgs(workspace, taskID)
	
	expected := []string{
		"run", "--rm",
		"-v", "/tmp/ws:/workspace",
		"-w", "/workspace",
		"--env-file", "/workspace/.claudomator-env",
		"-e", "CLAUDOMATOR_API_URL=http://localhost:8484",
		"-e", "CLAUDOMATOR_TASK_ID=task-123",
		"-e", "CLAUDOMATOR_DROP_DIR=/data/drops",
	}

	if len(args) != len(expected) {
		t.Fatalf("expected %d args, got %d", len(expected), len(args))
	}
	for i, v := range args {
		if v != expected[i] {
			t.Errorf("arg %d: expected %q, got %q", i, expected[i], v)
		}
	}
}

func TestContainerRunner_BuildInnerCmd(t *testing.T) {
	runner := &ContainerRunner{}
	
	t.Run("claude", func(t *testing.T) {
		tk := &task.Task{Agent: task.AgentConfig{Type: "claude"}}
		cmd := runner.buildInnerCmd(tk, "exec-456")
		
		cmdStr := strings.Join(cmd, " ")
		if !strings.Contains(cmdStr, "--resume exec-456") {
			t.Errorf("expected --resume flag, got %q", cmdStr)
		}
		if !strings.Contains(cmdStr, "-p /workspace/.claudomator-instructions.txt") {
			t.Errorf("expected instructions file path, got %q", cmdStr)
		}
	})

	t.Run("gemini", func(t *testing.T) {
		tk := &task.Task{Agent: task.AgentConfig{Type: "gemini"}}
		cmd := runner.buildInnerCmd(tk, "exec-456")
		
		cmdStr := strings.Join(cmd, " ")
		if !strings.HasPrefix(cmdStr, "gemini") {
			t.Errorf("expected gemini command, got %q", cmdStr)
		}
	})
}