package bot import ( "os" "regexp" "strings" "testing" ) // TestElevenPersonaMatchesJS pins elevenPersona to agent/eleven.mjs's // ELEVEN_PERSONA (a string-concatenation of double-quoted segments) so the Go // and Node guides can't drift — same approach as the command/chip drift tests, // and it needs no Node runtime. func TestElevenPersonaMatchesJS(t *testing.T) { raw, err := os.ReadFile("../../agent/eleven.mjs") if err != nil { t.Fatal(err) } // Match the run of concatenated string literals (not up to the first ";", // which appears INSIDE the text — "you share its name; own the joke"). m := regexp.MustCompile(`(?s)export const ELEVEN_PERSONA =((?:\s*"[^"]*"\s*\+?)+);`).FindSubmatch(raw) if m == nil { t.Fatal("ELEVEN_PERSONA not found in eleven.mjs") } var b strings.Builder for _, seg := range regexp.MustCompile(`"([^"]*)"`).FindAllStringSubmatch(string(m[1]), -1) { b.WriteString(seg[1]) } if got := b.String(); got != elevenPersona { t.Errorf("persona drift:\n js: %q\n go: %q", got, elevenPersona) } } // TestElevenKnowledge mirrors test/knowledge.test.mjs Go-side (Go is the primary // sidecar now): the embedded reference is substantial, covers the core topics, // and leaks NO operational secrets — the invariant that matters, since the text // is extractable by anyone chatting with Eleven. func TestElevenKnowledge(t *testing.T) { if len(appKnowledge) < 10000 { t.Fatalf("knowledge too short: %d chars", len(appKnowledge)) } for _, topic := range []string{`(?i)end-to-end`, `(?i)thread`, `(?i)invite`, `(?i)remind`, `Announcer`, `(?i)passkey|backup`} { if !regexp.MustCompile(topic).MatchString(appKnowledge) { t.Errorf("knowledge missing topic %q", topic) } } forbidden := map[string]string{ `\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b`: "an IP address", `(?i)run\.garden|elevenmessenger\.com|paulca`: "a real hostname/instance", `(?i)hetzner|\bmiren\b|1password`: "an operator/tooling name", `(?i)\.p8\b|admintok|LCHAT_ADMIN_TOKEN|Bearer\s+\w`: "a key/token", `(?i)BEGIN (?:EC |RSA |OPENSSH )?PRIVATE KEY`: "a private key", `(?i)ssh\s+root@|root@\d`: "an SSH target", } for pat, what := range forbidden { if regexp.MustCompile(pat).MatchString(appKnowledge) { t.Errorf("knowledge appears to contain %s (pattern %q)", what, pat) } } } func TestElevenBuiltins(t *testing.T) { if builtinPersona("Eleven") != elevenPersona { t.Error("Eleven should get the guide persona") } if builtinPersona("Claude") != "" || builtinDocs("Announcer") != "" { t.Error("non-Eleven identities have no builtin persona/docs") } docs := elevenDocs() if !strings.Contains(docs, "# Eleven — the complete guide") { t.Error("elevenDocs missing the knowledge base") } // The LIVE command list rides in the reference, so the two can't drift. if !strings.Contains(docs, "/theme") || !strings.Contains(docs, "/help") { t.Errorf("elevenDocs missing the command summary:\n%s", docs[len(docs)-400:]) } }