File size: 19,409 Bytes
8d52e72
 
 
c7eced2
8d52e72
c7eced2
49a03ba
 
 
 
 
 
7bd7f90
 
 
 
49a03ba
 
abb4b1a
 
 
 
 
 
 
 
49a03ba
 
 
 
 
 
8d52e72
1dc63a4
 
169f8e1
8d52e72
 
 
 
 
 
 
 
 
 
 
 
1dc63a4
8d52e72
 
 
 
 
56c51f4
 
 
8c39e75
 
56c51f4
2b84661
56c51f4
2b84661
56c51f4
76bdfe9
 
56c51f4
 
 
76bdfe9
56c51f4
c77f9c7
 
 
 
 
1778128
 
 
8d52e72
 
 
 
 
f61a724
8d52e72
 
 
 
 
 
 
 
 
c77f9c7
 
 
8d52e72
 
c77f9c7
 
 
 
 
 
 
ee32dd3
 
04140f3
 
f3e8b28
e6e90f2
 
f3e8b28
74afd5e
8d52e72
 
975d991
bef5045
8d52e72
 
 
1dc63a4
8d52e72
 
 
 
1dc63a4
 
925b307
 
8d52e72
 
 
262c3c2
c77f9c7
 
 
8d52e72
 
 
7bd7f90
 
8d52e72
 
 
1dc63a4
 
8d52e72
 
 
 
 
fa0a4e8
8d52e72
 
 
1dc63a4
8d52e72
c77f9c7
8c39e75
 
 
 
 
 
8268665
8f138db
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8268665
49a03ba
 
8268665
8d52e72
 
 
 
 
 
 
1e8e237
8d52e72
 
28bdb16
8d52e72
 
1e8e237
bef5045
e6e90f2
1e8e237
 
 
c77f9c7
 
 
1e8e237
 
c77f9c7
 
8d52e72
 
c77f9c7
 
8d52e72
 
8c39e75
925b307
 
e6e90f2
c77f9c7
 
28bdb16
 
c77f9c7
 
8d52e72
bef5045
8d52e72
 
 
 
 
 
 
 
 
 
49a03ba
 
8d52e72
 
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
const fs = require('fs')
const path = require('path')
const assert = require('assert')
const { assertCode, codePattern, readReaderSource } = require('../../support/reader_source_contract')

const root = path.resolve(__dirname, '../../..')
const readerEntry = fs.readFileSync(path.join(root, 'static/reader.js'), 'utf8')
const reader = readReaderSource(root)
assert.doesNotMatch(readerEntry, /^\s*(?:async\s+)?function\s+/m)
assertCode(readerEntry, 'from "./reader/reader-components.mjs"')
const searchController = fs.readFileSync(path.join(root, 'static/reader/search/reader-search-controller.mjs'), 'utf8')
assertCode(reader, 'import { createReaderSearchController } from "./reader/search/reader-search-controller.mjs"')
assertCode(reader, 'trackReaderResource(fullSearchController.dispose)')
assertCode(reader, 'backend: { mode: () => capability.mode, search: searchReaderText')
assert.doesNotMatch(reader, /dataset\.panelView\s*=\s*"full-search"/)
assert.doesNotMatch(searchController, /new Worker|\bfetch\(|import\(/)
const domSearch = fs.readFileSync(path.join(root, 'static/reader/search/reader-dom-search.mjs'), 'utf8')
assertCode(reader, 'import { createReaderDomSearch, fullSearchEscape, fullSearchSnippet, fullSearchPageOffset } from "./reader/search/reader-dom-search.mjs"')
assertCode(reader, 'trackReaderResource(domSearch.dispose)')
assertCode(reader, 'getTocEntries: () => navigationState.tocEntries')
assertCode(reader, 'domSearch.pruneMarks()')
assert.doesNotMatch(reader, /function (?:fullSearchDomMatches|createDomSearchSnapshot|createFullSearchDomLocator|fullSearchTextNodes|highlightTextParts)\(/)
assert.doesNotMatch(domSearch, /new Worker|\bfetch\(|import\(|readerRuntime|navigationState|fullSearchSession|fullSearchStatus/)
assertCode(domSearch, 'const stopGeneration = runtime.events.on("generation"')
assertCode(domSearch, 'function dispose() { stopGeneration()')
assertCode(domSearch, 'publishPage(page(0), page, true)')
const imageLoader = fs.readFileSync(path.join(root, 'static/reader/formats/reader-image-loader.mjs'), 'utf8')
assertCode(reader, 'import { createReaderImageLoader } from "./reader/formats/reader-image-loader.mjs"')
assertCode(reader, 'trackResource: trackReaderResource')
assertCode(reader, 'await imageLoader.load(image, target, renderController.signal)')
assert.doesNotMatch(reader, /function (?:waitReaderImage|loadReaderImage)\(/)
assert.doesNotMatch(imageLoader, /readerRuntime|readerContentUrl|pdfPageManifest|documentState|new Image|import\(/)
const css = fs.readFileSync(path.join(root, 'static/reader.css'), 'utf8')
assert.doesNotMatch(reader, /\b(?:renderFoliate|foliateSectionLoader)\b/)
assert.doesNotMatch(reader, /foliate-reader/)
assertCode(reader, 'if (markerFrame) cancelAnimationFrame(markerFrame)')
assert.strictEqual(reader.includes('document.querySelector("#toc-list").addEventListener'), false)
assert.strictEqual(reader.includes('setInterval(() => { const tab = document.querySelector("#toc-tab")'), false)
assert.strictEqual(reader.includes('setInterval('), false)
assert.strictEqual((reader.match(/function disposeReader\(\)/g) || []).length, 1)
assert.strictEqual((reader.match(/function setReaderPhase\(/g) || []).length, 1)
assert.strictEqual((reader.match(/function classifyReaderError\(/g) || []).length, 1)
assert.match(reader, /const readerLifecycle = readerRuntime\.state\.lifecycle/)
assert.doesNotMatch(reader, /(?:^|\n)\s*let readerStage\b/)
assert.match(reader, /readerRuntime\.setStage\(stage\)/)
assert.match(reader, /\$\{readerLifecycle\.stage\}/)
assertCode(reader, 'function scheduleSave() { if (readerLifecycle.disposed || readerAbortController.signal.aborted) return;')
assertCode(reader, 'readerLifecycle.disposed || !documentState.restorationReady')
assert.strictEqual((reader.match(/if \(!setReaderPhase\("ready"\)\) return/g) || []).length, 1)
assert.match(reader, /addEventListener\("pagehide"/)
assert.match(reader, /event\.persisted/)
assert.match(reader, /!event\.persisted/)
assert.doesNotMatch(reader, /id=["']ocr["']/i)
assert.match(reader, /validatePdfPageManifest/)
assert.match(reader, /const PDF_PREFETCH_MARGIN = 2400/)
assert.match(reader, /const visibleObserver = new IntersectionObserver/)
assert.match(reader, /promotePdfRenderWaiter\(shell\)/)
assert.match(reader, /function pdfPagePriority\(shell\)/)
assert.match(reader, /priority >= 3 \? "high" : priority >= 1 \? "auto" : "low"/)
assert.match(reader, /const waiter = \{\s*shell,\s*priority,/)
assert.match(reader, /waiter\.shell \? pdfPagePriority\(waiter\.shell\) : waiter\.priority/)
assert.match(reader, /function cancelSpeculativePdfRenders\(protectedShell\)/)
assert.match(reader, /isPdfPageVisible\(shell\)/)
assert.match(reader, /shell\._renderCancel\?\.\(\)/)
assert.match(reader, /const PDF_MANIFEST_PREFETCH_LIMIT = 12/)
assert.match(reader, /const PDF_MANIFEST_PREFETCH_CONCURRENCY = 3/)
assert.match(reader, /function takePdfManifestPrefetch\(target\)/)
assert.match(reader, /function schedulePdfManifestPrefetch\(page\)/)
assert.match(reader, /image\.fetchPriority = "low"/)
assert.match(reader, /pdfManifestPrefetchActive\.add\(record\)/)
assert.match(reader, /queuePdfManifestPrefetch\(\)/)
// Adjacent functions can have JSDoc or other comments between their declarations.
const pdfPageRenderMatch = reader.match(/function renderPdfImageShell\(shell, force = false, priority = false\) \{[\s\S]*?\n\}(?=(?:\s|\/\*[\s\S]*?\*\/|\/\/[^\r\n]*)+function renderPdfShell\()/)
assert.ok(pdfPageRenderMatch, 'PDF image renderer boundary before renderPdfShell')
const pdfPageRender = pdfPageRenderMatch[0]
assert.match(pdfPageRender, /const\s+target\s*=\s*(?:\/\*[\s\S]*?\*\/\s*)*(?:pdfPageManifest|\(\s*pdfPageManifest\s*\))\s*\.\s*pageUrl\(\s*entry\.page\s*\)/)
assert.match(pdfPageRender, /capability\?\.mode !== "image-pages"/)
assert.doesNotMatch(pdfPageRender, /pdfV3Repository\.preview|entry\.j|entry\.w/)
assert.doesNotMatch(reader, /renderHybridPdfCanvas|startPdfHybridDocument|leavePdfHybridMode/)
assert.match(reader, /chapterManifestObserver\?\.disconnect\(\)/)
assert.match(reader, /content\.dataset\.errorCode = code/)
assert.match(reader, /reader-request-manager\.js/)
assert.match(reader, /VoiceOfMLReaderRequests\.createReaderRequestManager\(\)/)
assert.match(reader, /readerRuntime\.track\(readerRequestManager\)/)
assert.doesNotMatch(reader, /legacyReaderTitle/)
for (const generation of ['navigation', 'search', 'bookmarks', 'pdf']) assert.match(reader, new RegExp(`nextReaderGeneration\\("${generation}"\\)`))
for (const timer of ['saveTimer', 'themeAnimationTimer', 'panelAnimationTimer']) assert.match(reader, new RegExp(`clearTimeout\\(${timer}\\)`))
assert.match(reader, /trackReaderResource\(destroy\)/)
assert.match(reader, /task\.destroy\(\)/)
assert.match(reader, /mediaElement\.pause\(\)/)
assert.match(reader, /mediaElement\.removeAttribute\("src"\)/)
assert.strictEqual(reader.includes('activeReaderControllers'), false)
assert.strictEqual(reader.includes('readerRequests'), false)
assert.match(reader, /function syncTocTab\(\)/)
assertCode(reader, 'function applyReaderMetadata(input) { const data = input == null ? null : parseMetadata(input)')
assert.strictEqual((reader.match(/function\s+applyReaderMetadata\s*\(/g) || []).length, 1)
const viewportDeclaration = codePattern('const viewport = /** @type {HTMLElement} */ (document.querySelector("#viewport"))').exec(reader)
const metadataApplication = codePattern('applyReaderMetadata(resolvedReaderData)').exec(reader)
assert.ok(viewportDeclaration && metadataApplication && viewportDeclaration.index < metadataApplication.index)
assertCode(reader, `const active = formatAdapters.active;
  if (!active) throw new Error("READER_ADAPTER_MISSING");
  const prepared = await awaitReader(active.open());
  assertReaderActive();
  const renderer = formatAdapters.active;
  if (!renderer) throw new Error("READER_ADAPTER_MISSING");
  await renderer.render(prepared);`)
assertCode(reader, 'await applyInitialRestoration(restored, generation)')
assertCode(reader, 'await restoreInitialPosition(entry, generation)')
assertCode(reader, 'const restored = await formatAdapters.active?.restore(entry, generation)')
assertCode(reader, 'if (!restored && isReaderGenerationCurrent("navigation", generation)) throw Object.assign(new Error("阅读位置恢复失败,原进度已保留,请重试加载。"), { code: "READER_RESTORE" })')
assert.match(reader, /const restorationPromise = loadReaderRestoration\(\)/)
assert.match(reader, /await renderer\.render\(prepared\)[\s\S]*?const lookup = restorationPromise\.then[\s\S]*?await awaitReader\(Promise\.race\(\[\s*lookup, waitForReader\(150\)\.then\(\(\) => null\)/)
assert.match(reader, /if \(history\) await restore\(history\.entry\)[\s\S]*?setReaderPhase\("ready"\)[\s\S]*?awaitReader\(lookup\)\.then\(async \(\{ entry \}\) => \{\s*await restore\(entry\);\s*enableSaving\(\);/)
assert.doesNotMatch(reader, /Promise\.all\(\[loadReaderRestoration\(\)/)
assert.strictEqual((reader.match(/function loadPdfDocument\(/g) || []).length, 1)
for (const renderer of ['renderImageDocument', 'renderMedia']) assert.strictEqual((reader.match(new RegExp(`function ${renderer}\\s*\\(`,'g')) || []).length, 1)
for (const renderer of ['renderTextDocument', 'renderMarkdownDocument']) assert.strictEqual((reader.match(new RegExp(`function ${renderer}\\(`,'g')) || []).length, 1)
for (const loader of ['loadTextDocument', 'loadMarkdownDocument', 'loadHtmlDocument']) assert.strictEqual((reader.match(new RegExp(`function ${loader}\\(`,'g')) || []).length, 1)
for (const loader of ['loadImageDocument', 'loadChapterManifestDocument']) assert.strictEqual((reader.match(new RegExp(`function ${loader}\\(`,'g')) || []).length, 1)
assert.match(reader, /reader-chapter-repository\.js/)
assert.match(reader, /reader-scroll-anchor\.js/)
assert.match(reader, /reader-section-virtualizer\.js/)
assert.match(reader, /VoiceOfMLReaderChapters\.createChapterScheduler\(/)
assert.match(reader, /VoiceOfMLReaderScroll\.createScrollAnchorManager\(/)
assert.match(reader, /VoiceOfMLReaderVirtual\.createSectionVirtualizer\(/)
assertCode(reader, 'readerRuntime.track(VoiceOfMLReaderScroll')
assert.match(reader, /event\.composedPath\(\)/)
assertCode(reader, 'chapterScrollAnchors.observe(article)')
assertCode(reader, 'chapterVirtualizer.dispose()')
assertCode(reader, 'const row = chapterRowAtOrAfter(Number(article.dataset.chapter))')
assertCode(reader, 'frame.insertBefore(article, row)')
assert.doesNotMatch(reader, /^let navigationGeneration\b/m)
assert.doesNotMatch(reader, /syncReaderState/)
assert.doesNotMatch(reader, /^(?:let|var|const)\s+title\b/m)
// This accessor reads runtime state without mirroring it.
const readerWithoutTocLocals = reader
  .replace(/const\s+tocEntries\s*=\s*\(\)\s*=>\s*\/\*[\s\S]*?\*\/\s*\(navigationState\.tocEntries\);/, '')
for (const mirror of ['zoom', 'currentPage', 'pageCount', 'restoredEntry', 'restorationReady', 'tocEntries', 'currentChapterIndex', 'fullSearchResults', 'fullSearchIndex', 'fullSearchGeneration', 'showingAllBookmarks', 'editingBookmark', 'pdfRenderGeneration']) assert.doesNotMatch(mirror === 'tocEntries' ? readerWithoutTocLocals : reader, new RegExp(`(?:let|var|const)\\s+${mirror}\\b`), mirror)
assert.doesNotMatch(reader, /readerRuntime\.updateFormat\(/)
for (const domain of ['document', 'navigation', 'search', 'panel']) assert.match(reader, new RegExp(`readerRuntime\\.state\\.${domain}`))
assert.match(reader, /readerRuntime\.currentGeneration\("pdf"\)/)
assertCode(reader, 'nextGeneration: () => nextReaderGeneration("search")')
assertCode(searchController, 'const generation = nextGeneration()')
assert.match(reader, /isReaderGenerationCurrent\("navigation", generation\)/)
assert.match(reader, /registerReaderFormatAdapters\(\)/)
assert.match(reader, /function disposeFormatResources\(mode\)/)
assertCode(reader, 'trustedChapterReferenceUrl(link.getAttribute("href"), chapterUrl')
assertCode(reader, 'element.removeAttribute(name)')
assert.doesNotMatch(reader, /function (?:navigateFormat|searchFormat)\(/)
assert.match(reader, /async function restoreFormat\(mode, entry, generation/)
assert.match(reader, /formatAdapters\.activate\(capability\.mode\)/)
assert.match(reader, /readerRuntime\.events\.on\("phase"/)
assert.strictEqual((reader.match(/function navigateTocEntry\(/g) || []).length, 1)
assert.match(reader, /await navigateTocEntry\(index,\s*\{\s*closePanel:\s*false\s*\}\)/)
assert.match(reader, /new IntersectionObserver/)
assert.doesNotMatch(reader, /article\.innerHTML = styles \+/)
assert.match(reader, /applyReaderMetadata\(resolvedReaderData\)/)
assert.doesNotMatch(css, /\.foliate-continuous/)
const vm = require('vm')
const priorityFunctions = reader.match(/function pdfPagePriority\(shell\) \{[\s\S]*?\n\}(?:\s|\/\*[\s\S]*?\*\/|\/\/[^\r\n]*)+function normalizePdfPriority\(priority\) \{[\s\S]*?\n\}/)
assert.ok(priorityFunctions, 'PDF page priority functions')
const priorityContext = { viewport: { getBoundingClientRect: () => ({ top: 0, bottom: 100 }) }, PDF_PREFETCH_MARGIN: 2400 }
vm.runInNewContext(priorityFunctions[0], priorityContext)
for (const [top, bottom, expected] of [[10, 90, 3], [70, 160, 2], [110, 190, 1], [2600, 2800, 0]])
  assert.strictEqual(priorityContext.pdfPagePriority({ getBoundingClientRect: () => ({ top, bottom }) }), expected)
assert.strictEqual(priorityContext.normalizePdfPriority(true), 3)
const sandbox = { self: {} }; sandbox.self = sandbox;
const frontMatterSource = fs.readFileSync(path.join(root, 'static/reader/formats/reader-html-format.mjs'), 'utf8')
const frontMatterStart = frontMatterSource.indexOf('export function stripMarkdownFrontMatter')
const frontMatterEnd = frontMatterSource.indexOf('\n}\n', frontMatterStart)
assert.ok(frontMatterStart >= 0 && frontMatterEnd > frontMatterStart, 'Markdown front matter helper')
const frontMatterContext = {}
vm.runInNewContext(
  frontMatterSource.slice(frontMatterStart, frontMatterEnd + 3).replace(/^export /, '') +
  ';this.stripMarkdownFrontMatter = stripMarkdownFrontMatter;',
  frontMatterContext
)
const stripFrontMatter = frontMatterContext.stripMarkdownFrontMatter
for (const [input, expected] of [
  ['---\ntitle: "标题"\nauthor: "作者"\nsection: "分类"\ndate: "日期"\nsource: "https://example.invalid"\nsource_path: "chinese/a.htm"\n---\n# 正文\n', '# 正文\n'],
  ['\uFEFF---\r\ntitle: "T"\r\n---\r\n正文', '正文'],
  ['---\ntitle: "T"\n---', ''],
  ['---\n\n---\n# Body', '---\n\n---\n# Body'],
  ['# Body\n---\n', '# Body\n---\n'],
  ['---\ntitle: "T"\n', '---\ntitle: "T"\n'],
]) assert.strictEqual(stripFrontMatter(input), expected)
assert.match(reader, /marked\.parse\(stripMarkdownFrontMatter\(text\)\)/)
function loadExports(file, name) { vm.runInNewContext(fs.readFileSync(path.join(root, 'static', file), 'utf8'), sandbox); return sandbox[name]; }
const contractFeatures = loadExports('reader/core/reader-contract.js', 'VoiceOfMLReader').features
const runtimeMatrix = loadExports('reader/core/reader-runtime.js', 'VoiceOfMLReaderRuntime').FEATURE_MATRIX
assert.strictEqual(runtimeMatrix, contractFeatures)
for (const mode of Object.keys(contractFeatures)) assert.strictEqual(JSON.stringify(runtimeMatrix[mode]), JSON.stringify(contractFeatures[mode]), mode)
assert.strictEqual(JSON.stringify(runtimeMatrix.unsupported), JSON.stringify({ toc: false, search: false, zoom: false, bookmarks: false, pagination: false, media: false }))
// Evaluate the owning registry with identifiable loaders/renderers, so comments or
// dead dispatch functions cannot satisfy the format wiring contract.
const registry = reader.match(/function\s+registerReaderFormatAdapters\s*\(\)\s*\{[\s\S]*?\n\}/)
assert.ok(registry, 'format adapter registry')
const expected = {
  image: ['loadImageDocument', 'renderImageDocument'],
  text: ['loadTextDocument', 'renderTextDocument'], markdown: ['loadMarkdownDocument', 'renderMarkdownDocument'],
  html: ['loadHtmlDocument', 'renderHtml'], 'epub-chapters': ['loadChapterManifestDocument', 'renderChapterManifest'],
  swf: ['loadSwfDocument', 'renderSwf'],
}
const registered = new Map(), calls = []
const registryContext = { extension: 'pdf', formatAdapters: { register: (mode, adapter) => registered.set(mode, adapter) } }
for (const name of [...new Set(Object.values(expected).flat()), 'loadPdfDocument', 'renderPdf', 'fetchReaderResponse', 'renderPdfPages', 'renderImagePages', 'renderMedia', 'restoreFormat', 'disposeFormatResources']) registryContext[name] = (...args) => calls.push([name, ...args])
vm.runInNewContext(registry[0] + '; registerReaderFormatAdapters();', registryContext)
assert.deepStrictEqual([...registered.keys()].sort(), [...Object.keys(expected), 'pdf', 'pdf-pages', 'image-pages', 'audio', 'video'].sort())
registered.get('pdf').open()
assert.deepStrictEqual(calls.splice(0), [['loadPdfDocument']], 'ordinary PDF uses PDF.js loader')
const preparedDocument = { pages: 2 }
registered.get('pdf').render(preparedDocument)
assert.deepStrictEqual(calls.splice(0), [['renderPdf', preparedDocument]], 'PDF render forwards the prepared document')
assertCode(registry[0], 'if (extension !== "djvu") return loadPdfDocument()')
assertCode(registry[0], 'releasePdfWorker?.()')
assertCode(registry[0], 'const loaderUrl = "/static/reader/pdf/reader-djvu-loader.mjs"')
assert.match(registry[0], /import\(loaderUrl\)\.then\((?:\s|\/\*[\s\S]*?\*\/)*module\s*=>\s*module\.openNativeDjvu\(readerContext\)\)/)
for (const [mode, [open, render]] of Object.entries(expected)) {
  assert.strictEqual(registered.get(mode).open, registryContext[open], mode + ' loader')
  registered.get(mode).render(preparedDocument)
  assert.deepStrictEqual(calls.splice(0), [[render, preparedDocument]], mode + ' renderer forwards the prepared document')
}
registered.get('pdf-pages').open()
assert.deepStrictEqual(calls.splice(0), [['fetchReaderResponse']])
const imageWindow = fs.readFileSync(path.join(root, 'static/reader/pdf/reader-pdf-page-window.mjs'), 'utf8')
  .replace(/^\s*\/\/.*$/gm, '')
assertCode(imageWindow, 'const initialPage = readerContext.initialReaderPage(totalPages); if (ownsOpeningPosition()) { startOpeningImage(initialPage, pageUrl(initialPage));')
registered.get('pdf-pages').render(preparedDocument)
assert.deepStrictEqual(calls.splice(0), [['renderPdfPages', preparedDocument]])
registered.get('image-pages').open()
assert.deepStrictEqual(calls.splice(0), [['fetchReaderResponse']])
registered.get('image-pages').render(preparedDocument)
assert.deepStrictEqual(calls.splice(0), [['renderImagePages', preparedDocument]])
for (const mode of ['audio', 'video']) {
  assert.strictEqual(registered.get(mode).open(), null, mode + ' has no separate preparation')
  registered.get(mode).render()
  assert.deepStrictEqual(calls.splice(0), [['renderMedia', mode]])
}
for (const [mode, adapter] of registered) {
  const entry = { page: 2 }
  adapter.restore(entry, 17)
  adapter.dispose()
  assert.deepStrictEqual(calls.splice(0), [['restoreFormat', mode, entry, 17], ['disposeFormatResources', mode]])
}
const html = fs.readFileSync(path.join(root, 'static/reader.html'), 'utf8')
const securityScript = html.indexOf('src="/static/reader/core/reader-security.js"')
assert.ok(securityScript >= 0 && securityScript < html.indexOf('src="/static/reader/core/reader-contract.js"'))
assert.match(reader, /readerRuntime\.track\(window\.__VOICE_PDF_PRELOAD__\)/)
console.log('reader architecture contracts passed')