diff options
| author | Peter Stone <thepeterstone@gmail.com> | 2026-03-06 23:55:07 +0000 |
|---|---|---|
| committer | Peter Stone <thepeterstone@gmail.com> | 2026-03-06 23:55:07 +0000 |
| commit | fd42a54d96fcd3342941caaeb61a4b0d5d3f1b4f (patch) | |
| tree | 0b9ef3b7f0ac3981aa310435d014c9f5e21089d4 /internal/api/validate_test.go | |
| parent | 7d4890cde802974b94db24071f63e7733c3670fd (diff) | |
recover: restore untracked work from recovery branch (no Gemini changes)
Recovered files with no Claude→Agent contamination:
- docs/adr/002-task-state-machine.md
- internal/api/logs.go/logs_test.go: task-level log streaming endpoint
- internal/api/validate.go/validate_test.go: POST /api/tasks/validate
- internal/api/server_test.go, storage/db_test.go: expanded test coverage
- scripts/reset-failed-tasks, reset-running-tasks
- web/app.js, index.html, style.css: frontend improvements
- web/test/: active-tasks-tab, delete-button, filter-tabs, sort-tasks tests
Manually applied from server.go diff (skipping Claude→Agent rename):
- taskLogStore field + validateCmdPath field
- DELETE /api/tasks/{id} route + handleDeleteTask
- GET /api/tasks/{id}/logs/stream route
- POST /api/tasks/{id}/resume route + handleResumeTimedOutTask
- handleCancelTask: allow cancelling PENDING/QUEUED tasks directly
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Diffstat (limited to 'internal/api/validate_test.go')
| -rw-r--r-- | internal/api/validate_test.go | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/internal/api/validate_test.go b/internal/api/validate_test.go new file mode 100644 index 0000000..5a1246b --- /dev/null +++ b/internal/api/validate_test.go @@ -0,0 +1,90 @@ +package api + +import ( + "bytes" + "encoding/json" + "net/http" + "net/http/httptest" + "testing" +) + +func TestValidateTask_Success(t *testing.T) { + srv, _ := testServer(t) + + validResult := validateResult{ + Clarity: "clear", + Ready: true, + Summary: "Instructions are clear and actionable.", + Questions: []validateQuestion{}, + Suggestions: []string{}, + } + resultJSON, _ := json.Marshal(validResult) + wrapper := map[string]string{"result": string(resultJSON)} + wrapperJSON, _ := json.Marshal(wrapper) + srv.validateCmdPath = createFakeClaude(t, string(wrapperJSON), 0) + + body := `{"name":"Test Task","claude":{"instructions":"Run go test ./... and report results."}}` + req := httptest.NewRequest("POST", "/api/tasks/validate", bytes.NewBufferString(body)) + req.Header.Set("Content-Type", "application/json") + w := httptest.NewRecorder() + + srv.Handler().ServeHTTP(w, req) + + if w.Code != http.StatusOK { + t.Fatalf("status: want 200, got %d; body: %s", w.Code, w.Body.String()) + } + + var result validateResult + if err := json.NewDecoder(w.Body).Decode(&result); err != nil { + t.Fatalf("failed to decode response: %v", err) + } + if result.Clarity == "" { + t.Error("expected non-empty clarity field in response") + } +} + +func TestValidateTask_MissingInstructions(t *testing.T) { + srv, _ := testServer(t) + + body := `{"name":"Test Task","claude":{"instructions":""}}` + req := httptest.NewRequest("POST", "/api/tasks/validate", bytes.NewBufferString(body)) + req.Header.Set("Content-Type", "application/json") + w := httptest.NewRecorder() + + srv.Handler().ServeHTTP(w, req) + + if w.Code != http.StatusBadRequest { + t.Fatalf("status: want 400, got %d; body: %s", w.Code, w.Body.String()) + } +} + +func TestValidateTask_MissingName(t *testing.T) { + srv, _ := testServer(t) + + body := `{"name":"","claude":{"instructions":"Do something useful."}}` + req := httptest.NewRequest("POST", "/api/tasks/validate", bytes.NewBufferString(body)) + req.Header.Set("Content-Type", "application/json") + w := httptest.NewRecorder() + + srv.Handler().ServeHTTP(w, req) + + if w.Code != http.StatusBadRequest { + t.Fatalf("status: want 400, got %d; body: %s", w.Code, w.Body.String()) + } +} + +func TestValidateTask_BadJSONFromClaude(t *testing.T) { + srv, _ := testServer(t) + srv.validateCmdPath = createFakeClaude(t, "not valid json at all", 0) + + body := `{"name":"Test Task","claude":{"instructions":"Do something useful."}}` + req := httptest.NewRequest("POST", "/api/tasks/validate", bytes.NewBufferString(body)) + req.Header.Set("Content-Type", "application/json") + w := httptest.NewRecorder() + + srv.Handler().ServeHTTP(w, req) + + if w.Code != http.StatusBadGateway { + t.Fatalf("status: want 502, got %d; body: %s", w.Code, w.Body.String()) + } +} |
