#!/usr/bin/env node import assert from 'node:assert/strict' import { readFile, mkdtemp, rm } from 'node:fs/promises' import { tmpdir } from 'node:os' import { join } from 'node:path' import { createRequire } from 'node:module' import { fileURLToPath } from 'node:url' import { build } from 'esbuild' import { buildCounterbalancedSchedule } from './counterbalanced-benchmark-schedule.mjs' import { summarizeBenchmarkSamples } from './benchmark-sample-summary.mjs' const root = fileURLToPath(new URL('../..', import.meta.url)) const entry = join(root, 'src/renderer/src/components/editor/raw-markdown-html.ts') const source = await readFile(entry, 'utf8') const cachedProbe = /if \(index > fenceProbe\) \{[\s\S]*?fenceMatch = fencePrefix.exec\(normalizedContent\)\n \}/ assert.match(source, cachedProbe) const oldProbe = String.raw`fenceMatch = normalizedContent.slice(index).match(/^\s*(\x60{3,}|~{3,})/)` const temp = await mkdtemp(join(tmpdir(), 'orca-rich-blank-bench-')) try { const scanners = {} for (const arm of ['baseline', 'current']) { const outfile = join(temp, `${arm}.cjs`) await build({ stdin: { contents: `export { encodeRawMarkdownHtmlForRichEditor as encode } from './src/renderer/src/components/editor/raw-markdown-html'; export { createRichMarkdownEditorCodec as codec } from './src/renderer/src/components/editor/rich-markdown-source-transport';`, resolveDir: root }, bundle: true, platform: 'node', format: 'cjs', outfile, plugins: arm === 'baseline' ? [ { name: 'old-probe', setup(plugin) { plugin.onLoad({ filter: /raw-markdown-html\.ts$/ }, () => ({ contents: source.replace(cachedProbe, oldProbe), loader: 'ts', resolveDir: join(root, 'src/renderer/src/components/editor') })) } } ] : [] }) const { encode, codec } = createRequire(import.meta.url)(outfile) scanners[arm] = (content) => encode(content, codec('0'.repeat(32))) } const fragments = [ '\n', ' \r\n', '\u00a0\u2028', '```\n', '~~~~\n', '