test(tests): R4.2e browser measurements of the Rust import (module worker page, same perimeter as the TS baseline)

r4-import.mjs runs the 226 baseline files and the hostile classes through a disposable
module worker calling SheetHandle.import_pdf in Chromium 156, Firefox 157 and WebKit 27.2
under the RSS watchdog (not a guaranteed limit); compare-imports.mjs prints TS vs Rust;
serve.mjs gains opt-in mounts (/r4/, /pkg/). Results 2026-10-18-r4-import.json: 666/678
agreements, the 12 others are the 4 declared files; W4 met (max 68 MiB linear); the
1 GiB ceiling traps in every engine.
This commit is contained in:
bchanot committed 2026-10-18 16:58:42 +02:00
1 parent cad485b13c
commit c84186b032
14 files changed
+3135 -17

No files matched your search

+153
View File
@@ -0,0 +1,153 @@
import {
copyFileSync,
existsSync,
mkdirSync,
readFileSync,
rmdirSync,
unlinkSync,
} from 'node:fs'
import { join } from 'node:path'
import { pathToFileURL } from 'node:url'
import { wasmStamp } from '../../wasm-stamp.mjs'
import { sha256 } from './inputs.mjs'
import { REPO_ROOT } from './paths.mjs'
/**
* The core module of packages/core-wasm as the R4 import page loads it:
* the sheet bundle the application embeds, a snapshot of both builds for
* the run (the module can be rebuilt while a run lasts), the module's facts
* for the results file, and a Node instance of the shipped build (to build
* the hostile envelopes exactly as pdf-import.budget.test.ts does).
*/
export const PKG_DIR = join(REPO_ROOT, 'packages/core-wasm/pkg')
export const PROOFS_DIR = join(REPO_ROOT, 'packages/core-wasm/pkg-proofs')
const SEED = join(REPO_ROOT, 'supabase/seed/anatomical-sheets/equine/draft')
const WASM = 'faunosteo_wasm_bg.wasm'
const GLUE = 'faunosteo_wasm.js'
const STAMP = 'BUILD_STAMP'
const SNAPSHOT_FILES = [GLUE, WASM, STAMP]
const PAGE_BYTES = 64 * 1024
const readText = (path) => readFileSync(path, 'utf8')
const readJson = (path) => JSON.parse(readText(path))
/** The bundled draft as apps/app/vite/sheet-bundle.ts embeds it. */
export function draftBundle() {
const assets = {}
const assetHashes = {}
for (const asset of readJson(join(SEED, 'assets.json'))) {
assets[asset.svg_asset_id] = readText(join(SEED, 'assets', asset.file))
assetHashes[asset.svg_asset_id] = asset.sha256
}
return JSON.stringify({
status: 'draft',
ref: readJson(join(SEED, 'sheet-ref.json')),
document: readJson(join(SEED, 'document.json')),
migrationMap: readJson(join(SEED, 'report-migration-map.json')),
assets,
assetHashes,
})
}
/** An unsigned LEB128 at `at`: `[value, next offset]`. */
function leb128(bytes, at) {
let value = 0
let shift = 0
for (;;) {
const byte = bytes[at]
at += 1
value += (byte & 0x7f) * 2 ** shift
if ((byte & 0x80) === 0) return [value, at]
shift += 7
}
}
/** The limits of the module's own memory (section 5), in 64 KiB pages. */
export function memoryLimits(bytes) {
let at = 8
while (at < bytes.length) {
const id = bytes[at]
const [size, body] = leb128(bytes, at + 1)
if (id === 5) {
const [, flagsAt] = leb128(bytes, body)
const flags = bytes[flagsAt]
const [initial, maxAt] = leb128(bytes, flagsAt + 1)
const maximum = flags & 1 ? leb128(bytes, maxAt)[0] : null
return { initialPages: initial, maximumPages: maximum }
}
at = body + size
}
return null
}
/** A copy of one build's served files under `dir`; null when not built. */
function copyBuild(source, dir) {
if (!SNAPSHOT_FILES.every((f) => existsSync(join(source, f)))) return null
mkdirSync(dir)
for (const file of SNAPSHOT_FILES) {
copyFileSync(join(source, file), join(dir, file))
}
return dir
}
/**
* The served copies of pkg/ and pkg-proofs/ under `parent`; `remove()`
* deletes the copied files one by one, then the two directories.
*/
export function snapshotBuilds(parent) {
const pkg = copyBuild(PKG_DIR, join(parent, 'pkg'))
const proofs = copyBuild(PROOFS_DIR, join(parent, 'pkg-proofs'))
const remove = () => {
for (const dir of [pkg, proofs].filter(Boolean)) {
for (const file of SNAPSHOT_FILES) unlinkSync(join(dir, file))
rmdirSync(dir)
}
}
return { pkg, proofs, remove }
}
function buildFacts(source, dir) {
if (!dir) return null
const wasm = readFileSync(join(dir, WASM))
const limits = memoryLimits(wasm)
const stampFile = join(dir, STAMP)
return {
dir: source.slice(REPO_ROOT.length + 1),
servedFrom: 'a copy made at the start of the run',
wasmBytes: wasm.length,
wasmSha256: sha256(wasm),
glueSha256: sha256(readFileSync(join(dir, GLUE))),
buildStamp: existsSync(stampFile) ? readText(stampFile).trim() : null,
memory: limits && {
...limits,
maximumBytes:
limits.maximumPages === null ? null : limits.maximumPages * PAGE_BYTES,
},
}
}
/** What the results file states about the modules the pages loaded. */
export function moduleFacts(snapshot) {
const stamp = wasmStamp()
const pkg = buildFacts(PKG_DIR, snapshot.pkg)
const proofs = buildFacts(PROOFS_DIR, snapshot.proofs)
return {
pkg,
proofs,
sourcesStamp: stamp,
pkgStampCurrent: pkg?.buildStamp === stamp,
proofsStampCurrent: proofs?.buildStamp === stamp,
note:
'sourcesStamp is scripts/wasm-stamp.mjs on the working tree; a stamp ' +
'that differs means the sources changed after the module was built',
}
}
/** A Node instance of the shipped build (`dir`), the draft sheet loaded. */
export async function nodeSheet(bundle, dir) {
const glue = await import(pathToFileURL(join(dir, GLUE)).href)
const module = await WebAssembly.compile(readFileSync(join(dir, WASM)))
await glue.default({ module_or_path: module })
return new glue.SheetHandle(bundle)
}
+160
View File
@@ -0,0 +1,160 @@
import { readFileSync, unlinkSync, writeFileSync } from 'node:fs'
import { join } from 'node:path'
import { deflateSync } from 'node:zlib'
import { nodeSheet } from './core-module.mjs'
import { FIXTURES_DIR } from './paths.mjs'
/**
* The hostile classes of packages/core-wasm/tests/pdf-import.budget.test.ts
* (plan §B.3, W4), built in Node with the same builders, written as
* temporary files for the browser run. The L and CAP envelopes are built
* as that suite builds them: the demo archive read by the shipped module,
* the report swapped in, a fresh `archive.snapshot`.
*/
const MiB = 1024 * 1024
// UTF-8, as the suite's TextEncoder (the envelopes hold accented text).
const ascii = (text) => Buffer.from(text, 'utf8')
/** A PDF holding `streams` as EmbeddedFile objects, Filespecs, the stamp. */
export function pdfWith(streams, padding = 0) {
const parts = [ascii('%PDF-1.7\n%\xE2\xE3\xCF\xD3\n')]
if (padding > 0) parts.push(ascii(`%${'x'.repeat(padding - 2)}\n`))
let n = 1
for (const stream of streams) {
const filter = stream.flate ? ' /Filter /FlateDecode' : ''
const length = stream.bytes.byteLength
parts.push(
ascii(`${n} 0 obj\n<< /Type /EmbeddedFile /Length ${length}${filter}`),
ascii(' >>\nstream\n'),
stream.bytes,
ascii('\nendstream\nendobj\n'),
)
if (stream.name) {
parts.push(
ascii(`${n + 1} 0 obj\n<< /Type /Filespec /F (${stream.name})`),
ascii(` /EF << /F ${n} 0 R >> >>\nendobj\n`),
)
}
n += 2
}
parts.push(
ascii(`${n} 0 obj\n<< /Keywords (faunosteo-archive/1) >>\nendobj\n%%EOF\n`),
)
return Buffer.concat(parts)
}
const zeros = (bytes) => Buffer.alloc(bytes)
const deflate = (bytes) => deflateSync(bytes)
/** `{"version":3,"a":[1,1,…]}` of about `bytes` bytes. */
export function denseNumbers(bytes) {
const head = '{"version":3,"a":['
const count = Math.floor((bytes - head.length - 2) / 2)
return ascii(`${head}${'1,'.repeat(count - 1)}1]}`)
}
/** `{"version":3,"a":["","",…]}`: one string per three bytes. */
function denseStrings(bytes) {
const head = '{"version":3,"a":['
const count = Math.floor((bytes - head.length - 2) / 3)
return ascii(`${head}${'"",'.repeat(count - 1)}""]}`)
}
/** `{"version":3,"a":[[…[1,1,…]…]]}` nested to `depth`. */
function deepArrays(bytes, depth) {
const head = `{"version":3,"a":${'['.repeat(depth - 1)}`
const tail = `${']'.repeat(depth - 1)}}`
const count = Math.floor((bytes - head.length - tail.length) / 2)
return ascii(`${head}${'1,'.repeat(count - 1)}1${tail}`)
}
const named = (bytes, extra = {}) => ({
bytes,
name: 'osteo-report.json',
...extra,
})
/** The demo's envelope with `report` and a fresh snapshot. */
function envelopePdf(sheet, demoArchive, reportFile) {
const report = JSON.parse(readFileSync(join(FIXTURES_DIR, reportFile)))
const input = JSON.stringify({ report })
const snapshot = JSON.parse(sheet.call('archive.snapshot', input))
if (!snapshot.ok) throw new Error(`${reportFile}: ${snapshot.kind}`)
const envelope = { ...demoArchive, report, sheetSnapshot: snapshot.value }
return pdfWith([named(ascii(JSON.stringify(envelope, null, 2)))])
}
async function envelopeClasses(bundle, pkgDir) {
const sheet = await nodeSheet(bundle, pkgDir)
const demo = readFileSync(join(FIXTURES_DIR, 'pdf/r3/demo.fr.logos.pdf'))
const read = JSON.parse(sheet.import_pdf(new Uint8Array(demo)))
if (!read.ok) throw new Error(`demo archive: ${read.kind}`)
const archive = read.value.read.archive
const build = (file) => () => envelopePdf(sheet, archive, file)
return [
{ id: 'L-envelope', build: build('r4/reports/L.json') },
{ id: 'CAP-envelope', build: build('r4/reports/CAP.json') },
]
}
const DENSE = 16 * MiB - 64
const ATTACK_CLASSES = [
{
id: 'dense-numbers-16mib',
build: () => pdfWith([named(denseNumbers(DENSE))]),
},
{
id: 'dense-strings-16mib',
build: () => pdfWith([named(denseStrings(DENSE))]),
},
{
id: 'depth-64-16mib',
build: () => pdfWith([named(deepArrays(DENSE, 64))]),
},
{
id: 'dense-numbers-copy-16mib',
ext: 'json',
build: () => denseNumbers(DENSE),
},
{
id: 'inflation-16mib',
build: () => pdfWith([named(deflate(zeros(16 * MiB)), { flate: true })]),
},
{
id: 'bomb-16mib-plus-1',
build: () =>
pdfWith([named(deflate(zeros(16 * MiB + 1)), { flate: true })]),
},
{
id: 'bombs-32x17mib',
build: () => {
const bomb = { bytes: deflate(zeros(17 * MiB)), flate: true }
const bombs = Array.from({ length: 32 }, () => bomb)
return pdfWith([...bombs, named(ascii('{"version":3}'))])
},
},
{
id: 'file-50mib',
build: () => pdfWith([named(ascii('{"version":3}'))], 50 * MiB - 400),
},
]
/**
* Every class (or the `wanted` ids) built and written under `dir`, the
* envelopes through the shipped build in `pkgDir`; `remove()` deletes them.
*/
export async function writeHostileClasses({ bundle, dir, pkgDir, wanted }) {
const envelopes = await envelopeClasses(bundle, pkgDir)
const all = [...envelopes, ...ATTACK_CLASSES]
const classes = all.filter((c) => !wanted || wanted.includes(c.id))
const written = classes.map((c) => {
const path = join(dir, `${c.id}.${c.ext ?? 'pdf'}`)
const bytes = c.build()
writeFileSync(path, bytes)
return { id: c.id, path, bytes: bytes.length }
})
const remove = () => written.forEach((c) => unlinkSync(c.path))
return { classes: written, remove }
}
+92
View File
@@ -0,0 +1,92 @@
import {
existsSync,
mkdtempSync,
readFileSync,
rmdirSync,
unlinkSync,
writeFileSync,
} from 'node:fs'
import { basename, join } from 'node:path'
import { expandGenerator, filesUnder, isGenerator } from './inputs.mjs'
import { FIXTURES_DIR, ORACLES_R4_DIR, relativeToRepo } from './paths.mjs'
/**
* The import file set of import-baseline.mjs (groups base, r3, step6,
* tolerance, read), listed the same way, so the R4 import measures the
* TypeScript baseline's perimeter file for file.
*
* shortcut: a copy of import-baseline.mjs's listing (R4.2e leaves the
* baseline script untouched); compare-imports.mjs checks that both runs
* hold the same files. Upgrade path: import-baseline.mjs imports this
* module.
*/
const READ_DIR = join(FIXTURES_DIR, 'pdf/r4/read')
const BASE_FILES = [
'report-v2.full.pdf',
'report-v2.minimal.pdf',
'report-v3.bare.pdf',
]
const isPdf = (path) => path.endsWith('.pdf')
function pdfsIn(group, dir, recursive = false) {
const paths = filesUnder(join(FIXTURES_DIR, dir), recursive).filter(isPdf)
return paths.map((path) => ({ group, path }))
}
function fixedGroups() {
return [
...BASE_FILES.map((f) => ({ group: 'base', path: join(FIXTURES_DIR, f) })),
...pdfsIn('r3', 'pdf/r3', true),
...pdfsIn('step6', 'pdf/step6'),
...pdfsIn('tolerance', 'pdf/r4/tolerance'),
]
}
/** The hostile set as read.json (O7) lists it; absent listed files reported. */
function hostileGroup() {
const oraclePath = join(ORACLES_R4_DIR, 'read.json')
if (!existsSync(READ_DIR)) {
return { inputs: [], missing: ['pdf/r4/read/'], listedBy: null }
}
const listed = existsSync(oraclePath)
? JSON.parse(readFileSync(oraclePath, 'utf8')).inputs
: filesUnder(READ_DIR).map((path) => ({ file: basename(path), kind: null }))
const present = listed.filter((i) => existsSync(join(READ_DIR, i.file)))
const missing = listed.filter((i) => !present.includes(i)).map((i) => i.file)
const inputs = present.map((i) => ({
group: 'read',
kind: i.kind,
path: join(READ_DIR, i.file),
}))
return {
inputs,
missing,
listedBy: existsSync(oraclePath) ? relativeToRepo(oraclePath) : 'directory',
}
}
/** Every import input, narrowed by `--groups` (null = all). */
export function importInputs(groups) {
const hostile = hostileGroup()
const wanted = (i) => !groups || groups.includes(i.group)
const inputs = [...fixedGroups(), ...hostile.inputs].filter(wanted)
return { inputs, hostile }
}
/** A generator description becomes a temporary file, removed after the run. */
export function materialise(input, scratch) {
if (!isGenerator(input.path)) {
return { path: input.path, cleanup: () => undefined }
}
const path = join(scratch, `${basename(input.path, '.gen.json')}.pdf`)
writeFileSync(path, expandGenerator(input.path))
return { path, cleanup: () => unlinkSync(path) }
}
/** A fresh directory under `parent` for the run's temporary files. */
export function scratchDir(parent) {
const dir = mkdtempSync(join(parent, 'faunosteo-r4-import-'))
return { dir, remove: () => rmdirSync(dir) }
}
+282
View File
@@ -0,0 +1,282 @@
import { median, spread } from './stats.mjs'
import { importGroupTable } from './summary.mjs'
/** Markdown tables of a results file r4-import.mjs wrote. */
const MiB = 1024 * 1024
const W2_MS = 1000
const orDash = (format) => (value) =>
value === null || value === undefined || Number.isNaN(value)
? '–'
: format(value)
const mb = orDash((bytes) => (bytes / MiB).toFixed(1))
const ms = orDash((value) => value.toFixed(0))
function table(header, rows) {
const line = (cells) => `| ${cells.join(' | ')} |`
const rule = line(header.map(() => '---'))
return [line(header), rule, ...rows.map(line)].join('\n')
}
function groupBy(items, keyOf) {
const groups = new Map()
for (const item of items) {
const key = keyOf(item)
groups.set(key, [...(groups.get(key) ?? []), item])
}
return groups
}
const values = (runs, pick) => runs.map(pick).filter(Number.isFinite)
const maxOf = (list) => (list.length ? Math.max(...list) : null)
/** "median (min–max)" or the single value. */
function range(list, format) {
const stats = spread(list)
if (!stats) return '–'
if (stats.n === 1) return format(stats.median)
return `${format(stats.median)} (${format(stats.min)}–${format(stats.max)})`
}
const growth = (r) => r.rssPeakBytes - r.rssBeforeBytes
const contentGrowth = (r) => r.rssPeakContentBytes - r.rssBeforeContentBytes
const linearGrowth = (r) => r.linear?.afterBytes - r.linear?.beforeRunBytes
export const outcomeOf = (r) =>
r.resultKind ? `${r.outcome} ${r.resultKind}` : r.outcome
function rustTimingRow([key, runs]) {
const [engine, group] = key.split(' ')
return [
engine,
group,
String(runs.length),
range(
values(runs, (r) => r.pageMs),
ms,
),
range(
values(runs, (r) => r.startMs),
ms,
),
range(
values(runs, (r) => r.taskMs),
ms,
),
ms(maxOf(values(runs, (r) => r.parseMs))),
mb(maxOf(values(runs, linearGrowth))),
range(
values(runs, (r) => r.compileMs),
ms,
),
]
}
export function rustTimingTable(runs) {
const header = [
'Engine',
'Group',
'Files',
'Page ms',
'Worker start ms',
'Worker task ms',
'Max parse ms',
'Max linear growth MiB',
'Compile ms (page load)',
]
const groups = groupBy(runs, (r) => `${r.engine} ${r.group}`)
return table(header, [...groups].map(rustTimingRow))
}
function hostileRow(r) {
return [
r.engine,
r.class,
mb(r.fileBytes),
outcomeOf(r),
ms(r.pageMs),
ms(r.startMs),
ms(r.taskMs),
mb(growth(r)),
mb(contentGrowth(r)),
mb(r.linear?.afterBytes),
mb(linearGrowth(r)),
mb(r.settled?.contentDeltaBytes),
]
}
export function hostileTable(runs) {
const header = [
'Engine',
'Class',
'File MiB',
'Outcome',
'Page ms',
'Start ms',
'Task ms',
'Summed peak growth MiB',
'Content peak growth MiB',
'Linear MiB',
'Linear growth MiB',
'Settled content delta MiB',
]
return table(header, runs.map(hostileRow))
}
function proofCell(r) {
const p = r.proofValue
if (!p) return r.detail ?? '–'
const linear = `linear ${mb(p.linearBytes)} MiB`
if ('second' in p) {
const first = p.first.returned ?? p.first.threw
const second = p.second.returned ?? p.second.threw
return `256 MiB → ${first}; 1100 MiB → ${second}; ${linear}`
}
const run = p.run.returned ?? p.run.threw
return `${run} after ${ms(p.run.ms)} ms; ${linear}`
}
export function proofsTable(runs) {
const header = [
'Engine',
'Proof',
'Outcome',
'Result',
'Summed peak growth MiB',
'Content peak growth MiB',
'Settled content delta MiB',
]
const rows = runs.map((r) => [
r.engine,
r.proof,
r.outcome,
proofCell(r),
mb(growth(r)),
mb(contentGrowth(r)),
mb(r.settled?.contentDeltaBytes),
])
return table(header, rows)
}
/** Settled content level before and after each import of one page. */
export function repeatTable(runs) {
const header = [
'Engine',
'Class',
'Settle',
'Outcomes',
'Content levels MiB',
'Delta per import MiB',
]
const list = (bytes) => (bytes ?? []).map(mb).join(' → ')
const rows = runs.map((r) => [
r.engine,
r.class,
r.settleMode ?? '–',
(r.outcomes ?? []).join(', ') || r.outcome,
list(r.contentLevels),
(r.contentDeltas ?? []).map(mb).join(', ') || r.error || '–',
])
return table(header, rows)
}
export function workerFactsTable(facts) {
const header = [
'Engine',
'Module cloned',
'URL fallback',
'Clone errors',
'Workers ready',
'Not ready',
'CSP violations (page + worker)',
]
const rows = Object.entries(facts).map(([engine, f]) => [
engine,
String(f.clone),
String(f.fetch),
f.cloneErrors.join('; ') || 'none',
String(f.started),
String(f.notStarted),
f.csp.join('; ') || 'none',
])
return table(header, rows)
}
/** Plan §B.3: back within 10 MiB of the pre-import level after GC. */
export function settledCheck(runs) {
const checked = runs.filter((r) => r.settled?.mode === 'gc')
if (!checked.length) return 'No run was settled by a forced GC.'
const over = checked.filter((r) => !r.settled.contentWithin10MiB)
const deltas = checked.map((r) => r.settled.contentDeltaBytes)
const lines = [
`${checked.length} Chromium runs settled by a forced GC: ` +
`${checked.length - over.length} within 10 MiB of the pre-import ` +
`content level; delta median ${mb(median(deltas))} MiB, ` +
`max ${mb(maxOf(deltas))} MiB, min ${mb(Math.min(...deltas))} MiB.`,
]
for (const r of over) {
const what = r.file ?? r.class ?? r.proof
lines.push(`- over: ${what} ${mb(r.settled.contentDeltaBytes)} MiB`)
}
return lines.join('\n')
}
/** W2: worker start + the L-size import ≤ 1 s (Chromium, this machine). */
export function w2Line(runs) {
const l = runs.find(
(r) => r.engine === 'chromium' && r.class === 'L-envelope',
)
if (!l) return 'W2: no Chromium L-envelope run.'
const verdict = l.pageMs <= W2_MS ? 'within' : 'over'
return (
`W2 (Chromium, L envelope): page ${ms(l.pageMs)} ms = start ` +
`${ms(l.startMs)} ms + task ${ms(l.taskMs)} ms + routing, transfer ` +
`and parse; ${verdict} the 1 s budget (${outcomeOf(l)}).`
)
}
function headLines(result) {
const engines = Object.entries(result.engines)
.map(([e, v]) => `${e} ${v}`)
.join(', ')
const pkg = result.module.pkg
const max = pkg.memory?.maximumBytes
return [
`Host: ${result.host.cpuModel}, ${result.host.logicalCpus} threads, ` +
`${mb(result.host.ramBytes)} MiB RAM.`,
`Engines: ${engines} (playwright-core ${result.playwrightCore}), headless.`,
`Module: ${pkg.dir}/faunosteo_wasm_bg.wasm ${pkg.wasmBytes} bytes, ` +
`sha256 ${pkg.wasmSha256}, memory maximum ${mb(max)} MiB, ` +
`stamp current: ${result.module.pkgStampCurrent}.`,
`CSP served: ${result.server.csp}`,
`Watchdog: ${result.watchdog.caveat}`,
]
}
export function r4Summary(result) {
const parts = [...headLines(result)]
if (result.import.runs.length) {
parts.push(
'Import by group (Rust worker):',
importGroupTable(result.import),
)
parts.push('Rust worker timings:', rustTimingTable(result.import.runs))
}
if (result.hostileClasses.runs.length) {
parts.push('Hostile classes:', hostileTable(result.hostileClasses.runs))
parts.push(w2Line(result.hostileClasses.runs))
}
if (result.repeat.runs.length) {
parts.push('Repeated imports, one page:', repeatTable(result.repeat.runs))
}
if (result.proofs.runs.length) {
parts.push('Memory proofs (pkg-proofs):', proofsTable(result.proofs.runs))
}
parts.push('Worker facts:', workerFactsTable(result.workerFacts))
const all = [
...result.import.runs,
...result.hostileClasses.runs,
...result.proofs.runs,
]
parts.push(settledCheck(all))
return parts.join('\n\n')
}
+21
View File
@@ -0,0 +1,21 @@
/**
* A results file as text: indented, except that each run of a `runs`
* array sits on one line, so a full R4 run (about 700 runs) stays under
* 1 MB and still diffs run by run.
*/
export function resultsJson(result) {
const runLists = []
const text = JSON.stringify(
result,
(key, value) => {
if (key !== 'runs' || !Array.isArray(value)) return value
runLists.push(value.map((run) => JSON.stringify(run)))
return `@@runs:${runLists.length - 1}@@`
},
1,
)
return text.replace(/"@@runs:(\d+)@@"/g, (_, i) => {
const runs = runLists[Number(i)]
return runs.length ? `[\n${runs.join(',\n')}\n]` : '[]'
})
}