summaryrefslogtreecommitdiff
path: root/internal/cli/project_test.go
diff options
context:
space:
mode:
authorClaudomator Agent <agent@claudomator>2026-03-16 21:02:07 +0000
committerClaudomator Agent <agent@claudomator>2026-03-16 21:02:07 +0000
commit26dc313f16a2827b0f7a4651f495f36f669cea73 (patch)
treeda8fcda11d986cf01b7cd75cee7abc6894287327 /internal/cli/project_test.go
parentb8381507ff61c7fb69a91490a9fd58403da8c0fa (diff)
feat: expose project field in API and CLI
- POST /api/tasks now reads and stores the project field from request body - GET /api/tasks/{id} returns project in response (via Task struct json tags) - list command: adds PROJECT column to tabwriter output - status command: prints Project line when non-empty - Tests: TestProject_RoundTrip (API), TestListTasks_ShowsProject, TestStatusCmd_ShowsProject (CLI) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Diffstat (limited to 'internal/cli/project_test.go')
-rw-r--r--internal/cli/project_test.go102
1 files changed, 102 insertions, 0 deletions
diff --git a/internal/cli/project_test.go b/internal/cli/project_test.go
new file mode 100644
index 0000000..c62e181
--- /dev/null
+++ b/internal/cli/project_test.go
@@ -0,0 +1,102 @@
+package cli
+
+import (
+ "bytes"
+ "io"
+ "os"
+ "path/filepath"
+ "strings"
+ "testing"
+ "time"
+
+ "github.com/thepeterstone/claudomator/internal/config"
+ "github.com/thepeterstone/claudomator/internal/storage"
+ "github.com/thepeterstone/claudomator/internal/task"
+)
+
+func makeProjectTask(t *testing.T, dir string) *task.Task {
+ t.Helper()
+ db, err := storage.Open(filepath.Join(dir, "test.db"))
+ if err != nil {
+ t.Fatalf("storage.Open: %v", err)
+ }
+ defer db.Close()
+
+ now := time.Now().UTC()
+ tk := &task.Task{
+ ID: "proj-task-id",
+ Name: "Project Task",
+ Project: "test-project",
+ Agent: task.AgentConfig{Type: "claude", Instructions: "do it", Model: "sonnet"},
+ Priority: task.PriorityNormal,
+ Tags: []string{},
+ DependsOn: []string{},
+ Retry: task.RetryConfig{MaxAttempts: 1, Backoff: "exponential"},
+ State: task.StatePending,
+ CreatedAt: now,
+ UpdatedAt: now,
+ }
+ if err := db.CreateTask(tk); err != nil {
+ t.Fatalf("CreateTask: %v", err)
+ }
+ return tk
+}
+
+func captureStdout(fn func()) string {
+ old := os.Stdout
+ r, w, _ := os.Pipe()
+ os.Stdout = w
+
+ fn()
+
+ w.Close()
+ os.Stdout = old
+ var buf bytes.Buffer
+ io.Copy(&buf, r)
+ return buf.String()
+}
+
+func withDB(t *testing.T, dbPath string, fn func()) {
+ t.Helper()
+ origCfg := cfg
+ if cfg == nil {
+ cfg = &config.Config{}
+ }
+ cfg.DBPath = dbPath
+ defer func() { cfg = origCfg }()
+ fn()
+}
+
+func TestListTasks_ShowsProject(t *testing.T) {
+ dir := t.TempDir()
+ dbPath := filepath.Join(dir, "test.db")
+ makeProjectTask(t, dir)
+
+ withDB(t, dbPath, func() {
+ out := captureStdout(func() {
+ if err := listTasks(""); err != nil {
+ t.Fatalf("listTasks: %v", err)
+ }
+ })
+ if !strings.Contains(out, "test-project") {
+ t.Errorf("list output missing project 'test-project':\n%s", out)
+ }
+ })
+}
+
+func TestStatusCmd_ShowsProject(t *testing.T) {
+ dir := t.TempDir()
+ dbPath := filepath.Join(dir, "test.db")
+ tk := makeProjectTask(t, dir)
+
+ withDB(t, dbPath, func() {
+ out := captureStdout(func() {
+ if err := showStatus(tk.ID); err != nil {
+ t.Fatalf("showStatus: %v", err)
+ }
+ })
+ if !strings.Contains(out, "test-project") {
+ t.Errorf("status output missing project 'test-project':\n%s", out)
+ }
+ })
+}