A local-first multi-agent app development platform, built on PenguinHarness
fix(web): 轨迹面板的「传输」默认就开着,没有轨迹的会话里也看得见
lmliheng103c3095ac27
diff --git a/changelog/unreleased/2026-11-13-trace-transport-frames.md b/changelog/unreleased/2026-11-13-trace-transport-frames.mdindex fd063890..2960f529 100644--- a/changelog/unreleased/2026-11-13-trace-transport-frames.md+++ b/changelog/unreleased/2026-11-13-trace-transport-frames.md@@ -10,42 +10,51 @@ When a live conversation went quiet there was no way to tell, from the browser,stopped arriving or the server had stopped writing: a frame is gone the moment it is delivered, anda reload replaces the connection with a different one.-The Trace panel now carries a **Transport** toggle, off by default. Switched on, it lists the SSE-frames this browser received — newest first, each with its event name, the id the channel gave it,-its byte length and the opening of its payload — together with the connection's own markers (`open`,+The Trace panel now carries a **Transport** view, recording by default. It lists the SSE frames+this browser received — newest first, each with its event name, the id the channel gave it, its byte+length and the opening of its payload — together with the connection's own markers (`open`,`reopen`, `stalled`, `live`, `probe`, `error`, `closed`) and one marker for any quiet stretch longer-than the server's heartbeat, carrying how long it lasted. The choice is remembered in the browser.+than the server's heartbeat, carrying how long it lasted. It does not have to be switched on first:+a stream that went quiet is noticed after the fact, and frames recorded only from the moment the+reader switches it on are exactly the ones already missed. Whoever does not want it can turn it off,+and the choice is remembered in the browser.## Details- `packages/web/src/api/sse-frames.ts`: the page-level ring (300 entries, oldest out), fed by- `api/sse.ts` with every frame it receives. Recording stays off unless the toggle turned it on- (`penguin.sseFrames`), and turning it off drops what was collected — a frozen list left on screen- would read as a stream that stopped. Identical consecutive markers closer together than ten- seconds collapse into one, so a browser retrying a dead connection cannot flush the ring.+ `api/sse.ts` with every frame it receives. Recording is on unless the toggle turned it off+ (`penguin.sseFrames`, written as `0` when off), and turning it off drops what was collected — a+ frozen list left on screen would read as a stream that stopped. Identical consecutive markers+ closer together than ten seconds collapse into one, so a browser retrying a dead connection cannot+ flush the ring.- `packages/web/src/features/traces/sse-frame-list.tsx`: the view — toggle, count, clear button androws — re-rendering on the recorder's notifications only while its dock tab is showing.- `packages/web/src/features/traces/transport-rows.ts`: which entries this Session's panel shows(its own channel plus the page's user-level one, marked, newest first, capped at 120 rows).-- `packages/web/src/features/traces/trace-panel.tsx`: the view, above the file pills.+- `packages/web/src/features/traces/trace-panel.tsx`: the view, above the file pills, and present in+ **every** state of the listing — while it loads, when it failed, and when the Session has produced+ no Trace file at all (the 「暂无轨迹」 empty state). That last one is exactly the moment the+ question "did the stream deliver anything" gets asked.- `packages/web/src/lib/format.ts`: `formatTime` also takes epoch milliseconds, so a live record'sown clock prints without a round trip through ISO text.## Tests-- `packages/web/test/sse-frames.test.ts`: recording stays off until the toggle and turns off with- the ring; the newest 300 survive; a quiet stretch past the heartbeat leaves one marker carrying- its length while one exactly at the interval leaves none; identical markers collapse and frames- never do; subscribers are notified until they leave; byte lengths are counted on UTF-8 and- previews capped.+- `packages/web/test/sse-frames.test.ts`: recording is on by default and turns off with the ring;+ the newest 300 survive; a quiet stretch past the heartbeat leaves one marker carrying its length+ while one exactly at the interval leaves none; identical markers collapse and frames never do;+ subscribers are notified until they leave; byte lengths are counted on UTF-8 and previews capped.- `packages/web/test/sse.test.ts`: frames reach the recorder from the subscription with their eventname, id and byte length.- `packages/web/test/transport-rows.test.ts`, `packages/web/test/sse-frame-list.test.ts`: row- selection, order and cap; and the rendered markup — off by default, the frames in the wire's own- words once on, another Session's channel left out.+ selection, order and cap; and the rendered markup — recording from the start, the frames in the+ wire's own words, another Session's channel left out.+- `packages/web/test/trace-panel.test.ts`: the panel's shell — the Transport view is drawn while the+ listing is still loading, and with no Session selected either.## Compatibility-No wire change, no new dependency, no Project config change. It is off by default, so a reader who-never opens the toggle sees the panel as it was. The view holds the receiving side only: what the+No wire change, no new dependency, no Project config change. It records by default, but only in the+current page's memory, never written to storage and never sent anywhere; a reader who does not want+it turns it off and sees the panel as it was. The view holds the receiving side only: what theserver wrote is not visible from the browser, and it does not claim otherwise.diff --git a/changelog/unreleased/2026-11-13-trace-transport-frames.zh.md b/changelog/unreleased/2026-11-13-trace-transport-frames.zh.mdindex b80d963e..e12d9a69 100644--- a/changelog/unreleased/2026-11-13-trace-transport-frames.zh.md+++ b/changelog/unreleased/2026-11-13-trace-transport-frames.zh.md@@ -9,32 +9,38 @@实时对话安静下来时,光从浏览器这边分不清是数据不再送达,还是服务端不再写:帧一送到就没了,刷新页面换来的又是另一条连接。-轨迹面板现在多了一个**传输**开关,默认关闭。打开后它列出本浏览器收到的 SSE 帧 —— 新的在上,每行给出事件名、+轨迹面板现在多了一个**传输**视图,默认就在记录。它列出本浏览器收到的 SSE 帧 —— 新的在上,每行给出事件名、通道给的 id、字节数和载荷开头 —— 外加连接自己的标记(`open` / `reopen` / `stalled` / `live` / `probe` /-`error` / `closed`),以及超过心跳间隔的静默标记(标出静默了多久)。选择记在浏览器里。+`error` / `closed`),以及超过心跳间隔的静默标记(标出静默了多久)。它不需要先被打开:流停了是事后才发现的,+而从打开开关那一刻才开始录的帧,恰恰就是已经错过的那批。不想要它的人可以关掉,选择记在浏览器里。## 细节- `packages/web/src/api/sse-frames.ts`:页面级环形缓冲(300 条,最旧的先出),由 `api/sse.ts` 在每收到一帧时写入。- 开关没打开就不记录(键是 `penguin.sseFrames`);关掉时把已收集的清掉 —— 一份冻在屏幕上的列表会被读成流停了。- 相邻且间隔不到十秒的同一个标记会合并成一条,否则一个不断重试死连接的浏览器会把环形缓冲冲掉。+ 默认记录,只有被关掉时才不记(键是 `penguin.sseFrames`,关掉时写 `0`);关掉时把已收集的清掉 —— 一份冻在+ 屏幕上的列表会被读成流停了。相邻且间隔不到十秒的同一个标记会合并成一条,否则一个不断重试死连接的浏览器会把+ 环形缓冲冲掉。- `packages/web/src/features/traces/sse-frame-list.tsx`:这个视图本身 —— 开关、计数、清空按钮和每一行 ——只在自己的停靠页显示时跟着记录器的通知重绘。- `packages/web/src/features/traces/transport-rows.ts`:本 Session 的面板显示哪些条目(它自己的通道加上页面那条用户级流,后者带标记),新的在上,最多 120 行。-- `packages/web/src/features/traces/trace-panel.tsx`:视图挂在文件药丸上方。+- `packages/web/src/features/traces/trace-panel.tsx`:视图画在文件药丸上方,并且在**每一种**列表状态下都在 ——+ 加载中、加载失败、以及这个会话还没有任何 Trace 文件(「暂无轨迹」)时都在。最后那种正是要问「实时流到底+ 有没有送来东西」的时刻。- `packages/web/src/lib/format.ts`:`formatTime` 也接受毫秒时间戳,现场的记录不必绕一圈 ISO 文本才能打印自己的钟。## 测试-- `packages/web/test/sse-frames.test.ts`:开关打开前不记录、关掉时清空;最近 300 条留下;超过心跳间隔的静默留下+- `packages/web/test/sse-frames.test.ts`:默认就记录、关掉时清空且不再记;最近 300 条留下;超过心跳间隔的静默留下一条带时长的标记,而刚好等于间隔的那次不留;相同标记合并、帧从不合并;订阅者一直被通知到退出为止;字节数按UTF-8 计算、预览有长度上限。- `packages/web/test/sse.test.ts`:帧从订阅处进入记录器,带着事件名、id 和字节数。- `packages/web/test/transport-rows.test.ts`、`packages/web/test/sse-frame-list.test.ts`:行的取舍、顺序与上限;- 以及渲染出来的内容 —— 默认关闭,打开后是协议自己的字眼,别的 Session 的通道不出现。+ 以及渲染出来的内容 —— 默认就在记录,行里是协议自己的字眼,别的 Session 的通道不出现。+- `packages/web/test/trace-panel.test.ts`:面板外壳 —— 列表还在加载时传输视图已经画出来,会话没有被选中时也画。## 兼容性-线上协议没变、没有新依赖、Project 配置没变。它默认关闭,没打开这个开关的人看到的还是原来那块面板。这个视图-只记录收到的那一半:服务端写了什么在浏览器这边看不见,它也不声称自己能看到。+线上协议没变、没有新依赖、Project 配置没变。它默认记录,但只留在当前页面的内存里,从不写进存储、也不发往别处;+不想要它的人关掉即可,看到的还是原来那块面板。这个视图只记录收到的那一半:服务端写了什么在浏览器这边看不见,+它也不声称自己能看到。diff --git a/packages/docs/content/sessions-and-traces.en.md b/packages/docs/content/sessions-and-traces.en.mdindex cf4586ec..7f459d3d 100644--- a/packages/docs/content/sessions-and-traces.en.md+++ b/packages/docs/content/sessions-and-traces.en.md@@ -185,9 +185,9 @@ The approval mechanism itself is covered in [Tools & Approval](/tools).### The Transport view (the live frames this page received)-The **Transport** toggle at the top of the Trace panel is off by default. Switched on, it records every frame this browser **actually received** on the live streams and lists them newest first: the SSE event name (`message` / `server_event` / `ping`), the id the channel gave it, its byte length and the opening of its payload — plus connection markers (`open` / `reopen` / `stalled` / `live` / `probe` / `error` / `closed`) and a `silence` marker carrying the length of any quiet stretch longer than the server's heartbeat. `user` on a row marks the `GET /api/events` stream; the rest belong to this Session.+The **Transport** view at the top of the Trace panel records by default, with nothing to switch on first. It records every frame this browser **actually received** on the live streams and lists them newest first: the SSE event name (`message` / `server_event` / `ping`), the id the channel gave it, its byte length and the opening of its payload — plus connection markers (`open` / `reopen` / `stalled` / `live` / `probe` / `error` / `closed`) and a `silence` marker carrying the length of any quiet stretch longer than the server's heartbeat. `user` on a row marks the `GET /api/events` stream; the rest belong to this Session.-It holds the receiving half: a frame in the list proves one arrived, and its absence proves nothing about what the server wrote. That is exactly why it exists — when a conversation looks stuck, it is where "the data never arrived" is told apart from "the server never wrote". The choice is remembered in this browser (`penguin.sseFrames`), and the ring keeps the newest 300 entries.+It holds the receiving half: a frame in the list proves one arrived, and its absence proves nothing about what the server wrote. That is exactly why it exists — when a conversation looks stuck, it is where "the data never arrived" is told apart from "the server never wrote". The view is there in every state of the listing, including a Session with no Trace file yet; whoever does not want it can turn it off, and the choice is remembered in this browser (`penguin.sseFrames`). The ring keeps the newest 300 entries.### Moving Trace files across deploymentsdiff --git a/packages/docs/content/sessions-and-traces.zh.md b/packages/docs/content/sessions-and-traces.zh.mdindex 51583b39..12af69f5 100644--- a/packages/docs/content/sessions-and-traces.zh.md+++ b/packages/docs/content/sessions-and-traces.zh.md@@ -185,9 +185,9 @@ Web App 的 Trace 视图和用量、成本统计都来自这份数据,不存### 传输视图(本页收到的实时帧)-Trace 面板顶部的**传输**开关默认关闭。打开后它记录本浏览器在实时流上**实际收到**的每一帧,倒序列出:事件名(`message` / `server_event` / `ping`)、通道给的 id、字节数和载荷开头,另外还有连接标记(`open` / `reopen` / `stalled` / `live` / `probe` / `error` / `closed`)和超过心跳间隔的 `silence` 标记(带静默时长)。同一行里 `用户级` 标记的是 `GET /api/events` 那条流,其余属于本 Session。+Trace 面板顶部的**传输**视图默认就在记录,不需要先打开。它记录本浏览器在实时流上**实际收到**的每一帧,倒序列出:事件名(`message` / `server_event` / `ping`)、通道给的 id、字节数和载荷开头,另外还有连接标记(`open` / `reopen` / `stalled` / `live` / `probe` / `error` / `closed`)和超过心跳间隔的 `silence` 标记(带静默时长)。同一行里 `用户级` 标记的是 `GET /api/events` 那条流,其余属于本 Session。-它记的是收到的那一半:能证明某一帧到过,不能证明服务端没有写过。这正是它存在的理由——对话看起来停住时,它是分辨「数据没送到」和「服务端没写」的地方。开关状态记在本浏览器(`penguin.sseFrames`),环形缓冲保留最近 300 条。+它记的是收到的那一半:能证明某一帧到过,不能证明服务端没有写过。这正是它存在的理由——对话看起来停住时,它是分辨「数据没送到」和「服务端没写」的地方。它在每一种列表状态下都在,包括这个会话还没有任何 Trace 文件的时候;不想要它的人可以关掉,选择记在本浏览器(`penguin.sseFrames`),环形缓冲保留最近 300 条。### 跨部署迁移 Trace 文件diff --git a/packages/web/src/api/sse-frames.ts b/packages/web/src/api/sse-frames.tsindex 3564708a..888c0efe 100644--- a/packages/web/src/api/sse-frames.ts+++ b/packages/web/src/api/sse-frames.ts@@ -4,10 +4,13 @@* other surface can: did the server write and nothing arrived, or was nothing ever written?* The page holds the received half only — the server's own writes are not visible from here.*- * Off by default, and it stays off unless the reader switches it on (the Trace panel's Transport- * toggle writes `penguin.sseFrames`): the ring keeps a payload's first characters, which is not- * something to record behind the reader's back, and the toggle is also what makes the cost- * bounded and deliberate rather than paid by every reader of every Session.+ * On by default, and the reader can turn it off (the Trace panel's Transport toggle writes+ * `penguin.sseFrames` with the OFF choice). It used to default off, and that turned out to+ * defeat the point: a stream that went quiet is noticed AFTER the fact, and frames recorded+ * only from the moment the reader switches it on are exactly the frames that are already gone.+ * The cost is what keeps it bearable rather than the default: entries live in this page's memory+ * only (never written to storage, never sent anywhere), the ring keeps the recent past (300+ * entries), and a payload is kept as its first characters (SSE_PREVIEW_CHARS).** Bounded: frames arrive at up to a few per second, so the ring keeps the recent past* (SSE_FRAME_CAP) and the oldest fall out. A channel that went quiet for longer than the@@ -60,12 +63,15 @@ const listeners = new Set<() => void>();/** Bytes of a payload, counted on the payload's own encoding rather than on UTF-16 code units. */const encoder = new TextEncoder();-/** Whether this browser is recording frames. Anything unreadable (private browsing, no storage) reads as off. */+/**+ * Whether this browser is recording frames. On unless the reader turned it off; anything+ * unreadable (private browsing, no storage) reads as on, since the entries never leave memory.+ */export function sseFramesEnabled(): boolean {try {- return localStorage.getItem(STORAGE_KEY) === "1";+ return localStorage.getItem(STORAGE_KEY) !== "0";} catch {- return false;+ return true;}}@@ -76,8 +82,8 @@ export function sseFramesEnabled(): boolean {*/export function setSseFramesEnabled(on: boolean): void {try {- if (on) localStorage.setItem(STORAGE_KEY, "1");- else localStorage.removeItem(STORAGE_KEY);+ if (on) localStorage.removeItem(STORAGE_KEY);+ else localStorage.setItem(STORAGE_KEY, "0");} catch {/* best-effort persistence (private browsing, quota) — the current page still records */}diff --git a/packages/web/src/features/traces/sse-frame-list.tsx b/packages/web/src/features/traces/sse-frame-list.tsxindex 2c412024..28b6ea90 100644--- a/packages/web/src/features/traces/sse-frame-list.tsx+++ b/packages/web/src/features/traces/sse-frame-list.tsx@@ -1,7 +1,7 @@/*** The Trace panel's Transport view: the SSE frames this browser actually received, newest first,- * behind a toggle that is OFF by default (see api/sse-frames.ts — it stores payload prefixes, so- * it is the reader's call, and the state is remembered in localStorage).+ * behind a toggle that is ON by default (see api/sse-frames.ts — the frames live in this page's+ * memory, and the off choice is remembered in localStorage).** Its question is the one nothing else on screen can answer: the live stream went quiet — did* data ever arrive, and what was in it? A row is one frame off the wire (its SSE event name, its@@ -14,8 +14,8 @@* prove that a frame arrived, never that one was never sent.** Live while it shows: frames land as the run streams, so the list re-renders on the recorder's- * own notifications. A hidden dock tab (or a turned-off toggle) records nothing to the screen and- * subscribes to nothing.+ * own notifications. A hidden dock tab (or a switched-off toggle) records nothing to the screen+ * and subscribes to nothing.*/import { useEffect, useReducer, useState } from "react";import { formatBytes, humanizeDuration } from "../../lib/format";diff --git a/packages/web/src/features/traces/trace-panel.tsx b/packages/web/src/features/traces/trace-panel.tsxindex 8357be9c..e1be0714 100644--- a/packages/web/src/features/traces/trace-panel.tsx+++ b/packages/web/src/features/traces/trace-panel.tsx@@ -110,15 +110,29 @@ export function TracePanel({// eslint-disable-next-line react-hooks/exhaustive-deps}, [active, listTick, session.sessionId]);+ // The Transport view is rendered ABOVE these branches rather than inside the populated one:+ // a Session with no Trace at all — nothing has run yet, or a run died before its first write —+ // is exactly when "did the stream deliver anything" is the question being asked, and an empty+ // state that swallowed the one view that answers it made the feature unreachable there.+ const transport = <SseFrameList sessionId={session.sessionId} active={active} />;+// The failure owns the whole panel only where there is nothing to keep: no listing yet// (here), or a listing with no file in it (below). With a file on screen it is a strip// above it instead.if (files === null) {- if (error !== null) return <EmptyState title={S.tracePanel.loadFailed} description={error} />;return (- <div className="space-y-3 p-4">- <Skeleton className="h-5 w-2/3" />- <Skeleton className="h-5 w-1/2" />+ <div className="min-h-0 flex-1 overflow-y-auto p-3">+ <div className="space-y-3">+ {transport}+ {error !== null ? (+ <EmptyState title={S.tracePanel.loadFailed} description={error} />+ ) : (+ <>+ <Skeleton className="h-5 w-2/3" />+ <Skeleton className="h-5 w-1/2" />+ </>+ )}+ </div></div>);}@@ -127,8 +141,18 @@ export function TracePanel({// selected file falls back to the newest one rather than emptying the panel.const activeFile = activeTraceFile(files, fileIndex);if (activeFile === null) {- if (error !== null) return <EmptyState title={S.tracePanel.loadFailed} description={error} />;- return <EmptyState title={S.tracePanel.empty} description={S.tracePanel.emptyHint} />;+ return (+ <div className="min-h-0 flex-1 overflow-y-auto p-3">+ <div className="space-y-3">+ {transport}+ {error !== null ? (+ <EmptyState title={S.tracePanel.loadFailed} description={error} />+ ) : (+ <EmptyState title={S.tracePanel.empty} description={S.tracePanel.emptyHint} />+ )}+ </div>+ </div>+ );}const visibleFiles = showAllFiles ? files : files.slice(0, FILE_PILL_CAP);@@ -143,9 +167,9 @@ export function TracePanel({{S.tracePanel.loadFailed} · {error}</NoticeStrip>)}- {/* What this browser received on the live streams (off unless switched on): the one+ {/* What this browser received on the live streams (off unless switched off): the oneplace a stalled stream can be told from a quiet one. */}- <SseFrameList sessionId={session.sessionId} active={active} />+ {transport}<div className="flex flex-wrap items-center gap-1.5"><span className="mr-1 text-xs text-gray-400">{S.traces.filesTitle}</span>{visibleFiles.map((f) => (diff --git a/packages/web/src/lib/strings-en.ts b/packages/web/src/lib/strings-en.tsindex 49021e8d..faacb446 100644--- a/packages/web/src/lib/strings-en.ts+++ b/packages/web/src/lib/strings-en.ts@@ -381,7 +381,7 @@ export const en: Strings = {transportOn: "Recording",transportOff: "Off",transportHint:- "Records the live frames this browser actually received, so a stalled stream can be read as data that never arrived rather than a server that never wrote.",+ "Off: turning it back on records the live frames this browser receives (this page's memory only, the last 300) — so a stalled stream can be read as data that never arrived rather than a server that never wrote.",transportCount: (n: number) => `Last ${n} frames, newest first`,transportEmpty: "No frames received yet",transportClear: "Clear",diff --git a/packages/web/src/lib/strings.ts b/packages/web/src/lib/strings.tsindex 8f1f0486..5902744d 100644--- a/packages/web/src/lib/strings.ts+++ b/packages/web/src/lib/strings.ts@@ -451,7 +451,7 @@ export const zh = {transportOn: "记录中",transportOff: "已关闭",transportHint:- "打开后记录本浏览器实际收到的实时帧:实时流停了时,用它看是数据没送到,还是服务端没写。",+ "已关闭:打开后重新记录本浏览器收到的实时帧(只留在本页内存,最多 300 条)—— 实时流停了时,用它看是数据没送到,还是服务端没写。",transportCount: (n: number) => `最近 ${n} 帧,新的在上`,transportEmpty: "还没有收到帧",transportClear: "清空",diff --git a/packages/web/test/sse-frame-list.test.ts b/packages/web/test/sse-frame-list.test.tsindex 0f37cbcc..b8dac968 100644--- a/packages/web/test/sse-frame-list.test.ts+++ b/packages/web/test/sse-frame-list.test.ts@@ -1,7 +1,7 @@/**- * The Transport view's markup (features/traces/sse-frame-list.tsx): off by default, and what a- * reader gets once it is on — the recorded frames, newest first, in the wire's own words, with- * another Session's channel kept out.+ * The Transport view's markup (features/traces/sse-frame-list.tsx): on by default, so frames are+ * there when a reader goes looking, and what a reader gets — the recorded frames, newest first,+ * in the wire's own words, with another Session's channel kept out.*/import { createElement } from "react";import { renderToStaticMarkup } from "react-dom/server";@@ -35,7 +35,16 @@ afterEach(() => {const render = (sessionId = "s1") =>renderToStaticMarkup(createElement(SseFrameList, { sessionId, active: true }));-it("starts off, saying what turning it on would do", () => {+it("records from the start, listing what arrived", () => {+ noteSseFrame(receivedEntry("session", "s1", "ping", null, "{}"));+ const html = render();+ expect(html).toContain(S.tracePanel.transportOn);+ expect(html).toContain(S.tracePanel.transportCount(1));+ expect(html).not.toContain(S.tracePanel.transportHint);+});++it("while switched off, says what turning it back on would do", () => {+ setSseFramesEnabled(false);noteSseFrame(receivedEntry("session", "s1", "ping", null, "{}"));const html = render();expect(html).toContain(S.tracePanel.transportOff);diff --git a/packages/web/test/sse-frames.test.ts b/packages/web/test/sse-frames.test.tsindex 13a1a707..08563cd6 100644--- a/packages/web/test/sse-frames.test.ts+++ b/packages/web/test/sse-frames.test.ts@@ -49,8 +49,15 @@ beforeEach(() => {const frame = (id: string | null = null) =>receivedEntry("session", "s1", "ping", id, JSON.stringify({ type: "task_state" }));-it("records nothing until the toggle is on, and drops the ring when it goes off", () => {+it("records by default, and drops the ring while it is switched off", () => {+ expect(sseFramesEnabled()).toBe(true);+ noteSseFrame(frame());+ expect(sseFrames()).toHaveLength(1);++ setSseFramesEnabled(false);expect(sseFramesEnabled()).toBe(false);+ expect(sseFrames()).toEqual([]);+ // Switched off means nothing new lands either — the ring on screen is the past, not a resuming list.noteSseFrame(frame());expect(sseFrames()).toEqual([]);@@ -58,10 +65,6 @@ it("records nothing until the toggle is on, and drops the ring when it goes off"expect(sseFramesEnabled()).toBe(true);noteSseFrame(frame());expect(sseFrames()).toHaveLength(1);-- setSseFramesEnabled(false);- expect(sseFramesEnabled()).toBe(false);- expect(sseFrames()).toEqual([]);});it("keeps the newest cap's worth, dropping the oldest", () => {diff --git a/packages/web/test/trace-panel.test.ts b/packages/web/test/trace-panel.test.tsnew file mode 100644index 00000000..a560c74a--- /dev/null+++ b/packages/web/test/trace-panel.test.ts@@ -0,0 +1,49 @@+/**+ * The Trace panel's shell (features/traces/trace-panel.tsx): the Transport view is on screen in+ * EVERY state of the file listing, not only when a Trace file is readable.+ *+ * Regression: it used to be rendered inside the branch that has a file to show, so a Session that+ * had produced no Trace yet — the panel's 「暂无轨迹」 empty state, which is exactly the state a+ * conversation that never got an answer sits in — swallowed it, and the one view that answers+ * "did the stream deliver anything" was unreachable when the question was being asked.+ *+ * Rendered to static markup, so the effects that fetch the listing never run: every scenario+ * below is the `files === null` state the panel mounts in.+ */+import { createElement } from "react";+import { renderToStaticMarkup } from "react-dom/server";+import { beforeEach, expect, it, vi } from "vitest";+import type { SessionInfo } from "@adelie/server/api";+import { TracePanel } from "../src/features/traces/trace-panel";+import { S } from "../src/lib/strings";++function memoryStorage(): Storage {+ const map = new Map<string, string>();+ return {+ getItem: (key: string) => map.get(key) ?? null,+ setItem: (key: string, value: string) => void map.set(key, value),+ removeItem: (key: string) => void map.delete(key),+ } as unknown as Storage;+}++beforeEach(() => {+ vi.stubGlobal("localStorage", memoryStorage());+});++const session = { sessionId: "s1" } as unknown as SessionInfo;++it("draws the Transport view while the listing is still loading", () => {+ const html = renderToStaticMarkup(+ createElement(TracePanel, { session, active: true, reloadSignal: 0 }),+ );+ expect(html).toContain(S.tracePanel.transport);+ // The loading branch still draws its skeleton below it.+ expect(html).toContain("animate-pulse");+});++it("draws it with no Session selected either", () => {+ const html = renderToStaticMarkup(+ createElement(TracePanel, { session, active: false, reloadSignal: 3 }),+ );+ expect(html).toContain(S.tracePanel.transport);+});