import { beforeAll, describe, expect, it } from "bun:test"; import { UserMessageComponent } from "../../../src/modes/components/user-message"; import { initTheme } from "../../../src/modes/theme/theme"; beforeAll(async () => { await initTheme(false); }); function render(text: string): string { return new UserMessageComponent(text).render(80).join("\n"); } describe("UserMessageComponent magic-keyword highlighting", () => { it("gradient-paints a magic keyword in the rendered (sent) message bubble", () => { const raw = render("please orchestrate the rollout"); // Visible text is preserved. expect(Bun.stripANSI(raw)).toContain("please orchestrate the rollout"); // The keyword is gradient-painted: a per-character foreground sequence is emitted, // and the word no longer survives as a contiguous run in the rendered bytes. expect(raw).toContain("\x1b[38"); expect(raw).not.toContain("orchestrate"); }); it("does not paint a keyword inside an inline code span", () => { const raw = render("ship the `orchestrate` helper"); expect(Bun.stripANSI(raw)).toContain("orchestrate"); // Code spans render through the code style as a single run — the word stays intact. expect(raw).toContain("orchestrate"); }); it("does not paint a keyword inside a fenced code block", () => { const raw = render("intro\n```\norchestrate\n```"); expect(Bun.stripANSI(raw)).toContain("orchestrate"); expect(raw).toContain("orchestrate"); }); });