feat: consolidate local-first mnote web runtime

This commit is contained in:
lix-2026
2026-05-28 22:01:44 +08:00
parent 7354807ee9
commit 39b9a0183a
154 changed files with 13591 additions and 12728 deletions
@@ -521,7 +521,16 @@ async function main() {
assert(fs.existsSync(assetPath), "测试前置条件:附件文件应存在");
fs.unlinkSync(assetPath);
await page.waitForFunction(
() => {
async () => {
const now = Date.now();
if (
typeof window.__mnoteRefreshEditorLocalAttachmentExistence === "function"
&& (!window.__mnoteTask479LastAttachmentRefreshAt || now - window.__mnoteTask479LastAttachmentRefreshAt > 500)
) {
window.__mnoteTask479LastAttachmentRefreshAt = now;
window.__mnoteRefreshEditorLocalAttachmentExistence();
await new Promise((resolve) => setTimeout(resolve, 250));
}
const link = Array.from(document.querySelectorAll('.document-pane[data-pane-role="primary"] .editor-surface .ProseMirror a[href*="/api/local-folder/files/open"]'))
.find((node) => (node.textContent || "").includes("resource-note.md"));
return link instanceof HTMLAnchorElement && link.getAttribute("data-mnote-attachment-missing") === "true";
@@ -560,12 +569,16 @@ async function main() {
// 预期行为:链接应保留
const linkPreserved = linkTextAfter.includes("resource-note.md");
const popupCountBefore = popups.length;
const brokenLink = page
.locator('.document-pane[data-pane-role="primary"] .editor-surface .ProseMirror a', {
hasText: "resource-note.md",
})
.first();
await brokenLink.click({ timeout: UI_TIMEOUT_MS });
await page.evaluate(() => {
const brokenLink = Array.from(document.querySelectorAll('.document-pane[data-pane-role="primary"] .editor-surface .ProseMirror a'))
.find((node) => node instanceof HTMLAnchorElement && (node.textContent || "").includes("resource-note.md"));
if (!(brokenLink instanceof HTMLAnchorElement)) throw new Error("broken_link_missing");
brokenLink.dispatchEvent(new MouseEvent("click", {
bubbles: true,
cancelable: true,
view: window,
}));
});
await page.waitForTimeout(1500);
const popupCountAfter = popups.length;
const resourceTabErrorVisible = await page
@@ -602,10 +615,36 @@ async function main() {
}
} catch (err) {
overallOk = false;
const debugState = await page.evaluate(async () => {
const collectLinks = () => Array.from(document.querySelectorAll('.document-pane[data-pane-role="primary"] .editor-surface .ProseMirror a'))
.map((node) => ({
text: node.textContent || "",
href: node instanceof HTMLAnchorElement ? node.getAttribute("href") || "" : "",
missing: node instanceof HTMLElement ? node.getAttribute("data-mnote-attachment-missing") : "",
className: node instanceof HTMLElement ? node.getAttribute("class") || "" : "",
}));
const beforeManualRefresh = collectLinks();
if (typeof window.__mnoteRefreshEditorLocalAttachmentExistence === "function") {
window.__mnoteRefreshEditorLocalAttachmentExistence();
await new Promise((resolve) => setTimeout(resolve, 1500));
}
const pane = document.querySelector('.document-pane[data-pane-role="primary"]');
const editor = pane?.querySelector('.editor-surface .ProseMirror');
return {
url: window.location.href,
hasManualRefresh: typeof window.__mnoteRefreshEditorLocalAttachmentExistence,
status: pane?.querySelector('[data-runtime-editor-status]')?.getAttribute("data-runtime-editor-status") || "",
conflictVisible: Boolean(pane?.querySelector('[data-testid="mnote-editor-conflict-panel"]')),
editorText: editor instanceof HTMLElement ? (editor.textContent || "").slice(0, 500) : "",
beforeManualRefresh,
afterManualRefresh: collectLinks(),
};
}).catch((debugErr) => ({ debugError: debugErr.message }));
checks[checkId] = {
ok: false,
message: `删除真实附件后正文链接保留检查失败: ${err.message}`,
error: err.stack,
debugState,
};
}
}