Skip to content

Commit 535798b

Browse files
committed
test(file-viewer): consolidate split test files into one per module
Match the dir's one-test-per-module convention: fold the markdown-parse property/fuzz suite into markdown-parse.test.ts and the editability corpus into round-trip-safety.test.ts (both already tested the same module from a separate-concern file). No coverage change — same assertions, fewer files (12 -> 10).
1 parent d8966b6 commit 535798b

4 files changed

Lines changed: 241 additions & 283 deletions

File tree

apps/sim/app/workspace/[workspaceId]/files/components/file-viewer/rich-markdown-editor/markdown-parse.fuzz.test.ts

Lines changed: 0 additions & 93 deletions
This file was deleted.

apps/sim/app/workspace/[workspaceId]/files/components/file-viewer/rich-markdown-editor/markdown-parse.test.ts

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { Editor } from '@tiptap/core'
55
import { afterEach, describe, expect, it } from 'vitest'
66
import { createMarkdownContentExtensions } from './extensions'
77
import { parseMarkdownToDoc, serializeMarkdownBody, splitMarkdownBlocks } from './markdown-parse'
8+
import { isRoundTripSafe } from './round-trip-safety'
89

910
let editor: Editor | null = null
1011
afterEach(() => {
@@ -141,3 +142,64 @@ describe('parseMarkdownToDoc (chunked)', () => {
141142
expect(serializeMarkdownBody(body)).toBe(oneShot(body))
142143
})
143144
})
145+
146+
/** Deterministic PRNG (mulberry32) so a failure is always reproducible from its seed. */
147+
function rng(seed: number) {
148+
return () => {
149+
seed |= 0
150+
seed = (seed + 0x6d2b79f5) | 0
151+
let t = Math.imul(seed ^ (seed >>> 15), 1 | seed)
152+
t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t
153+
return ((t ^ (t >>> 14)) >>> 0) / 4294967296
154+
}
155+
}
156+
157+
const FUZZ_BLOCKS: Array<(r: () => number) => string> = [
158+
() => '# Heading one',
159+
() => '### Heading three',
160+
(r) =>
161+
`A paragraph with **bold**, *italic*, \`code\`, and a [link](https://x.com/${Math.floor(r() * 99)}).`,
162+
() => '- tight a\n- tight b\n- tight c',
163+
() => '- loose a\n\n- loose b\n\n- loose c',
164+
() => '1. ordered one\n2. ordered two\n3. ordered three',
165+
() => '1. First\n - sub bullet\n - another\n 1. deep ordered\n 2. item\n2. Second',
166+
() => '1. item\n\n a second paragraph inside the item\n\n2. next item',
167+
() => '> a blockquote\n> spanning lines\n>\n> > and a nested one',
168+
() => '| col a | col b |\n| --- | --- |\n| 1 | 2 |\n| 3 | 4 |',
169+
() => '```ts\nconst x = 1\n\nfunction f() {\n return x\n}\n```',
170+
() => '- [ ] todo one\n- [x] done two\n - [ ] subtask',
171+
() => '---',
172+
() => '![alt](https://img.example/a.png)',
173+
() => '[![badge](https://img.shields.io/x.svg)](https://link.example)',
174+
() => 'Text with ~~strikethrough~~ and a soft \nline break inside it.',
175+
// Raw HTML / reference defs route to the whole-document fallback, so fidelity must still hold even
176+
// though the doc itself opens read-only (idempotency is only asserted for editable docs).
177+
() => '<div class="note">\n\nwrapped content\n\n</div>',
178+
() => 'See [the docs][ref].\n\n[ref]: https://example.com/docs',
179+
]
180+
181+
function buildFuzzDoc(seed: number): string {
182+
const r = rng(seed)
183+
const count = 2 + Math.floor(r() * 8)
184+
const parts: string[] = []
185+
for (let i = 0; i < count; i++) parts.push(FUZZ_BLOCKS[Math.floor(r() * FUZZ_BLOCKS.length)](r))
186+
return parts.join('\n\n')
187+
}
188+
189+
describe('chunked parse — property test over randomized documents', () => {
190+
it('chunked === one-shot for every document, and idempotent for every editable one', () => {
191+
const failures: Array<{ seed: number; kind: string }> = []
192+
for (let seed = 1; seed <= 400; seed++) {
193+
const body = buildFuzzDoc(seed)
194+
const chunked = serializeMarkdownBody(body)
195+
// Fidelity is the load-bearing invariant — chunked must never diverge from the whole-document
196+
// parse, for ANY input; idempotency only needs to hold where the doc is editable (raw HTML is
197+
// non-idempotent in the underlying editor regardless of chunking, which is why it opens read-only).
198+
if (chunked !== oneShot(body)) failures.push({ seed, kind: 'fidelity' })
199+
else if (isRoundTripSafe(body) && serializeMarkdownBody(chunked) !== chunked) {
200+
failures.push({ seed, kind: 'idempotency' })
201+
}
202+
}
203+
expect(failures).toEqual([])
204+
})
205+
})

apps/sim/app/workspace/[workspaceId]/files/components/file-viewer/rich-markdown-editor/round-trip-editable-corpus.test.ts

Lines changed: 0 additions & 190 deletions
This file was deleted.

0 commit comments

Comments
 (0)