Implement Rust web sidebar title and tree interactions

This commit is contained in:
lix-2026
2026-04-30 05:46:36 +08:00
parent 559c5ce652
commit 3cc090ba5e
35 changed files with 3029 additions and 424 deletions
+2 -2
View File
@@ -71,8 +71,8 @@ async function checkSearchShell() {
assert(response.headers.get("x-mnote-web-owner") === "mnote-web", "Search shell 缺少 mnote-web owner header");
assert(response.headers.get("x-mnote-web-shell") === "search", "Search shell 缺少 search shell header");
assert(text.includes("mnote.search_shell.v1"), "Search shell 缺少 contract schema");
assert(text.includes("react_search_palette"), "Search shell 缺少 search palette island");
return { owner: "mnote-web", shell: "search", island: "react_search_palette" };
assert(text.includes("search_interaction_island"), "Search shell 缺少 search interaction island");
return { owner: "mnote-web", shell: "search", island: "search_interaction_island" };
}
async function checkAiBridge() {
+14
View File
@@ -96,6 +96,11 @@ async function readText(baseUrl, path, init) {
const text = await response.text();
assert.equal(response.status, 200, `${path} 请求失败: ${response.status} ${text.slice(0, 200)}`);
assert.equal(response.headers.get("x-mnote-web-owner"), "mnote-web", `${path} 缺少 mnote-web owner`);
assert.equal(
response.headers.get("x-mnote-legacy-upstream"),
null,
`${path} 默认主路径不应出现 Next fallback header`,
);
return { response, text };
}
@@ -116,6 +121,10 @@ async function validateSkipNextRuntimePlan() {
}
async function validateCoreShellsWithoutNext(baseUrl) {
const root = await readText(baseUrl, "/?workspaceId=ws_demo");
assert.match(root.text, /data-mnote-shell="workspace"/);
assert.doesNotMatch(root.text, /next-app-router/i);
const auth = await readText(baseUrl, "/auth");
assert.match(auth.text, /data-mnote-shell="auth"/);
assert.doesNotMatch(auth.text, /next-app-router/i);
@@ -134,6 +143,11 @@ async function validateCoreShellsWithoutNext(baseUrl) {
const search = await readText(baseUrl, "/search?workspaceId=ws_demo&q=Rust");
assert.equal(search.response.headers.get("x-mnote-web-shell"), "search");
assert.match(search.text, /mnote\.search_shell\.v1/);
const mindmap = await readText(baseUrl, "/mindmap/doc_1/mind_1");
assert.equal(mindmap.response.headers.get("x-mnote-web-shell"), "mindmap");
assert.match(mindmap.text, /mnote\.mindmap_shell\.v1/);
assert.doesNotMatch(mindmap.text, /next-app-router/i);
}
async function validateDocs() {
@@ -0,0 +1,37 @@
#!/usr/bin/env node
"use strict";
const assert = require("node:assert");
const BASE_URL = (process.env.MNOTE_UI_BASE_URL || "http://127.0.0.1:3000").replace(/\/$/, "");
async function fetchText(path) {
const response = await fetch(`${BASE_URL}${path}`);
const text = await response.text();
assert.equal(response.status, 200, `${path} 请求失败: ${response.status} ${text.slice(0, 200)}`);
return { response, text };
}
async function main() {
const page = await fetchText("/documents/doc_1?workspaceId=ws_demo");
assert.match(page.text, /__MNOTE_TREE_LIVE_BOOTSTRAP__/);
assert.match(page.text, /mnote\.tree_live_bootstrap\.v1/);
assert.match(page.text, /\/api\/tree\/events/);
assert.match(page.text, /tree:snapshot/);
assert.match(page.text, /tree:delta/);
assert.match(page.text, /tree:resync/);
const events = await fetchText("/api/tree/events?workspaceId=ws_demo&maxPolls=0");
assert.match(events.response.headers.get("content-type") || "", /text\/event-stream/);
assert.equal(events.response.headers.get("x-mnote-tree-stream-owner"), "rust-web");
assert.match(events.text, /event:\s*snapshot/);
assert.match(events.text, /id:\s*/);
assert.match(events.text, /"revision"/);
console.log(JSON.stringify({ ok: true, owner: "rust-web", stream: "/api/tree/events" }, null, 2));
}
main().catch((error) => {
console.error(error instanceof Error ? error.stack || error.message : String(error));
process.exit(1);
});
@@ -0,0 +1,46 @@
#!/usr/bin/env node
"use strict";
const assert = require("node:assert");
const BASE_URL = (process.env.MNOTE_UI_BASE_URL || "http://127.0.0.1:3000").replace(/\/$/, "");
async function main() {
const response = await fetch(`${BASE_URL}/search?workspaceId=ws_demo&q=Rust`);
const html = await response.text();
assert.equal(response.status, 200, `/search 请求失败: ${response.status} ${html.slice(0, 200)}`);
assert.equal(response.headers.get("x-mnote-web-shell"), "search");
assert.match(html, /mnote\.search_shell\.v1/);
assert.match(html, /search\.documents\.query/);
assert.match(html, /data-search-results-owner="rust-kernel"/);
assert.match(html, /search-result/);
assert.doesNotMatch(html, /react_search_palette/);
const api = await fetch(`${BASE_URL}/api/search/documents`, {
method: "POST",
headers: { "content-type": "application/json" },
body: JSON.stringify({
workspaceId: "ws_demo",
query: "Rust",
filters: {
titleOnly: false,
exact: false,
includeOcr: false,
onlyCurrentPage: false,
timeRange: "any",
timeField: "updated",
},
}),
});
const payload = await api.json();
assert.equal(api.status, 200, `/api/search/documents 请求失败: ${api.status}`);
assert.equal(payload.projectionOwner, "rust-kernel");
assert.equal(payload.meta.queryName, "search.documents.query");
console.log(JSON.stringify({ ok: true, projectionOwner: payload.projectionOwner }, null, 2));
}
main().catch((error) => {
console.error(error instanceof Error ? error.stack || error.message : String(error));
process.exit(1);
});
@@ -0,0 +1,37 @@
#!/usr/bin/env node
"use strict";
const assert = require("node:assert");
const BASE_URL = (process.env.MNOTE_UI_BASE_URL || "http://127.0.0.1:3000").replace(/\/$/, "");
async function main() {
const response = await fetch(`${BASE_URL}/api/hermes/bridge`, {
method: "POST",
headers: { "content-type": "application/json" },
body: JSON.stringify({
stream: true,
scope: "document",
messages: [{ role: "user", content: "生成摘要" }],
context: { documentId: "doc_1", workspaceId: "ws_demo" },
}),
});
const payload = await response.json();
assert.equal(response.status, 200, `/api/hermes/bridge 请求失败: ${response.status}`);
assert.equal(response.headers.get("x-mnote-ai-bridge-owner"), "rust-web-hermes");
assert.equal(payload.canonicalRoute, "/api/hermes/bridge");
assert.match(payload.eventStreamEndpoint || "", /\/api\/hermes\/events\//);
assert.equal(payload.contract.structuredWriteOwner, "rust-web-hermes");
assert.deepEqual(payload.structuredWrite.allowedCommands, [
"page.body.save",
"tree.node.create",
"kernel.edge.attach",
]);
console.log(JSON.stringify({ ok: true, bridgeOwner: "rust-web-hermes" }, null, 2));
}
main().catch((error) => {
console.error(error instanceof Error ? error.stack || error.message : String(error));
process.exit(1);
});
@@ -0,0 +1,25 @@
#!/usr/bin/env node
"use strict";
const assert = require("node:assert");
const BASE_URL = (process.env.MNOTE_UI_BASE_URL || "http://127.0.0.1:3000").replace(/\/$/, "");
async function main() {
const response = await fetch(`${BASE_URL}/mindmap/doc_1/mind_1`);
const html = await response.text();
assert.equal(response.status, 200, `/mindmap 请求失败: ${response.status} ${html.slice(0, 200)}`);
assert.equal(response.headers.get("x-mnote-web-shell"), "mindmap");
assert.match(html, /mnote\.mindmap_shell\.v1/);
assert.match(html, /mindmap\.projection\.get/);
assert.match(html, /mindmap\.command\.apply/);
assert.match(html, /rust-kernel/);
assert.doesNotMatch(html, /next-app-router/);
console.log(JSON.stringify({ ok: true, projectionOwner: "rust-kernel" }, null, 2));
}
main().catch((error) => {
console.error(error instanceof Error ? error.stack || error.message : String(error));
process.exit(1);
});