Files
deepseek-harness/scripts/markdown.spec.ts
T
imccyu 1e24617aad perf(docs): parse each Markdown document once in documentation gates
markdown links parsed anchor targets twice more and probed existence
without a cache; translation pairing reparsed every document after link
normalization and globbed four times; the README model-experience and
limitations checks parsed each README three times; type equivalence
parsed all 1,835 documents; Session format references reparsed each pair
four times. Each gate now parses a document once: links and anchors come
from one tree, pairing reuses the original tree when every rewritten
destination keeps the block structure and falls back to a full reparse
otherwise, the README checks share one tree, a text prefilter skips
documents that cannot hold a source-equivalence fence, and the
persistence renderer passes its trees on. Outputs are byte-identical on
the repository, and seeded faults are reported identically.

Refs #5852
2026-10-12 11:06:53 +08:00

39 lines
1.1 KiB
TypeScript

/** Regression coverage for reusing one parse across the Markdown gate helpers. */
import { describe, expect, it } from 'vitest'
import { markdownHeadingLines, markdownProseLines, parseMarkdown } from './markdown.ts'
const SOURCE = [
'# Title',
'',
'Prose <!-- hidden --> kept.',
'<!-- comment only -->',
'',
'```ts',
'# not a heading',
'```',
'',
'Setext heading',
'--------------',
'',
].join('\n')
describe('Markdown parse reuse', () => {
it('derives prose lines and headings from a supplied parse exactly as from its own parse', () => {
const tree = parseMarkdown(SOURCE)
const unchanged = structuredClone(tree)
const prose = markdownProseLines(SOURCE, tree)
const headings = markdownHeadingLines(SOURCE, tree)
expect(prose).toEqual(markdownProseLines(SOURCE))
expect(headings).toEqual(markdownHeadingLines(SOURCE))
expect(prose.map(line => line.index)).toEqual([1, 2, 3, 5, 9, 10, 11, 12])
expect(headings).toEqual([
{ depth: 1, index: 1, raw: '# Title', text: 'Title' },
{ depth: 2, index: 10, raw: 'Setext heading', text: 'Setext heading' },
])
expect(tree).toEqual(unchanged)
})
})