vomebook commited on
Commit ยท
2db6cf4
1
Parent(s): b2c4db9
Organize chapter layout and image reader contracts
Browse filesFiles changed (17)
- README.md+3-1
- eslint.config.mjs+1-1
- scripts/reader/README.txt+5
- scripts/check_reader_core_coverage.mjs โ scripts/reader/check_reader_core_coverage.mjsRenamed+9-9
- scripts/check_reader_image_loader_coverage.mjs โ scripts/reader/check_reader_image_loader_coverage.mjsRenamed+3-3
- tests/reader/chapters/README.txtAdded+15
- tests/test_reader_chapter_preload.js โ tests/reader/chapters/test_reader_chapter_preload.jsRenamed+1-1
- tests/test_reader_chapter_repository.js โ tests/reader/chapters/test_reader_chapter_repository.jsRenamed+3-3
- tests/test_reader_chapter_scheduler.js โ tests/reader/chapters/test_reader_chapter_scheduler.jsRenamed+1-1
- tests/reader/images/README.txtAdded+15
- tests/test_reader_image_loader.mjs โ tests/reader/images/test_reader_image_loader.mjsRenamed+1-1
- tests/test_reader_image_loader_contract.mjs โ tests/reader/images/test_reader_image_loader_contract.mjsRenamed+1-1
- tests/test_reader_image_memory.mjs โ tests/reader/images/test_reader_image_memory.mjsRenamed+1-1
- tests/reader/layout/README.txtAdded+12
- tests/test_reader_scroll_anchor.js โ tests/reader/layout/test_reader_scroll_anchor.jsRenamed+2-2
- tests/test_reader_section_virtualizer.js โ tests/reader/layout/test_reader_section_virtualizer.jsRenamed+2-2
- tests/test_static_checks.py+14-14
16 unmodified lines171819202021222311 unmodified lines353637383940414216 unmodified lines
- `app.py`ใ`backend/`๏ผๆๅกๅ
ฅๅฃไธๅ็ซฏๆจกๅ๏ผ`backend/native/` ไธบๆฌๅฐๆ็ดข็ดขๅผๆฉๅฑๆบ็ ใ- `static/`๏ผSpace ็ๆ็ดขใ้
่ฏปๅจๅ Service Worker ่ตๆบ๏ผ`data/` ไธบๆ็ดข็ดขๅผๅ็ฎๅฝๆฐๆฎใ- `tests/`๏ผๅ็ซฏใNode ๅๆต่งๅจๆต่ฏ๏ผๅทฒๆด็็้ขๅๆต่ฏๆพๅจ `tests/search/`ใ`tests/reader/` ็ญ็ฎๅฝใPDF ๅ
จๆๆ็ดข่ง `tests/reader/pdf-search/README.txt`๏ผPDF ็ฝ็ป่ง `tests/reader/pdf-network/README.txt`๏ผ่ฏทๆฑๅๆๆกฃๅ ่ฝฝ่ง `tests/reader/transport/README.txt`ใ- `tests/`๏ผๅ็ซฏใNode ๅๆต่งๅจๆต่ฏ๏ผๅทฒๆด็็้ขๅๆต่ฏๆพๅจ `tests/search/`ใ`tests/reader/` ็ญ็ฎๅฝใPDF ๅ
จๆๆ็ดข่ง `tests/reader/pdf-search/README.txt`๏ผPDF ็ฝ็ป่ง `tests/reader/pdf-network/README.txt`๏ผ่ฏทๆฑๅๆๆกฃๅ ่ฝฝ่ง `tests/reader/transport/README.txt`๏ผ็ซ ่ๅๅธๅฑ่ง `tests/reader/chapters/` ไธ `tests/reader/layout/`๏ผๅพ็ๅ ่ฝฝ่ง `tests/reader/images/`ใ- `scripts/build/`ใ`scripts/benchmarks/`๏ผๆๅปบๅๅบๅ๏ผ`scripts/reader/`ใ`scripts/search/` ๆฏๆ้ขๅๅฝ็ป็ๆฃๆฅ๏ผๅ
ถไปๆฃๆฅๆ็ๅจ `scripts/`ใ- `quality/`๏ผ่ฆ็็ใไธฅๆ ผๆฃๆฅๅ mutation ๅฎกๆ ธๅบ็บฟ๏ผ`Dockerfile` ๅฎไนๆๅปบๅ้จ็ฝฒ้จ็ฆใ
11 unmodified linesnode scripts/reader/check_document_loader_coverage.mjsnode scripts/reader/check_pdf_network_coverage.mjsnode scripts/reader/check_pdf_network_mutations.mjsnode scripts/reader/check_reader_core_coverage.mjsnode scripts/reader/check_reader_image_loader_coverage.mjs```
ๆต่งๅจๆต่ฏ่ฟ้่ฆ Playwrightใๆต่งๅจๅ Reader vendor๏ผๅฎๆดๅ็ซๆต่ฏ้ๆฉ่ง GitHub ไปๅบ็ `.github/workflows/reader-refactor.yml`ใAndroid ๅ
ฑไบซๅญๅจๅธธไปฅ `noexec` ๆ่ฝฝ๏ผๅบๅจๆฏๆๆง่กๅ็ฌฆๅท้พๆฅ็็ฎๅฝไธญๅฎ่ฃ
ไพ่ตๅ่ฟ่กๆฃๆฅใไฟฎๆนไธ่ชๅจๅๅธ๏ผๆถๅๅไปๅบ็ๅๆดๅบๅ
ๅๅธ Space๏ผๅๅๅธ GitHub ไปๅบๅนถๆฃๆฅๅ็ซ CI๏ผGitHub ๅทฅไฝๆตไผๆๅ Space ็ main๏ผใ56 unmodified lines5758596060616256 unmodified lines { files: ["{scripts,tests}/**/*.js"], languageOptions: { sourceType: "commonjs" } }, { files: ["tests/reader/djvu/test_reader_djvu_only.mjs"], languageOptions: { globals: { VoiceOfMLReader: "readonly" } } }, { files: ["tests/reader/djvu/test_reader_djvu_png.mjs"], languageOptions: { globals: { VoiceOfMLReaderSecurity: "readonly" } } }, { files: ["tests/test_reader_image_memory.mjs"], languageOptions: { globals: { window: "readonly" } } }, { files: ["tests/reader/images/test_reader_image_memory.mjs"], languageOptions: { globals: { window: "readonly" } } }, { files: ["tests/test_reader_pdf_scroll_scheduling.mjs"], languageOptions: { globals: { document: "readonly" } } }];7 unmodified lines89101112131415161718197 unmodified lines node scripts/reader/check_document_loader_coverage.mjs node scripts/reader/check_pdf_network_coverage.mjs node scripts/reader/check_pdf_network_mutations.mjs node scripts/reader/check_reader_core_coverage.mjs node scripts/reader/check_reader_image_loader_coverage.mjs
The image contracts are documented in `tests/reader/images/README.txt`.The chapter and layout gate is documented in `tests/reader/chapters/README.txt`and `tests/reader/layout/README.txt`.The PDF network gates are documented in `tests/reader/pdf-network/README.txt`.The request and document loading gates are documented in`tests/reader/transport/README.txt`.1223456789910111112131314151613 unmodified lines30313233343536373334353637383940import { spawnSync } from "node:child_process";import {hasPassingTapContracts} from "./check_tap_contracts.mjs";import {hasPassingTapContracts} from "../check_tap_contracts.mjs";
// Each run includes exactly one own-source file, so Node's aggregate// thresholds cannot hide a regression in another file or in an empty report.// Baseline measured 2026-11-03 on Node v26.11.1, using the named tests only.const gates = [ { source:"reader-section-virtualizer.js", directory:"formats", lines:100, branches:100, functions:100, tests:["tests/test_reader_section_virtualizer.js"] }, tests:["tests/reader/layout/test_reader_section_virtualizer.js"] }, { source:"reader-chapter-repository.js", directory:"formats", lines:100, branches:98.86, functions:100, tests:["tests/test_reader_chapter_repository.js", "tests/test_reader_chapter_scheduler.js", "tests/test_reader_chapter_preload.js"] }, tests:["tests/reader/chapters/test_reader_chapter_repository.js", "tests/reader/chapters/test_reader_chapter_scheduler.js", "tests/reader/chapters/test_reader_chapter_preload.js"] }, { source:"reader-scroll-anchor.js", directory:"ui", lines:100, branches:89.61, functions:100, tests:["tests/test_reader_scroll_anchor.js"] } tests:["tests/reader/layout/test_reader_scroll_anchor.js"] }];
for (const gate of gates) {13 unmodified lines }); const values = rows.length === 1 ? rows[0].split("|").slice(1,4).map(value=>Number(value.trim())) : []; const text = result.stdout || ""; const expected = {"tests/test_reader_section_virtualizer.js": "reader section virtualizer contracts passed", "tests/test_reader_chapter_repository.js": "reader chapter repository contracts passed", "tests/test_reader_chapter_scheduler.js": "reader chapter scheduler contracts passed", "tests/test_reader_chapter_preload.js": "chapter manifest preload validation, reuse, body deadline and disposal passed", "tests/test_reader_scroll_anchor.js": "reader scroll anchor contracts passed"}; const expected = {"tests/reader/layout/test_reader_section_virtualizer.js": "reader section virtualizer contracts passed", "tests/reader/chapters/test_reader_chapter_repository.js": "reader chapter repository contracts passed", "tests/reader/chapters/test_reader_chapter_scheduler.js": "reader chapter scheduler contracts passed", "tests/reader/chapters/test_reader_chapter_preload.js": "chapter manifest preload validation, reuse, body deadline and disposal passed", "tests/reader/layout/test_reader_scroll_anchor.js": "reader scroll anchor contracts passed"}; const missingTests = gate.tests.some(name => typeof expected[name] !== "string") || !hasPassingTapContracts(text, gate.tests.map(name => ({name, marker: expected[name]}))); if (result.status !== 0 || rows.length !== 1 ||1223451 unmodified line78910101112134 unmodified lines1819202121222324import {spawnSync} from 'node:child_process';import {hasPassingTapContracts} from './check_tap_contracts.mjs';import {hasPassingTapContracts} from '../check_tap_contracts.mjs';
// Node 26/V8, this module only, under the synthetic contracts below.const minimum = [100, 87.18, 91.67];1 unmodified line '--test', '--test-concurrency=1', '--test-reporter=tap', '--experimental-test-coverage', '--test-coverage-include=**/static/reader/formats/reader-image-loader.mjs', ...minimum.map((value, index) => `--test-coverage-${['lines', 'branches', 'functions'][index]}=${value}`), 'tests/test_reader_image_loader.mjs', 'tests/test_reader_image_loader_contract.mjs' 'tests/reader/images/test_reader_image_loader.mjs', 'tests/reader/images/test_reader_image_loader_contract.mjs'], {encoding: 'utf8'});if (result.stdout) process.stdout.write(result.stdout);if (result.stderr) process.stderr.write(result.stderr);4 unmodified lines return match ? [match.slice(1).map(Number)] : [];});const required = [ {name: 'tests/test_reader_image_loader.mjs', marker: 'Reader image loader: direct load, cleanup, cancellation, HTTP errors and bounded fallback passed'}, {name: 'tests/reader/images/test_reader_image_loader.mjs', marker: 'Reader image loader: direct load, cleanup, cancellation, HTTP errors and bounded fallback passed'}, {name: 'direct image success clears handlers and the tracked resource'}, {name: 'image cancellation settles immediately even when the reader stays active'}, {name: 'resource disposal settles without retaining handlers or starting fallback'}123456789101112131415Reader chapter repository, scheduling and preload contracts===========================================================
Run from the repository root with Node 26:
node scripts/reader/check_reader_core_coverage.mjs
The chapter contracts exercise shared loads, bounded demand scheduling,cancellation, disposal, preload validation and resource ownership. The gatemeasures reader-chapter-repository.js only for this group and requires 100%lines, 98.86% branches and 100% functions. It also independently gates thesection virtualizer and scroll-anchor modules described in ../layout/README.txt.
These synthetic Node contracts do not replace Reader browser integration tests.The chapter preload test accepts an optional repository root argument.1 unmodified line234556781 unmodified lineconst fs = require('fs');const path = require('path');const vm = require('vm');const root = process.argv[2] ? path.resolve(process.argv[2]) : path.resolve(__dirname, '..');const root = process.argv[2] ? path.resolve(process.argv[2]) : path.resolve(__dirname, '../../..');const contract = fs.readFileSync(path.join(root, 'static/reader/core/reader-contract.js'), 'utf8');const security = fs.readFileSync(path.join(root, 'static/reader/core/reader-security.js'), 'utf8');const source = 'https://voiceofml-search.hf.space/api/reader-bucket-resource?path=' + encodeURIComponent(5 unmodified lines6789910111251 unmodified lines646566676768697027 unmodified lines98991001011011021031045 unmodified linesfunction createRepository(options) { const sandbox = { self: {}, DOMException }; sandbox.self = sandbox; const filename = path.join(__dirname, "../static/reader/formats/reader-chapter-repository.js"); const filename = path.join(__dirname, "../../../static/reader/formats/reader-chapter-repository.js"); vm.runInNewContext(fs.readFileSync(filename, "utf8"), sandbox, { filename }); return sandbox.VoiceOfMLReaderChapters.createChapterRepository(options);}51 unmodified lines sandbox.self = sandbox; vm.createContext(sandbox); vm.runInContext('Array.from = () => new Array(1)', sandbox); const filename = path.join(__dirname, "../static/reader/formats/reader-chapter-repository.js"); const filename = path.join(__dirname, "../../../static/reader/formats/reader-chapter-repository.js"); vm.runInContext(fs.readFileSync(filename, "utf8"), sandbox, {filename}); let finds = 0; const sparse = sandbox.VoiceOfMLReaderChapters.createChapterRepository({count:1,27 unmodified lines assert.strictEqual(cancelled.pending.length, 0);
const fallback = { DOMException, AbortController }; const filename = path.join(__dirname, "../static/reader/formats/reader-chapter-repository.js"); const filename = path.join(__dirname, "../../../static/reader/formats/reader-chapter-repository.js"); vm.runInNewContext(fs.readFileSync(filename, "utf8"), fallback, { filename }); assert.strictEqual(typeof fallback.VoiceOfMLReaderChapters.createChapterRepository, "function"); console.log("reader chapter repository contracts passed");5 unmodified lines678991011125 unmodified linesasync function main() { const sandbox = { DOMException, AbortController }; sandbox.self = sandbox; const filename = path.join(__dirname, "../static/reader/formats/reader-chapter-repository.js"); const filename = path.join(__dirname, "../../../static/reader/formats/reader-chapter-repository.js"); vm.runInNewContext(fs.readFileSync(filename, "utf8"), sandbox, { filename }); const starts = [], held = new Map(); const scheduler = sandbox.VoiceOfMLReaderChapters.createChapterScheduler({123456789101112131415Reader image loading and memory contracts=========================================
Run from the repository root with Node 26:
node tests/reader/images/test_reader_image_loader.mjs node scripts/reader/check_reader_image_loader_coverage.mjs node tests/reader/images/test_reader_image_memory.mjs
The image-loader gate runs named synthetic lifecycle, fallback and cancellationcontracts for static/reader/formats/reader-image-loader.mjs only. Its V8 floorsare 100% lines, 87.18% branches and 91.67% functions. The separate memory testexercises PDF/image rendering and eviction; it is not included in that gate.The memory test accepts an optional repository root argument. Site-specificexpectations remain distinct. Both sites run these tests in the Reader workflow.122345import assert from "node:assert/strict";import { createReaderImageLoader } from "../static/reader/formats/reader-image-loader.mjs";import { createReaderImageLoader } from "../../../static/reader/formats/reader-image-loader.mjs";
const oldLocation = globalThis.location;const oldNavigator = Object.getOwnPropertyDescriptor(globalThis, "navigator");1233456import assert from 'node:assert/strict';import test from 'node:test';import {createReaderImageLoader} from '../static/reader/formats/reader-image-loader.mjs';import {createReaderImageLoader} from '../../../static/reader/formats/reader-image-loader.mjs';
function fixture() { const controller = new AbortController(), tracked = new Set(), requests = [];1 unmodified line234556781 unmodified lineimport path from 'node:path';import {fileURLToPath, pathToFileURL} from 'node:url';
const root = path.resolve(process.argv[2] || path.join(path.dirname(fileURLToPath(import.meta.url)), '..'));const root = path.resolve(process.argv[2] || path.join(path.dirname(fileURLToPath(import.meta.url)), '../../..'));const load = name => import(pathToFileURL(path.join(root, 'static/reader', name)).href);const {createReaderPdfScheduler} = await load('pdf/reader-pdf-scheduler.mjs');const {createReaderPdfRenderer, pdfOutputScale} = await load('pdf/reader-pdf-renderer.mjs');123456789101112Reader layout contracts=======================
Run from the repository root with Node 26:
node scripts/reader/check_reader_core_coverage.mjs
The section virtualizer contracts require 100% lines, branches and functionsfor reader-section-virtualizer.js. The scroll-anchor contracts require 100%lines, 89.61% branches and 100% functions for reader-scroll-anchor.js. The gatealso independently measures the chapter repository; see ../chapters/README.txt.All thresholds are source-specific, not whole-Reader or browser coverage.5 unmodified lines67899101112134 unmodified lines1471481491501501511521535 unmodified linesfunction loadManager(options) { const sandbox = { self: {} }; sandbox.self = sandbox; const filename = path.join(__dirname, "../static/reader/ui/reader-scroll-anchor.js"); const filename = path.join(__dirname, "../../../static/reader/ui/reader-scroll-anchor.js"); vm.runInNewContext(fs.readFileSync(filename, "utf8"), sandbox, { filename }); return sandbox.VoiceOfMLReaderScroll.createScrollAnchorManager(options);}134 unmodified lines assert.strictEqual(noObserver.capture(), null); noObserver.dispose();
const filename = path.join(__dirname, "../static/reader/ui/reader-scroll-anchor.js"); const filename = path.join(__dirname, "../../../static/reader/ui/reader-scroll-anchor.js"); const fallback = {}; vm.runInNewContext(fs.readFileSync(filename, "utf8"), fallback, { filename }); assert.strictEqual(typeof fallback.VoiceOfMLReaderScroll.createScrollAnchorManager, "function");5 unmodified lines6789910111224 unmodified lines37383940404142435 unmodified linesfunction loadVirtualizer(options) { const sandbox = { self: {} }; sandbox.self = sandbox; const filename = path.join(__dirname, "../static/reader/formats/reader-section-virtualizer.js"); const filename = path.join(__dirname, "../../../static/reader/formats/reader-section-virtualizer.js"); vm.runInNewContext(fs.readFileSync(filename, "utf8"), sandbox, { filename }); return sandbox.VoiceOfMLReaderVirtual.createSectionVirtualizer(options);}24 unmodified lines virtualizer.dispose(); assert.strictEqual(virtualizer.trim(0).removed, 0); const fallback = {}; const filename = path.join(__dirname, "../static/reader/formats/reader-section-virtualizer.js"); const filename = path.join(__dirname, "../../../static/reader/formats/reader-section-virtualizer.js"); vm.runInNewContext(fs.readFileSync(filename, "utf8"), fallback, { filename }); assert.strictEqual(typeof fallback.VoiceOfMLReaderVirtual.createSectionVirtualizer, "function"); console.log("reader section virtualizer contracts passed");1121 unmodified lines112211231124112511261127112811251126112711281129113011311132113311331134113511351136113711381137113811391140114113 unmodified lines11551156115711581158115911601161116211611162116311641165286 unmodified lines1452145314541455145614571455145614571458145914601121 unmodified lines paths = ["static/reader/formats/reader-section-virtualizer.js", "static/reader/formats/reader-chapter-repository.js", "static/reader/ui/reader-scroll-anchor.js", "static/reader/core/reader-contract.js", "static/reader/core/reader-security.js", "scripts/check_reader_core_coverage.mjs", "tests/test_reader_section_virtualizer.js", "tests/test_reader_chapter_repository.js", "tests/test_reader_chapter_scheduler.js", "tests/test_reader_chapter_preload.js", "tests/test_reader_scroll_anchor.js"] "static/reader/core/reader-security.js", "scripts/reader/check_reader_core_coverage.mjs", "tests/reader/layout/test_reader_section_virtualizer.js", "tests/reader/chapters/test_reader_chapter_repository.js", "tests/reader/chapters/test_reader_chapter_scheduler.js", "tests/reader/chapters/test_reader_chapter_preload.js", "tests/reader/layout/test_reader_scroll_anchor.js"] for path in [*paths, "scripts/check_tap_contracts.mjs"]: target = self.root / path target.parent.mkdir(parents=True, exist_ok=True) shutil.copyfile(ROOT / path, target) check = ["node", "scripts/check_reader_core_coverage.mjs"] check = ["node", paths[5]] self.assert_check(self.run_check(*check), True, "reader-chapter-repository.js") gate = self.root / "scripts/check_reader_core_coverage.mjs" gate = self.root / paths[5] original_gate = gate.read_text() first = 'tests/test_reader_chapter_repository.js' second = 'tests/test_reader_chapter_scheduler.js' first = 'tests/reader/chapters/test_reader_chapter_repository.js' second = 'tests/reader/chapters/test_reader_chapter_scheduler.js' list_anchor = '"' + first + '", "' + second + '",' self.assertEqual(original_gate.count(list_anchor), 1) gate.write_text(original_gate.replace(list_anchor, '"' + first + '", "' + first + '",'))13 unmodified lines chapter_test.write_text(original_test.replace('reader chapter repository contracts passed', 'renamed success marker')) self.assert_check(self.run_check(*check), False, "passing named tests") chapter_test.write_text(original_test) (self.root / "tests/test_reader_scroll_anchor.js").write_text( (self.root / paths[10]).write_text( 'const test = require("node:test"); test("empty", () => {});\n') self.assert_check(self.run_check(*check), False, "reader-scroll-anchor.js") (self.root / "tests/test_reader_scroll_anchor.js").write_text( 'require("../static/reader/ui/reader-scroll-anchor.js");\n') (self.root / paths[10]).write_text( 'require("../../../static/reader/ui/reader-scroll-anchor.js");\n') self.assert_check(self.run_check(*check), False, "coverage")
def test_pdf_network_safety_mutation_gate_rejects_unexpected_failure(self):286 unmodified lines self.assert_check(self.run_check(*check), False, 'one source row above each minimum')
def test_reader_image_loader_coverage_gate_fails_closed(self): paths = ["static/reader/formats/reader-image-loader.mjs", "scripts/check_reader_image_loader_coverage.mjs", "scripts/check_tap_contracts.mjs", "tests/test_reader_image_loader.mjs", "tests/test_reader_image_loader_contract.mjs"] paths = ["static/reader/formats/reader-image-loader.mjs", "scripts/reader/check_reader_image_loader_coverage.mjs", "scripts/check_tap_contracts.mjs", "tests/reader/images/test_reader_image_loader.mjs", "tests/reader/images/test_reader_image_loader_contract.mjs"] for path in paths: target = self.root / path target.parent.mkdir(parents=True, exist_ok=True)README.md+3-1
eslint.config.mjs+1-1
scripts/reader/README.txt+5
scripts/check_reader_core_coverage.mjs โ scripts/reader/check_reader_core_coverage.mjsRenamed+9-9
scripts/check_reader_image_loader_coverage.mjs โ scripts/reader/check_reader_image_loader_coverage.mjsRenamed+3-3
tests/reader/chapters/README.txtAdded+15
tests/test_reader_chapter_preload.js โ tests/reader/chapters/test_reader_chapter_preload.jsRenamed+1-1
tests/test_reader_chapter_repository.js โ tests/reader/chapters/test_reader_chapter_repository.jsRenamed+3-3
tests/test_reader_chapter_scheduler.js โ tests/reader/chapters/test_reader_chapter_scheduler.jsRenamed+1-1
tests/reader/images/README.txtAdded+15
tests/test_reader_image_loader.mjs โ tests/reader/images/test_reader_image_loader.mjsRenamed+1-1
tests/test_reader_image_loader_contract.mjs โ tests/reader/images/test_reader_image_loader_contract.mjsRenamed+1-1
tests/test_reader_image_memory.mjs โ tests/reader/images/test_reader_image_memory.mjsRenamed+1-1
tests/reader/layout/README.txtAdded+12
tests/test_reader_scroll_anchor.js โ tests/reader/layout/test_reader_scroll_anchor.jsRenamed+2-2
tests/test_reader_section_virtualizer.js โ tests/reader/layout/test_reader_section_virtualizer.jsRenamed+2-2
tests/test_static_checks.py+14-14