Redesign the UI on brain's look: sidebar with search, Overview, modules, grouped Settings
- Left sidebar as in brain: search at the top (press /), Overview, Inventory, the modules (Content with Inbox, Sources, Scheduled and Published; later phases greyed out), Settings at the bottom; a top bar with breadcrumbs, and a menu that slides in on narrow screens. - brain's colour tokens, type, radius and shadows, with a dark theme that follows the system setting. - Settings as grouped tabs: Profile; Social accounts (was Credentials, now keys and sign-in together per network); Core & Hermes; AI, which now holds the API keys too. Old addresses redirect. - /search matches every word across posts, fetched items, the inventory, products and settings pages. - Overview: a card per module, then the setup checklist, folded once done. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+88
-17
@@ -11,12 +11,15 @@ import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"supermarket/internal/bridge"
|
||||
"supermarket/internal/content"
|
||||
"supermarket/internal/core"
|
||||
"supermarket/internal/db"
|
||||
"supermarket/internal/inventory"
|
||||
"supermarket/internal/mcpserver"
|
||||
"supermarket/internal/models"
|
||||
"supermarket/internal/profile"
|
||||
"supermarket/internal/secrets"
|
||||
)
|
||||
@@ -86,9 +89,9 @@ func TestEveryPageRenders(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
for _, path := range []string{"/", "/?msg=saved", "/profile", "/inventory", "/inventory?relationship=partner",
|
||||
for _, path := range []string{"/", "/?msg=saved", "/settings/profile", "/inventory", "/inventory?relationship=partner",
|
||||
"/inventory/new", "/inventory/1", "/inventory/import", "/inventory/export",
|
||||
"/settings/ai", "/settings/credentials", "/core", "/static/app.css", "/static/htmx.min.js", "/healthz",
|
||||
"/settings/ai", "/settings/accounts", "/settings/core", "/static/app.css", "/search", "/search?q=rival", "/search?q=nothing+here", "/static/htmx.min.js", "/healthz",
|
||||
"/content", "/content/1", "/content/1?dismissed=1", "/inbox", "/inbox?msg=drafted",
|
||||
"/content/scheduled", "/content/published"} {
|
||||
rec := do(h, http.MethodGet, path, nil, nil)
|
||||
@@ -114,21 +117,21 @@ func TestGuardRejectsForeignHostsAndCrossSitePosts(t *testing.T) {
|
||||
}
|
||||
|
||||
form := url.Values{"name": {"Acme"}, "description": {"x"}}
|
||||
rec = do(h, http.MethodPost, "/profile", strings.NewReader(form.Encode()), map[string]string{
|
||||
rec = do(h, http.MethodPost, "/settings/profile", strings.NewReader(form.Encode()), map[string]string{
|
||||
"Content-Type": "application/x-www-form-urlencoded",
|
||||
"Origin": "https://evil.example",
|
||||
})
|
||||
if rec.Code != http.StatusForbidden {
|
||||
t.Errorf("cross-origin POST: got %d", rec.Code)
|
||||
}
|
||||
rec = do(h, http.MethodPost, "/profile", strings.NewReader(form.Encode()), map[string]string{
|
||||
rec = do(h, http.MethodPost, "/settings/profile", strings.NewReader(form.Encode()), map[string]string{
|
||||
"Content-Type": "application/x-www-form-urlencoded",
|
||||
"Sec-Fetch-Site": "cross-site",
|
||||
})
|
||||
if rec.Code != http.StatusForbidden {
|
||||
t.Errorf("cross-site POST without Origin: got %d", rec.Code)
|
||||
}
|
||||
if rec := postForm(h, "/profile", form); rec.Code != http.StatusSeeOther {
|
||||
if rec := postForm(h, "/settings/profile", form); rec.Code != http.StatusSeeOther {
|
||||
t.Errorf("same-origin POST: got %d %s", rec.Code, rec.Body.String())
|
||||
}
|
||||
}
|
||||
@@ -144,7 +147,7 @@ func TestProfileAndInventoryForms(t *testing.T) {
|
||||
"website_branch": {"", ""}, "website_plausible": {"", ""}, "website_gsc": {"", ""}, "website_bing": {"", ""},
|
||||
"account_x": {"@acme"}, "subreddits": {"r/selfhosted\n/r/homelab"},
|
||||
}
|
||||
if rec := postForm(h, "/profile", form); rec.Code != http.StatusSeeOther {
|
||||
if rec := postForm(h, "/settings/profile", form); rec.Code != http.StatusSeeOther {
|
||||
t.Fatalf("save profile: %d %s", rec.Code, rec.Body.String())
|
||||
}
|
||||
p, _ := profile.Load(s.DB)
|
||||
@@ -162,7 +165,7 @@ func TestProfileAndInventoryForms(t *testing.T) {
|
||||
}
|
||||
|
||||
// Missing description: the form comes back with an error, nothing saved.
|
||||
rec := postForm(h, "/profile", url.Values{"name": {"Other"}})
|
||||
rec := postForm(h, "/settings/profile", url.Values{"name": {"Other"}})
|
||||
if rec.Code != http.StatusOK || !strings.Contains(rec.Body.String(), "required") {
|
||||
t.Errorf("invalid profile: %d", rec.Code)
|
||||
}
|
||||
@@ -196,20 +199,88 @@ func TestProfileAndInventoryForms(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestCredentialsKeepAndRemove(t *testing.T) {
|
||||
func TestAccountsKeepAndRemove(t *testing.T) {
|
||||
s, h := newTestServer(t, nil)
|
||||
postForm(h, "/settings/credentials", url.Values{secrets.AnthropicAPIKey: {" sk-1 "}, secrets.YouTubeAPIKey: {"yt"}})
|
||||
postForm(h, "/settings/accounts", url.Values{secrets.XClientID: {" id-1 "}, secrets.YouTubeAPIKey: {"yt"}})
|
||||
// Empty field keeps the value; remove clears it.
|
||||
postForm(h, "/settings/credentials", url.Values{secrets.AnthropicAPIKey: {""}, "remove:" + secrets.YouTubeAPIKey: {"on"}})
|
||||
if got := s.Secrets.Get(secrets.AnthropicAPIKey); got != "sk-1" {
|
||||
t.Errorf("anthropic key = %q", got)
|
||||
postForm(h, "/settings/accounts", url.Values{secrets.XClientID: {""}, "remove:" + secrets.YouTubeAPIKey: {"on"}})
|
||||
if got := s.Secrets.Get(secrets.XClientID); got != "id-1" {
|
||||
t.Errorf("x client id = %q", got)
|
||||
}
|
||||
if s.Secrets.Has(secrets.YouTubeAPIKey) {
|
||||
t.Error("youtube key should be removed")
|
||||
}
|
||||
page := do(h, http.MethodGet, "/settings/credentials", nil, nil).Body.String()
|
||||
if strings.Contains(page, "sk-1") {
|
||||
t.Error("the credentials page must never show a saved value")
|
||||
// The AI keys aren't on this tab, so it can't change them.
|
||||
postForm(h, "/settings/accounts", url.Values{secrets.AnthropicAPIKey: {"sk-x"}})
|
||||
if s.Secrets.Has(secrets.AnthropicAPIKey) {
|
||||
t.Error("the accounts form saved an AI key")
|
||||
}
|
||||
page := do(h, http.MethodGet, "/settings/accounts", nil, nil).Body.String()
|
||||
if strings.Contains(page, "id-1") {
|
||||
t.Error("the accounts page must never show a saved value")
|
||||
}
|
||||
}
|
||||
|
||||
func TestAIKeysOnTheAITab(t *testing.T) {
|
||||
s, h := newTestServer(t, nil)
|
||||
form := url.Values{"provider": {"anthropic"}, "model": {"claude-opus-5-5"}, "effort": {"medium"},
|
||||
secrets.AnthropicAPIKey: {" sk-1 "}}
|
||||
if rec := postForm(h, "/settings/ai", form); rec.Code != http.StatusSeeOther {
|
||||
t.Fatalf("save: %d %s", rec.Code, rec.Body.String())
|
||||
}
|
||||
if got := s.Secrets.Get(secrets.AnthropicAPIKey); got != "sk-1" {
|
||||
t.Errorf("anthropic key = %q", got)
|
||||
}
|
||||
// A form that needs fixing still keeps the key typed into it.
|
||||
rec := postForm(h, "/settings/ai", url.Values{"provider": {"openai"}, "model": {"m"}, secrets.OpenAIAPIKey: {"ok-2"}})
|
||||
if rec.Code != http.StatusOK || s.Secrets.Get(secrets.OpenAIAPIKey) != "ok-2" {
|
||||
t.Errorf("openai without address: %d, key %q", rec.Code, s.Secrets.Get(secrets.OpenAIAPIKey))
|
||||
}
|
||||
postForm(h, "/settings/ai", url.Values{"provider": {"anthropic"}, "model": {"m"}, "remove:" + secrets.AnthropicAPIKey: {"on"}})
|
||||
if s.Secrets.Has(secrets.AnthropicAPIKey) {
|
||||
t.Error("anthropic key should be removed")
|
||||
}
|
||||
if page := do(h, http.MethodGet, "/settings/ai", nil, nil).Body.String(); strings.Contains(page, "ok-2") {
|
||||
t.Error("the AI page must never show a saved key")
|
||||
}
|
||||
}
|
||||
|
||||
func TestOldAddressesRedirect(t *testing.T) {
|
||||
_, h := newTestServer(t, nil)
|
||||
for old, now := range map[string]string{"/profile": "/settings/profile", "/core": "/settings/core",
|
||||
"/settings/credentials": "/settings/accounts", "/settings": "/settings/profile"} {
|
||||
rec := do(h, http.MethodGet, old, nil, nil)
|
||||
if rec.Code/100 != 3 || rec.Header().Get("Location") != now {
|
||||
t.Errorf("%s: %d → %q", old, rec.Code, rec.Header().Get("Location"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestSearch(t *testing.T) {
|
||||
s, h := newTestServer(t, nil)
|
||||
if err := inventory.Save(s.DB, &inventory.Entry{Name: "Rival Corp", Relationship: "competitor", Description: "Makes gadgets."}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := content.SaveItems(s.DB, []models.ContentItem{{ID: "rss:1", AppName: "Rival Corp", Source: models.SourceRSS,
|
||||
Title: "Gadget 2 launches", Body: "Faster gadgets for everyone", PublishedAt: time.Now()}}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := content.CreateDrafts(s.DB, []content.Draft{{InventoryName: "Rival Corp", Kind: "competitor",
|
||||
Channel: "x", Content: "Our widgets beat any gadget"}}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
body := do(h, http.MethodGet, "/search?q=GADGET", nil, nil).Body.String()
|
||||
for _, want := range []string{"Rival Corp", "Gadget 2 launches", "Our widgets beat any gadget", `href="/content/1"`, `href="/inbox"`} {
|
||||
if !strings.Contains(body, want) {
|
||||
t.Errorf("search for gadget: missing %q", want)
|
||||
}
|
||||
}
|
||||
// Every word must match.
|
||||
if body := do(h, http.MethodGet, "/search?q=gadget+launches", nil, nil).Body.String(); strings.Contains(body, "Our widgets") {
|
||||
t.Error("a draft without \"launches\" matched")
|
||||
}
|
||||
if body := do(h, http.MethodGet, "/search?q=anthropic+key", nil, nil).Body.String(); !strings.Contains(body, `href="/settings/ai"`) {
|
||||
t.Error("settings search should find the AI tab")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -258,12 +329,12 @@ func TestMCPNeedsTokenAndChecksIn(t *testing.T) {
|
||||
|
||||
func TestProfileDraftNeedsAI(t *testing.T) {
|
||||
s, h := newTestServer(t, nil)
|
||||
body := do(h, http.MethodGet, "/profile", nil, nil).Body.String()
|
||||
body := do(h, http.MethodGet, "/settings/profile", nil, nil).Body.String()
|
||||
if !strings.Contains(body, `<a href="/settings/ai">choose an AI provider</a>`) || !strings.Contains(body, `class="secondary" disabled>Draft`) {
|
||||
t.Errorf("profile without AI:\n%s", body)
|
||||
}
|
||||
_ = s.Secrets.Set(map[string]string{secrets.AnthropicAPIKey: "k"})
|
||||
if body := do(h, http.MethodGet, "/profile", nil, nil).Body.String(); strings.Contains(body, "choose an AI provider") {
|
||||
if body := do(h, http.MethodGet, "/settings/profile", nil, nil).Body.String(); strings.Contains(body, "choose an AI provider") {
|
||||
t.Error("warning shown with an AI key saved")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user