Phase 0: turn Supermarket into a Dockerized local web app
Replace the old Go TUI with a web app (port 8470) that runs in a container as a CoreDesktop sibling: - cmd/supermarket server with htmx web UI: dashboard, company profile, inventory (partners/competitors), AI and credential settings, and a Core & Hermes page - SQLite storage and a secrets store under ~/.local/share/supermarket - AI providers (Anthropic, OpenAI-compatible) behind one interface - MCP server and a Hermes bridge to the Federated Core MCP hub - Import of the old Coremarketing TUI's state - install.sh / update.sh / lib.sh, Dockerfile, compose.yaml, the bin/supermarket launcher and hermes/setup.sh Posting is not wired back up yet; that comes in Phase 1. See PLAN.md. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,82 @@
|
||||
package profile
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"supermarket/internal/ai"
|
||||
)
|
||||
|
||||
type fakeAI struct {
|
||||
prompt string
|
||||
reply any
|
||||
}
|
||||
|
||||
func (f *fakeAI) Generate(_ context.Context, req ai.Request) (string, error) {
|
||||
f.prompt = req.Prompt
|
||||
raw, _ := json.Marshal(f.reply)
|
||||
return string(raw), nil
|
||||
}
|
||||
|
||||
func TestDraftReadsUsefulPages(t *testing.T) {
|
||||
mux := http.NewServeMux()
|
||||
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.URL.Path != "/" {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
w.Header().Set("Content-Type", "text/html")
|
||||
w.Write([]byte(`<html><head><title>Acme & Co</title><meta name="description" content="Widgets for teams">
|
||||
<script>var secret = "ignore me";</script><style>.x{}</style></head>
|
||||
<body><h1>Widgets</h1><p>Fast widgets.</p>
|
||||
<a href="/about">About us</a> <a href="/pricing#plans">Pricing</a> <a href="/blog/post">Blog</a>
|
||||
<a href="https://elsewhere.example/about">Partner</a></body></html>`))
|
||||
})
|
||||
mux.HandleFunc("/about", func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
||||
w.Write([]byte(`<p>Founded in 2020.</p>`))
|
||||
})
|
||||
mux.HandleFunc("/pricing", func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "text/html")
|
||||
w.Write([]byte(`<p>$10 a month.</p>`))
|
||||
})
|
||||
srv := httptest.NewServer(mux)
|
||||
defer srv.Close()
|
||||
|
||||
fake := &fakeAI{reply: map[string]any{
|
||||
"name": "Acme", "description": "Widgets for teams.", "positioning": "", "voice": "plain",
|
||||
"keywords": []string{"widgets", " "}, "products": []any{map[string]any{"name": "Widget", "description": "", "url": "", "pricing": "$10", "benefits": []string{}}},
|
||||
"targets": map[string]any{"industries": []string{}, "company_sizes": []string{}, "roles": []string{"CTO"}, "regions": []string{}, "problems": []string{}, "buying_signals": []string{}, "technologies": []string{}},
|
||||
"accounts": map[string]any{"x": "@acme", "linkedin": ""},
|
||||
}}
|
||||
p, err := Draft(context.Background(), fake, srv.URL)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if p.Name != "Acme" || p.Accounts.X != "acme" || len(p.Keywords) != 1 || p.Targets.Roles[0] != "CTO" {
|
||||
t.Errorf("draft: %+v", p)
|
||||
}
|
||||
if len(p.Websites) != 1 || !strings.HasPrefix(p.Websites[0].URL, srv.URL) {
|
||||
t.Errorf("website: %+v", p.Websites)
|
||||
}
|
||||
for _, want := range []string{"Title: Acme & Co", "Description: Widgets for teams", "Fast widgets.", "Founded in 2020.", "$10 a month."} {
|
||||
if !strings.Contains(fake.prompt, want) {
|
||||
t.Errorf("prompt is missing %q", want)
|
||||
}
|
||||
}
|
||||
for _, unwanted := range []string{"ignore me", "elsewhere"} {
|
||||
if strings.Contains(fake.prompt, unwanted) {
|
||||
t.Errorf("prompt contains %q", unwanted)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestDraftRejectsBadURL(t *testing.T) {
|
||||
if _, err := Draft(context.Background(), &fakeAI{}, "ftp://example.com"); err == nil {
|
||||
t.Error("expected an error")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user