import assert from "node:assert/strict"; import test from "node:test"; import type { WorkbenchSessionRecord } from "../src/types/index.ts"; import { initialWorkbenchSessionIdFromLocation } from "../src/stores/workbench-projection.ts"; import { createWorkbenchServerState, reduceWorkbenchServerState, selectActiveMessages, selectActiveSession, selectTraceAuthorityById } from "../src/stores/workbench-server-state.ts"; test("Workbench route parsing accepts only session routes", () => { assert.equal(initialWorkbenchSessionIdFromLocation({ pathname: "/workbench/sessions/ses_route" }), "ses_route"); assert.equal(initialWorkbenchSessionIdFromLocation({ pathname: "/workbench/sessions/cnv_route" }), null); assert.equal(initialWorkbenchSessionIdFromLocation({ pathname: "/workspace/sessions/ses_route" }), null); assert.equal(initialWorkbenchSessionIdFromLocation({ pathname: "/workbench" }), null); }); test("Workbench server-state is keyed only by session and trace", () => { const session: WorkbenchSessionRecord = { sessionId: "ses_route", threadId: "thr_route", messages: [{ id: "msg_route", messageId: "msg_route", role: "user", title: "用户", text: "route prompt", status: "sent", createdAt: "2026-06-18T00:00:00.000Z", sessionId: "ses_route" }] }; let state = createWorkbenchServerState(); state = reduceWorkbenchServerState(state, { type: "session.detail", session }); state = reduceWorkbenchServerState(state, { type: "trace.snapshot", traceId: "trc_route", trace: { traceId: "trc_route", status: "completed", events: [{ seq: 1, type: "done" }] } }); assert.equal(selectActiveSession(state, "ses_route")?.sessionId, "ses_route"); assert.deepEqual(selectActiveMessages(state, "ses_route").map((message) => message.id), ["msg_route"]); assert.equal(selectTraceAuthorityById(state).trc_route?.traceId, "trc_route"); });