fix: relink rust web tree editor runtime

This commit is contained in:
lix-2026
2026-04-29 14:36:24 +08:00
parent 6c3d20ca55
commit 33ddda9dfd
28 changed files with 1839 additions and 303 deletions
@@ -56,12 +56,21 @@ async function main() {
const floatingAi = page.getByTestId("wolai-floating-ai");
const floatingHelp = page.getByTestId("wolai-floating-help");
const content = page.locator(".mnote-content").first();
const homeContent = page.locator(".mnote-home").first();
const staticHomeLinks = page.locator(".mnote-home-links");
const documentShell = page.locator(".document-shell").first();
const emptyState = page.locator('[data-testid="mnote-workspace-empty-state"]').first();
assert.equal(await staticHomeLinks.count(), 0, "根页仍使用 .mnote-home-links 静态设计列表作为主内容");
const hasDocumentShell = (await documentShell.count()) > 0;
const hasEmptyState = (await emptyState.count()) > 0;
assert(hasDocumentShell || hasEmptyState, "根页必须渲染真实 active page shell 或明确空 workspace state");
const sidebarBox = await boundingBox(sidebar, "左侧栏");
const topbarBox = await boundingBox(topbar, "顶栏");
const contentBox = await boundingBox(content, "主内容区");
const homeContentBox = await boundingBox(homeContent, "首页正文");
const primaryContentBox = hasDocumentShell
? await boundingBox(documentShell, "active page shell")
: await boundingBox(emptyState, "空 workspace state");
const floatingAiBox = await boundingBox(floatingAi, "AI 浮动按钮");
const floatingHelpBox = await boundingBox(floatingHelp, "帮助浮动按钮");
@@ -73,8 +82,8 @@ async function main() {
assert(contentBox.y >= topbarBox.y + topbarBox.height - 2, "主内容区不应被顶栏遮挡");
assert(floatingAiBox.x > sidebarBox.width, "AI 浮动按钮不应落入左侧栏");
assert(floatingHelpBox.x > sidebarBox.width, "帮助浮动按钮不应落入左侧栏");
assert(!boxesIntersect(floatingAiBox, homeContentBox), "AI 浮动按钮不应遮挡首页正文");
assert(!boxesIntersect(floatingHelpBox, homeContentBox), "帮助浮动按钮不应遮挡首页正文");
assert(!boxesIntersect(floatingAiBox, primaryContentBox), "AI 浮动按钮不应遮挡主内容");
assert(!boxesIntersect(floatingHelpBox, primaryContentBox), "帮助浮动按钮不应遮挡主内容");
assert(floatingHelpBox.y > floatingAiBox.y, "帮助按钮应位于 AI 按钮下方");
await page.screenshot({ path: SCREENSHOT_PATH, fullPage: true });
@@ -0,0 +1,186 @@
#!/usr/bin/env node
"use strict";
const assert = require("node:assert");
const { chromium } = require("playwright");
const { fetchWithTimeout } = require("./task114-rust-web-gateway-entry-smoke.js");
const BASE_URL = (process.env.MNOTE_UI_BASE_URL || "http://127.0.0.1:3000").replace(/\/+$/, "");
const UI_TIMEOUT_MS = Number(process.env.MNOTE_SMOKE_UI_TIMEOUT_MS || 30_000);
async function readJsonResponse(response, label) {
const text = await response.text();
let payload = null;
try {
payload = text ? JSON.parse(text) : null;
} catch {
throw new Error(`${label} 返回了非 JSON 内容: ${text.slice(0, 1200)}`);
}
assert(response.ok, `${label} 请求失败: ${response.status}; body: ${text.slice(0, 1200)}`);
return payload;
}
async function postTreeCommand(body, label) {
const response = await fetchWithTimeout(`${BASE_URL}/api/tree/commands`, {
method: "POST",
headers: { "content-type": "application/json" },
body: JSON.stringify(body),
});
const payload = await readJsonResponse(response, label);
const result = payload && typeof payload.result === "object" ? payload.result : null;
assert(result, `${label} 缺少 result`);
return result;
}
async function createTempPage(title, extra = {}) {
const result = await postTreeCommand(
{
action: "create",
title,
...extra,
},
`创建临时页面 ${title}`,
);
assert(result.documentId, `创建临时页面 ${title} 缺少 documentId`);
assert(result.workspaceId, `创建临时页面 ${title} 缺少 workspaceId`);
return {
documentId: result.documentId,
workspaceId: result.workspaceId,
title,
};
}
async function purgeTempPage(target) {
if (!target?.documentId || !target?.workspaceId) return;
await postTreeCommand(
{
action: "purge",
workspaceId: target.workspaceId,
documentId: target.documentId,
},
`清理临时页面 ${target.documentId}`,
);
}
async function waitForSidebarRow(page, documentId) {
const selector = `[data-testid="wolai-sidebar-row"][data-node-id="${documentId}"]`;
const row = page.locator(selector).first();
await row.waitFor({ state: "visible", timeout: UI_TIMEOUT_MS });
return row;
}
async function readTreeSnapshot(workspaceId) {
const response = await fetchWithTimeout(
`${BASE_URL}/api/tree/events?workspaceId=${encodeURIComponent(workspaceId)}&maxPolls=0`,
{ headers: { accept: "text/event-stream" } },
);
const text = await response.text();
assert.equal(response.status, 200, `/api/tree/events 请求失败: ${response.status}; body: ${text.slice(0, 1200)}`);
assert.equal(response.headers.get("x-mnote-web-owner"), "mnote-web");
assert.match(text, /event:\s*snapshot|event:snapshot/, "tree events 未返回 snapshot 事件");
return text;
}
async function main() {
const suffix = Date.now().toString(36);
const rootTitle = `task120-root-${suffix}`;
const childTitle = `task120-child-${suffix}`;
let rootPage = null;
let childPage = null;
const browser = await chromium.launch({ headless: true });
const context = await browser.newContext({ viewport: { width: 1440, height: 960 } });
const page = await context.newPage();
try {
rootPage = await createTempPage(rootTitle);
childPage = await createTempPage(childTitle, {
workspaceId: rootPage.workspaceId,
parentId: rootPage.documentId,
});
const targetUrl = `${BASE_URL}/documents/${encodeURIComponent(rootPage.documentId)}?workspaceId=${encodeURIComponent(rootPage.workspaceId)}`;
const response = await page.goto(targetUrl, { waitUntil: "domcontentloaded", timeout: UI_TIMEOUT_MS });
assert(response, "文档页没有返回响应");
assert.equal(response.status(), 200, `文档页状态码异常: ${response.status()}`);
assert.equal(response.headers()["x-mnote-web-owner"], "mnote-web", "文档页必须由 mnote-web 拥有");
const rootRow = await waitForSidebarRow(page, rootPage.documentId);
const childRow = await waitForSidebarRow(page, childPage.documentId);
await expectRowTitle(rootRow, rootTitle, "root row 标题");
await expectRowTitle(childRow, childTitle, "child row 标题");
assert.equal(await childRow.getAttribute("data-parent-id"), rootPage.documentId, "子页面 row 缺少真实 parent id");
assert.equal(await rootRow.getAttribute("data-active"), "true", "当前文档 root row 没有 active 标记");
await childRow.click({ timeout: UI_TIMEOUT_MS });
await page.waitForURL((url) => url.pathname === `/documents/${childPage.documentId}`, {
timeout: UI_TIMEOUT_MS,
waitUntil: "domcontentloaded",
});
const activeChildRow = await waitForSidebarRow(page, childPage.documentId);
assert.equal(await activeChildRow.getAttribute("data-active"), "true", "点击 child row 后 active 标记未切换");
const renamedTitle = `${childTitle}-renamed`;
await postTreeCommand(
{
action: "rename",
workspaceId: childPage.workspaceId,
documentId: childPage.documentId,
title: renamedTitle,
},
"重命名临时子页面",
);
await page.reload({ waitUntil: "domcontentloaded", timeout: UI_TIMEOUT_MS });
const renamedRow = await waitForSidebarRow(page, childPage.documentId);
await expectRowTitle(renamedRow, renamedTitle, "重命名后 child row 标题");
const snapshotText = await readTreeSnapshot(rootPage.workspaceId);
assert(snapshotText.includes(rootPage.documentId), "tree events snapshot 未包含 root 页面");
assert(snapshotText.includes(childPage.documentId), "tree events snapshot 未包含 child 页面");
const purgedChild = childPage;
childPage = null;
await purgeTempPage(purgedChild);
await page.goto(targetUrl, { waitUntil: "domcontentloaded", timeout: UI_TIMEOUT_MS });
await page.waitForFunction(
(documentId) => !document.querySelector(`[data-testid="wolai-sidebar-row"][data-node-id="${documentId}"]`),
purgedChild.documentId,
{ timeout: UI_TIMEOUT_MS },
);
console.log(
JSON.stringify(
{
ok: true,
baseUrl: BASE_URL,
workspaceId: rootPage.workspaceId,
rootDocumentId: rootPage.documentId,
childDocumentId: purgedChild.documentId,
},
null,
2,
),
);
} finally {
if (childPage) {
await purgeTempPage(childPage).catch(() => undefined);
}
if (rootPage) {
await purgeTempPage(rootPage).catch(() => undefined);
}
await page.close().catch(() => undefined);
await context.close().catch(() => undefined);
await browser.close().catch(() => undefined);
}
}
async function expectRowTitle(row, expected, label) {
const text = (await row.innerText({ timeout: UI_TIMEOUT_MS })).trim();
assert(text.includes(expected), `${label} 不匹配: expected=${expected}; actual=${text}`);
}
if (require.main === module) {
main().catch((error) => {
console.error(error instanceof Error ? error.stack || error.message : String(error));
process.exit(1);
});
}
@@ -0,0 +1,186 @@
#!/usr/bin/env node
"use strict";
const assert = require("node:assert");
const { chromium } = require("playwright");
const { fetchWithTimeout } = require("./task114-rust-web-gateway-entry-smoke.js");
const BASE_URL = (process.env.MNOTE_UI_BASE_URL || "http://127.0.0.1:3000").replace(/\/+$/, "");
const UI_TIMEOUT_MS = Number(process.env.MNOTE_SMOKE_UI_TIMEOUT_MS || 30_000);
async function readJsonResponse(response, label) {
const text = await response.text();
let payload = null;
try {
payload = text ? JSON.parse(text) : null;
} catch {
throw new Error(`${label} 返回了非 JSON 内容: ${text.slice(0, 1200)}`);
}
assert(response.ok, `${label} 请求失败: ${response.status}; body: ${text.slice(0, 1200)}`);
return payload;
}
async function postTreeCommand(body, label) {
const response = await fetchWithTimeout(`${BASE_URL}/api/tree/commands`, {
method: "POST",
headers: { "content-type": "application/json" },
body: JSON.stringify(body),
});
const payload = await readJsonResponse(response, label);
const result = payload && typeof payload.result === "object" ? payload.result : null;
assert(result, `${label} 缺少 result`);
return result;
}
async function createTempDocument() {
const title = `task121-editor-${Date.now().toString(36)}`;
const result = await postTreeCommand({ action: "create", title }, "创建临时编辑文档");
assert(result.documentId, "创建临时编辑文档缺少 documentId");
assert(result.workspaceId, "创建临时编辑文档缺少 workspaceId");
return {
documentId: result.documentId,
workspaceId: result.workspaceId,
title,
};
}
async function purgeTempDocument(target) {
if (!target?.documentId || !target?.workspaceId) return;
await postTreeCommand(
{
action: "purge",
workspaceId: target.workspaceId,
documentId: target.documentId,
},
`清理临时编辑文档 ${target.documentId}`,
);
}
async function fetchPageAggregate(target) {
const response = await fetchWithTimeout(
`${BASE_URL}/api/page-aggregate/${encodeURIComponent(target.documentId)}?workspaceId=${encodeURIComponent(target.workspaceId)}`,
);
const payload = await readJsonResponse(response, "读取 Page Aggregate");
assert.equal(response.headers.get("x-mnote-web-owner"), "mnote-web", "Page Aggregate 必须由 mnote-web 拥有");
return payload;
}
async function waitForRuntimeIsland(page) {
const root = page.locator('[data-testid="mnote-leptos-tiptap-island-editor-root"]').first();
await root.waitFor({ state: "visible", timeout: UI_TIMEOUT_MS });
const editor = page
.locator('[data-testid="mnote-leptos-tiptap-island-editor-root"] .editor-surface .ProseMirror[contenteditable="true"]')
.first();
await editor.waitFor({ state: "visible", timeout: UI_TIMEOUT_MS });
await page.waitForFunction(
() => {
const host = document.querySelector('[data-testid="mnote-leptos-tiptap-island-editor-root"]');
const observability = document.querySelector('[data-editor-host-observability]');
const editorNode = host?.querySelector('.editor-surface .ProseMirror[contenteditable="true"]');
return (
host?.getAttribute("data-editor-host-kind") === "leptos_tiptap_island" &&
host?.getAttribute("data-runtime-editor-status") !== "error" &&
observability?.getAttribute("data-editor-host-active") === "leptos_tiptap_island" &&
editorNode instanceof HTMLElement &&
editorNode.isContentEditable
);
},
null,
{ timeout: UI_TIMEOUT_MS },
);
return editor;
}
async function readEditorText(page) {
return page.evaluate(() => {
const editor = document.querySelector(
'[data-testid="mnote-leptos-tiptap-island-editor-root"] .editor-surface .ProseMirror',
);
return editor?.textContent ?? "";
});
}
async function waitForSaved(page, expectedText) {
await page.waitForFunction(
(text) => {
const host = document.querySelector('[data-testid="mnote-leptos-tiptap-island-editor-root"]');
const editor = host?.querySelector('.editor-surface .ProseMirror');
return host?.getAttribute("data-runtime-editor-status") === "saved" && (editor?.textContent ?? "").includes(text);
},
expectedText,
{ timeout: UI_TIMEOUT_MS },
);
}
async function main() {
const browser = await chromium.launch({ headless: true });
const context = await browser.newContext({ viewport: { width: 1440, height: 960 } });
const page = await context.newPage();
let target = null;
try {
target = await createTempDocument();
const url = `${BASE_URL}/documents/${encodeURIComponent(target.documentId)}?workspaceId=${encodeURIComponent(target.workspaceId)}`;
const response = await page.goto(url, { waitUntil: "domcontentloaded", timeout: UI_TIMEOUT_MS });
assert(response, "文档页没有返回响应");
assert.equal(response.status(), 200, `文档页状态码异常: ${response.status()}`);
assert.equal(response.headers()["x-mnote-web-owner"], "mnote-web", "文档页必须由 mnote-web 拥有");
const bootstrap = await page.locator('script#__MNOTE_EDITOR_BOOTSTRAP__[type="application/json"]').textContent({ timeout: UI_TIMEOUT_MS });
assert(bootstrap && bootstrap.includes(target.documentId), "editor bootstrap 未包含当前 documentId");
const aggregateScript = await page.locator('script#__MNOTE_PAGE_AGGREGATE__[type="application/json"]').textContent({ timeout: UI_TIMEOUT_MS });
assert(aggregateScript && aggregateScript.includes(target.documentId), "Page Aggregate script 未包含当前 documentId");
const editor = await waitForRuntimeIsland(page);
const text = `task121-persist-${Date.now().toString(36)}`;
await editor.click({ timeout: UI_TIMEOUT_MS });
await page.keyboard.type(text, { delay: 25 });
await waitForSaved(page, text);
assert((await readEditorText(page)).includes(text), "输入文本未进入 ProseMirror");
await page.reload({ waitUntil: "domcontentloaded", timeout: UI_TIMEOUT_MS });
await waitForRuntimeIsland(page);
await page.waitForFunction(
(expected) => {
const editorNode = document.querySelector(
'[data-testid="mnote-leptos-tiptap-island-editor-root"] .editor-surface .ProseMirror',
);
return (editorNode?.textContent ?? "").includes(expected);
},
text,
{ timeout: UI_TIMEOUT_MS },
);
const aggregate = await fetchPageAggregate(target);
const aggregateText = JSON.stringify(aggregate.result ?? aggregate);
assert(aggregateText.includes(text), "保存后 Page Aggregate 未读回唯一文本");
console.log(
JSON.stringify(
{
ok: true,
baseUrl: BASE_URL,
documentId: target.documentId,
workspaceId: target.workspaceId,
text,
},
null,
2,
),
);
} finally {
if (target) {
await purgeTempDocument(target).catch(() => undefined);
}
await page.close().catch(() => undefined);
await context.close().catch(() => undefined);
await browser.close().catch(() => undefined);
}
}
if (require.main === module) {
main().catch((error) => {
console.error(error instanceof Error ? error.stack || error.message : String(error));
process.exit(1);
});
}
@@ -0,0 +1,104 @@
#!/usr/bin/env node
"use strict";
const assert = require("node:assert");
const { chromium } = require("playwright");
const { fetchWithTimeout } = require("./task114-rust-web-gateway-entry-smoke.js");
const BASE_URL = (process.env.MNOTE_UI_BASE_URL || "http://127.0.0.1:3000").replace(/\/+$/, "");
const UI_TIMEOUT_MS = Number(process.env.MNOTE_SMOKE_UI_TIMEOUT_MS || 30_000);
async function readJsonResponse(response, label) {
const text = await response.text();
let payload = null;
try {
payload = text ? JSON.parse(text) : null;
} catch {
throw new Error(`${label} 返回了非 JSON 内容: ${text.slice(0, 1200)}`);
}
assert(response.ok, `${label} 请求失败: ${response.status}; body: ${text.slice(0, 1200)}`);
return payload;
}
async function postTreeCommand(body, label) {
const response = await fetchWithTimeout(`${BASE_URL}/api/tree/commands`, {
method: "POST",
headers: { "content-type": "application/json" },
body: JSON.stringify(body),
});
const payload = await readJsonResponse(response, label);
const result = payload && typeof payload.result === "object" ? payload.result : null;
assert(result, `${label} 缺少 result`);
return result;
}
async function main() {
const browser = await chromium.launch({ headless: true });
const context = await browser.newContext({ viewport: { width: 1440, height: 960 } });
const page = await context.newPage();
let created = null;
try {
const response = await page.goto(`${BASE_URL}/`, { waitUntil: "domcontentloaded", timeout: UI_TIMEOUT_MS });
assert(response, "根页没有返回响应");
assert.equal(response.status(), 200, `根页状态码异常: ${response.status()}`);
assert.equal(response.headers()["x-mnote-web-owner"], "mnote-web", "根页必须由 mnote-web 拥有");
const createButton = page.getByTestId("wolai-sidebar-create-page").first();
await createButton.waitFor({ state: "visible", timeout: UI_TIMEOUT_MS });
await createButton.click({ timeout: UI_TIMEOUT_MS });
await page.waitForURL((url) => url.pathname.startsWith("/documents/"), {
timeout: UI_TIMEOUT_MS,
waitUntil: "domcontentloaded",
});
const createdUrl = new URL(page.url());
const documentId = decodeURIComponent(createdUrl.pathname.replace(/^\/documents\//, ""));
const workspaceId = createdUrl.searchParams.get("workspaceId") || "";
assert(documentId, "新建后 URL 缺少 documentId");
assert(workspaceId, "新建后 URL 缺少 workspaceId");
created = { documentId, workspaceId };
await page.locator('[data-testid="mnote-leptos-tiptap-island-editor-root"]').waitFor({
state: "visible",
timeout: UI_TIMEOUT_MS,
});
await page
.locator('[data-testid="mnote-leptos-tiptap-island-editor-root"] .editor-surface .ProseMirror[contenteditable="true"]')
.first()
.waitFor({ state: "visible", timeout: UI_TIMEOUT_MS });
assert(created?.documentId, "UI 新建未捕获到 documentId");
assert(page.url().includes(created.documentId), "新建后 URL 未进入新文档");
console.log(
JSON.stringify(
{
ok: true,
baseUrl: BASE_URL,
documentId: created.documentId,
workspaceId: created.workspaceId,
},
null,
2,
),
);
} finally {
if (created?.documentId && created?.workspaceId) {
await postTreeCommand(
{ action: "purge", workspaceId: created.workspaceId, documentId: created.documentId },
`清理 UI 新建页面 ${created.documentId}`,
).catch(() => undefined);
}
await page.close().catch(() => undefined);
await context.close().catch(() => undefined);
await browser.close().catch(() => undefined);
}
}
if (require.main === module) {
main().catch((error) => {
console.error(error instanceof Error ? error.stack || error.message : String(error));
process.exit(1);
});
}