| 1 | package bot |
| 2 | |
| 3 | import ( |
| 4 | "os" |
| 5 | "regexp" |
| 6 | "strings" |
| 7 | "testing" |
| 8 | ) |
| 9 | |
| 10 | // TestElevenPersonaMatchesJS pins elevenPersona to agent/eleven.mjs's |
| 11 | // ELEVEN_PERSONA (a string-concatenation of double-quoted segments) so the Go |
| 12 | // and Node guides can't drift — same approach as the command/chip drift tests, |
| 13 | // and it needs no Node runtime. |
| 14 | func TestElevenPersonaMatchesJS(t *testing.T) { |
| 15 | raw, err := os.ReadFile("../../agent/eleven.mjs") |
| 16 | if err != nil { |
| 17 | t.Fatal(err) |
| 18 | } |
| 19 | // Match the run of concatenated string literals (not up to the first ";", |
| 20 | // which appears INSIDE the text — "you share its name; own the joke"). |
| 21 | m := regexp.MustCompile(`(?s)export const ELEVEN_PERSONA =((?:\s*"[^"]*"\s*\+?)+);`).FindSubmatch(raw) |
| 22 | if m == nil { |
| 23 | t.Fatal("ELEVEN_PERSONA not found in eleven.mjs") |
| 24 | } |
| 25 | var b strings.Builder |
| 26 | for _, seg := range regexp.MustCompile(`"([^"]*)"`).FindAllStringSubmatch(string(m[1]), -1) { |
| 27 | b.WriteString(seg[1]) |
| 28 | } |
| 29 | if got := b.String(); got != elevenPersona { |
| 30 | t.Errorf("persona drift:\n js: %q\n go: %q", got, elevenPersona) |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | // TestElevenKnowledge mirrors test/knowledge.test.mjs Go-side (Go is the primary |
| 35 | // sidecar now): the embedded reference is substantial, covers the core topics, |
| 36 | // and leaks NO operational secrets — the invariant that matters, since the text |
| 37 | // is extractable by anyone chatting with Eleven. |
| 38 | func TestElevenKnowledge(t *testing.T) { |
| 39 | if len(appKnowledge) < 10000 { |
| 40 | t.Fatalf("knowledge too short: %d chars", len(appKnowledge)) |
| 41 | } |
| 42 | for _, topic := range []string{`(?i)end-to-end`, `(?i)thread`, `(?i)invite`, `(?i)remind`, `Announcer`, `(?i)passkey|backup`} { |
| 43 | if !regexp.MustCompile(topic).MatchString(appKnowledge) { |
| 44 | t.Errorf("knowledge missing topic %q", topic) |
| 45 | } |
| 46 | } |
| 47 | forbidden := map[string]string{ |
| 48 | `\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b`: "an IP address", |
| 49 | `(?i)run\.garden|elevenmessenger\.com|paulca`: "a real hostname/instance", |
| 50 | `(?i)hetzner|\bmiren\b|1password`: "an operator/tooling name", |
| 51 | `(?i)\.p8\b|admintok|LCHAT_ADMIN_TOKEN|Bearer\s+\w`: "a key/token", |
| 52 | `(?i)BEGIN (?:EC |RSA |OPENSSH )?PRIVATE KEY`: "a private key", |
| 53 | `(?i)ssh\s+root@|root@\d`: "an SSH target", |
| 54 | } |
| 55 | for pat, what := range forbidden { |
| 56 | if regexp.MustCompile(pat).MatchString(appKnowledge) { |
| 57 | t.Errorf("knowledge appears to contain %s (pattern %q)", what, pat) |
| 58 | } |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | func TestElevenBuiltins(t *testing.T) { |
| 63 | if builtinPersona("Eleven") != elevenPersona { |
| 64 | t.Error("Eleven should get the guide persona") |
| 65 | } |
| 66 | if builtinPersona("Claude") != "" || builtinDocs("Announcer") != "" { |
| 67 | t.Error("non-Eleven identities have no builtin persona/docs") |
| 68 | } |
| 69 | docs := elevenDocs() |
| 70 | if !strings.Contains(docs, "# Eleven — the complete guide") { |
| 71 | t.Error("elevenDocs missing the knowledge base") |
| 72 | } |
| 73 | // The LIVE command list rides in the reference, so the two can't drift. |
| 74 | if !strings.Contains(docs, "/theme") || !strings.Contains(docs, "/help") { |
| 75 | t.Errorf("elevenDocs missing the command summary:\n%s", docs[len(docs)-400:]) |
| 76 | } |
| 77 | } |
| 78 | |