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>
83 lines
2.5 KiB
Go
83 lines
2.5 KiB
Go
package inventory
|
|
|
|
import (
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
|
|
"supermarket/internal/db"
|
|
)
|
|
|
|
func TestParseYAMLForms(t *testing.T) {
|
|
for name, doc := range map[string]string{
|
|
"list": "- name: A\n- name: B\n relationship: competitor\n",
|
|
"inventory": "inventory:\n- name: A\n- name: B\n relationship: competitor\n",
|
|
"applications": "applications:\n- name: A\n- name: B\n relationship: competitor\ncredentials: {}\n",
|
|
} {
|
|
entries, err := ParseYAML([]byte(doc), Partner)
|
|
if err != nil || len(entries) != 2 {
|
|
t.Errorf("%s: %v %v", name, entries, err)
|
|
continue
|
|
}
|
|
if entries[0].Relationship != Partner || entries[1].Relationship != Competitor {
|
|
t.Errorf("%s: relationships %q %q", name, entries[0].Relationship, entries[1].Relationship)
|
|
}
|
|
}
|
|
if _, err := ParseYAML([]byte("{{{"), Partner); err == nil {
|
|
t.Error("expected an error for invalid YAML")
|
|
}
|
|
}
|
|
|
|
func TestNormalize(t *testing.T) {
|
|
e := Entry{Name: " X ", Relationship: "Partner", MentionPolicy: "name", Subreddits: []string{"r/a", "/r/b"}}
|
|
if err := e.Normalize(); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if e.Name != "X" || e.Relationship != Partner || e.MentionPolicy != "" || strings.Join(e.Subreddits, ",") != "a,b" {
|
|
t.Errorf("%+v", e)
|
|
}
|
|
bad := Entry{Name: "Y", Relationship: "friend"}
|
|
if err := bad.Normalize(); err == nil {
|
|
t.Error("expected an error for an unknown relationship")
|
|
}
|
|
bad = Entry{Name: "Z", Relationship: Competitor, MentionPolicy: "sometimes"}
|
|
if err := bad.Normalize(); err == nil {
|
|
t.Error("expected an error for an unknown mention policy")
|
|
}
|
|
}
|
|
|
|
func TestImportAndExportRoundTrip(t *testing.T) {
|
|
d, err := db.Open(filepath.Join(t.TempDir(), "app.db"))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
defer d.Close()
|
|
in := []Entry{
|
|
{Name: "A", Relationship: Partner, Hashtags: []string{"a"}},
|
|
{Name: "B", Relationship: Competitor, TalkingPoints: "We're cheaper."},
|
|
{Name: "", Relationship: Watch},
|
|
}
|
|
r := Import(d, in, false)
|
|
if r.Added != 2 || len(r.Errors) != 1 {
|
|
t.Errorf("first import: %+v", r)
|
|
}
|
|
r = Import(d, []Entry{{Name: "a", Relationship: Watch}}, false)
|
|
if r.Skipped != 1 {
|
|
t.Errorf("existing name should be skipped: %+v", r)
|
|
}
|
|
r = Import(d, []Entry{{Name: "a", Relationship: Watch}}, true)
|
|
if r.Updated != 1 {
|
|
t.Errorf("overwrite: %+v", r)
|
|
}
|
|
|
|
all, _ := List(d, "")
|
|
out, err := ExportYAML(all)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
back, err := ParseYAML(out, Partner)
|
|
if err != nil || len(back) != 2 || back[1].TalkingPoints != "We're cheaper." || back[0].Relationship != Watch {
|
|
t.Errorf("round trip: %+v %v\n%s", back, err, out)
|
|
}
|
|
}
|