diff --git a/scripts/live-files.mjs b/scripts/live-files.mjs index 7dbd65d17f..00902d4542 100644 --- a/scripts/live-files.mjs +++ b/scripts/live-files.mjs @@ -45,6 +45,9 @@ export const LIVE_FILES = [ "tests/win-cmd-argv.test.ts", "tests/zcode-mcp-degraded.test.ts", "tests/zcode-real-cli.test.ts", + // appended, NOT alphabetical: slot = index drives each file's zone port + // band (preload-zone-slot), so mid-list inserts renumber every later band + "tests/storage-durability.test.ts", ]; /** Band width per live file: the zone ladder drifts +1 per EADDRINUSE retry; diff --git a/src/server/admin.ts b/src/server/admin.ts index 2029c5ec7b..d22f1ee82e 100644 --- a/src/server/admin.ts +++ b/src/server/admin.ts @@ -30,7 +30,7 @@ import { formatUpstreamError, getUpstreamConnectionStatus, proxyDispatcher, reco import { detectStaleInstall, getLastInstall } from "../update.js"; import { getPlannedUpgrade, getUpdatePolicyState } from "../update-policy.js"; import { PACKAGE_NAME, VERSION, BUILD_COMMIT } from "../version.js"; -import { buildBlockContent, buildMessageContent, buildOverview, buildSessionDetail, buildSessionList, buildSessionPage, handleConfigGet, handleConfigPut, hiddenEmptyCount, renderUI, type BlockContentView } from "../web/index.js"; +import { buildBlockContent, buildMessageContent, buildOverview, buildSessionDetail, buildSessionList, buildSessionPage, buildSessionTree, handleConfigGet, handleConfigPut, hiddenEmptyCount, renderUI, type BlockContentView } from "../web/index.js"; import { buildSessionReportMd, buildSessionReportSvg } from "../web/report.js"; import { queryLogLines } from "../web/logs-query.js"; import { buildDiagnostics } from "../web/diagnostics.js"; @@ -215,6 +215,8 @@ export async function handleAdminRoute(req: http.IncomingMessage, res: http.Serv if (req.method === "GET" && req.url?.startsWith("/__bili/logs")) return sendWebLogs(res, req); if (req.method === "GET" && req.url?.startsWith("/__bili/diagnostics")) return sendDiagnostics(res, req.url); if (req.method === "GET" && req.url?.startsWith("/__bili/sessions/") && req.url.endsWith("/detail")) return sendWebSessionDetail(res, req.url); + // #4173: compact fold-edge feed for the live tree thumbnail (5s client poll). + if (req.method === "GET" && req.url?.startsWith("/__bili/sessions/") && req.url.endsWith("/tree")) return sendWebSessionTree(res, req.url); // #3917: one block's original text for the 压缩结构 tree — lazy per click, so // the detail payload never carries whole originals. if (req.method === "GET" && req.url !== undefined && isBlockContentPath(req.url)) return sendWebBlockContent(res, req.url); @@ -264,7 +266,16 @@ export async function handleAdminRoute(req: http.IncomingMessage, res: http.Serv // framed document's prefers-color-scheme. const rawTheme = u.searchParams.get("theme"); const theme = rawTheme === "light" || rawTheme === "dark" ? rawTheme : undefined; - const headers: Record = { "content-type": "text/html; charset=utf-8" }; + const headers: Record = { + "content-type": "text/html; charset=utf-8", + // The entire client bundle ships INLINE in this one document, so + // without a cache directive the browser's HEURISTIC caching can pin + // a stale build across a proxy upgrade — the user keeps loading the + // old UI long after the server moved on (seen live: a fresh deploy + // of new web features stayed invisible until a hard refresh). + // Revalidating every load is fine: the shell is stateless HTML. + "cache-control": "no-cache", + }; // #3xxx: the dsh settings pane's #3100 pre-flight fetches this route // CROSS-ORIGIN (dsh web serves the page on its own port, the proxy on // another — both loopback names, so isTrustedAdminOrigin above accepts @@ -1242,6 +1253,26 @@ async function sendWebSessionDetail(res: http.ServerResponse, url: string): Prom res.end(JSON.stringify(detail, null, 2)); } +// #4173: minimal edge set for the tree thumbnail — see buildSessionTree. +async function sendWebSessionTree(res: http.ServerResponse, url: string): Promise { + const prefix = "/__bili/sessions/"; + const suffix = "/tree"; + let id = ""; + try { + id = decodeURIComponent(url.slice(prefix.length, -suffix.length)); + } catch { + // malformed percent-encoding → unknown session (404 below) + } + const tree = await buildSessionTree(id); + if (!tree) { + res.writeHead(404, { "content-type": "application/json" }); + res.end(JSON.stringify({ error: `unknown session: ${id}` })); + return; + } + res.writeHead(200, { "content-type": "application/json", "cache-control": "no-store" }); + res.end(JSON.stringify(tree)); +} + // #3917: `/__bili/sessions//block-content?blockId=bN&view=one|full`. const BLOCK_CONTENT_PATH = "/block-content"; diff --git a/src/web/client.ts b/src/web/client.ts index 6dac7f63dc..2e868368f1 100644 --- a/src/web/client.ts +++ b/src/web/client.ts @@ -1837,17 +1837,30 @@ export const WEB_CLIENT = `(function () { }); return { children: children, roots: roots }; } - // #3917: at-a-glance view of the same folds. Layered top-down (roots on top, - // each fold one level below the block that absorbed it), edges drawn as - // beziers — a knowledge-graph-ish shape for reading structure, while the - // list view stays the place to read concrete messages. A wide tree is scaled - // to fit the card rather than hiding nodes behind a horizontal scroll. + // #3917: at-a-glance view of the same folds. Layered (roots first, each fold + // one level beyond the block that absorbed it), edges drawn as beziers — a + // knowledge-graph-ish shape for reading structure, while the list view stays + // the place to read concrete messages. Modest trees are scaled down to fit + // the card; pathologically WIDE ones used to be scaled the same way and + // became sub-pixel smears (a 161-leaf session fits ≈ 0.05 ⇒ 6px boxes), so + // those rotate: depth runs along x, sibling stacks pile along y at full node + // size (#4173). const GRAPH_NODE_W = 118; const GRAPH_NODE_H = 36; const GRAPH_GAP_X = 16; const GRAPH_LEVEL_H = 84; const GRAPH_FIT_W = 1120; - function blockGraphLayout(blocks) { + // #4173 review: the in-page live map draws with tighter nodes so long + // sessions stay one readable drawing; every other call site keeps the + // original full-size metrics byte-for-byte. + const MAP_NODE_W = 92; + const MAP_NODE_H = 30; + const MAP_GAP_X = 8; + const MAP_LEVEL_H = 46; + const FULL_METRICS = { w: GRAPH_NODE_W, h: GRAPH_NODE_H, gx: GRAPH_GAP_X, lh: GRAPH_LEVEL_H }; + const MAP_METRICS = { w: MAP_NODE_W, h: MAP_NODE_H, gx: MAP_GAP_X, lh: MAP_LEVEL_H }; + function blockGraphLayout(blocks, m) { + m = m || FULL_METRICS; const shape = blockTreeShape(blocks); const nodes = []; const links = []; @@ -1864,11 +1877,11 @@ export const WEB_CLIENT = `(function () { let x; if (!childNodes.length) { x = cursor; - cursor += GRAPH_NODE_W + GRAPH_GAP_X; + cursor += m.w + m.gx; } else { x = (childNodes[0].x + childNodes[childNodes.length - 1].x) / 2; } - const node = { b: b, x: x, y: depth * GRAPH_LEVEL_H }; + const node = { b: b, x: x, y: depth * m.lh }; nodes.push(node); if (depth > maxDepth) maxDepth = depth; childNodes.forEach(function (c) { links.push([node, c]); }); @@ -1877,41 +1890,147 @@ export const WEB_CLIENT = `(function () { const roots = shape.roots.length ? shape.roots : blocks; roots.forEach(function (r) { place(r, 0); }); if (!nodes.length) return { nodes: [], links: [], width: 0, height: 0 }; - return { nodes: nodes, links: links, width: cursor - GRAPH_GAP_X, height: maxDepth * GRAPH_LEVEL_H + GRAPH_NODE_H }; - } - function buildGraphSvg(blocks) { - const layout = blockGraphLayout(blocks); - if (!layout.nodes.length) return ""; + return { nodes: nodes, links: links, width: cursor - m.gx, height: maxDepth * m.lh + m.h }; + } + // #4173: vertical mirror of blockGraphLayout — depth is the x-axis and the + // shared cursor packs sibling stacks along y. Chosen when a tree is far + // wider than it is tall: rotating puts the long dimension on the one axis + // the page scrolls, keeping every box at natural size (the in-page map's + // tighter metrics arrive from the caller). + function blockGraphLayoutVertical(blocks, m) { + m = m || FULL_METRICS; + const shape = blockTreeShape(blocks); + const nodes = []; + const links = []; + let cursor = 0; + let maxDepth = 0; + const place = function (b, depth) { + if (depth > 40) return null; + const kids = shape.children[b.blockId] || []; + const childNodes = []; + kids.forEach(function (k) { + const kid = place(k, depth + 1); + if (kid) childNodes.push(kid); + }); + let y; + if (!childNodes.length) { + y = cursor; + cursor += m.h + m.gx; + } else { + y = (childNodes[0].y + childNodes[childNodes.length - 1].y) / 2; + } + const node = { b: b, x: depth * (m.w + m.gx), y: y }; + nodes.push(node); + if (depth > maxDepth) maxDepth = depth; + childNodes.forEach(function (c) { links.push([node, c]); }); + return node; + }; + const roots = shape.roots.length ? shape.roots : blocks; + roots.forEach(function (r) { place(r, 0); }); + if (!nodes.length) return { nodes: [], links: [], width: 0, height: 0 }; + return { nodes: nodes, links: links, width: maxDepth * (m.w + m.gx) + m.w, height: cursor - m.gx }; + } + // #4173: orientation shared by the full graph and the in-pane tree map — + // flat unless the tree overflows the card AND rotation shortens the long + // dimension; small trees stay byte-identical to the original rendering. + function graphLayouts(blocks, m) { + const lh = blockGraphLayout(blocks, m); + const lv = lh.width > GRAPH_FIT_W ? blockGraphLayoutVertical(blocks, m) : null; + const vertical = !!lv && lv.height < lh.width; + return { layout: vertical ? lv : lh, vertical: vertical }; + } + // Bezier for one parent→child edge in either orientation — shared by every + // #4173 drawing (static graph and live in-pane map) so they always agree. + function graphEdgePath(l, pad, vertical, m) { + m = m || FULL_METRICS; + if (vertical) { + const x1 = l[0].x + pad + m.w; + const y1 = l[0].y + pad + m.h / 2; + const x2 = l[1].x + pad; + const y2 = l[1].y + pad + m.h / 2; + const mx = (x1 + x2) / 2; + return "M" + x1 + " " + y1 + " C" + mx + " " + y1 + " " + mx + " " + y2 + " " + x2 + " " + y2; + } + const x1 = l[0].x + pad + m.w / 2; + const y1 = l[0].y + pad + m.h; + const x2 = l[1].x + pad + m.w / 2; + const y2 = l[1].y + pad; + const my = (y1 + y2) / 2; + return "M" + x1 + " " + y1 + " C" + x1 + " " + my + " " + x2 + " " + my + " " + x2 + " " + y2; + } + // #4173: "wrapped" switches this same labeled drawing into in-pane map mode: + // it carries its NATURAL pixel size (width/height attrs) so the pane can + // show it 1:1 inside a scrollable viewport; zoom resizes the wrapping + // .tm-inner box (the svg fills it via CSS), which keeps scroll ranges + // honest while the browser scales the drawing uniformly. + function buildGraphSvg(blocks, wrapped, m) { + m = m || FULL_METRICS; + const g = graphLayouts(blocks, m); + const layout = g.layout; + const vertical = g.vertical; + if (!layout.nodes.length) return { html: "", vertical: false, width: 0, height: 0 }; const pad = 14; - const half = GRAPH_NODE_W / 2; const W = Math.ceil(layout.width + pad * 2); const H = Math.ceil(layout.height + pad * 2); const fit = W > GRAPH_FIT_W ? GRAPH_FIT_W / W : 1; const parts = []; - parts.push(''); + parts.push(''); + if (wrapped) parts.push(''); + // compact rows carry the two text lines closer together + const idY = m.h >= 36 ? 15 : 12; + const metaY = m.h >= 36 ? 28 : 22; layout.links.forEach(function (l) { - const x1 = l[0].x + pad + half; - const y1 = l[0].y + pad + GRAPH_NODE_H; - const x2 = l[1].x + pad + half; - const y2 = l[1].y + pad; - const my = (y1 + y2) / 2; - parts.push(''); + parts.push(''); }); layout.nodes.forEach(function (n) { const b = n.b; const tierNum = Number(b.tier) || 1; const cls = "g-node tier-" + (tierNum > 3 ? "n" : String(tierNum)) + (b.active ? "" : " inactive"); const ratio = b.compressedTokens > 0 && b.summaryTokens > 0 ? (100 * b.summaryTokens / b.compressedTokens).toFixed(1) + "%" : ""; - const meta = fmtW(b.compressedTokens) + " → " + fmtW(b.summaryTokens) + (ratio ? " " + ratio : ""); + const meta = fmtW(b.compressedTokens) + " \u2192 " + fmtW(b.summaryTokens) + (ratio ? " " + ratio : ""); + // #4173 review: the message span (mXXXX-mYYYY) belongs on the node, + // not only in the list row; tokens stay in the hover tooltip. + const rr = refRangeOf(b); parts.push('' - + "" + escapeHtml(b.blockId + " · T" + tierNum + " · " + blockTopic(b)) + "" - + '' - + '' + escapeHtml(b.blockId + " · T" + tierNum) + "" - + '' + escapeHtml(meta) + "" + + "" + escapeHtml(b.blockId + " \u00b7 T" + tierNum + (rr ? " \u00b7 " + rr : "") + " \u00b7 " + meta + " \u00b7 " + blockTopic(b)) + "" + + '' + + '' + escapeHtml(b.blockId + " \u00b7 T" + tierNum) + "" + + '' + escapeHtml(rr || meta) + "" + ""); }); + if (wrapped) parts.push(""); parts.push(""); - return parts.join(""); + return { html: parts.join(""), vertical: vertical, width: W, height: H }; + } + // #4173: the scrollable inner frame of the in-pane tree map — sized at the + // drawing's natural pixels; treeMapApply() resizes it when zooming. + function treeMapInnerHtml(graph) { + if (!graph.html) return ""; + return '
' + graph.html + "
"; + } + function treeMapApply(view) { + const inner = view.querySelector(".tm-inner"); + if (!inner) return; + const k = view.__vm ? view.__vm.k : 1; + const nw = parseFloat(inner.getAttribute("data-nw")) || 0; + const nh = parseFloat(inner.getAttribute("data-nh")) || 0; + inner.style.width = (nw * k) + "px"; + inner.style.height = (nh * k) + "px"; + } + function treeMapFit(view) { + const inner = view.querySelector(".tm-inner"); + if (!inner) return; + const nw = parseFloat(inner.getAttribute("data-nw")) || 0; + const nh = parseFloat(inner.getAttribute("data-nh")) || 0; + if (!nw || !nh) return; + // #4173 review: the map flows with the page, so Fit shrinks the whole + // tree into roughly the current viewport and centers it there. + const w = Math.max(320, document.documentElement.clientWidth - 120); + const h = Math.max(320, window.innerHeight - 180); + view.__vm = { k: Math.min(1, Math.min(w / nw, h / nh) * 0.98) }; + treeMapApply(view); + const r = inner.getBoundingClientRect(); + window.scrollBy(0, (r.top + (nh * view.__vm.k) / 2) - window.innerHeight / 2); } function refRangeOf(b) { if (!b.startRef) return ""; @@ -1920,7 +2039,10 @@ export const WEB_CLIENT = `(function () { function blockNodeHtml(b, shape, idx, depth) { const kids = shape.children[b.blockId] || []; const tierNum = Number(b.tier) || 1; - const openAttr = depth < 2 || (b.active && depth < 3) ? " open" : ""; + // #4173 review: rows start COLLAPSED — a 200-block session must not + // open as a wall of expanded cards. The tree-map click opens the + // target row for you; expands any row on demand. + const openAttr = ""; const badge = b.active ? '' + t("det.block_active") + "" : '' + t("det.block_inactive") + ""; @@ -1932,6 +2054,15 @@ export const WEB_CLIENT = `(function () { if (b.effectiveMessageCount) meta.push(t("det.tree_msgs", { n: b.effectiveMessageCount })); if (refRange) meta.push(refRange); meta.push(timeAgo(b.createdAt)); + // #4173 review: long summaries open as five clamped lines + a show-all + // button. Closed
rows have no layout, so whether the clamp + // actually cut anything is measured once on first expand (below). + const sumLong = String(b.summary || "").trim().length > 64; + let bodyInner = renderBlockMd(b.summary || ""); + if (sumLong) { + bodyInner = '
' + bodyInner + '
' + + '"; + } const bid = escapeHtml(b.blockId); let html = '
" + '' + bid + "" + badge + extBadge @@ -1939,7 +2070,7 @@ export const WEB_CLIENT = `(function () { + '' + escapeHtml(meta.join(" · ")) + "" + '" + "" - + '
' + renderBlockMd(b.summary || "") + "
" + + '
' + bodyInner + "
" + '
' + '" + '" @@ -1980,7 +2111,7 @@ export const WEB_CLIENT = `(function () { } const stats = blockTreeStats(blocks); const tierBits = Object.keys(stats.tiers).sort(function (a, b) { return Number(a) - Number(b); }).map(function (k) { return "T" + k + " ×" + stats.tiers[k]; }); - parts.push('
' + parts.push('
' + "" + escapeHtml(t("det.tree_total", { n: blocks.length })) + "" + "" + escapeHtml(t("det.tree_active", { n: stats.active })) + "" + "" + escapeHtml(t("det.tree_split", { x: fmtW(stats.coverTokens), y: fmtW(stats.summaryTokens), p: stats.coverTokens > 0 ? (100 * stats.summaryTokens / stats.coverTokens).toFixed(1) + "%" : t("common.none") })) + "" @@ -1990,7 +2121,13 @@ export const WEB_CLIENT = `(function () { const shape = blockTreeShape(blocks); const idxOf = {}; blocks.forEach(function (b, i) { if (idxOf[b.blockId] === undefined) idxOf[b.blockId] = i; }); - parts.push('
"); + parts.push('
' + t("det.tree_map_hint") + '
"); + const mapGraph = buildGraphSvg(blocks, true, MAP_METRICS); + // #4173 review: the live map comes FIRST (总揽全局), the full block + // list stacks below it — with the old order the map ended up under a + // screen of detail rows. + parts.push(''); parts.push('
'); parts.push('
'); const rootBlocks = shape.roots.length ? shape.roots : blocks; @@ -1998,20 +2135,20 @@ export const WEB_CLIENT = `(function () { parts.push("
"); parts.push('
' + t("det.tree_hint") + "
"); parts.push("
"); - parts.push('"); parts.push("
"); return parts.join(""); } function buildDetailHtml(d) { const parts = []; + // Hoisted above the page head so the tab count badge can share the same + // array (originally declared further down, inside the tree pane). + const blocks = d.blockDetails || []; parts.push('' + t("common.back") + ""); parts.push('

' + escapeHtml(d.title || d.label || d.id.slice(0, 16)) + '

' + escapeHtml(d.id) + "
" + detailBadges(d) + "
"); parts.push('
' + t("det.report_note") + '
'); // #3917: the detail page splits into panes — overview (identity, usage, // cache economics), the compression tree, and the handoff document. The // blocks card moved out of the overview into its own tier-tree pane. - const blocks = d.blockDetails || []; parts.push('
' + '" + '" @@ -2361,6 +2498,7 @@ if (d.keepalive) kv(parts, t("det.keepalive"), d.keepalive.tierLabel + " · " + bindBlockContentActions(d); bindTreeModeActions(); bindDetTabs(); + bindTreeMap(); bindCacheReportActions(d); bindSessionReportActions(d); bindTrajectoryBrush(d); @@ -2582,6 +2720,9 @@ if (d.keepalive) kv(parts, t("det.keepalive"), d.keepalive.tierLabel + " · " + const view = btn.getAttribute("data-view") === "full" ? "full" : "one"; const box = $("blk-content-" + bid); if (!box) return; + // #4173 review: pressing the same button again collapses the + // raw view (it used to be one-way, so users were stuck). + if (!box.hidden && box.getAttribute("data-view") === view) { box.hidden = true; return; } if (box.getAttribute("data-state") === "ok" && box.getAttribute("data-view") === view) { box.hidden = false; return; } box.hidden = false; box.setAttribute("data-state", "loading"); @@ -2628,6 +2769,29 @@ if (d.keepalive) kv(parts, t("det.keepalive"), d.keepalive.tierLabel + " · " + } }); }); + // #4173 review: measure each clamped summary when its row first opens — + // a closed
has no layout, so the cut-or-not verdict can only + // happen here; rows the clamp never shortened lose their button. + document.querySelectorAll(".block-node").forEach(function (det) { + det.addEventListener("toggle", function () { + if (!det.open) return; + const body = det.querySelector(":scope > .body.md"); + if (!body || body.__sumChk) return; + body.__sumChk = 1; + let sum = null, btn = null; + for (let i = 0; i < body.children.length; i++) { + const c = body.children[i]; + if (c.classList.contains("blk-sum")) sum = c; + if (c.classList.contains("blk-sum-toggle")) btn = c; + } + if (!sum || !btn) return; + if (sum.scrollHeight <= sum.clientHeight + 2) { sum.classList.remove("clamp"); btn.remove(); return; } + btn.addEventListener("click", function () { + const clamped = sum.classList.toggle("clamp"); + btn.textContent = clamped ? t("det.tree_sum_more") : t("det.tree_sum_less"); + }); + }); + }); } // #3917: the compression pane carries two readings of the same data — the // list (read concrete messages) and the graph (read the overall shape). @@ -2639,8 +2803,15 @@ if (d.keepalive) kv(parts, t("det.keepalive"), d.keepalive.tierLabel + " · " + const btns = Array.prototype.slice.call(document.querySelectorAll(".tree-mode")); const setMode = function (mode) { const g = mode === "graph"; - list.hidden = g; + // #4173 review: graph mode STACKS the live map above the full + // block list (总揽全局 + 看细节 in one screen); list mode just + // hides the drawing. The list is never hidden anymore — it used + // to be, which read as "all the per-block details were lost". + list.hidden = false; graph.hidden = !g; + // #4173 review: Fit only makes sense while the tree drawing is visible. + const fit = $("tm-fit"); + if (fit) fit.hidden = !g; btns.forEach(function (b) { b.classList.toggle("active", b.getAttribute("data-mode") === mode); }); }; btns.forEach(function (b) { @@ -2649,19 +2820,70 @@ if (d.keepalive) kv(parts, t("det.keepalive"), d.keepalive.tierLabel + " · " + setMode(b.getAttribute("data-mode") === "graph" ? "graph" : "list"); }); }); - graph.querySelectorAll(".g-node").forEach(function (n) { - n.addEventListener("click", function () { - const bid = n.getAttribute("data-bid"); - if (!bid) return; - setMode("list"); - const row = document.querySelector('.block-node[data-bid="' + bid + '"]'); - if (!row) return; - row.open = true; - row.classList.add("flash"); - row.scrollIntoView({ block: "center", behavior: "smooth" }); - setTimeout(function () { row.classList.remove("flash"); }, 1600); - }); + // #4173 review: default to the live map stacked over the list. + setMode("graph"); + } + // #4173: the in-pane live tree panorama. The drawing renders at NATURAL + // size (a block box is always 118x36 px, labels readable) inside a + // natively scrollable viewport — pathological trees (very wide OR very + // tall) stay legible instead of meeting into smears. All interaction + // binds on the stable #tree-graph container (event delegation) because the + // 5s poller swaps its innerHTML. The map flows WITH the page (a plain + // wheel scrolls the document over it); Ctrl/⌘-wheel or trackpad pinch + // zooms around the cursor by resizing .tm-inner, #tm-fit shrinks the whole + // tree into the current viewport, double-click restores natural size, and + // a plain click on a node jumps to that block's row in the list below. + // Zoom state (view.__vm) survives re-renders. + function bindTreeMap() { + const view = $("tree-graph"); + if (!view) return; + const fb = $("tm-fit"); + if (fb) fb.addEventListener("click", function () { treeMapFit(view); }); + view.addEventListener("dblclick", function () { view.__vm = null; treeMapApply(view); }); + view.addEventListener("wheel", function (e) { + if (!e.ctrlKey) return; // a plain wheel keeps scrolling the page + e.preventDefault(); + const inner = view.querySelector(".tm-inner"); + if (!inner) return; + const old = view.__vm ? view.__vm.k : 1; + const k2 = Math.max(0.02, Math.min(8, old * Math.exp(-e.deltaY * 0.0015))); + if (k2 === old) return; + const r0 = inner.getBoundingClientRect(); + const px = (e.clientX - r0.left) / old; + const py = (e.clientY - r0.top) / old; + view.__vm = { k: k2 }; + treeMapApply(view); + const r1 = inner.getBoundingClientRect(); + // hold the world point under the cursor still while the page reflows + window.scrollBy((r1.left + px * k2) - (r0.left + px * old), (r1.top + py * k2) - (r0.top + py * old)); + }, { passive: false }); + let downAt = null; + view.addEventListener("pointerdown", function (e) { + if (e.button !== 0) return; + downAt = { x: e.clientX, y: e.clientY }; + }); + view.addEventListener("pointerup", function (e) { + if (!downAt) return; + const moved = Math.abs(e.clientX - downAt.x) > 3 || Math.abs(e.clientY - downAt.y) > 3; + downAt = null; + if (moved) return; + // The page can scroll under a pressed finger, so the node under + // the pointer has to be hit-tested by point rather than target. + let el = e.target; + try { el = document.elementFromPoint(e.clientX, e.clientY) || e.target; } catch (err) {} + const n = el && el.closest ? el.closest("[data-bid]") : null; + if (!n) return; + const bid = n.getAttribute("data-bid"); + const row = document.querySelector('.block-node[data-bid="' + bid + '"]'); + if (!row) return; + row.open = true; + row.classList.add("flash"); + // #4173 review: land at the TOP of the block — long rows used to + // scroll to their middle and looked lost. + row.scrollIntoView({ block: "start", behavior: "smooth" }); + setTimeout(function () { row.classList.remove("flash"); }, 1600); }); + view.addEventListener("pointercancel", function () { downAt = null; }); } function bindCacheReportActions(d) { const copyB = $("cacherpt-copy"); @@ -3666,6 +3888,41 @@ if (d.keepalive) kv(parts, t("det.keepalive"), d.keepalive.tierLabel + " · " + }); } + // #4173: keep the in-pane tree panorama live while a session detail is open. + // Decorative lane: failures keep the last good frame and never touch the + // error strip or the #1937 backoff ladder (always resolves true). Re-renders + // only when the block population actually changed; the viewer's zoom + // (view.__vm) is restored on top of each rebuild. + let mapBusy = false; + let lastMapSig = ""; + async function refreshTreeMap() { + if (mapBusy) return true; + const view = $("tree-graph"); + if (!view) return true; + const m = location.hash.match(new RegExp("^#/session/(.+)$")); + if (!m) return true; + mapBusy = true; + try { + const r = await json(API_ROOT + "/sessions/" + encodeURIComponent(m[1]) + "/tree"); + if (r && Array.isArray(r.blocks)) { + const sig = r.blocks.map(function (b) { return b.blockId + String(b.tier) + (b.active ? "a" : "") + ":" + (b.directBlockIds || []).join(","); }).join("|"); + if (sig !== lastMapSig) { + lastMapSig = sig; + // #4173 review: swap only the drawing frame so the pane's other + // children (the legend row) survive live refreshes. + view.querySelectorAll(".tm-inner").forEach(function (el) { el.remove(); }); + view.insertAdjacentHTML("afterbegin", treeMapInnerHtml(buildGraphSvg(r.blocks, true, MAP_METRICS))); + treeMapApply(view); + } + } + } catch (e) { + /* decorative lane — keep the stale frame */ + } finally { + mapBusy = false; + } + return true; + } + hydrate(); initStaticHandlers(); route(); @@ -3684,6 +3941,8 @@ if (d.keepalive) kv(parts, t("det.keepalive"), d.keepalive.tierLabel + " · " + // A paged-down or searched list must not be clobbered by the background refresh. if (current === "sessions" && $("session-detail-view").hidden && sesPage === 1 && !hasActiveFilters()) ok = (await refreshSessions(false, 1)) && ok; else if (current === "logs") ok = (await loadLogs()) && ok; + // #4173: session DETAIL view → keep the in-pane tree panorama live. + else if (current === "sessions") ok = (await refreshTreeMap()) && ok; if (ok) { pollFailures = 0; nextPollAt = 0; hideDataError(); } else { pollFailures += 1; diff --git a/src/web/i18n.ts b/src/web/i18n.ts index 83ba91a6a2..723875a271 100644 --- a/src/web/i18n.ts +++ b/src/web/i18n.ts @@ -389,6 +389,8 @@ export const MESSAGES: Record> = { "det.tree_msgs": "{n} 条消息", "det.tree_direct": "直属 {n} 条", "det.tree_orig_one": "原文(本层)", + "det.tree_sum_more": "查看全部", + "det.tree_sum_less": "收起", "det.tree_orig_full": "原文(全部)", "det.tree_orig_meta": "{n} 条消息 · {b}", "det.tree_orig_truncated": "已截断至 {b}", @@ -398,7 +400,8 @@ export const MESSAGES: Record> = { "det.tree_hint": "按压缩的父子关系嵌套:T1 收原始消息,T2 收 T1 的块,以此类推。点「原文」按需加载内容。", "det.tree_view_list": "列表", "det.tree_view_graph": "树图", - "det.tree_graph_hint": "整体形状:每个方块是一个压缩块,从上到下是「谁压缩了谁」。点方块跳到列表里对应的一行。", + "det.tree_map_hint": "图随页面滚动 · Ctrl/⌘ 滚轮或捏合缩放 · 点按块跳到列表对应行 · 「适配」整树缩进一屏 · 双击还原原始大小 · 每 5 秒自动刷新", + "det.tree_map_fit": "适配", "det.tree_graph_legend": "实线框=活跃,虚线框=已归档", "det.handoff": "会话交接文档", "det.handoff_hint": "与 bili export 相同的内容 —— 复制粘贴到新会话即可继续", @@ -928,6 +931,8 @@ export const MESSAGES: Record> = { "det.tree_msgs": "{n} msgs", "det.tree_direct": "{n} direct", "det.tree_orig_one": "Original (this level)", + "det.tree_sum_more": "Show all", + "det.tree_sum_less": "Collapse", "det.tree_orig_full": "Original (full)", "det.tree_orig_meta": "{n} messages · {b}", "det.tree_orig_truncated": "truncated at {b}", @@ -937,7 +942,8 @@ export const MESSAGES: Record> = { "det.tree_hint": "Nested by fold parent: T1 folds raw messages, T2 folds T1 blocks, and so on. Original loads the covered bytes on demand.", "det.tree_view_list": "List", "det.tree_view_graph": "Tree map", - "det.tree_graph_hint": "Overall shape: each box is one block, top-down is which block folded which. Click a box to jump to that row in the list.", + "det.tree_map_hint": "scrolls with the page · Ctrl/⌘-wheel or pinch to zoom · click a block to jump to its list row · Fit shrinks the whole tree into the viewport · double-click resets · auto-refresh every 5 s", + "det.tree_map_fit": "Fit", "det.tree_graph_legend": "solid border = active, dashed = archived", "det.handoff": "Handoff document", "det.handoff_hint": "Same content as bili export — paste into a new session to continue", diff --git a/src/web/index.ts b/src/web/index.ts index 0878a71528..7a4fb71a56 100644 --- a/src/web/index.ts +++ b/src/web/index.ts @@ -9,8 +9,8 @@ export { readUpstreamSettings, } from "./api.js"; -export { buildOverview, buildSessionList, buildSessionPage, buildSessionDetail, buildBlockContent, buildMessageContent, hiddenEmptyCount } from "./sessions-data.js"; -export type { BlockContentLookup, BlockContentView, MessageContentLookup } from "./sessions-data.js"; +export { buildOverview, buildSessionList, buildSessionPage, buildSessionDetail, buildSessionTree, buildBlockContent, buildMessageContent, hiddenEmptyCount } from "./sessions-data.js"; +export type { BlockContentLookup, BlockContentView, MessageContentLookup, WebSessionTreeNode } from "./sessions-data.js"; export function renderUI(origin: string, opts?: { embed?: boolean; theme?: "light" | "dark" }): string { // #1426 fix: reuse the bundle-safe VERSION from src/version.ts — resolving diff --git a/src/web/sessions-data.ts b/src/web/sessions-data.ts index 14537b46b7..b28b5b7a69 100644 --- a/src/web/sessions-data.ts +++ b/src/web/sessions-data.ts @@ -1022,6 +1022,51 @@ export function buildSessionDetail(id: string): Promise return done; } +// #4173 (live tree thumbnail): the compact edge feed behind GET /sessions//tree. +// Block id, tier, activity and fold edges ONLY — no summaries, tokens or refs: +// a 180-block session ships ~6KB so the web UI can re-poll every 5s while a live +// compression run redraws the page-head minimap. +export interface WebSessionTreeNode { + blockId: string; + tier: number; + active: boolean; + // #4173 review: the covered message span (canonicalized ascending) so the + // live tree-map nodes can label "mXXXX–mYYYY" without shipping summaries. + startRef?: string; + endRef?: string; + parentBlockId?: string; + directBlockIds: string[]; +} + +const TREE_MAX_BLOCKS = 5000; + +export async function buildSessionTree(id: string): Promise<{ blocks: WebSessionTreeNode[] } | null> { + const found = await loadSessionById(id); + if (!found) return null; + // Same first-parent-wins inversion as renderDetail's parentBlockIdOf. + const parentOf = new Map(); + for (const b of found.session.state.blocks) { + for (const childId of b.directBlockIds || []) { + if (!parentOf.has(childId)) parentOf.set(childId, b.blockId); + } + } + const blocks: WebSessionTreeNode[] = found.session.state.blocks.slice(0, TREE_MAX_BLOCKS).map((b) => { + const span = + b.startRef !== undefined && b.endRef !== undefined + ? orderedRefPair(b.startRef, b.endRef) + : null; + return { + blockId: b.blockId, + tier: b.tier, + active: b.active !== false, + ...(span ? { startRef: span[0], endRef: span[1] } : {}), + ...(parentOf.get(b.blockId) !== undefined ? { parentBlockId: parentOf.get(b.blockId)! } : {}), + directBlockIds: (b.directBlockIds || []).slice(), + }; + }); + return { blocks }; +} + function renderDetail(session: Session, live: boolean): WebSessionDetail { // renderHandoff reads lastMessages (a bounded snapshot) — safe for disk // sessions; the v2 fallback path renders header + block summaries. diff --git a/src/web/styles.ts b/src/web/styles.ts index 27f6942135..a487552c94 100644 --- a/src/web/styles.ts +++ b/src/web/styles.ts @@ -261,11 +261,20 @@ td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; font-fam .block-tree { max-height: 70vh; overflow-y: auto; border-top: 1px solid var(--border-soft); } /* #3917: list ⇄ graph switch for the compression pane, plus the graph itself (layered block boxes on a light canvas, tier-tinted borders). */ -.tree-modes { display: flex; gap: 6px; margin: 0 0 10px; } +.tree-modes { display: flex; gap: 6px; margin: 0 0 10px; align-items: center; } +.tree-modes .hint { flex: 1; font-size: 11px; color: var(--text-muted); } .tree-mode { color: var(--text-muted); } .tree-mode.active { color: var(--accent); border-color: var(--accent); background: var(--bg-muted); } -.tree-graph { max-height: 70vh; overflow: auto; border-top: 1px solid var(--border-soft); padding: 12px 8px 8px; background: var(--bg-muted); border-radius: 0 0 10px 10px; } .g-svg { display: block; max-width: 100%; height: auto; } +/* #4173 review: the live map flows WITH the page — no inner scroll box, so a + long session reads as one continuous document (drawing on top, list below). + The drawing keeps full-size fonts unless it is the compact map. */ +.tm-view { position: relative; } +.tm-svg { display: block; width: 100%; height: 100%; } +.tm-svg .g-id { font-size: 10px; } +.tm-svg .g-meta { font-size: 9px; } +/* zoom resizes .tm-inner; the browser scales the svg uniformly to fill it. */ +.tm-inner { position: relative; margin: 0 auto; } .g-edge { stroke: var(--accent); stroke-width: 1.6; opacity: .5; } .g-node { cursor: pointer; } .g-node rect { fill: #fff; stroke: var(--border-soft); stroke-width: 1.4; } @@ -273,10 +282,13 @@ td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; font-fam .g-node.tier-2 rect { stroke: #7a5af8; fill: #f6f3ff; } .g-node.tier-3 rect { stroke: #bf8700; fill: #fffaf0; } .g-node.tier-n rect { stroke: #8a8f99; fill: #f7f8fa; } -.g-node.inactive rect { stroke-dasharray: 4 3; opacity: .75; } +.g-node.inactive rect { stroke: var(--border-soft); fill: var(--bg-muted); stroke-dasharray: 4 3; } +.g-node.inactive text { opacity: .5; } .g-node:hover rect { stroke-width: 2.4; } .g-id { font: 600 11px ui-monospace, SFMono-Regular, Menlo, monospace; fill: var(--text); } .g-meta { font: 10px ui-monospace, SFMono-Regular, Menlo, monospace; fill: var(--text-muted); } +.blk-sum.clamp { display: -webkit-box; -webkit-line-clamp: 5; -webkit-box-orient: vertical; overflow: hidden; } +.blk-sum-toggle { margin-top: 6px; } .block-node.flash { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 8px; } .block-node .block-node { margin-left: 18px; border-left: 2px solid var(--border-soft); } .block-node summary { align-items: center; flex-wrap: wrap; row-gap: 4px; } diff --git a/tests/web-blocks-tree.test.ts b/tests/web-blocks-tree.test.ts index 5257669e45..43cd135e3b 100644 --- a/tests/web-blocks-tree.test.ts +++ b/tests/web-blocks-tree.test.ts @@ -8,7 +8,7 @@ import { createInitialState, defaultCountTokens } from "acp-kernel"; import type { CompressionBlock } from "acp-kernel"; import { LazyBlockContents, _resetSessionsForTest, getSession } from "../src/session.ts"; import { SessionStore, _setStoreForTest } from "../src/persist.ts"; -import { _resetDiskCacheForTest, buildBlockContent, buildMessageContent, buildSessionDetail } from "../src/web/sessions-data.ts"; +import { _resetDiskCacheForTest, buildBlockContent, buildMessageContent, buildSessionDetail, buildSessionTree } from "../src/web/sessions-data.ts"; import { MESSAGES } from "../src/web/i18n.ts"; import { WEB_CLIENT } from "../src/web/client.ts"; @@ -168,6 +168,23 @@ test("#3917: a folded message the host pruned reports a miss instead of a guess" assert.deepEqual(await buildMessageContent("tree-pruned", "m00001"), { ok: false, reason: "unknown-message" }); }); +test("#4173: the live tree endpoint ships ids/tiers/edges/spans — no summaries", async () => { + // #4173 review: nodes label their covered message span; non-monotonic + // stored spans are canonicalized ascending before leaving the server. + const t1 = mkBlock("b1", 1, "## T1 summary\n- point one", ["rm1"], ["rm1"], [], ["m00010", "m00005"]); + const t2 = mkBlock("b2", 2, "T2 summary", ["rm3"], ["rm1", "rm3"], ["b1"], ["m00001", "m00030"]); + seedSession("tree-live", [t1, t2]); + const tree = await buildSessionTree("tree-live"); + assert.ok(tree); + assert.equal(tree.blocks.length, 2); + const byId = new Map(tree.blocks.map((b) => [b.blockId, b])); + assert.deepEqual(byId.get("b1"), { blockId: "b1", tier: 1, active: true, startRef: "m00005", endRef: "m00010", parentBlockId: "b2", directBlockIds: [] }, "the child names its fold parent AND its message span"); + assert.deepEqual(byId.get("b2"), { blockId: "b2", tier: 2, active: true, startRef: "m00001", endRef: "m00030", directBlockIds: ["b1"] }, "the root has no parent field at all"); + // The whole point of the compact feed: no summary bytes on the wire. + assert.ok(!JSON.stringify(tree).includes("point one"), "summaries never leave the server"); + assert.equal(await buildSessionTree("no-such-session"), null, "unknown session resolves to a 404 payload"); +}); + test("#3917: the tree's strings exist in both locales with identical placeholders", () => { const keys = [ "det.tab_overview", @@ -188,7 +205,10 @@ test("#3917: the tree's strings exist in both locales with identical placeholder "det.tree_hint", "det.tree_view_list", "det.tree_view_graph", - "det.tree_graph_hint", + "det.tree_map_hint", + "det.tree_sum_more", + "det.tree_sum_less", + "det.tree_map_fit", "det.tree_graph_legend", ]; const placeholders = (s: string) => (s.match(/\{[a-z]+\}/g) ?? []).sort().join(","); @@ -206,10 +226,114 @@ test("#3917: the web client bundle stays parseable JS after the tree additions", assert.match(WEB_CLIENT, /function buildTreePane\(blocks\)/); assert.match(WEB_CLIENT, /\/block-content\?blockId=/); // the graph reading of the same folds: layered boxes + list⇄graph switch - assert.match(WEB_CLIENT, /function buildGraphSvg\(blocks\)/); - assert.match(WEB_CLIENT, /function blockGraphLayout\(blocks\)/); + assert.match(WEB_CLIENT, /function buildGraphSvg\(blocks/); + assert.match(WEB_CLIENT, /function blockGraphLayout\(blocks,/); + // #4173: pathologically wide trees rotate instead of shrinking to sub-pixel + assert.match(WEB_CLIENT, /function blockGraphLayoutVertical\(blocks,/); + assert.match(WEB_CLIENT, /g-svg-v/); + // #4173: in-pane live tree map — the full labeled drawing in wrapped mode + // (compact nodes at natural pixel size flowing with the page), fed by + // GET /sessions//tree on the 5s poller; wheel/pan/click bind on the + // stable #tree-graph container and zoom resizes .tm-inner via treeMapApply. + assert.match(WEB_CLIENT, /function graphLayouts\(blocks,/); + assert.match(WEB_CLIENT, /function buildGraphSvg\(blocks, wrapped,/); + assert.match(WEB_CLIENT, /class="tm-g"/); + assert.match(WEB_CLIENT, /class="tm-inner" data-nw=/); + assert.match(WEB_CLIENT, /function treeMapInnerHtml\(graph\)/); + assert.match(WEB_CLIENT, /function treeMapApply\(view\)/); + assert.match(WEB_CLIENT, /function treeMapFit\(view\)/); + assert.match(WEB_CLIENT, /function bindTreeMap\(\)/); + assert.match(WEB_CLIENT, /function refreshTreeMap\(\)/); + assert.match(WEB_CLIENT, /addEventListener\("wheel"/); + // #4173 review: plain wheel scrolls the page over the in-flow map; only + // Ctrl/pinch wheels zoom (anchored via window.scrollBy), and the map draws + // with tighter metrics than the legacy fit-shrunk graph. + assert.match(WEB_CLIENT, /if \(!e\.ctrlKey\) return;/); + assert.match(WEB_CLIENT, /const MAP_METRICS = \{ w: MAP_NODE_W/); + assert.match(WEB_CLIENT, /window\.scrollBy\(/); + assert.match(WEB_CLIENT, /pointerdown/); + assert.match(WEB_CLIENT, /tm-fit/); + // #4173 review: Fit is mode-gated (visible only while the tree drawing shows) + // and live refreshes swap just the .tm-inner frame so the legend row survives. + assert.match(WEB_CLIENT, /fit\.hidden = !g/); + assert.match(WEB_CLIENT, /insertAdjacentHTML\("afterbegin", treeMapInnerHtml/); + // #4173 review: click-to-jump hit-tests by point (pointer capture + // retargets the event), and graph mode stacks map+list instead of hiding + // the detail rows. + assert.match(WEB_CLIENT, /document\.elementFromPoint\(e\.clientX, e\.clientY\)/); + assert.match(WEB_CLIENT, /list\.hidden = false/); + // #4173 review: list rows start collapsed; tree nodes carry the message + // span (mXXXX–mYYYY); the raw-text button can be pressed again to close. + assert.match(WEB_CLIENT, /const openAttr = "";/); + assert.match(WEB_CLIENT, /const rr = refRangeOf\(b\)/); + assert.match(WEB_CLIENT, /escapeHtml\(rr \|\| meta\)/); + assert.match(WEB_CLIENT, /if \(!box\.hidden && box\.getAttribute\("data-view"\) === view\) \{ box\.hidden = true; return; \}/); + // #4173 review: jump lands at the top of the target row; long summaries + // open as five clamped lines behind a show-all toggle. + assert.match(WEB_CLIENT, /row\.scrollIntoView\(\{ block: "start", behavior: "smooth" \}\)/); + assert.match(WEB_CLIENT, /blk-sum clamp/); + assert.match(WEB_CLIENT, /blk-sum-toggle/); + assert.match(WEB_CLIENT, /body\.__sumChk/); + assert.ok(WEB_CLIENT.includes('"/sessions/" + encodeURIComponent(m[1]) + "/tree"'), "#4173 tree URL wiring present in the bundle"); assert.match(WEB_CLIENT, /"g-node tier-" \+/); assert.match(WEB_CLIENT, /data-mode="graph"/); assert.match(WEB_CLIENT, /id="tree-graph"/); assert.match(WEB_CLIENT, /\.block-node\[data-bid=/); }); + +// #4173: run the actual layout/graph code from the bundle against fixtures. +test("#4173: wide trees rotate to vertical full-size instead of shrinking to smears", () => { + const start = WEB_CLIENT.indexOf("function blockTreeShape("); + const end = WEB_CLIENT.indexOf("function refRangeOf("); + assert.ok(start > 0 && end > start, "graph section anchors present in the bundle"); + const stubs = "var escapeHtml=function(s){return String(s);};var fmtW=function(n){return String(n);};var blockTopic=function(b){return b.topic||'';};var t=function(k){return k;};var refRangeOf=function(b){return '';};"; + const ctx = vm.createContext({}); + vm.runInContext(stubs + WEB_CLIENT.slice(start, end) + "this.api={blockGraphLayout:blockGraphLayout,blockGraphLayoutVertical:blockGraphLayoutVertical,buildGraphSvg:buildGraphSvg,graphLayouts:graphLayouts};;this.api", ctx, { filename: "web-graph.js" }); + const api = ctx.api; + + // 30 independent T1 roots → flat row 4004px wide: the old code fit-scaled it + // to ≈ 33px boxes; now it must rotate. + const wide = []; + for (let i = 0; i < 30; i++) wide.push({ blockId: "b" + i, tier: 1, active: true, parentBlockId: undefined }); + const res = api.buildGraphSvg(wide); + assert.equal(res.vertical, true, "a 30-root flat tree rotates"); + assert.match(res.html, /class="g-svg g-svg-v"/); + assert.ok((res.html.match(/data-bid=/g) || []).length === 30, "rotation keeps every node"); + const m = res.html.match(/ width="(\d+)" height="(\d+)"/); + assert.ok(m, "svg carries explicit dimensions"); + // vertical extent ≈ 30 slots × 52 − gap (+padding), rendered UNscaled (width axis ~3 levels) + assert.ok(Number(m[1]) < 600, "long dimension moved off the width axis (got " + m[1] + "px)"); + assert.ok(Number(m[2]) >= 1400, "height holds the 30 stacked nodes near natural size (got " + m[2] + "px)"); + + // small deep chain: stays top-down, byte-level unchanged rendering path + const chain = [{ blockId: "c1", tier: 1, active: true, parentBlockId: undefined }, { blockId: "c2", tier: 2, active: true, parentBlockId: "c1" }, { blockId: "c3", tier: 3, active: true, parentBlockId: "c2" }]; + const small = api.buildGraphSvg(chain); + assert.equal(small.vertical, false, "a narrow chain does not rotate"); + assert.doesNotMatch(small.html, /g-svg-v/); + assert.ok(small.html.includes('viewBox="0 0'), "still an svg"); + + // empty tree keeps the old falsy contract via {html:""} + const none = api.buildGraphSvg([]); + assert.equal(none.html, ""); + + // #4173: the in-pane live map reuses the full labeled drawing — every node + // keeps its box AND its text — but switches into wrapped mode: content sits + // in the pan/zoom group and the svg tag carries NO fixed + // size attributes (CSS owns the viewport). The plain path is untouched. + const mapRes = api.buildGraphSvg(wide, true); + const mapWide = mapRes.html; + assert.ok(mapWide.startsWith(''), "map wraps its drawing in the transform group"); + assert.ok(mapWide.includes("]*>/)[0].includes("width="), "plain svg keeps fit size attrs"); + const mapChain = api.buildGraphSvg(chain, true).html; + assert.ok(mapChain.length > 0 && mapChain.includes('viewBox="0 0'), "a narrow chain renders a non-empty map with viewBox geometry"); + assert.equal(api.buildGraphSvg([], true).html, "", "empty tree renders nothing"); +});