From 55f94ee1ecbc6f40fc766f2244fe64f498b1f932 Mon Sep 17 00:00:00 2001 From: Farnabaz Date: Wed, 18 Nov 2026 20:00:14 +0100 Subject: [PATCH] test: add regression tests for `$` tokens without math plugin (#136) The auto-close bug from #136 (a trailing `$skill-name` treated as an unclosed inline math opener, producing `$skill-name$`) was fixed in #394 (v0.7.0): math auto-close now only runs when the math plugin is registered. These tests lock that fix in place. No source changes. - `test/auto-close.test.ts`: `autoCloseMarkdown` with default options leaves the reporter's three inputs unchanged. - `test/math.test.ts`: end-to-end through `parseMarkdown`/`renderMarkdown`. Without the math plugin, the inputs parse to plain text or a link with `$imagegen` text and the correct href, and render back to the source. With `math()`, a trailing `Value $x` is still auto-closed into inline math. This checks the `math: hasPlugin('math')` wiring in `index.ts` in both directions. Closes #136 --- packages/comark/test/auto-close.test.ts | 10 ++++++++ packages/comark/test/math.test.ts | 34 +++++++++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/packages/comark/test/auto-close.test.ts b/packages/comark/test/auto-close.test.ts index 8b64b85b..2c8ad1ad 100644 --- a/packages/comark/test/auto-close.test.ts +++ b/packages/comark/test/auto-close.test.ts @@ -713,6 +713,16 @@ describe('attributes scope', () => { }) }) +describe('dollar-prefixed tokens without math (#136)', () => { + it.each([ + '$skill-name', + '[$imagegen](/Users/user01/.codex/skills/.system/imagegen/SKILL.md)', + 'Codex uses [$imagegen](/Users/user01/.codex/skills/.system/imagegen/SKILL.md) and $skill-name.', + ])('should leave %s unchanged', (input) => { + expect(autoCloseMarkdown(input)).toBe(input) + }) +}) + describe('inline code spans as literal regions', () => { it('should not count asterisks inside a closed code span', () => { const input = 'text `a*b` and **bold' diff --git a/packages/comark/test/math.test.ts b/packages/comark/test/math.test.ts index 73bf8ad5..9690ab19 100644 --- a/packages/comark/test/math.test.ts +++ b/packages/comark/test/math.test.ts @@ -59,3 +59,37 @@ Inline \(E = mc^2\) and \[x^2\] end.` expect(await renderMarkdown(document)).toBe(source) }) }) + +describe('dollar-prefixed tokens and auto-close (#136)', () => { + const href = '/Users/user01/.codex/skills/.system/imagegen/SKILL.md' + + it('keeps a trailing `$skill-name` as plain text without the math plugin', async () => { + const document = await parseMarkdown('$skill-name') + + expect(document.nodes).toEqual([['p', {}, '$skill-name']]) + expect(await renderMarkdown(document)).toBe('$skill-name') + }) + + it('keeps `$` inside link text without the math plugin', async () => { + const source = `[$imagegen](${href})` + const document = await parseMarkdown(source) + + expect(document.nodes).toEqual([['p', {}, ['a', { href }, '$imagegen']]]) + expect(await renderMarkdown(document)).toBe(source) + }) + + it('keeps a link and a trailing `$skill-name.` intact without the math plugin', async () => { + const source = `Codex uses [$imagegen](${href}) and $skill-name.` + const document = await parseMarkdown(source) + + expect(document.nodes).toEqual([['p', {}, 'Codex uses ', ['a', { href }, '$imagegen'], ' and $skill-name.']]) + expect(await renderMarkdown(document)).toBe(source) + }) + + it('auto-closes a trailing unclosed `$` when the math plugin is registered', async () => { + const document = await parseMarkdown('Value $x', { plugins: [math()] }) + + expect(document.nodes).toEqual([['p', {}, 'Value ', ['math', { class: 'math inline', content: 'x' }, 'x']]]) + expect(await renderMarkdown(document)).toBe('Value $x$') + }) +})