#!/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); });