Files
archie/internal/webui/api_task_meta_test.go
T
sam 815272a421 feat(tasks): serve the lifecycle presentation catalog from /api/task-meta
Archie owns the status and action vocabulary in internal/taskstate, but the
dashboard had to keep a hand-synced copy of the display labels, pill severities
and action confirm prompts -- so a new status or action silently rendered
wrong until someone edited the frontend.

- add taskstate.Statuses() and taskstate.ActionCatalog() so the rules and their
  presentation live in one place
- expose GET /api/task-meta returning {statuses, actions}
- add a client base/task-meta.js that fetches the catalog and exposes
  statusLabel/statusKind/statusIds/attentionStatusIds/actionFor, with a
  freeze-dried default snapshot so the dashboard renders instantly and keeps
  working when archied is unreachable
- tests for the catalog, the endpoint and the client accessors
2026-08-28 00:41:12 +00:00

58 lines
1.4 KiB
Go

package webui
import (
"encoding/json"
"net/http"
"net/http/httptest"
"testing"
)
// The dashboard derives everything it can present from /api/task-meta. If the
// catalog is empty or malformed the frontend falls back to its own defaults and
// the whole point of the endpoint -- one server-held vocabulary -- is lost.
func TestTaskMetaCatalog(t *testing.T) {
srv := newTestServer(t)
req := httptest.NewRequestWithContext(t.Context(), http.MethodGet, "/api/task-meta", nil)
w := httptest.NewRecorder()
srv.Handler().ServeHTTP(w, req)
if w.Code != http.StatusOK {
t.Fatalf("status = %d, body %s", w.Code, w.Body)
}
var got struct {
Statuses []struct {
ID string `json:"id"`
Label string `json:"label"`
Kind string `json:"kind"`
NeedsYou bool `json:"needs_you"`
} `json:"statuses"`
Actions []struct {
ID string `json:"id"`
Label string `json:"label"`
Kind string `json:"kind"`
Confirm string `json:"confirm"`
} `json:"actions"`
}
if err := json.Unmarshal(w.Body.Bytes(), &got); err != nil {
t.Fatalf("unmarshal: %v", err)
}
if len(got.Statuses) == 0 {
t.Error("statuses empty")
}
if len(got.Actions) == 0 {
t.Error("actions empty")
}
for _, s := range got.Statuses {
if s.ID == "" || s.Label == "" {
t.Errorf("status missing id/label: %+v", s)
}
}
for _, a := range got.Actions {
if a.ID == "" || a.Label == "" {
t.Errorf("action missing id/label: %+v", a)
}
}
}