Sam owns this codebase and reads Vue fluently, not Preact; a UI its maintainer
cannot read is the liability that outweighs the port. shadcn-vue is Vue-only,
so adopting it means the framework moves with it.
Scaffolded per the official Vite guide: `npm create vite --template vue-ts`,
Tailwind v4 via @tailwindcss/vite, `shadcn-vue init` (Reka UI, Lucide, neutral
base, CSS variables). Button and DropdownMenu are added, the latter being what
the pending navigation restructure needs.
Two deviations from the guide, both forced:
- The guide sets `baseUrl` alongside `paths`. TypeScript 6 deprecates
`baseUrl` and errors on it, and this project is heading for TS 7 native, so
`paths` stands alone and resolves relative to the config file. Not a
downgrade: the scaffold's typescript ~6.0.2 is untouched.
- vite.config.ts keeps `base: "./"` and unhashed asset names. ui/embed.go
embeds a committed dist/, served from a path the build does not know;
hashed names would also orphan a file in git on every rebuild.
The Preact app and its 43 test files are deleted rather than ported, on Sam's
instruction: tests return when there is behaviour worth pinning rather than a
port to re-assert. `task test:ui` is now a vue-tsc typecheck, which is what
would actually catch a broken component; an empty `npm test` would pass
vacuously.
ui/src/router/index.ts carries the route table and is the new source of truth
for TestDashboardPagesRegistryCoversEveryRoute, which parsed main.jsx before.
Keeping that contract alive matters: it is what caught the stale /chat entry
earlier today. Every route resolves to a named placeholder view, so an unported
page is visibly unported rather than blank.
golangci-lint now excludes ui/node_modules. The dashboard toolchain pulls in
`flatted`, which ships a Go implementation beside its JavaScript, and the gate
was failing on complexity in a vendored third-party file.
The shadcn MCP server is registered in the root .mcp.json. `shadcn-vue mcp init`
writes it to the directory it runs in, which for a nested ui/ is a path Claude
Code never reads.
172 lines
5.2 KiB
Go
172 lines
5.2 KiB
Go
package gateway
|
|
|
|
import (
|
|
"context"
|
|
"os"
|
|
"path/filepath"
|
|
"regexp"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
// quietContext is the tool execution context; the tools never use it beyond
|
|
// 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*"([^"]+)"`)
|
|
|
|
// 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]
|
|
}
|
|
|
|
// One route per line. 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
|
|
for line := range strings.SplitSeq(block, "\n") {
|
|
match := routePathRe.FindStringSubmatch(line)
|
|
if match == nil || strings.Contains(line, "nav: false") {
|
|
continue
|
|
}
|
|
paths = append(paths, match[1])
|
|
}
|
|
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 {
|
|
t.Fatal("page_index tool not available")
|
|
}
|
|
if entry.Name != "page_index" {
|
|
t.Fatalf("tool name = %q", entry.Name)
|
|
}
|
|
out, err := entry.Handler(quietContext(), map[string]any{})
|
|
if err != nil {
|
|
t.Fatalf("page_index handler: %v", err)
|
|
}
|
|
res, ok := out.(PageIndexResult)
|
|
if !ok {
|
|
t.Fatalf("page_index returned %T, want PageIndexResult", out)
|
|
}
|
|
if len(res.Pages) != len(DashboardPages()) {
|
|
t.Fatalf("page_index returned %d pages, want %d", len(res.Pages), len(DashboardPages()))
|
|
}
|
|
}
|
|
|
|
func TestDashboardNavigateResolvesKnownRoute(t *testing.T) {
|
|
entry, ok := dashboardNavigateTool()
|
|
if !ok {
|
|
t.Fatal("dashboard_navigate tool not available")
|
|
}
|
|
out, err := entry.Handler(quietContext(), map[string]any{"path": "/tasks"})
|
|
if err != nil {
|
|
t.Fatalf("dashboard_navigate(/tasks): %v", err)
|
|
}
|
|
res, ok := out.(DashboardNavigateResult)
|
|
if !ok {
|
|
t.Fatalf("dashboard_navigate returned %T, want DashboardNavigateResult", out)
|
|
}
|
|
if res.Path != "/tasks" {
|
|
t.Fatalf("resolved path = %q, want /tasks", res.Path)
|
|
}
|
|
if res.Label == "" {
|
|
t.Fatal("resolved label is empty")
|
|
}
|
|
}
|
|
|
|
func TestDashboardNavigateRejectsUnknownRoute(t *testing.T) {
|
|
entry, ok := dashboardNavigateTool()
|
|
if !ok {
|
|
t.Fatal("dashboard_navigate tool not available")
|
|
}
|
|
_, err := entry.Handler(quietContext(), map[string]any{"path": "/not-a-page"})
|
|
if err == nil {
|
|
t.Fatal("dashboard_navigate(/not-a-page) returned no error")
|
|
}
|
|
}
|
|
|
|
func TestDashboardNavigateRejectsEmptyPath(t *testing.T) {
|
|
entry, _ := dashboardNavigateTool()
|
|
if _, err := entry.Handler(quietContext(), map[string]any{}); err == nil {
|
|
t.Fatal("dashboard_navigate with no path returned no error")
|
|
}
|
|
}
|
|
|
|
func TestDashboardToolsBindWebOnly(t *testing.T) {
|
|
// Only the web channel should carry dashboard tooling: pointing a Telegram
|
|
// operator at an internal dashboard route is meaningless.
|
|
web := PageIndexTools("web")
|
|
if len(web) == 0 {
|
|
t.Fatal("web channel should get dashboard tools")
|
|
}
|
|
names := map[string]bool{}
|
|
for _, e := range web {
|
|
names[e.Name] = true
|
|
}
|
|
if !names["page_index"] || !names["dashboard_navigate"] {
|
|
t.Fatalf("web dashboard tools missing page_index/dashboard_navigate: %v", names)
|
|
}
|
|
|
|
// A non-web channel gets none.
|
|
if got := PageIndexTools("telegram"); len(got) != 0 {
|
|
t.Fatalf("telegram channel got %d dashboard tools, want 0", len(got))
|
|
}
|
|
}
|