Files
mnote/scripts/task107-document-runtime-save-smoke.js
T
lix-2026 41e958769e feat: land page aggregate and phase7 document ai mainline
- 收口 page aggregate 读取、本地状态与命令客户端\n- 接入 phase7 document ai sidecar 与前端编排入口\n- 更新 architecture 与 design 状态迁移
2026-04-23 07:38:34 +08:00

109 lines
3.3 KiB
JavaScript

"use strict";
const { chromium } = require("playwright");
const {
BASE_URL,
UI_TIMEOUT_MS,
assert,
cleanupDocuments,
ensureAuthenticated,
prepareTempTreeFixture,
openDocument,
requireMnoteWebSmokeBaseUrl,
} = require("./tree-shell-smoke-helpers");
async function openRuntimeDebug(page, fixture) {
const runtimeBaseUrl = requireMnoteWebSmokeBaseUrl();
await page.goto(`${BASE_URL}/api/auth/mnote-web-token`, { waitUntil: "commit", timeout: UI_TIMEOUT_MS });
await page.goto(
`${runtimeBaseUrl}/document-debug?documentId=${fixture.parentId}&workspaceId=${fixture.workspaceId}&host=task107-smoke`,
{ waitUntil: "commit", timeout: UI_TIMEOUT_MS },
);
await page.getByText("Document Runtime Debug").waitFor({ state: "visible", 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 fixture = null;
let caughtError = null;
try {
await ensureAuthenticated(page, context.request);
fixture = await prepareTempTreeFixture(context.request);
await openDocument(page, fixture.workspaceId, fixture.parentId);
await openRuntimeDebug(page, fixture);
const textarea = page.locator("textarea[data-block-input-id]").first();
await textarea.waitFor({ state: "visible", timeout: UI_TIMEOUT_MS });
await textarea.fill("persist runtime content", { timeout: UI_TIMEOUT_MS });
await page.locator("#editor-save-status").getByText("saved").waitFor({
state: "visible",
timeout: UI_TIMEOUT_MS,
});
await page.reload({ waitUntil: "commit", timeout: UI_TIMEOUT_MS });
const reloadedTextarea = page.locator("textarea[data-block-input-id]").first();
await reloadedTextarea.waitFor({ state: "visible", timeout: UI_TIMEOUT_MS });
assert(
(await reloadedTextarea.inputValue()) === "persist runtime content",
"刷新后未回放最近一次保存内容",
);
await page.goto(
`${BASE_URL}/documents/${fixture.parentId}?workspaceId=${encodeURIComponent(fixture.workspaceId)}`,
{ waitUntil: "commit", timeout: UI_TIMEOUT_MS },
);
await page.getByRole("button", { name: "进入编辑" }).waitFor({
state: "visible",
timeout: UI_TIMEOUT_MS,
});
assert(
(await page.locator(`iframe[title="mnote-web-document-shell-${fixture.parentId}"]`).count()) === 0,
"默认文档页不应继续挂载 runtime debug iframe",
);
console.log(
JSON.stringify(
{
ok: true,
baseUrl: BASE_URL,
workspaceId: fixture.workspaceId,
documentId: fixture.parentId,
},
null,
2,
),
);
} catch (error) {
caughtError = error;
} finally {
if (fixture) {
try {
await cleanupDocuments(context.request, fixture.createdIds);
} catch (cleanupError) {
if (!caughtError) {
caughtError = cleanupError;
}
}
}
await page.close().catch(() => undefined);
await context.close().catch(() => undefined);
await browser.close().catch(() => undefined);
}
if (caughtError) {
throw caughtError;
}
}
main().catch((error) => {
console.error(error instanceof Error ? error.stack || error.message : String(error));
process.exit(1);
});