import { afterEach, beforeAll, describe, expect, it } from "bun:test"; import { Markdown } from "@oh-my-pi/pi-tui"; import { Settings } from "../../../src/config/settings"; import { getMarkdownTheme, getThemeByName, setMarkdownMermaidRendering, setThemeInstance, } from "../../../src/modes/theme/theme"; import { buildSystemPrompt } from "../../../src/system-prompt"; const workspaceTree = { rootPath: "/tmp/project", rendered: "", truncated: false, totalLines: 0, agentsMdFiles: [], }; function stripAnsi(text: string): string { return text.replace(/\x1b\[[0-9;]*m/g, ""); } beforeAll(async () => { await Settings.init({ inMemory: true }); const theme = await getThemeByName("dark"); if (!theme) throw new Error("theme unavailable"); setThemeInstance(theme); }); afterEach(() => { setMarkdownMermaidRendering(true); }); describe("Mermaid rendering setting", () => { it("removes the Mermaid prompt note when rendering is disabled", async () => { const { systemPrompt } = await buildSystemPrompt({ renderMermaid: false, contextFiles: [], skills: [], toolNames: [], workspaceTree, }); expect(systemPrompt.join("\n")).not.toContain("```mermaid"); }); it("falls back to a highlighted code fence when rendering is disabled", () => { setMarkdownMermaidRendering(false); const markdown = new Markdown("```mermaid\ngraph TD\n A --> B\n```", 0, 0, getMarkdownTheme()); const lines = stripAnsi(markdown.render(80).join("\n")); expect(lines).toContain("```mermaid"); expect(lines).toContain("graph TD"); expect(lines).toContain("-->"); }); });