fix local markdown attachment regressions

This commit is contained in:
lix-2026
2026-05-29 11:13:05 +08:00
parent 1109e3c0d8
commit cbe789e034
63 changed files with 3249 additions and 1502 deletions
@@ -112,7 +112,6 @@ async function main() {
let staleScopeChildrenRequests = 0;
let scopedRootProjectionRequests = 0;
let workspaceRootProjectionRequests = 0;
let forceChangingWatchRevision = false;
let localWatchRevision = 0;
page.on("console", (message) => {
@@ -140,24 +139,6 @@ async function main() {
}
await route.continue();
});
await page.route("**/api/tree/local-folder-watch**", async (route) => {
if (!forceChangingWatchRevision) {
await route.continue();
return;
}
localWatchRevision += 1;
await route.fulfill({
status: 200,
contentType: "application/json",
body: JSON.stringify({
ok: true,
result: {
revision: `forced-watch-${localWatchRevision}`,
},
}),
});
});
try {
await waitForHttpOk(`${baseUrl}/health`, 60_000);
const authResponse = await context.request.fetch(`${baseUrl}/api/auth`, {
@@ -239,30 +220,40 @@ async function main() {
relativePath,
expanded: row.getAttribute("aria-expanded"),
selected: row.getAttribute("data-selected"),
focused: row.getAttribute("data-focused"),
active: row.getAttribute("data-active"),
}
: null;
};
const firstMarkdownPath = firstParent + "/" + firstParent.split("/").pop() + ".md";
const secondMarkdownPath = secondParent + "/" + secondParent.split("/").pop() + ".md";
return {
first: readRow(firstParent),
second: readRow(secondParent),
firstMarkdownVisible: Boolean(document.querySelector(`#sidebar-file-tree-root .tree-row[data-shell-mode="filetree"][data-local-relative-path="${CSS.escape(firstParent + "/" + firstParent.split("/").pop() + ".md")}"]`)),
secondMarkdownVisible: Boolean(document.querySelector(`#sidebar-file-tree-root .tree-row[data-shell-mode="filetree"][data-local-relative-path="${CSS.escape(secondParent + "/" + secondParent.split("/").pop() + ".md")}"]`)),
firstMarkdown: readRow(firstMarkdownPath),
secondMarkdown: readRow(secondMarkdownPath),
};
}, { firstParent: firstCreatedParentPath, secondParent: secondCreatedParentPath });
assert.equal(
createExpansionState.first?.expanded,
"false",
`连续新建页面不应把上一个页面包目录自动展开: ${JSON.stringify(createExpansionState)}`,
createExpansionState.second?.expanded,
"true",
`新建页面后当前页面包目录应展开,避免焦点落到父文件夹: ${JSON.stringify(createExpansionState)}`,
);
assert.equal(
createExpansionState.second?.expanded,
"false",
`连续新建页面不应为了选中内部 md 而展开当前页面包目录: ${JSON.stringify(createExpansionState)}`,
createExpansionState.secondMarkdown?.selected,
"true",
`新建页面后应选中内部 Markdown 行: ${JSON.stringify(createExpansionState)}`,
);
assert.equal(
createExpansionState.secondMarkdown?.focused,
"true",
`新建页面后文件树焦点应落在内部 Markdown 行: ${JSON.stringify(createExpansionState)}`,
);
assert.equal(
createExpansionState.secondMarkdown?.active,
"true",
`新建页面后 active 应落在内部 Markdown 行: ${JSON.stringify(createExpansionState)}`,
);
assert.equal(createExpansionState.firstMarkdownVisible, false, `上一个页面包内部 md 不应闪现/常驻: ${JSON.stringify(createExpansionState)}`);
assert.equal(createExpansionState.secondMarkdownVisible, false, `当前页面包内部 md 不应闪现/常驻: ${JSON.stringify(createExpansionState)}`);
assert.equal(createExpansionState.second?.active, "true", `当前页面包目录应承接 active 状态: ${JSON.stringify(createExpansionState)}`);
const scopedUrl = new URL(baseUrl);
if (workspaceId) scopedUrl.searchParams.set("workspaceId", workspaceId);
@@ -341,13 +332,27 @@ async function main() {
"scoped 文件树收到非 scope root snapshot 不应兜底重拉 scope 根 projection",
);
const scopedRootRequestsBeforeCoarseWatch = scopedRootProjectionRequests;
forceChangingWatchRevision = true;
await page.waitForTimeout(1600);
forceChangingWatchRevision = false;
localWatchRevision += 1;
await page.evaluate((revision) => {
window.dispatchEvent(new CustomEvent("tree:local-folder-watch-batch", {
detail: {
payload: {
schema: "mnote.local_folder_watch_batch.v1",
sourceKind: "local_folder",
revision: `forced-watch-${revision}`,
affectedParents: [{ relativePath: "", reason: "coarse-watch" }],
changedPaths: [{ relativePath: "design", kind: "Modify(Name(Both))" }],
eventKinds: ["Modify(Name(Both))"],
fallbackResync: false,
},
},
}));
}, localWatchRevision);
await page.waitForTimeout(300);
assert.equal(
scopedRootProjectionRequests,
scopedRootRequestsBeforeCoarseWatch,
"scoped 文件树收到 coarse local-folder-watch revision 不应重拉 scope 根 projection",
"scoped 文件树收到 coarse local-folder 事件不应重拉 scope 根 projection",
);
const rowSelector = '#sidebar-file-tree-root .tree-row[data-shell-mode="filetree"][data-local-relative-path="design/03-rust-web"]';