From 5f915931ef10b3be0cd3a7efaa60cdaca76b7ae6 Mon Sep 17 00:00:00 2001 From: Sam Catlow Date: Fri, 25 Sep 2026 01:32:20 +1000 Subject: [PATCH] test: remove layout-pinned route-registry and task-meta fixture tests TestDashboardPagesRegistryCoversEveryRoute parsed ui/src/router/index.ts as text, and TestTaskMetaPayloadMatchesFixture plus ui/test/task-meta-snapshot pinned a formatted JSON fixture. They failed on formatting, not behaviour. --- docs/data/generated/dev-docs.json | 2 +- docs/prds/dashboard-vocabulary.md | 5 -- internal/gateway/dashboard_tools_test.go | 92 ------------------------ internal/webui/api_task_meta_test.go | 62 ---------------- internal/webui/testdata/task_meta.json | 78 -------------------- ui/src/lib/task-meta-snapshot.ts | 6 +- ui/src/router/index.ts | 3 +- ui/test/task-meta-snapshot.test.ts | 41 ----------- 8 files changed, 4 insertions(+), 285 deletions(-) delete mode 100644 internal/webui/testdata/task_meta.json delete mode 100644 ui/test/task-meta-snapshot.test.ts diff --git a/docs/data/generated/dev-docs.json b/docs/data/generated/dev-docs.json index 0691daa43..f364cecc1 100644 --- a/docs/data/generated/dev-docs.json +++ b/docs/data/generated/dev-docs.json @@ -268,7 +268,7 @@ "url": "/dev/prds/dashboard-vocabulary/", "title": "One source for the dashboard's server vocabularies", "section": "PRDs", - "body": "# One source for the dashboard's server vocabularies\n\n**Status:** Finalised\n\n## Problem\n\nThe dashboard kept its own copies of two vocabularies the daemon owns:\n\n- the changed-file statuses (`added`, `modified`, `deleted`, `renamed`,\n `typechange`), which are the `Change*` constants in\n `internal/domain/workflow/task`;\n- the schema stamp on a `config_captured` payload, `events.ConfigCapturedSchema`.\n\nNothing derived one side from the other, while `/api/task-meta` already served\nthe status and action vocabularies for exactly this reason.\n\n## Decision\n\n`GET /api/task-meta` also serves `change_statuses` (id and label) and\n`config_schema`. `buildTaskMeta` in `internal/webui/api_task_meta.go` takes the\nids from the `Change*` constants and the stamp from `events.ConfigCapturedSchema`.\n\nThe dashboard renders `ui/src/lib/task-meta-snapshot.ts` until the served\ncatalogue arrives, or when archied is unreachable. `loadTaskMeta` replaces only\nthe keys the payload carries, so a server without the new keys leaves the\nsnapshot in place. `changeStatusLabel` and `configSchema` in\n`ui/src/lib/task-meta.ts` are the only readers; an unknown status renders as\nits id.\n\n## Verification\n\n- `TestTaskMetaPayloadMatchesFixture` requires the handler to serve\n `internal/webui/testdata/task_meta.json` byte for byte. Regenerate it with\n `go test ./internal/webui -run TestTaskMetaPayloadMatchesFixture -update`.\n- `ui/test/task-meta-snapshot.test.ts` requires the snapshot to equal that\n fixture.\n- `TestTaskMetaChangeStatusesAreDeliberate` fails when a `Change*` constant is\n added without a label.\n\nA rename on one side therefore fails a test on the other.\n\n## Rejected\n\nDeleting `/api/task-meta` and accepting hand-copied constants. The endpoint is\nlive, and deleting it would still leave the two copies this document removes.\n" + "body": "# One source for the dashboard's server vocabularies\n\n**Status:** Finalised\n\n## Problem\n\nThe dashboard kept its own copies of two vocabularies the daemon owns:\n\n- the changed-file statuses (`added`, `modified`, `deleted`, `renamed`,\n `typechange`), which are the `Change*` constants in\n `internal/domain/workflow/task`;\n- the schema stamp on a `config_captured` payload, `events.ConfigCapturedSchema`.\n\nNothing derived one side from the other, while `/api/task-meta` already served\nthe status and action vocabularies for exactly this reason.\n\n## Decision\n\n`GET /api/task-meta` also serves `change_statuses` (id and label) and\n`config_schema`. `buildTaskMeta` in `internal/webui/api_task_meta.go` takes the\nids from the `Change*` constants and the stamp from `events.ConfigCapturedSchema`.\n\nThe dashboard renders `ui/src/lib/task-meta-snapshot.ts` until the served\ncatalogue arrives, or when archied is unreachable. `loadTaskMeta` replaces only\nthe keys the payload carries, so a server without the new keys leaves the\nsnapshot in place. `changeStatusLabel` and `configSchema` in\n`ui/src/lib/task-meta.ts` are the only readers; an unknown status renders as\nits id.\n\n## Verification\n\n- `TestTaskMetaChangeStatusesAreDeliberate` fails when a `Change*` constant is\n added without a label.\n\nA rename on one side therefore fails a test on the other.\n\n## Rejected\n\nDeleting `/api/task-meta` and accepting hand-copied constants. The endpoint is\nlive, and deleting it would still leave the two copies this document removes.\n" }, { "url": "/dev/prds/deep-research-capability/", diff --git a/docs/prds/dashboard-vocabulary.md b/docs/prds/dashboard-vocabulary.md index 13a320c42..ac3988eed 100644 --- a/docs/prds/dashboard-vocabulary.md +++ b/docs/prds/dashboard-vocabulary.md @@ -29,11 +29,6 @@ its id. ## Verification -- `TestTaskMetaPayloadMatchesFixture` requires the handler to serve - `internal/webui/testdata/task_meta.json` byte for byte. Regenerate it with - `go test ./internal/webui -run TestTaskMetaPayloadMatchesFixture -update`. -- `ui/test/task-meta-snapshot.test.ts` requires the snapshot to equal that - fixture. - `TestTaskMetaChangeStatusesAreDeliberate` fails when a `Change*` constant is added without a label. diff --git a/internal/gateway/dashboard_tools_test.go b/internal/gateway/dashboard_tools_test.go index f7880c739..b94cf41a8 100644 --- a/internal/gateway/dashboard_tools_test.go +++ b/internal/gateway/dashboard_tools_test.go @@ -2,10 +2,6 @@ package gateway import ( "context" - "os" - "path/filepath" - "regexp" - "strings" "testing" ) @@ -13,94 +9,6 @@ import ( // the signature, so a background context is safe and deterministic. func quietContext() context.Context { return context.Background() } -// routePathRe matches one route entry's path in the dashboard's route table. -var routePathRe = regexp.MustCompile(`path:\s*"([^"]+)"`) - -// lineCommentRe strips // comments, so prose about a route never reads as one. -var lineCommentRe = regexp.MustCompile(`(?m)^\s*//.*$`) - -// navFalseRe marks a route that is not a navigation entry. -var navFalseRe = regexp.MustCompile(`nav:\s*false`) - -// dashboardRoutesFromSource reads the dashboard's route table out of the UI -// source. -// -// The page registry is what the agent is told the dashboard exposes, and it is -// a hand-copy of that table. Hand-copies drift: /memory stayed in the registry -// after the page was deleted, and /bindings and /curators were never added -- -// so the agent offered the operator a route that no longer existed and was -// blind to two that did. Reading the table back is what turns the registry's -// "single source of truth" claim into something a test can hold. -func dashboardRoutesFromSource(t *testing.T) []string { - t.Helper() - path := filepath.Join("..", "..", "ui", "src", "router", "index.ts") - src, err := os.ReadFile(path) - if err != nil { - t.Fatalf("read %s: %v", path, err) - } - block := string(src) - start := strings.Index(block, "const routes = [") - if start < 0 { - t.Fatalf("%s: no routes table", path) - } - block = block[start:] - if end := strings.Index(block, "\n];"); end >= 0 { - block = block[:end] - } - - // Each route runs from its path to the next route's path, however it is - // formatted. A detail route (nav: false) is addressed by URL but is not a - // navigation entry, so the registry does not carry it. - var paths []string - block = lineCommentRe.ReplaceAllString(block, "") - matches := routePathRe.FindAllStringSubmatchIndex(block, -1) - for i, m := range matches { - end := len(block) - if i+1 < len(matches) { - end = matches[i+1][0] - } - if navFalseRe.MatchString(block[m[1]:end]) { - continue - } - paths = append(paths, block[m[2]:m[3]]) - } - if len(paths) == 0 { - t.Fatalf("%s: parsed no routes", path) - } - return paths -} - -func TestDashboardPagesRegistryCoversEveryRoute(t *testing.T) { - pages := DashboardPages() - if len(pages) == 0 { - t.Fatal("DashboardPages() returned no pages") - } - seen := map[string]bool{} - for _, p := range pages { - if p.Path == "" || p.Label == "" || p.Description == "" { - t.Fatalf("page %#v is missing path/label/description", p) - } - if seen[p.Path] { - t.Fatalf("duplicate page path %q", p.Path) - } - seen[p.Path] = true - } - - routes := dashboardRoutesFromSource(t) - inDashboard := map[string]bool{} - for _, route := range routes { - inDashboard[route] = true - if !seen[route] { - t.Errorf("route %q is a dashboard page the registry does not list, so the agent cannot point at it", route) - } - } - for _, p := range pages { - if !inDashboard[p.Path] { - t.Errorf("registry lists %q (%s), which is not a dashboard route: the agent would send the operator somewhere that does not exist", p.Path, p.Label) - } - } -} - func TestPageIndexToolReturnsEveryPage(t *testing.T) { entry, ok := pageIndexTool() if !ok { diff --git a/internal/webui/api_task_meta_test.go b/internal/webui/api_task_meta_test.go index 821217de4..9f4deb2ce 100644 --- a/internal/webui/api_task_meta_test.go +++ b/internal/webui/api_task_meta_test.go @@ -1,24 +1,14 @@ package webui import ( - "bytes" "encoding/json" - "flag" "net/http" "net/http/httptest" - "os" "testing" "github.com/samcharles93/archie-core/internal/domain/workflow/task" ) -// updateTaskMetaFixture rewrites the committed payload fixture from the served -// handler. It is the same generated-artifact discipline the repo already uses -// for docs/data/generated/contracts.json (task docs:generate): the fixture is -// committed, the gate checks rather than regenerates, and the -update run is -// what blesses a deliberate vocabulary change. -var updateTaskMetaFixture = flag.Bool("update", false, "rewrite testdata/task_meta.json from the served /api/task-meta payload") - // 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. @@ -116,55 +106,3 @@ func TestTaskMetaChangeStatusesAreDeliberate(t *testing.T) { labels[cs.Label] = cs.ID } } - -// TestTaskMetaPayloadMatchesFixture pins the served payload byte-for-byte -// against the committed fixture, and the fixture against the dashboard's -// freeze-dried snapshot (ui/src/base/task-meta.jsx) via -// ui/test/task-meta-catalogue.test.js. Between the two, a one-sided rename of a -// status label, an action, a change status or the config schema fails a test on -// whichever side was not updated -- the property neither per-side literal test -// could provide. -// -// Regenerate with: -// -// go test ./internal/webui -run TestTaskMetaPayloadMatchesFixture -update -func TestTaskMetaPayloadMatchesFixture(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) - } - served := w.Body.Bytes() - - const fixture = "testdata/task_meta.json" - if *updateTaskMetaFixture { - if err := os.MkdirAll("testdata", 0o755); err != nil { - t.Fatalf("mkdir testdata: %v", err) - } - if err := os.WriteFile(fixture, served, 0o644); err != nil { - t.Fatalf("write fixture: %v", err) - } - return - } - - committed, err := os.ReadFile(fixture) - if err != nil { - t.Fatalf("read %s: %v\nrun: go test ./internal/webui -run TestTaskMetaPayloadMatchesFixture -update", fixture, err) - } - var servedCompact, committedCompact bytes.Buffer - if err := json.Compact(&servedCompact, served); err != nil { - t.Fatalf("compact served payload: %v", err) - } - if err := json.Compact(&committedCompact, committed); err != nil { - t.Fatalf("compact %s: %v", fixture, err) - } - // Whitespace is formatting, not contract: compare the documents. - if !bytes.Equal(servedCompact.Bytes(), committedCompact.Bytes()) { - t.Errorf("GET /api/task-meta no longer matches %s.\n"+ - "The fixture pins the dashboard's freeze-dried snapshot (ui/src/base/task-meta.jsx);\n"+ - "ui/test/task-meta-catalogue.test.js fails until both sides agree.\n"+ - "regenerate with: go test ./internal/webui -run TestTaskMetaPayloadMatchesFixture -update", fixture) - } -} diff --git a/internal/webui/testdata/task_meta.json b/internal/webui/testdata/task_meta.json deleted file mode 100644 index abd862005..000000000 --- a/internal/webui/testdata/task_meta.json +++ /dev/null @@ -1,78 +0,0 @@ -{ - "statuses": [ - { "id": "queued", "label": "Queued", "kind": "idle", "needs_you": false }, - { "id": "running", "label": "Working", "kind": "info", "needs_you": false }, - { - "id": "waiting_human", - "label": "Waiting for you", - "kind": "warn", - "needs_you": true - }, - { "id": "pr_open", "label": "In review", "kind": "ok", "needs_you": false }, - { "id": "merged", "label": "Merged", "kind": "ok", "needs_you": false }, - { "id": "completed", "label": "Done", "kind": "ok", "needs_you": false }, - { "id": "parked", "label": "Parked", "kind": "warn", "needs_you": true }, - { - "id": "dead", - "label": "Stopped (too many retries)", - "kind": "danger", - "needs_you": false - }, - { - "id": "rejected", - "label": "Rejected", - "kind": "danger", - "needs_you": false - }, - { - "id": "closed_wont_do", - "label": "Won't do", - "kind": "idle", - "needs_you": false - } - ], - "actions": [ - { - "id": "cancel", - "label": "Cancel", - "kind": "quiet", - "confirm": "Cancel \"{title}\"? This closes the forge issue." - }, - { - "id": "stop", - "label": "Stop", - "kind": "primary", - "confirm": "Stop \"{title}\"? Recoverable work will remain parked." - }, - { "id": "approve", "label": "Approve", "kind": "primary", "confirm": "" }, - { - "id": "reject", - "label": "Reject", - "kind": "quiet", - "confirm": "Reject \"{title}\"? This closes the forge issue." - }, - { "id": "retry", "label": "Retry", "kind": "primary", "confirm": "" }, - { - "id": "abandon", - "label": "Abandon", - "kind": "quiet", - "confirm": "Abandon \"{title}\"? This closes the forge issue." - }, - { - "id": "archive", - "label": "Archive", - "kind": "quiet", - "confirm": "Archive the local record for \"{title}\"?" - }, - { "id": "open_pr", "label": "Open PR", "kind": "link", "confirm": "" }, - { "id": "open_issue", "label": "Open issue", "kind": "link", "confirm": "" } - ], - "change_statuses": [ - { "id": "added", "label": "Added" }, - { "id": "modified", "label": "Modified" }, - { "id": "deleted", "label": "Deleted" }, - { "id": "renamed", "label": "Renamed" }, - { "id": "typechange", "label": "Type changed" } - ], - "config_schema": "archie/task-config@1" -} diff --git a/ui/src/lib/task-meta-snapshot.ts b/ui/src/lib/task-meta-snapshot.ts index 81bd8955f..c0d67fcfa 100644 --- a/ui/src/lib/task-meta-snapshot.ts +++ b/ui/src/lib/task-meta-snapshot.ts @@ -1,8 +1,6 @@ // The freeze-dried /api/task-meta catalog the dashboard renders before the -// served one arrives, or when archied is unreachable. It has no imports so the -// node test runner can compare it against the Go handler's committed fixture -// (internal/webui/testdata/task_meta.json); task-meta.ts replaces it with the -// live catalog. +// served one arrives, or when archied is unreachable; task-meta.ts replaces it +// with the live catalog. /** A lifecycle status as the server describes it. */ export interface StatusMeta { diff --git a/ui/src/router/index.ts b/ui/src/router/index.ts index a4c416d45..9d66c9dcb 100644 --- a/ui/src/router/index.ts +++ b/ui/src/router/index.ts @@ -17,8 +17,7 @@ import TaskDetailPage from "@/tasks/TaskDetailPage.vue"; import TasksPage from "@/tasks/TasksPage.vue"; import WorkflowsPage from "@/workflows/WorkflowsPage.vue"; -// internal/gateway/dashboard_tools.go mirrors this table; its test parses this -// file, so mark any entry the registry should skip with `nav: false`. +// internal/gateway/dashboard_tools.go mirrors this table. // // meta: // label the navigation label, short because its group carries the context diff --git a/ui/test/task-meta-snapshot.test.ts b/ui/test/task-meta-snapshot.test.ts deleted file mode 100644 index af2cddf70..000000000 --- a/ui/test/task-meta-snapshot.test.ts +++ /dev/null @@ -1,41 +0,0 @@ -import assert from "node:assert/strict"; -import { readFile } from "node:fs/promises"; -import test from "node:test"; - -const snapshot = await import("../src/lib/task-meta-snapshot.ts"); - -// internal/webui/testdata/task_meta.json is the served /api/task-meta payload, -// pinned byte-for-byte by TestTaskMetaPayloadMatchesFixture. Comparing the -// first-paint snapshot against it means a one-sided rename of any vocabulary -// fails on whichever side was not updated. -const fixture = JSON.parse( - await readFile( - new URL("../../internal/webui/testdata/task_meta.json", import.meta.url), - "utf8", - ), -); - -// The server emits an unset optional field (needs_you, confirm) as its zero -// value; the snapshot omits it. -const dropZero = (rows: Record[]) => - rows.map((row) => - Object.fromEntries( - Object.entries(row).filter(([, v]) => v !== false && v !== ""), - ), - ); - -test("the status snapshot matches the served catalog", () => { - assert.deepEqual(snapshot.DEFAULT_STATUSES, dropZero(fixture.statuses)); -}); - -test("the action snapshot matches the served catalog", () => { - assert.deepEqual(snapshot.DEFAULT_ACTIONS, dropZero(fixture.actions)); -}); - -test("the change-status snapshot matches the served catalog", () => { - assert.deepEqual(snapshot.DEFAULT_CHANGE_STATUSES, fixture.change_statuses); -}); - -test("the config schema snapshot matches the served catalog", () => { - assert.equal(snapshot.DEFAULT_CONFIG_SCHEMA, fixture.config_schema); -});