Files
mnote/scripts/task522-page-aggregate-compat-fallback-contract.js
T
lix-2026 627213dc01 feat: add evidence search and stabilize pdf previews
- add document evidence parsing/search/open routes, Hermes tool wiring, local index settings/status, and the document-evidence skill plus design notes
- fix PDF resource tabs by rendering PDFs inline with pdf.js canvases instead of iframe preview pages, release PDF documents on close, and document the fourth-PDF stall bug
- keep PDF preview at 2x rendering while removing the previous lazy-load/placeholder direction, and make dev:hot bind loopback defaults externally reachable

Verification:
- node --check rust/crates/mnote-web/browser/document-resource-tab-runtime.js
- node scripts/task-dev-hot-plan-test.js
- cargo test -p mnote-web --manifest-path rust/Cargo.toml pdf_preview_page_does_not_render_visible_toolbar
- cargo test -p mnote-web --manifest-path rust/Cargo.toml document_shell_returns_page_aggregate_snapshot
- cargo build -p mnote-web --manifest-path rust/Cargo.toml
- browser smoke: sequentially opened the four tea_seed_oil_cosmetic PDFs; fourth PDF rendered 15/15 canvases, iframeCount=0, browser errors=0
2026-06-04 18:51:16 +08:00

159 lines
3.9 KiB
JavaScript

#!/usr/bin/env node
"use strict";
const assert = require("node:assert/strict");
const fs = require("node:fs");
const path = require("node:path");
const vm = require("node:vm");
const RUNTIME_PATH = path.join(
process.cwd(),
"rust/crates/mnote-web/browser/document-tiptap-conversion-runtime.js",
);
function loadConversionRuntime() {
const source = fs
.readFileSync(RUNTIME_PATH, "utf8")
.replace(/\bexport const\s+([A-Za-z0-9_]+)\s*=/g, "const $1 =");
const sandbox = { console };
vm.runInNewContext(
`${source}\n;globalThis.__mnoteExports = { pageBodyTiptapDocumentSource, pageBodyTiptapDocument };`,
sandbox,
{ filename: RUNTIME_PATH },
);
return sandbox.__mnoteExports;
}
function paragraphText(doc) {
return doc?.content?.[0]?.content?.[0]?.text || "";
}
function firstTableCellText(doc) {
return doc?.content?.[0]?.content?.[0]?.content?.[0]?.content?.[0]?.content?.[0]?.text || "";
}
function taskItemChecked(doc) {
return doc?.content?.[0]?.content?.[0]?.attrs?.checked;
}
const {
pageBodyTiptapDocumentSource,
pageBodyTiptapDocument,
} = loadConversionRuntime();
const blockDocument = {
type: "doc",
content: [{
type: "paragraph",
attrs: { blockId: "block-truth" },
content: [{ type: "text", text: "Block truth" }],
}],
};
const legacyContent = [{
id: "legacy-1",
type: "paragraph",
content: [{ type: "text", text: "Legacy fallback" }],
}];
const localWithBlockAndLegacy = {
projectionSource: "local_markdown.content",
blockDocument,
content: legacyContent,
};
assert.equal(
pageBodyTiptapDocumentSource(localWithBlockAndLegacy),
"page_aggregate.block_document",
);
assert.equal(
paragraphText(pageBodyTiptapDocument(localWithBlockAndLegacy)),
"Block truth",
);
const localWithProjectedTable = {
projectionSource: "local_markdown.content",
blockDocument: {
documentId: "local-md:design~2F07-ai~2Fdone~2F7-45-chatonly-api-provider-runtime-v1.md",
rootBlockIds: ["table-1"],
blocks: [{
blockId: "table-1",
type: "table",
attrs: {
tiptapTable: {
type: "table",
content: [{
type: "tableRow",
content: [{
type: "tableCell",
attrs: { colspan: 1, rowspan: 1, colwidth: null },
content: [{
type: "paragraph",
content: [{ type: "text", text: "Provider 类别" }],
}],
}],
}],
},
},
contentNodes: [],
}],
},
};
assert.equal(
firstTableCellText(pageBodyTiptapDocument(localWithProjectedTable)),
"Provider 类别",
);
const localWithProjectedTodo = {
projectionSource: "local_markdown.content",
blockDocument: {
documentId: "local-md:design~2F07-ai~2Fprocess~2F7-46-document-evidence-retrieval-kernel-v1.md",
rootBlockIds: ["todo-1"],
blocks: [{
blockId: "todo-1",
type: "todo",
attrs: { checked: true },
contentNodes: [{ text: "graph traversal 结果必须带证据引用。", styles: {} }],
}],
},
};
assert.equal(
taskItemChecked(pageBodyTiptapDocument(localWithProjectedTodo)),
true,
);
const localLegacyOnly = {
projectionSource: "local_markdown.content",
content: legacyContent,
};
assert.equal(
pageBodyTiptapDocumentSource(localLegacyOnly),
"local_markdown.content",
);
assert.equal(
paragraphText(pageBodyTiptapDocument(localLegacyOnly)),
"Legacy fallback",
);
const compatLegacyOnly = {
content: legacyContent,
};
assert.equal(
pageBodyTiptapDocumentSource(compatLegacyOnly),
"compat.legacy_content",
);
assert.equal(
paragraphText(pageBodyTiptapDocument(compatLegacyOnly)),
"Legacy fallback",
);
assert.equal(
pageBodyTiptapDocumentSource({}, "Fallback text"),
"degraded.fallback_text",
);
assert.equal(
paragraphText(pageBodyTiptapDocument({}, "Fallback text")),
"Fallback text",
);
console.log("task522 page aggregate compat fallback contract passed");