complete local markdown resource lifecycle contract

This commit is contained in:
lix-2026
2026-05-24 03:22:03 +08:00
parent 6df74fb4e0
commit 36eac664f2
8 changed files with 269 additions and 33 deletions
@@ -459,6 +459,27 @@ async function main() {
const assetPath = path.join(resourceDir, "resource-note.md");
assert(fs.existsSync(assetPath), "测试前置条件:附件文件应存在");
fs.unlinkSync(assetPath);
await page.waitForFunction(
() => {
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";
},
null,
{ timeout: UI_TIMEOUT_MS },
);
const missingMarkedBeforeReload = await page.evaluate(() => {
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
? {
missing: link.getAttribute("data-mnote-attachment-missing"),
text: link.textContent || "",
}
: null;
});
const markdownAfterDeleteBeforeReload = fs.readFileSync(path.join(root, relativePath), "utf8");
assert(markdownAfterDeleteBeforeReload.includes("[resource-note.md](README/resource-note.md)"), "watcher 标记 missing 不应改写 Markdown 正文");
// 刷新页面
await page.reload({ waitUntil: "domcontentloaded", timeout: UI_TIMEOUT_MS });
@@ -508,6 +529,7 @@ async function main() {
assetPath,
deleted: true,
linkPreserved,
missingMarkedBeforeReload,
editorText: linkTextAfter.slice(0, 500),
popupCount: popupCountAfter - popupCountBefore,
resourceTabErrorVisible,