feat: align local-first workspace direction

Document the VSCode-like local-first product shape, demote Convex to a control-plane role, and retire stale architecture drafts.

Add local workspace migration/export references plus smoke coverage for no-Convex managed workspace startup, local markdown title/body/options persistence, asset upload behavior, and Convex fixture export.

Verification: git diff --cached --check; node scripts/check-local-first-convex-guard.js --staged; node scripts/task444-convex-workspace-export-local-fixture-smoke.js; node scripts/task166-local-first-managed-workspace-no-convex-smoke.js; node scripts/task167-local-markdown-title-body-options-no-convex-smoke.js
This commit is contained in:
lix-2026
2026-05-19 08:11:58 +08:00
parent 68d321e297
commit cdff672aa5
67 changed files with 5242 additions and 932 deletions
@@ -10,6 +10,9 @@ const BASE_URL = (process.env.MNOTE_WEB_SMOKE_BASE_URL || "http://127.0.0.1:3000
const UI_TIMEOUT_MS = Number(process.env.MNOTE_SMOKE_UI_TIMEOUT_MS || 30_000);
const OUTPUT_DIR = path.join(process.cwd(), "tmp", "task436-local-markdown-open-document-external-change-smoke");
const RESULT_PATH = path.join(OUTPUT_DIR, "result.json");
const CHROMIUM_EXECUTABLE_PATH = process.env.PLAYWRIGHT_CHROMIUM_EXECUTABLE_PATH
|| ["/usr/bin/google-chrome-stable", "/usr/bin/google-chrome", "/snap/bin/chromium"]
.find((candidate) => fs.existsSync(candidate));
function fileUrl(localPath) {
return `file://${localPath}`;
@@ -37,6 +40,21 @@ function markdown(title, lines) {
].join("\n");
}
function writeWorkspaceManifest(root, ownerId) {
const metadataDir = path.join(root, ".mnote");
fs.mkdirSync(metadataDir, { recursive: true });
fs.writeFileSync(
path.join(metadataDir, "workspace.json"),
`${JSON.stringify({
workspaceId: `local-ws:${ownerId}:task436`,
ownerId,
createdAt: new Date().toISOString(),
capabilities: ["local_files", "markdown_edit"],
}, null, 2)}\n`,
"utf8",
);
}
async function quickLogin(page) {
await page.goto(`${BASE_URL}/auth`, { waitUntil: "domcontentloaded", timeout: UI_TIMEOUT_MS });
const quickLoginButton = page.getByRole("button", { name: "测试账号快速登录" });
@@ -99,6 +117,37 @@ async function typeDirtyText(page, text) {
await waitForEditorText(page, text.trim());
}
async function callMarkdownEdit(root, relativePath, search, replace) {
const response = await fetch(`${BASE_URL}/api/hermes/tools/mnote/call`, {
method: "POST",
headers: {
"content-type": "application/json",
"x-mnote-actor-id": "user_real",
"x-mnote-actor-type": "user",
},
body: JSON.stringify({
toolName: "mnote.doc.markdown_edit",
workspaceId: "local-ws:user_real:task436",
documentId: localMdDocumentId(relativePath),
sourceKind: "local_folder",
rootUri: fileUrl(root),
sessionId: `sess-task436-${Date.now()}`,
runId: `run-task436-${Date.now()}`,
toolCallId: `call-task436-${Date.now()}`,
traceId: `trace-task436-${Date.now()}`,
idempotencyKey: `idem-task436-${Date.now()}`,
dryRun: false,
args: {
operations: [{ search, replace }],
},
}),
});
const payload = await response.json().catch(() => null);
assert.equal(response.status, 200, `AI markdown_edit 应成功写入: ${JSON.stringify(payload)}`);
assert.equal(payload?.result?.source, "local_folder", `AI markdown_edit 应走 local_folder: ${JSON.stringify(payload)}`);
return payload;
}
async function runStep(label, navigationEvents, action) {
const before = navigationEvents.length;
await action();
@@ -117,15 +166,21 @@ async function run() {
const files = {
clean: "clean-sync.md",
dirty: "dirty-conflict.md",
aiDirty: "dirty-ai-conflict.md",
rename: "rename-open.md",
delete: "delete-open.md",
};
writeWorkspaceManifest(root, "user_real");
fs.writeFileSync(path.join(root, files.clean), markdown("Clean Sync", ["initial clean"]), "utf8");
fs.writeFileSync(path.join(root, files.dirty), markdown("Dirty Conflict", ["initial dirty"]), "utf8");
fs.writeFileSync(path.join(root, files.aiDirty), markdown("Dirty AI Conflict", ["initial ai dirty"]), "utf8");
fs.writeFileSync(path.join(root, files.rename), markdown("Rename Open", ["initial rename"]), "utf8");
fs.writeFileSync(path.join(root, files.delete), markdown("Delete Open", ["initial delete"]), "utf8");
const browser = await chromium.launch({ headless: true });
const browser = await chromium.launch({
headless: true,
...(CHROMIUM_EXECUTABLE_PATH ? { executablePath: CHROMIUM_EXECUTABLE_PATH } : {}),
});
const context = await browser.newContext({
viewport: { width: 1280, height: 860 },
extraHTTPHeaders: {
@@ -171,6 +226,23 @@ async function run() {
assert(runtime.text.includes(localToken), "dirty 冲突时不应静默覆盖用户正在编辑的内容");
}));
await openDocument(page, root, files.aiDirty);
await waitForEditorText(page, "initial ai dirty");
await page.waitForTimeout(300);
navigationEvents.length = 0;
steps.push(await runStep("dirty 文档 AI 后台写入后进入冲突提示", navigationEvents, async () => {
const localToken = `local-ai-dirty-${Date.now()}`;
const aiToken = `ai-background-${Date.now()}`;
await typeDirtyText(page, ` ${localToken}`);
await callMarkdownEdit(root, files.aiDirty, "initial ai dirty", `initial ai dirty ${aiToken}`);
await waitForEditorStatus(page, "external-change-conflict");
const runtime = await readEditorRuntime(page);
assert(runtime.error.includes("本地 Markdown 文件已在外部更新"), `AI 写入冲突提示不正确: ${JSON.stringify(runtime)}`);
assert(runtime.text.includes(localToken), "AI 写入冲突时不应静默覆盖用户正在编辑的内容");
const saved = fs.readFileSync(path.join(root, files.aiDirty), "utf8");
assert(saved.includes(aiToken), "AI 后台写入应已落盘,供后续合并处理");
}));
await openDocument(page, root, files.rename);
await waitForEditorText(page, "initial rename");
await page.waitForTimeout(300);