From b50b83fbd827e9307a3a2041be48e11762482876 Mon Sep 17 00:00:00 2001 From: Harry Yep Date: Tue, 30 Jun 2026 17:38:44 +0800 Subject: [PATCH] test(desktop): add math-delimiter fixtures for the react-streamdown preprocess swap lock the four behaviors the built-in normalizeMathDelimiters/escapeCurrencyDollars introduce over the deleted custom helpers: $$$$ display math stays intact, double-backslash brackets and [/math]/[/inline] tag pairs rewrite to dollar delimiters, and currency dollars in prose are escaped. the existing preprocessMarkdown suite had no math cases. --- .../assistant-ui/markdown-text.test.ts | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/apps/desktop/src/components/assistant-ui/markdown-text.test.ts b/apps/desktop/src/components/assistant-ui/markdown-text.test.ts index b3ea416d0664..748bef09e288 100644 --- a/apps/desktop/src/components/assistant-ui/markdown-text.test.ts +++ b/apps/desktop/src/components/assistant-ui/markdown-text.test.ts @@ -210,4 +210,29 @@ describe('preprocessMarkdown', () => { expect(() => preprocessMarkdown(input)).not.toThrow() }) + + it('keeps $$$$ display math intact instead of escaping it as currency', () => { + const output = preprocessMarkdown('$$5x = 10$$') + + expect(output).toContain('$$5x = 10$$') + expect(output).not.toContain('\\$') + }) + + it('rewrites double-backslash bracket math to dollar delimiters', () => { + const output = preprocessMarkdown('\\\\(x^2\\\\)') + + expect(output).toContain('$x^2$') + }) + + it('rewrites [/math] and [/inline] tag pairs to dollar delimiters', () => { + expect(preprocessMarkdown('[/math]a+b[/math]')).toContain('$$a+b$$') + expect(preprocessMarkdown('[/inline]x[/inline]')).toContain('$x$') + }) + + it('escapes currency dollars in prose so they are not parsed as math', () => { + const output = preprocessMarkdown('$5 and $10') + + expect(output).toContain('\\$5') + expect(output).toContain('\\$10') + }) })