chore: align local-first control plane and editor fixes
- wire SQLite control-plane access/session paths into Rust web local-folder routes - preserve local Markdown attachment semantics across upload, reload, and secondary-pane resource tabs - refresh design governance docs, Reasonix task templates, and bug records - retire root .mcp.json local MCP config
This commit is contained in:
@@ -1,41 +1,105 @@
|
||||
#!/usr/bin/env node
|
||||
"use strict";
|
||||
|
||||
const fs = require("node:fs/promises");
|
||||
const assert = require("node:assert/strict");
|
||||
const fs = require("node:fs");
|
||||
const fsp = require("node:fs/promises");
|
||||
const os = require("node:os");
|
||||
const path = require("node:path");
|
||||
const { chromium } = require("playwright");
|
||||
const {
|
||||
BASE_URL,
|
||||
UI_TIMEOUT_MS,
|
||||
assert,
|
||||
cleanupDocuments,
|
||||
createTempDocument,
|
||||
ensureAuthenticated,
|
||||
openDocument,
|
||||
openFilesystemView,
|
||||
renameDocument,
|
||||
requestJson,
|
||||
} = require("./tree-shell-smoke-helpers");
|
||||
|
||||
const BASE_URL = (process.env.MNOTE_WEB_SMOKE_BASE_URL || "http://127.0.0.1:3000").replace(/\/+$/, "");
|
||||
const UI_TIMEOUT_MS = Number(process.env.MNOTE_SMOKE_UI_TIMEOUT_MS || 30_000);
|
||||
const CHROMIUM_EXECUTABLE_PATH = process.env.PLAYWRIGHT_CHROMIUM_EXECUTABLE_PATH
|
||||
|| ["/usr/bin/google-chrome-stable", "/usr/bin/google-chrome", "/snap/bin/chromium", "/usr/bin/chromium"]
|
||||
.find((candidate) => fs.existsSync(candidate));
|
||||
|
||||
const TASK = "task443-filetree-mindmap-click-active-row-smoke";
|
||||
const OUT_DIR = path.join(process.cwd(), "tmp", TASK);
|
||||
const RESULT_PATH = path.join(OUT_DIR, "result.json");
|
||||
const ACTOR_ID = "user_real";
|
||||
|
||||
async function writeResult(result) {
|
||||
await fs.mkdir(OUT_DIR, { recursive: true });
|
||||
await fs.writeFile(RESULT_PATH, `${JSON.stringify({ ...result, resultPath: RESULT_PATH }, null, 2)}\n`, "utf8");
|
||||
function fileUrl(localPath) {
|
||||
return `file://${localPath}`;
|
||||
}
|
||||
|
||||
async function createMindmap(request, workspaceId, documentId, mindmapId, title) {
|
||||
return await requestJson(request, `/api/mindmap/${encodeURIComponent(documentId)}/${encodeURIComponent(mindmapId)}`, {
|
||||
method: "POST",
|
||||
data: {
|
||||
commandName: "mindmaps.put",
|
||||
workspaceId,
|
||||
createOnly: true,
|
||||
data: { root: { data: { text: title }, children: [] } },
|
||||
},
|
||||
});
|
||||
function localMdDocumentId(relativePath) {
|
||||
return `local-md:${relativePath.replaceAll("/", "~2F")}`;
|
||||
}
|
||||
|
||||
function documentUrl(root, relativePath) {
|
||||
const url = new URL(`${BASE_URL}/documents/${encodeURIComponent(localMdDocumentId(relativePath))}`);
|
||||
url.searchParams.set("sourceKind", "local_folder");
|
||||
url.searchParams.set("rootUri", fileUrl(root));
|
||||
url.searchParams.set("treeView", "filetree");
|
||||
return url.toString();
|
||||
}
|
||||
|
||||
function writeWorkspaceManifest(root) {
|
||||
fs.mkdirSync(path.join(root, ".mnote"), { recursive: true });
|
||||
fs.writeFileSync(
|
||||
path.join(root, ".mnote", "workspace.json"),
|
||||
`${JSON.stringify({
|
||||
workspaceId: `local-ws:${ACTOR_ID}:task443`,
|
||||
ownerId: ACTOR_ID,
|
||||
createdAt: new Date().toISOString(),
|
||||
capabilities: ["local_files", "tree_commands", "markdown_edit", "asset_upload"],
|
||||
}, null, 2)}\n`,
|
||||
"utf8",
|
||||
);
|
||||
}
|
||||
|
||||
function writeMindmapFixture(root, stamp) {
|
||||
const pageDir = path.join(root, "Task443");
|
||||
fs.mkdirSync(pageDir, { recursive: true });
|
||||
fs.writeFileSync(
|
||||
path.join(pageDir, "Task443.md"),
|
||||
[
|
||||
"---",
|
||||
`title: TEST-443-mindmap-active-${stamp}`,
|
||||
"---",
|
||||
"",
|
||||
"# TEST 443",
|
||||
"",
|
||||
`[TEST-443-mind-${stamp}](map-${stamp}.mindmap.json)`,
|
||||
"",
|
||||
].join("\n"),
|
||||
"utf8",
|
||||
);
|
||||
fs.writeFileSync(
|
||||
path.join(pageDir, `map-${stamp}.mindmap.json`),
|
||||
`${JSON.stringify({ data: { uid: "root", text: `TEST-443-mind-${stamp}` }, children: [] }, null, 2)}\n`,
|
||||
"utf8",
|
||||
);
|
||||
return {
|
||||
relativePath: "Task443/Task443.md",
|
||||
documentId: localMdDocumentId("Task443/Task443.md"),
|
||||
mindmapFileName: `map-${stamp}.mindmap.json`,
|
||||
};
|
||||
}
|
||||
|
||||
async function writeResult(result) {
|
||||
await fsp.mkdir(OUT_DIR, { recursive: true });
|
||||
await fsp.writeFile(RESULT_PATH, `${JSON.stringify({ ...result, resultPath: RESULT_PATH }, null, 2)}\n`, "utf8");
|
||||
}
|
||||
|
||||
async function waitForMindmapRow(page, mindmapFileName) {
|
||||
await page.waitForFunction((fileName) => {
|
||||
return Array.from(document.querySelectorAll('#sidebar-file-tree-root .tree-row[data-shell-mode="filetree"]'))
|
||||
.some((row) => (row.getAttribute("data-asset-id") || "").includes(fileName));
|
||||
}, mindmapFileName, { timeout: UI_TIMEOUT_MS });
|
||||
}
|
||||
|
||||
async function clickMindmapRow(page, mindmapFileName) {
|
||||
await page.evaluate((fileName) => {
|
||||
const row = Array.from(document.querySelectorAll('#sidebar-file-tree-root .tree-row[data-shell-mode="filetree"]'))
|
||||
.find((candidate) => (candidate.getAttribute("data-asset-id") || "").includes(fileName));
|
||||
const link = row?.querySelector(".tree-link");
|
||||
if (!(link instanceof HTMLElement)) {
|
||||
throw new Error(`找不到 mindmap 文件行: ${fileName}`);
|
||||
}
|
||||
link.click();
|
||||
}, mindmapFileName);
|
||||
}
|
||||
|
||||
async function readSelectedFileTreeRows(page) {
|
||||
@@ -44,6 +108,7 @@ async function readSelectedFileTreeRows(page) {
|
||||
rowId: row.getAttribute("data-row-id") || "",
|
||||
rowKind: row.getAttribute("data-row-kind") || "",
|
||||
docId: row.getAttribute("data-document-id") || row.getAttribute("data-doc-id") || "",
|
||||
ownerDocumentId: row.getAttribute("data-owner-document-id") || "",
|
||||
assetId: row.getAttribute("data-asset-id") || "",
|
||||
objectIdentity: row.getAttribute("data-object-identity") || "",
|
||||
title: (row.textContent || "").trim().slice(0, 160),
|
||||
@@ -52,9 +117,23 @@ async function readSelectedFileTreeRows(page) {
|
||||
}
|
||||
|
||||
(async () => {
|
||||
await fs.mkdir(OUT_DIR, { recursive: true });
|
||||
const browser = await chromium.launch({ headless: true });
|
||||
const context = await browser.newContext({ viewport: { width: 1440, height: 900 } });
|
||||
await fsp.mkdir(OUT_DIR, { recursive: true });
|
||||
const root = fs.mkdtempSync(path.join(os.tmpdir(), "mnote-task443-local-mindmap-"));
|
||||
const stamp = Date.now().toString().slice(-8);
|
||||
writeWorkspaceManifest(root);
|
||||
const fixture = writeMindmapFixture(root, stamp);
|
||||
|
||||
const browser = await chromium.launch({
|
||||
headless: true,
|
||||
...(CHROMIUM_EXECUTABLE_PATH ? { executablePath: CHROMIUM_EXECUTABLE_PATH } : {}),
|
||||
});
|
||||
const context = await browser.newContext({
|
||||
viewport: { width: 1440, height: 900 },
|
||||
extraHTTPHeaders: {
|
||||
"x-mnote-actor-id": ACTOR_ID,
|
||||
"x-mnote-actor-type": "user",
|
||||
},
|
||||
});
|
||||
const page = await context.newPage();
|
||||
const navEvents = [];
|
||||
const network = [];
|
||||
@@ -68,10 +147,9 @@ async function readSelectedFileTreeRows(page) {
|
||||
}
|
||||
});
|
||||
|
||||
let doc = null;
|
||||
const result = {
|
||||
baseUrl: BASE_URL,
|
||||
fixture: {},
|
||||
fixture: { root, ...fixture },
|
||||
beforeSelectedRows: [],
|
||||
afterSelectedRows: [],
|
||||
navEvents,
|
||||
@@ -80,35 +158,29 @@ async function readSelectedFileTreeRows(page) {
|
||||
};
|
||||
|
||||
try {
|
||||
await ensureAuthenticated(page, context.request);
|
||||
doc = await createTempDocument(context.request, null);
|
||||
const stamp = Date.now().toString().slice(-8);
|
||||
const title = `TEST-443-mindmap-active-${stamp}`;
|
||||
await renameDocument(context.request, doc.workspaceId, doc.documentId, title);
|
||||
const mindmapId = `mindmap_443_active_${stamp}`;
|
||||
await createMindmap(context.request, doc.workspaceId, doc.documentId, mindmapId, `TEST-443-mind-${stamp}`);
|
||||
result.fixture = { ...doc, title, mindmapId };
|
||||
|
||||
await openDocument(page, doc.workspaceId, doc.documentId);
|
||||
await openFilesystemView(page);
|
||||
await page.waitForSelector(`#sidebar-file-tree-root .tree-row[data-asset-id="${mindmapId}"]`, { timeout: UI_TIMEOUT_MS });
|
||||
result.beforeSelectedRows = await readSelectedFileTreeRows(page);
|
||||
|
||||
await page.click(`#sidebar-file-tree-root .tree-row[data-asset-id="${mindmapId}"] .tree-link`, { timeout: UI_TIMEOUT_MS });
|
||||
await page.waitForFunction(
|
||||
({ documentId, mindmapId }) => {
|
||||
const url = new URL(window.location.href);
|
||||
if (!url.pathname.includes(`/documents/${encodeURIComponent(documentId)}`)) return false;
|
||||
const rt = url.searchParams.get("resourceTab") || "";
|
||||
if (!rt) return false;
|
||||
return decodeURIComponent(rt).includes(`resource:mindmap:${documentId}:${mindmapId}`);
|
||||
},
|
||||
{ documentId: doc.documentId, mindmapId },
|
||||
{ timeout: UI_TIMEOUT_MS },
|
||||
);
|
||||
await page.waitForSelector(`#sidebar-file-tree-root .tree-row[data-asset-id="${mindmapId}"][data-selected="true"]`, {
|
||||
await page.goto(documentUrl(root, fixture.relativePath), { waitUntil: "domcontentloaded", timeout: UI_TIMEOUT_MS });
|
||||
await page.locator('[data-testid="mnote-leptos-tiptap-island-editor-root"]').first().waitFor({
|
||||
state: "visible",
|
||||
timeout: UI_TIMEOUT_MS,
|
||||
});
|
||||
await waitForMindmapRow(page, fixture.mindmapFileName);
|
||||
result.beforeSelectedRows = await readSelectedFileTreeRows(page);
|
||||
|
||||
await clickMindmapRow(page, fixture.mindmapFileName);
|
||||
await page.waitForFunction(
|
||||
({ documentId, fileName }) => {
|
||||
const url = new URL(window.location.href);
|
||||
if (!url.pathname.includes(`/documents/${encodeURIComponent(documentId)}`)) return false;
|
||||
const rt = decodeURIComponent(url.searchParams.get("resourceTab") || "");
|
||||
return rt.includes("resource:mindmap:") && rt.includes(documentId) && rt.includes(fileName);
|
||||
},
|
||||
{ documentId: fixture.documentId, fileName: fixture.mindmapFileName },
|
||||
{ timeout: UI_TIMEOUT_MS },
|
||||
);
|
||||
await page.waitForFunction((fileName) => {
|
||||
return Array.from(document.querySelectorAll('#sidebar-file-tree-root .tree-row[data-shell-mode="filetree"][data-selected="true"]'))
|
||||
.some((row) => (row.getAttribute("data-asset-id") || "").includes(fileName));
|
||||
}, fixture.mindmapFileName, { timeout: UI_TIMEOUT_MS });
|
||||
result.afterUrl = page.url();
|
||||
result.afterSelectedRows = await readSelectedFileTreeRows(page);
|
||||
const screenshotPath = path.join(OUT_DIR, "after-mindmap-click.png");
|
||||
@@ -116,11 +188,11 @@ async function readSelectedFileTreeRows(page) {
|
||||
result.screenshots.push(screenshotPath);
|
||||
|
||||
assert(
|
||||
result.afterSelectedRows.some((row) => row.rowId === `asset:${mindmapId}` && row.assetId === mindmapId),
|
||||
result.afterSelectedRows.some((row) => row.assetId.includes(fixture.mindmapFileName)),
|
||||
`点击 mindmap 文件行后应保持 asset row 选中: ${JSON.stringify(result.afterSelectedRows)}`,
|
||||
);
|
||||
assert(
|
||||
!result.afterSelectedRows.some((row) => row.rowId === `doc:${doc.documentId}`),
|
||||
!result.afterSelectedRows.some((row) => row.rowId === `doc:${fixture.documentId}`),
|
||||
`点击 mindmap 文件行后不应闪回父页面行选中: ${JSON.stringify(result.afterSelectedRows)}`,
|
||||
);
|
||||
|
||||
@@ -135,8 +207,8 @@ async function readSelectedFileTreeRows(page) {
|
||||
});
|
||||
throw error;
|
||||
} finally {
|
||||
if (doc) await cleanupDocuments(context.request, [doc.documentId]).catch(() => null);
|
||||
await browser.close().catch(() => null);
|
||||
fs.rmSync(root, { recursive: true, force: true });
|
||||
}
|
||||
})().catch((error) => {
|
||||
console.error(error instanceof Error ? error.stack || error.message : error);
|
||||
|
||||
Reference in New Issue
Block a user