GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — opencode/packages/patchmark/scripts/fuzz-differential.ts at main · neumark/opencode

Expand file tree

/

fuzz-differential.ts

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
57 lines (43 loc) · 1.76 KB
/

fuzz-differential.ts

Copy path

File metadata and controls

57 lines (43 loc) · 1.76 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// Differential fuzzing: patchmark one-shot HTML vs commonmark.js (core) and micromark + GFM (gfm: true).
// Usage: bun scripts/fuzz-differential.ts [coreCases=100000] [gfmCases=30000] [seed=1]
import { generate, mutate, normalizeHtml, patchmark, referenceCore, referenceGfm, rng } from "../test/fuzz"
import { isKnownGfmDivergence } from "../test/fuzz-known"
const coreCases = Number(process.argv[2] ?? 100_000)
const gfmCases = Number(process.argv[3] ?? 30_000)
const seed = Number(process.argv[4] ?? 1)
const r = rng(seed)
let coreDiffs = 0
const t0 = performance.now()
for (let i = 0; i < coreCases; i++) {
const md = r() < 0.6 ? generate(r, false) : mutate(r)
const want = referenceCore(md)
const got = patchmark(md, false)
if (got !== want) {
coreDiffs++
if (coreDiffs <= 15)
console.log(`CORE DIFF #${i} ${JSON.stringify(md)}\n got ${JSON.stringify(got)}\n want ${JSON.stringify(want)}`)
}
}
const t1 = performance.now()
let gfmDiffs = 0
let gfmKnown = 0
for (let i = 0; i < gfmCases; i++) {
const md = r() < 0.7 ? generate(r, true) : mutate(r)
const want = normalizeHtml(referenceGfm(md))
const got = normalizeHtml(patchmark(md, true))
if (got !== want) {
if (isKnownGfmDivergence(md, got, want)) {
gfmKnown++
continue
}
gfmDiffs++
if (gfmDiffs <= 15)
console.log(`GFM DIFF #${i} ${JSON.stringify(md)}\n got ${JSON.stringify(got)}\n want ${JSON.stringify(want)}`)
}
}
const t2 = performance.now()
console.log(`Core CommonMark: ${coreCases} cases in ${((t1 - t0) / 1000).toFixed(1)}s — ${coreDiffs} diffs`)
console.log(
`GFM: ${gfmCases} cases in ${((t2 - t1) / 1000).toFixed(1)}s — ${gfmDiffs} unexpected diffs (${gfmKnown} known narrow divergences)`,
)
if (coreDiffs > 0 || gfmDiffs > 0) process.exit(1)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.