| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795 |
- // @vitest-environment jsdom
- import { createElement, type ReactNode } from "react";
- import { renderToStaticMarkup } from "react-dom/server";
- import { describe, expect, it, vi } from "vitest";
- import { act, render } from "@testing-library/react";
- import type { GitRepositorySummary, ZCodeSessionRunningSubagent } from "@zcode/shared";
- import type {
- BackgroundWorkSummary,
- GoalState,
- PlanState,
- ToolCallRow,
- WorkflowRunState,
- } from "@zcode/shared/zcode-protocol-v4";
- import { getStatusPanelTodoFocusWindow } from "@/v4/ConversationStatusPanel.js";
- const statusPanelCapture = vi.hoisted(() => ({
- collapsibles: [] as Array<{
- onOpenChange?: (open: boolean) => void;
- open?: boolean;
- section?: string;
- }>,
- radioGroups: [] as Array<{
- onValueChange?: (value: string) => void;
- value?: string;
- }>,
- hoverCards: [] as Array<{
- closeDelay?: number;
- onOpenChange?: (open: boolean) => void;
- open?: boolean;
- openDelay?: number;
- }>,
- gitBranchSwitchers: [] as Array<Record<string, unknown>>,
- }));
- vi.mock("@/ControlHintTooltip.js", async (importOriginal) => ({
- ...(await importOriginal<typeof import("@/ControlHintTooltip.js")>()),
- ControlHintTooltip: ({ children }: { children: ReactNode }) => children,
- }));
- vi.mock("@/GitActionMenu.js", () => ({
- GitActionMenu: () => createElement("div", { "data-testid": "mock-git-action-menu" }),
- }));
- vi.mock("@/GitBranchSwitcher.js", () => ({
- GitBranchSwitcher: (props: Record<string, unknown>) => {
- statusPanelCapture.gitBranchSwitchers.push(props);
- return createElement("div", { "data-testid": "mock-git-branch-switcher" });
- },
- }));
- vi.mock("@/components/ui/dropdown-menu.js", () => ({
- DropdownMenu: ({ children }: { children: ReactNode }) =>
- createElement("div", { "data-testid": "mock-dropdown" }, children),
- DropdownMenuContent: ({ children }: { children: ReactNode }) =>
- createElement("div", { "data-testid": "mock-dropdown-content" }, children),
- DropdownMenuRadioGroup: ({
- children,
- onValueChange,
- value,
- }: {
- children: ReactNode;
- onValueChange?: (value: string) => void;
- value?: string;
- }) => {
- statusPanelCapture.radioGroups.push({ onValueChange, value });
- return createElement(
- "div",
- { "data-testid": "mock-radio-group", "data-value": value },
- children,
- );
- },
- DropdownMenuRadioItem: ({ children, value }: { children: ReactNode; value: string }) =>
- createElement("div", { "data-testid": "mock-radio-item", "data-value": value }, children),
- DropdownMenuTrigger: ({ children }: { children: ReactNode }) => children,
- }));
- vi.mock("@/components/ui/hover-card.js", () => ({
- HoverCard: ({
- children,
- closeDelay,
- onOpenChange,
- open,
- openDelay,
- }: {
- children: ReactNode;
- closeDelay?: number;
- onOpenChange?: (open: boolean) => void;
- open?: boolean;
- openDelay?: number;
- }) => {
- statusPanelCapture.hoverCards.push({ closeDelay, onOpenChange, open, openDelay });
- return createElement("div", { "data-slot": "hover-card" }, children);
- },
- HoverCardTrigger: ({ children }: { children: ReactNode }) => children,
- HoverCardContent: ({
- align,
- children,
- side,
- sideOffset,
- ...props
- }: {
- align?: string;
- children: ReactNode;
- side?: string;
- sideOffset?: number;
- [key: string]: unknown;
- }) =>
- createElement(
- "div",
- {
- "data-align": align,
- "data-side": side,
- "data-side-offset": sideOffset,
- "data-slot": "hover-card-content",
- ...props,
- },
- children,
- ),
- }));
- vi.mock("@/components/ui/collapsible.js", () => ({
- Collapsible: ({
- children,
- defaultOpen: _defaultOpen,
- onOpenChange,
- open,
- ...props
- }: {
- children: ReactNode;
- defaultOpen?: boolean;
- onOpenChange?: (open: boolean) => void;
- open?: boolean;
- [key: string]: unknown;
- }) => {
- statusPanelCapture.collapsibles.push({
- onOpenChange,
- open,
- section: props["data-status-section"] as string | undefined,
- });
- return createElement("div", { "data-slot": "collapsible", ...props }, children);
- },
- CollapsibleTrigger: ({ children }: { children: ReactNode }) => children,
- CollapsibleContent: ({ children }: { children: ReactNode }) =>
- createElement("div", { "data-slot": "collapsible-content" }, children),
- }));
- vi.mock("@/i18n/IntlProvider.js", () => ({
- useZCodeIntl: () => ({
- intl: {
- formatMessage: (descriptor: { id: string }, values?: Record<string, string>) => {
- const durationUnits: Record<string, string> = {
- "chat.summaryPanel.duration.hours": "小时",
- "chat.summaryPanel.duration.minutes": "分",
- "chat.summaryPanel.duration.seconds": "秒",
- };
- return (
- durationUnits[descriptor.id] ??
- (values ? `${descriptor.id} ${Object.values(values).join("/")}` : descriptor.id)
- );
- },
- },
- locale: "zh-CN",
- }),
- }));
- function gitSummary(overrides: Partial<GitRepositorySummary> = {}): GitRepositorySummary {
- return {
- workspacePath: "/repo",
- repoRoot: "/repo",
- workspaceInRepoPath: "",
- autoRefreshWatchPaths: [],
- branchName: "main",
- trackingBranchName: "origin/main",
- headRefType: "branch",
- ahead: 0,
- behind: 0,
- isDirty: true,
- isGitAvailable: true,
- isRepository: true,
- ...overrides,
- };
- }
- function goalState(overrides: Partial<GoalState> = {}): GoalState {
- return {
- targetId: "goal-1",
- objective: "修好状态面板",
- summaryTitle: null,
- timeUsedSeconds: 0,
- activeRunStartedAtMs: null,
- status: "active",
- iteration: 1,
- verifications: [],
- iterations: [],
- ...overrides,
- };
- }
- function planState(overrides: Partial<PlanState> = {}): PlanState {
- return {
- updatedAt: 1_700_000_000_000,
- items: [
- { id: "1", content: "看 z-code-2", status: "completed" },
- { id: "2", content: "复刻浮层", status: "inProgress" },
- ],
- ...overrides,
- };
- }
- describe("getStatusPanelTodoFocusWindow", () => {
- const items = (count: number, currentIndex: number | null) =>
- planState({
- items: Array.from({ length: count }, (_, index) => ({
- id: String(index + 1),
- content: `Todo ${index + 1}`,
- status:
- index === currentIndex
- ? ("inProgress" as const)
- : index < 2
- ? ("completed" as const)
- : ("pending" as const),
- })),
- }).items;
- it("keeps up to six snapshot items fully visible in original order", () => {
- const snapshot = items(6, 2);
- const window = getStatusPanelTodoFocusWindow(snapshot);
- expect(window.compact).toBe(false);
- expect(window.precedingItems).toEqual([]);
- expect(window.focusItems).toEqual(snapshot);
- expect(window.followingItems).toEqual([]);
- });
- it("focuses the running item and its following context without reordering", () => {
- const window = getStatusPanelTodoFocusWindow(items(8, 3));
- expect(window.compact).toBe(true);
- expect(window.precedingItems.map((item) => item.id)).toEqual(["1", "2", "3"]);
- expect(window.focusItems.map((item) => item.id)).toEqual(["4", "5", "6"]);
- expect(window.followingItems.map((item) => item.id)).toEqual(["7", "8"]);
- });
- it("backfills the focus window when the running item is near the end", () => {
- const window = getStatusPanelTodoFocusWindow(items(8, 7));
- expect(window.focusItems.map((item) => item.id)).toEqual(["6", "7", "8"]);
- expect(window.followingItems).toEqual([]);
- });
- it("uses the first unfinished item or final three completed items as fallback", () => {
- const pendingWindow = getStatusPanelTodoFocusWindow(items(8, null));
- const completedWindow = getStatusPanelTodoFocusWindow(
- items(8, null).map((item) => ({ ...item, status: "completed" as const })),
- );
- expect(pendingWindow.focusItems.map((item) => item.id)).toEqual(["3", "4", "5"]);
- expect(completedWindow.focusItems.map((item) => item.id)).toEqual(["6", "7", "8"]);
- });
- });
- function backgroundWork(overrides: Partial<BackgroundWorkSummary> = {}): BackgroundWorkSummary {
- return {
- workId: "work-1",
- kind: "subagent",
- title: "探索渲染逻辑",
- status: "running",
- startedAt: Date.now() - 8_000,
- anchorRowId: null,
- ...overrides,
- };
- }
- function runningSubagent(
- overrides: Partial<ZCodeSessionRunningSubagent> = {},
- ): ZCodeSessionRunningSubagent {
- return {
- childSessionId: "child-session",
- subagentType: "Explore",
- title: "探索渲染逻辑",
- status: "running",
- startedAt: Date.now() - 8_000,
- ...overrides,
- };
- }
- // 面板自己从 workflowRuns 投影 + backgroundWorks 联接出行(模型层的活儿),所以这里造的是
- // 两侧输入,而不是行——行的形状由 v4ConversationStatusPanelModel.test.ts 穷举。
- /** 声明了三站(盘点 → 计划 → 构建)、正在「计划」的 run。 */
- function phasedRunProjection(overrides: Partial<WorkflowRunState> = {}): WorkflowRunState {
- return workflowRunProjection({
- phaseNames: ["盘点", "计划", "构建"],
- phases: [{ name: "盘点", rounds: 1 }],
- currentPhase: "计划",
- ...overrides,
- });
- }
- function workflowRunProjection(overrides: Partial<WorkflowRunState> = {}): WorkflowRunState {
- return {
- runId: "dwfrun-1",
- toolCallId: "tool-wf-1",
- status: "running",
- usage: { spentTokens: 0, nodesUsed: 0 },
- actors: [],
- nodes: [
- { siteId: "ask#1", ordinal: 1, phase: "settled" },
- { siteId: "ask#2", ordinal: 2, phase: "dispatched" },
- { siteId: "ask#3", ordinal: 3, phase: "queued" },
- ],
- lastEventSequence: 1,
- ...overrides,
- };
- }
- function sessionPlan(rowId: number, markdown: string): ToolCallRow {
- return {
- rowId,
- turnId: `turn-${rowId}`,
- createdAt: 1_700_000_000_000 + rowId,
- createdAtSeq: rowId,
- kind: "toolCall",
- toolCallId: `plan-${rowId}`,
- toolName: "ExitPlanMode",
- status: "success",
- input: { plan: markdown },
- inputText: JSON.stringify({ plan: markdown }),
- };
- }
- async function renderStatusPanel(props: Record<string, unknown>) {
- const { ConversationStatusPanel } = await import("@/v4/ConversationStatusPanel.js");
- return renderToStaticMarkup(
- createElement(ConversationStatusPanel, {
- workspacePath: "/repo",
- gitSummary: gitSummary(),
- gitDirtyFileCount: 2,
- gitWorktreeChangeSummary: { added: 12, removed: 3 },
- onRefreshGit: vi.fn(),
- ...props,
- }),
- );
- }
- describe("ConversationStatusPanel", () => {
- it("uses vertical viewport-bound overlays only on mobile Web remote control", async () => {
- const longPlan = planState({
- items: Array.from({ length: 9 }, (_, index) => ({
- id: String(index + 1),
- content: `Todo ${index + 1}`,
- status: index === 4 ? ("inProgress" as const) : ("pending" as const),
- })),
- });
- statusPanelCapture.gitBranchSwitchers = [];
- const mobileHtml = await renderStatusPanel({
- isMobileViewport: true,
- isWebRemoteControl: true,
- plan: longPlan,
- summaryPanelVariantOverride: "panel",
- });
- expect(statusPanelCapture.gitBranchSwitchers.at(-1)?.popoverSide).toBe("bottom");
- expect(statusPanelCapture.gitBranchSwitchers.at(-1)?.popoverClassName).toContain(
- "max-w-[calc(100vw-2rem)]",
- );
- expect(mobileHtml).toContain('data-side="bottom"');
- statusPanelCapture.gitBranchSwitchers = [];
- const desktopHtml = await renderStatusPanel({
- isMobileViewport: false,
- isWebRemoteControl: false,
- plan: longPlan,
- summaryPanelVariantOverride: "panel",
- });
- expect(statusPanelCapture.gitBranchSwitchers.at(-1)?.popoverSide).toBe("left");
- expect(desktopHtml).toContain('data-side="left"');
- });
- it("goal 计时器只在活动态起一次:投影换一个等值的 goal 对象不重建 interval,暂停即拆掉", async () => {
- // 修订 2026-09-12:此前 effect 以整个 goal 对象为依赖,每个 goal 事件都同步 setNow 并重建
- // interval——落在投影帧的同步提交里,给 React 的嵌套更新计数记一笔(与工作流卡崩溃同形)。
- vi.useFakeTimers();
- vi.setSystemTime(10_000);
- const setIntervalSpy = vi.spyOn(globalThis, "setInterval");
- const clearIntervalSpy = vi.spyOn(globalThis, "clearInterval");
- try {
- const { ConversationStatusPanel } = await import("@/v4/ConversationStatusPanel.js");
- const renderGoal = (goal: GoalState) =>
- createElement(ConversationStatusPanel, {
- workspacePath: "/repo",
- gitSummary: null,
- summaryPanelVariantOverride: "panel",
- goal,
- onPauseGoal: vi.fn(),
- onResumeGoal: vi.fn(),
- });
- const view = render(renderGoal(goalState({ activeRunStartedAtMs: 10_000 })));
- const intervalsAfterMount = setIntervalSpy.mock.calls.length;
- expect(intervalsAfterMount).toBeGreaterThan(0);
- // 同值、不同对象的 goal 帧 ×3:不再有新的 interval。
- for (let i = 0; i < 3; i += 1) {
- view.rerender(renderGoal(goalState({ activeRunStartedAtMs: 10_000, iteration: 1 + i })));
- }
- expect(setIntervalSpy.mock.calls.length).toBe(intervalsAfterMount);
- // 秒针仍在走:过 2 秒后用时文案跟着变。
- const before = view.container.textContent;
- act(() => vi.advanceTimersByTime(2_000));
- expect(view.container.textContent).not.toBe(before);
- // 暂停:interval 拆掉,不再起新的。
- const clearsBefore = clearIntervalSpy.mock.calls.length;
- view.rerender(renderGoal(goalState({ status: "paused", activeRunStartedAtMs: null })));
- expect(clearIntervalSpy.mock.calls.length).toBeGreaterThan(clearsBefore);
- expect(setIntervalSpy.mock.calls.length).toBe(intervalsAfterMount);
- } finally {
- setIntervalSpy.mockRestore();
- clearIntervalSpy.mockRestore();
- vi.useRealTimers();
- }
- });
- it("uses neutral labels for mixed position buckets and keeps previews mutually exclusive", async () => {
- statusPanelCapture.hoverCards = [];
- const { ConversationStatusPanel } = await import("@/v4/ConversationStatusPanel.js");
- const view = render(
- createElement(ConversationStatusPanel, {
- workspacePath: "/repo",
- gitSummary: null,
- summaryPanelVariantOverride: "panel",
- plan: planState({
- items: [
- { id: "1", content: "Todo 1", status: "completed" },
- { id: "2", content: "Todo 2", status: "completed" },
- { id: "3", content: "Todo 3", status: "pending" },
- { id: "4", content: "Todo 4", status: "pending" },
- { id: "5", content: "Todo 5", status: "inProgress" },
- { id: "6", content: "Todo 6", status: "pending" },
- { id: "7", content: "Todo 7", status: "pending" },
- { id: "8", content: "Todo 8", status: "pending" },
- { id: "9", content: "Todo 9", status: "completed" },
- ],
- }),
- }),
- );
- expect(view.container.textContent).toContain("chat.statusPanel.todoEarlierFold 4");
- expect(view.container.textContent).toContain("chat.statusPanel.todoLaterFold 2");
- let previews = statusPanelCapture.hoverCards.slice(-2);
- expect(previews.map((preview) => preview.open)).toEqual([false, false]);
- await act(async () => previews[0]?.onOpenChange?.(true));
- previews = statusPanelCapture.hoverCards.slice(-2);
- expect(previews.map((preview) => preview.open)).toEqual([true, false]);
- await act(async () => previews[1]?.onOpenChange?.(true));
- previews = statusPanelCapture.hoverCards.slice(-2);
- expect(previews.map((preview) => preview.open)).toEqual([false, true]);
- view.unmount();
- });
- it("renders all six Todos without fold controls at the compact threshold", async () => {
- const html = await renderStatusPanel({
- gitSummary: null,
- gitWorktreeChangeSummary: null,
- summaryPanelVariantOverride: "panel",
- plan: planState({
- items: Array.from({ length: 6 }, (_, index) => ({
- id: String(index + 1),
- content: `Todo ${index + 1}`,
- status: index === 0 ? "completed" : "pending",
- })),
- }),
- });
- expect(html).toContain("Todo 1");
- expect(html).toContain("Todo 6");
- expect(html).not.toContain("data-status-todo-preview-trigger");
- });
- it("keeps the full long Todo content and title", async () => {
- const content =
- "检查包含多个测试项目的目录,逐项核对配置文件、依赖安装状态、测试入口和输出目录是否完整";
- const html = await renderStatusPanel({
- summaryPanelVariantOverride: "panel",
- plan: planState({
- items: [{ id: "long-todo", content, status: "inProgress" }],
- }),
- });
- expect(html).toContain(`title="${content}"`);
- expect(html).toContain(content);
- });
- it("renders terminal plans newest-first and maps a row to the plan detail tab", async () => {
- const html = await renderStatusPanel({
- gitSummary: null,
- gitWorktreeChangeSummary: null,
- summaryPanelVariantOverride: "panel",
- parentSessionId: "parent-session",
- sessionPlans: [sessionPlan(3, "# 较早计划"), sessionPlan(9, "# 最新计划")],
- onOpenPlanDetail: vi.fn(),
- });
- const { buildSessionPlanOpenRequest } = await import("@/v4/ConversationStatusPanel.js");
- expect(html).toContain('data-status-section="sessionPlans"');
- expect(html).toContain('data-status-section-scroll="sessionPlans"');
- expect(html.indexOf("最新计划")).toBeLessThan(html.indexOf("较早计划"));
- expect(
- buildSessionPlanOpenRequest("parent-session", {
- rowId: 9,
- toolCallId: "plan-9",
- markdown: "# 最新计划",
- title: "最新计划",
- planFilePath: "/repo/.zcode/plans/latest.md",
- }),
- ).toEqual({
- parentSessionId: "parent-session",
- toolCallId: "plan-9",
- markdown: "# 最新计划",
- planFilePath: "/repo/.zcode/plans/latest.md",
- });
- });
- it("keeps the shell mounted for plan-only mini state", async () => {
- const html = await renderStatusPanel({
- gitSummary: null,
- gitWorktreeChangeSummary: null,
- summaryPanelVariantOverride: "mini",
- sessionPlans: [sessionPlan(4, "# 唯一计划")],
- });
- expect(html).toContain('data-state="collapsed"');
- expect(html).toContain("唯一计划");
- expect(html).toContain("chat.summaryPanel.showPanel");
- });
- it("orders expanded sections as Git, Goal, plans, Todo, terminals, workflows, and Agents", async () => {
- const html = await renderStatusPanel({
- summaryPanelVariantOverride: "panel",
- goal: goalState(),
- sessionPlans: [sessionPlan(4, "# 会话计划")],
- plan: planState(),
- backgroundWorks: [
- backgroundWork({ kind: "bash" }),
- backgroundWork({ workId: "dwfrun-1", kind: "workflow" }),
- ],
- workflowRuns: [workflowRunProjection()],
- runningSubagents: [runningSubagent()],
- });
- const indexes = [
- "environment",
- "goal",
- "sessionPlans",
- "plan",
- "terminal",
- "workflow",
- "agent",
- ].map((section) => html.indexOf(`data-status-section="${section}"`));
- expect(indexes.every((index) => index >= 0)).toBe(true);
- expect(indexes).toEqual([...indexes].sort((left, right) => left - right));
- });
- it("renders the mini shell with one-line git summary", async () => {
- const html = await renderStatusPanel({
- summaryPanelVariantOverride: "mini",
- });
- expect(html).toContain('data-state="collapsed"');
- expect(html).toContain("chat.summaryPanel.showPanel");
- expect(html).toContain("chat.statusPanel.changes");
- expect(html).toContain("+12");
- expect(html).toContain("-3");
- expect(html).not.toContain("mock-git-action-menu");
- });
- it("keeps goal and running background authority on the mini shell", async () => {
- const html = await renderStatusPanel({
- summaryPanelVariantOverride: "mini",
- goal: goalState(),
- runningSubagents: [runningSubagent()],
- });
- expect(html).toContain('data-state="collapsed"');
- expect(html).toContain('data-goal-status="active"');
- expect(html).toContain('data-goal-objective="修好状态面板"');
- expect(html).toContain('data-running-background-count="1"');
- expect(html).toContain("修好状态面板");
- expect(html).not.toContain("chat.summaryPanel.runningBackgroundTasksMiniValue 1");
- expect(html).not.toContain("lucide-bot");
- });
- it("uses Bot for Subagent-only mini summaries and reserves Activity for mixed work", async () => {
- const subagentOnly = await renderStatusPanel({
- gitSummary: null,
- gitWorktreeChangeSummary: null,
- summaryPanelVariantOverride: "mini",
- runningSubagents: [runningSubagent()],
- });
- expect(subagentOnly).toContain("chat.statusPanel.runningAgentsValue 1");
- expect(subagentOnly).not.toContain("chat.summaryPanel.runningBackgroundTasksMiniValue 1");
- expect(subagentOnly).not.toMatch(/\d+秒/u);
- expect(subagentOnly).toContain("lucide-bot");
- expect(subagentOnly).not.toContain("lucide-activity");
- expect(subagentOnly).not.toContain("lucide-square-terminal");
- const bashOnly = await renderStatusPanel({
- gitSummary: null,
- gitWorktreeChangeSummary: null,
- summaryPanelVariantOverride: "mini",
- backgroundWorks: [backgroundWork({ kind: "bash" })],
- });
- expect(bashOnly).toContain("chat.summaryPanel.runningBackgroundTasksMiniValue 1");
- expect(bashOnly).not.toContain("chat.statusPanel.runningAgentsValue 1");
- expect(bashOnly).toContain("lucide-square-terminal");
- expect(bashOnly).not.toContain("lucide-bot");
- expect(bashOnly).not.toContain("lucide-activity");
- const mixed = await renderStatusPanel({
- gitSummary: null,
- gitWorktreeChangeSummary: null,
- summaryPanelVariantOverride: "mini",
- backgroundWorks: [backgroundWork({ workId: "bash-1", kind: "bash" })],
- runningSubagents: [runningSubagent()],
- });
- expect(mixed).toContain("chat.statusPanel.runningAgentsValuePlural 2");
- expect(mixed).not.toContain("chat.summaryPanel.runningBackgroundTasksMiniValuePlural 2");
- expect(mixed).toContain("lucide-activity");
- expect(mixed).not.toContain("lucide-bot");
- expect(mixed).not.toContain("lucide-square-terminal");
- });
- // ── Workflows 分区(docs/dynamic-workflow/presentation.md「Other places a run appears」)──
- // 一行两行高:第一行 名称 + 时长,第二行 侧栏同款轨道 + phase 词。状态词不再可见(灯和 phase
- // 已经说了),但仍进打开按钮的无障碍名。步数只在没有 phase 表时出现。
- it("renders a run as name and time over the sidebar rail and its phase words", async () => {
- const { ConversationStatusPanel } = await import("@/v4/ConversationStatusPanel.js");
- const view = render(
- createElement(ConversationStatusPanel, {
- workspacePath: "/repo",
- gitSummary: null,
- summaryPanelVariantOverride: "panel",
- workflowRuns: [phasedRunProjection()],
- backgroundWorks: [
- backgroundWork({
- workId: "dwfrun-1",
- kind: "workflow",
- title: "重构状态胶囊",
- startedAt: Date.now() - 194_000,
- }),
- ],
- workflowSectionOpen: true,
- onCancelBackgroundWork: vi.fn(),
- onOpenWorkflowRun: vi.fn(),
- }),
- );
- const row = view.container.querySelector<HTMLElement>('[data-workflow-run-id="dwfrun-1"]');
- const lineOne = row?.querySelector<HTMLElement>("[data-workflow-island-line='name']");
- const lineTwo = row?.querySelector<HTMLElement>("[data-workflow-island-line='phase']");
- expect(lineOne?.textContent).toContain("重构状态胶囊");
- expect(lineOne?.querySelector("[data-workflow-run-elapsed]")?.textContent).toBe("3分 14秒");
- // 轨道就是侧栏那一条:done / running / pending 三种灯按声明序排开。
- expect(
- [...(lineTwo?.querySelectorAll("[data-rail-station]") ?? [])].map((lamp) =>
- lamp.getAttribute("data-rail-station"),
- ),
- ).toEqual(["done", "running", "pending"]);
- expect(lineTwo?.textContent).toContain("计划");
- // 可见文字里没有状态词、没有步数、没有「已运行」前缀。
- expect(row?.textContent).not.toContain("chat.toolCall.workflow.run.status.running");
- expect(row?.textContent).not.toContain("chat.toolCall.workflow.card.steps");
- expect(row?.textContent).not.toContain("chat.longRunning");
- // 状态词挪进打开按钮的无障碍名:名称 · 状态 · phase。
- expect(
- row?.querySelector('[data-workflow-run-details-trigger="true"]')?.getAttribute("aria-label"),
- ).toBe(
- "chat.toolCall.workflow.openRunDetails · 重构状态胶囊 · chat.toolCall.workflow.run.status.running · 计划",
- );
- // Stop 叠在时长上(悬停 / 键盘焦点时出现),无障碍名与卡片的「停止运行」同一个 key。
- const stop = row?.querySelector<HTMLElement>(
- '[data-testid="v4-background-work-cancel-dwfrun-1"]',
- );
- expect(stop?.getAttribute("aria-label")).toBe("chat.toolCall.workflow.run.cancel");
- expect(stop?.textContent).toContain("chat.statusPanel.runningStop");
- view.unmount();
- });
- it("joins parallel burning phases with ∥ and draws the twin segment", async () => {
- const html = await renderStatusPanel({
- gitSummary: null,
- gitWorktreeChangeSummary: null,
- summaryPanelVariantOverride: "panel",
- workflowRuns: [
- phasedRunProjection({
- phaseNames: ["准备", "安全", "性能"],
- phaseAlongside: [[], [], [1]],
- phases: [
- { name: "准备", rounds: 1 },
- { name: "安全", rounds: 1 },
- ],
- currentPhase: "性能",
- nodes: [
- { siteId: "ask#1", ordinal: 1, phase: "settled", phaseName: "准备" },
- { siteId: "ask#2", ordinal: 2, phase: "executing", phaseName: "安全" },
- { siteId: "ask#3", ordinal: 3, phase: "executing", phaseName: "性能" },
- ],
- }),
- ],
- workflowSectionOpen: true,
- });
- expect(html).toContain("安全 ∥ 性能");
- expect(html).toContain('data-rail-twin="true"');
- });
- it("falls back to one lamp and steps when the script declared no phases", async () => {
- const html = await renderStatusPanel({
- gitSummary: null,
- gitWorktreeChangeSummary: null,
- summaryPanelVariantOverride: "panel",
- workflowRuns: [workflowRunProjection()],
- workflowSectionOpen: true,
- });
- expect(html).toContain('data-workflow-island-line="phase"');
- expect(html).toContain('data-workflow-run-lamp="running"');
- expect(html).toContain("chat.toolCall.workflow.card.steps 1/3");
- expect(html).not.toContain("data-rail-station");
- });
- it("shows a pending run as a hollow lamp and the status word, with no time", async () => {
- const html = await renderStatusPanel({
- gitSummary: null,
- gitWorktreeChangeSummary: null,
- summaryPanelVariantOverride: "panel",
- workflowRuns: [workflowRunProjection({ status: "pending" })],
- backgroundWorks: [backgroundWork({ workId: "dwfrun-1", kind: "workflow", title: "迁移" })],
- workflowSectionOpen: true,
- });
- expect(html).toContain('data-workflow-run-lamp="pending"');
- expect(html).toContain("chat.toolCall.workflow.run.status.pending");
- expect(html).not.toContain("data-workflow-run-elapsed");
- expect(html).not.toContain("chat.toolCall.workflow.card.steps");
- });
- it("drops seconds from the elapsed time past an hour", async () => {
- const html = await renderStatusPanel({
- gitSummary: null,
- gitWorktreeChangeSummary: null,
- summaryPanelVariantOverride: "panel",
- workflowRuns: [workflowRunProjection()],
- backgroundWorks: [
- backgroundWork({
- workId: "dwfrun-1",
- kind: "workflow",
- title: "长跑",
- startedAt: Date.now() - 3_727_000,
- }),
- ],
- workflowSectionOpen: true,
- });
- expect(html).toMatch(/data-workflow-run-elapsed="true"[^>]*>1小时 2分</u);
- expect(html).not.toContain("1小时 2分 7秒");
- });
- // 头部右侧开合一个样:灯 + 「{n} 个运行中」。折叠时不再换成「所有 run 里最长的时长」——那不是
- // 任何一条 run 的时间。
- it("reads the same live count in the section header open or folded", async () => {
- const works = [
- backgroundWork({ workId: "dwfrun-1", kind: "workflow", startedAt: Date.now() - 3_727_000 }),
- backgroundWork({ workId: "dwfrun-2", kind: "workflow", startedAt: Date.now() - 5_000 }),
- ];
- const runs = [workflowRunProjection(), workflowRunProjection({ runId: "dwfrun-2" })];
- for (const open of [true, false]) {
- const html = await renderStatusPanel({
- gitSummary: null,
- gitWorktreeChangeSummary: null,
- summaryPanelVariantOverride: "panel",
- workflowRuns: runs,
- backgroundWorks: works,
- workflowSectionOpen: open,
- });
- const header = html.slice(
- html.indexOf('data-status-section-trigger="workflow"'),
- html.indexOf(
- 'data-slot="collapsible-content"',
- html.indexOf('data-status-section="workflow"'),
- ),
- );
- expect(header).toContain("chat.statusPanel.workflowsLive 2");
- expect(header).not.toMatch(/\d+秒/u);
- }
- });
- // 已结束入口在滚动区之外:runs 多到要滚时它也不会被滚出视野。
- it("keeps the ended-runs entry below the scrolling run list", async () => {
- const { ConversationStatusPanel } = await import("@/v4/ConversationStatusPanel.js");
- const view = render(
- createElement(ConversationStatusPanel, {
- workspacePath: "/repo",
- gitSummary: null,
- summaryPanelVariantOverride: "panel",
- workflowRuns: [workflowRunProjection()],
- endedWorkflowRunCount: 3,
- parentSessionId: "parent-a",
- workflowSectionOpen: true,
- onOpenWorkflowRunDirectory: vi.fn(),
- }),
- );
- const scroll = view.container.querySelector('[data-status-section-scroll="workflow"]');
- const trigger = view.container.querySelector('[data-testid="workflow-run-directory-trigger"]');
- const row = view.container.querySelector('[data-workflow-run-id="dwfrun-1"]');
- expect(scroll?.contains(row)).toBe(true);
- expect(trigger).not.toBeNull();
- expect(scroll?.contains(trigger)).toBe(false);
- view.unmount();
- });
- // 未命名规则:core 的 workflowTaskSubject 兜底链落到 taskId(≡ runId ≡ workId),投影再把
- // 非空 description 原样抄进 title——所以「题名恰好等于 id」是唯一可靠的未命名信号。
- it("substitutes the shared fallback name when the title is just the run id", async () => {
- const html = await renderStatusPanel({
- gitSummary: null,
- gitWorktreeChangeSummary: null,
- summaryPanelVariantOverride: "panel",
- workflowRuns: [workflowRunProjection()],
- backgroundWorks: [
- backgroundWork({ workId: "dwfrun-1", kind: "workflow", title: "dwfrun-1" }),
- ],
- workflowSectionOpen: true,
- });
- expect(html).toContain("chat.toolCall.workflow.fallbackName");
- expect(html).not.toContain(">dwfrun-1<");
- });
- it("keeps a degraded skew row without status or steps but with its Stop control", async () => {
- const html = await renderStatusPanel({
- gitSummary: null,
- gitWorktreeChangeSummary: null,
- summaryPanelVariantOverride: "panel",
- // 旧 CLI:只有 workflow work,没有 workflowRuns 投影键。
- backgroundWorks: [
- backgroundWork({ workId: "dwfrun-skew", kind: "workflow", title: "旧 CLI 的 run" }),
- ],
- workflowSectionOpen: true,
- onCancelBackgroundWork: vi.fn(),
- });
- expect(html).toContain('data-status-section="workflow"');
- expect(html).toContain("旧 CLI 的 run");
- expect(html).toContain('data-testid="v4-background-work-cancel-dwfrun-skew"');
- expect(html).not.toContain("chat.toolCall.workflow.run.status.");
- expect(html).not.toContain("chat.toolCall.workflow.card.steps");
- expect(html).not.toContain('data-workflow-island-line="phase"');
- expect(html).toContain("data-workflow-run-elapsed");
- });
- it("drops elapsed and Stop for a run whose background work is gone", async () => {
- const html = await renderStatusPanel({
- gitSummary: null,
- gitWorktreeChangeSummary: null,
- summaryPanelVariantOverride: "panel",
- workflowRuns: [workflowRunProjection()],
- workflowSectionOpen: true,
- onCancelBackgroundWork: vi.fn(),
- });
- expect(html).toContain("chat.toolCall.workflow.card.steps 1/3");
- expect(html).not.toContain("data-workflow-run-elapsed");
- // 无 work → 无 workId → 停不了;Stop 的两个前提字段在模型层就一起缺席。
- expect(html).not.toContain("v4-background-work-cancel");
- expect(html).not.toContain("chat.statusPanel.runningStop");
- });
- it("opens the run details tab through a transparent sibling button", async () => {
- const onOpenWorkflowRun = vi.fn();
- const { ConversationStatusPanel } = await import("@/v4/ConversationStatusPanel.js");
- const view = render(
- createElement(ConversationStatusPanel, {
- workspacePath: "/repo",
- gitSummary: null,
- summaryPanelVariantOverride: "panel",
- workflowRuns: [workflowRunProjection()],
- workflowSectionOpen: true,
- onOpenWorkflowRun,
- }),
- );
- const trigger = view.container.querySelector<HTMLButtonElement>(
- '[data-workflow-run-details-trigger="true"]',
- );
- expect(trigger).not.toBeNull();
- // Stop 是行内嵌套交互,所以详情入口不能是整行 button——透明同级按钮,与 Agent 行同款。
- expect(trigger?.getAttribute("aria-label")).toBe(
- "chat.toolCall.workflow.openRunDetails · chat.toolCall.workflow.fallbackName · chat.toolCall.workflow.run.status.running · chat.toolCall.workflow.card.steps 1/3",
- );
- await act(async () => trigger?.click());
- expect(onOpenWorkflowRun).toHaveBeenCalledWith({
- runId: "dwfrun-1",
- toolCallId: "tool-wf-1",
- });
- view.unmount();
- });
- it("carries the workflow name into the target for a named run", async () => {
- // 任务岛入口曾只交出 runId + toolCallId,详情页标签因此兜底成通用名,而工具卡入口显示真名。
- // 行的题名由 workflowRuns 投影按 workId ≡ runId 联接 workflow 后台任务的 title 得到。
- const onOpenWorkflowRun = vi.fn();
- const { ConversationStatusPanel } = await import("@/v4/ConversationStatusPanel.js");
- const view = render(
- createElement(ConversationStatusPanel, {
- workspacePath: "/repo",
- gitSummary: null,
- summaryPanelVariantOverride: "panel",
- workflowRuns: [workflowRunProjection()],
- backgroundWorks: [
- backgroundWork({ workId: "dwfrun-1", kind: "workflow", title: "Ship the release" }),
- ],
- workflowSectionOpen: true,
- onOpenWorkflowRun,
- }),
- );
- const trigger = view.container.querySelector<HTMLButtonElement>(
- '[data-workflow-run-details-trigger="true"]',
- );
- await act(async () => trigger?.click());
- expect(onOpenWorkflowRun).toHaveBeenCalledWith({
- runId: "dwfrun-1",
- toolCallId: "tool-wf-1",
- workflowName: "Ship the release",
- });
- view.unmount();
- });
- it("omits the workflow name for an unnamed run (title ≡ runId)", async () => {
- // `title ≡ runId` 是未命名 run 的兜底样子;把 runId 冻进标签比通用兜底名更糟,所以不带出去。
- const onOpenWorkflowRun = vi.fn();
- const { ConversationStatusPanel } = await import("@/v4/ConversationStatusPanel.js");
- const view = render(
- createElement(ConversationStatusPanel, {
- workspacePath: "/repo",
- gitSummary: null,
- summaryPanelVariantOverride: "panel",
- workflowRuns: [workflowRunProjection()],
- backgroundWorks: [
- backgroundWork({ workId: "dwfrun-1", kind: "workflow", title: "dwfrun-1" }),
- ],
- workflowSectionOpen: true,
- onOpenWorkflowRun,
- }),
- );
- const trigger = view.container.querySelector<HTMLButtonElement>(
- '[data-workflow-run-details-trigger="true"]',
- );
- await act(async () => trigger?.click());
- expect(onOpenWorkflowRun).toHaveBeenCalledWith({
- runId: "dwfrun-1",
- toolCallId: "tool-wf-1",
- });
- view.unmount();
- });
- it("leaves a row without toolCallId or host callback unclickable", async () => {
- const withoutToolCallId = await renderStatusPanel({
- gitSummary: null,
- gitWorktreeChangeSummary: null,
- summaryPanelVariantOverride: "panel",
- workflowRuns: [workflowRunProjection({ toolCallId: undefined })],
- workflowSectionOpen: true,
- onOpenWorkflowRun: vi.fn(),
- });
- expect(withoutToolCallId).toContain('data-workflow-run-id="dwfrun-1"');
- expect(withoutToolCallId).not.toContain("data-workflow-run-details-trigger");
- const withoutHostCallback = await renderStatusPanel({
- gitSummary: null,
- gitWorktreeChangeSummary: null,
- summaryPanelVariantOverride: "panel",
- workflowRuns: [workflowRunProjection()],
- workflowSectionOpen: true,
- });
- expect(withoutHostCallback).toContain('data-workflow-run-id="dwfrun-1"');
- expect(withoutHostCallback).not.toContain("data-workflow-run-details-trigger");
- });
- it("keeps the projection order of active runs instead of sorting by start time", async () => {
- const html = await renderStatusPanel({
- gitSummary: null,
- gitWorktreeChangeSummary: null,
- summaryPanelVariantOverride: "panel",
- // 投影序即启动序;后启动的 run 反而 startedAt 更早也不许把它排到前面。
- workflowRuns: [
- workflowRunProjection({ runId: "dwfrun-late", toolCallId: "tool-late" }),
- workflowRunProjection({ runId: "dwfrun-early", toolCallId: "tool-early" }),
- ],
- backgroundWorks: [
- backgroundWork({
- workId: "dwfrun-late",
- kind: "workflow",
- title: "后启动",
- startedAt: Date.now() - 1_000,
- }),
- backgroundWork({
- workId: "dwfrun-early",
- kind: "workflow",
- title: "先启动",
- startedAt: Date.now() - 60_000,
- }),
- ],
- workflowSectionOpen: true,
- });
- expect(html.indexOf('data-workflow-run-id="dwfrun-late"')).toBeLessThan(
- html.indexOf('data-workflow-run-id="dwfrun-early"'),
- );
- });
- // ── 已结束的 run 折进页脚行(docs/dynamic-workflow/presentation.md「Other places a run appears」)──
- it("folds ended runs into a footer row that opens the run directory", async () => {
- const onOpenWorkflowRunDirectory = vi.fn();
- const { ConversationStatusPanel } = await import("@/v4/ConversationStatusPanel.js");
- const view = render(
- createElement(ConversationStatusPanel, {
- workspacePath: "/repo",
- gitSummary: null,
- summaryPanelVariantOverride: "panel",
- workflowRuns: [workflowRunProjection()],
- endedWorkflowRunCount: 3,
- parentSessionId: "parent-a",
- workflowSectionOpen: true,
- onOpenWorkflowRunDirectory,
- }),
- );
- const trigger = view.container.querySelector<HTMLButtonElement>(
- '[data-testid="workflow-run-directory-trigger"]',
- );
- expect(trigger).not.toBeNull();
- // 桶名刻意不是「已完成」:这个桶里也有失败与取消的 run。
- expect(trigger?.textContent).toContain("chat.statusPanel.endedWorkflows");
- expect(trigger?.textContent).toContain("3");
- await act(async () => trigger?.click());
- expect(onOpenWorkflowRunDirectory).toHaveBeenCalledWith({ parentSessionId: "parent-a" });
- view.unmount();
- });
- it("keeps the Workflows section when nothing is active but history exists (the restart entry)", async () => {
- // 重启后 workflowRuns 投影为空(memory-only)。只按活动数开门的那一版在这里整块消失,
- // 于是通往 run 目录的唯一入口也没了——这条用例就是钉住那个失效。
- const html = await renderStatusPanel({
- gitSummary: null,
- gitWorktreeChangeSummary: null,
- summaryPanelVariantOverride: "panel",
- endedWorkflowRunCount: 2,
- parentSessionId: "parent-a",
- workflowSectionOpen: true,
- onOpenWorkflowRunDirectory: vi.fn(),
- });
- expect(html).toContain('data-status-section="workflow"');
- expect(html).toContain('data-testid="workflow-run-directory-trigger"');
- expect(html).toContain('data-ended-workflow-count="2"');
- // 一行活动 run 都没有,所以不该出现任何 run 行。
- expect(html).not.toContain("data-workflow-run-id");
- });
- it("hides the footer row when there is no history, no session, or no host callback", async () => {
- const noHistory = await renderStatusPanel({
- gitSummary: null,
- gitWorktreeChangeSummary: null,
- summaryPanelVariantOverride: "panel",
- workflowRuns: [workflowRunProjection()],
- endedWorkflowRunCount: 0,
- parentSessionId: "parent-a",
- workflowSectionOpen: true,
- onOpenWorkflowRunDirectory: vi.fn(),
- });
- expect(noHistory).toContain('data-workflow-run-id="dwfrun-1"');
- expect(noHistory).not.toContain("workflow-run-directory-trigger");
- // 点了没反应的入口比没有入口更糟:缺会话或缺回调时整行缺席。
- const noCallback = await renderStatusPanel({
- gitSummary: null,
- gitWorktreeChangeSummary: null,
- summaryPanelVariantOverride: "panel",
- workflowRuns: [workflowRunProjection()],
- endedWorkflowRunCount: 5,
- parentSessionId: "parent-a",
- workflowSectionOpen: true,
- });
- expect(noCallback).not.toContain("workflow-run-directory-trigger");
- const noSession = await renderStatusPanel({
- gitSummary: null,
- gitWorktreeChangeSummary: null,
- summaryPanelVariantOverride: "panel",
- workflowRuns: [workflowRunProjection()],
- endedWorkflowRunCount: 5,
- workflowSectionOpen: true,
- onOpenWorkflowRunDirectory: vi.fn(),
- });
- expect(noSession).not.toContain("workflow-run-directory-trigger");
- });
- it("names the live run in the mini capsule instead of counting it (an ended run is not activity)", async () => {
- const html = await renderStatusPanel({
- gitSummary: null,
- gitWorktreeChangeSummary: null,
- summaryPanelVariantOverride: "mini",
- workflowRuns: [workflowRunProjection()],
- endedWorkflowRunCount: 7,
- parentSessionId: "parent-a",
- onOpenWorkflowRunDirectory: vi.fn(),
- });
- expect(html).toContain('data-running-workflow-count="1"');
- expect(html).toContain('data-running-background-count="1"');
- expect(html).toContain('data-workflow-pill="dwfrun-1"');
- expect(html).toContain("chat.toolCall.workflow.fallbackName");
- expect(html).not.toContain("chat.summaryPanel.runningBackgroundTasksMiniValue");
- expect(html).not.toContain("chat.statusPanel.endedWorkflows");
- });
- // 活的工作流排在胶囊最前:它在跑时就是会话在做的事;todo / goal / git 都让位。
- it("puts a live workflow ahead of the to-do, goal and git summaries in the pill", async () => {
- const html = await renderStatusPanel({
- summaryPanelVariantOverride: "mini",
- plan: planState(),
- goal: goalState(),
- workflowRuns: [
- phasedRunProjection(),
- workflowRunProjection({ runId: "dwfrun-2", status: "pending" }),
- ],
- backgroundWorks: [
- backgroundWork({ workId: "dwfrun-1", kind: "workflow", title: "重构状态胶囊" }),
- backgroundWork({ workId: "dwfrun-2", kind: "workflow", title: "第二条" }),
- ],
- });
- const pill = html.slice(html.indexOf("data-workflow-pill"));
- expect(pill).toContain("重构状态胶囊");
- expect(pill).toContain('data-workflow-run-lamp="running"');
- expect(pill).toContain("计划");
- expect(pill).toContain("+1");
- expect(pill).not.toContain("第二条");
- expect(html).not.toContain("复刻浮层");
- expect(html).not.toContain("chat.statusPanel.changes");
- });
- // 展开后看到的不能比胶囊还少:胶囊显示着工作流时,点它展开面板并同时打开「工作流」分区——
- // 哪怕读者先前手动折过它。胶囊显示别的(todo / git …)时不碰这个分区。
- it("opens the Workflows section when the clicked pill was showing a workflow", async () => {
- const { ConversationStatusPanel } = await import("@/v4/ConversationStatusPanel.js");
- const onVariantChange = vi.fn();
- const onWorkflowSectionOpenChange = vi.fn();
- const view = render(
- createElement(ConversationStatusPanel, {
- workspacePath: "/repo",
- gitSummary: null,
- summaryPanelVariantOverride: "mini",
- workflowRuns: [workflowRunProjection()],
- workflowSectionOpen: false,
- onVariantChange,
- onWorkflowSectionOpenChange,
- }),
- );
- const pill = view.container.querySelector("[data-workflow-pill]")?.closest("button");
- await act(async () => pill?.click());
- expect(onVariantChange).toHaveBeenCalledWith("panel");
- expect(onWorkflowSectionOpenChange).toHaveBeenCalledWith(true);
- view.unmount();
- const onOtherSectionOpenChange = vi.fn();
- const todoView = render(
- createElement(ConversationStatusPanel, {
- workspacePath: "/repo",
- gitSummary: null,
- summaryPanelVariantOverride: "mini",
- plan: planState(),
- onVariantChange: vi.fn(),
- onWorkflowSectionOpenChange: onOtherSectionOpenChange,
- }),
- );
- const todoPill = todoView.container.querySelector<HTMLButtonElement>(
- 'button[aria-label="chat.summaryPanel.showPanel"]',
- );
- await act(async () => todoPill?.click());
- expect(onOtherSectionOpenChange).not.toHaveBeenCalled();
- todoView.unmount();
- });
- it("shows a degraded run in the pill by name alone, without a lamp", async () => {
- const html = await renderStatusPanel({
- gitSummary: null,
- gitWorktreeChangeSummary: null,
- summaryPanelVariantOverride: "mini",
- backgroundWorks: [
- backgroundWork({ workId: "dwfrun-skew", kind: "workflow", title: "旧 CLI 的 run" }),
- ],
- });
- expect(html).toContain('data-workflow-pill="dwfrun-skew"');
- expect(html).toContain("旧 CLI 的 run");
- expect(html).not.toContain("data-workflow-run-lamp");
- });
- it("shows the ended-runs metric in the mini capsule when nothing else is alive", async () => {
- // Bug 复现:工作区无 Git 变更、workflow 跑完的瞬间——卸载闸门为了 run 目录入口保留
- // 壳(canRenderEndedWorkflows),但胶囊兜底链没有终态分支,渲染成一条 2px 空壳线。
- const html = await renderStatusPanel({
- gitSummary: null,
- gitWorktreeChangeSummary: null,
- summaryPanelVariantOverride: "mini",
- workflowRuns: [],
- endedWorkflowRunCount: 3,
- parentSessionId: "parent-a",
- onOpenWorkflowRunDirectory: vi.fn(),
- });
- expect(html).toContain('data-state="collapsed"');
- expect(html).toContain("chat.statusPanel.endedWorkflows");
- expect(html).toContain("3");
- });
- it("keeps the ended-runs metric behind the directory gate (no session or callback → no capsule text)", async () => {
- // 与页脚同一条规则:目录打不开时,报数就是一个点了没反应的入口。此时 hasContent 也是
- // false,整个壳按既有闸门卸载。
- const html = await renderStatusPanel({
- gitSummary: null,
- gitWorktreeChangeSummary: null,
- summaryPanelVariantOverride: "mini",
- workflowRuns: [],
- endedWorkflowRunCount: 3,
- parentSessionId: "parent-a",
- });
- expect(html).not.toContain("chat.statusPanel.endedWorkflows");
- expect(html).not.toContain('data-state="collapsed"');
- });
- it("shows the workflow pill even when terminals run beside it", async () => {
- const mixedWithWorkflow = await renderStatusPanel({
- gitSummary: null,
- gitWorktreeChangeSummary: null,
- summaryPanelVariantOverride: "mini",
- workflowRuns: [workflowRunProjection()],
- backgroundWorks: [backgroundWork({ workId: "bash-1", kind: "bash" })],
- });
- expect(mixedWithWorkflow).toContain('data-running-background-count="2"');
- expect(mixedWithWorkflow).toContain('data-workflow-pill="dwfrun-1"');
- expect(mixedWithWorkflow).toContain("lucide-workflow");
- expect(mixedWithWorkflow).not.toContain("lucide-activity");
- expect(mixedWithWorkflow).not.toContain("chat.summaryPanel.runningBackgroundTasksMiniValue");
- });
- it("keeps the capsule alive for a workflow run as the only content", async () => {
- const html = await renderStatusPanel({
- gitSummary: null,
- gitWorktreeChangeSummary: null,
- summaryPanelVariantOverride: "mini",
- workflowRuns: [workflowRunProjection()],
- });
- expect(html).toContain('data-testid="chat-summary-panel"');
- expect(html).toContain('data-state="collapsed"');
- });
- it("controls the workflow section open state and forwards manual collapse", async () => {
- const onWorkflowSectionOpenChange = vi.fn();
- statusPanelCapture.collapsibles = [];
- const html = await renderStatusPanel({
- gitSummary: null,
- gitWorktreeChangeSummary: null,
- summaryPanelVariantOverride: "panel",
- workflowRuns: [workflowRunProjection()],
- workflowSectionOpen: true,
- onWorkflowSectionOpenChange,
- });
- expect(html).toContain('data-status-section-trigger="workflow"');
- const workflow = statusPanelCapture.collapsibles.find((entry) => entry.section === "workflow");
- expect(workflow?.open).toBe(true);
- workflow?.onOpenChange?.(false);
- expect(onWorkflowSectionOpenChange).toHaveBeenCalledWith(false);
- });
- it("shows realtime activity only when the capsule has no primary status", async () => {
- const gitPrimary = await renderStatusPanel({
- summaryPanelVariantOverride: "mini",
- runningSubagents: [runningSubagent()],
- });
- expect(gitPrimary).toContain("chat.statusPanel.changes");
- expect(gitPrimary).not.toContain("chat.summaryPanel.runningBackgroundTasksMiniValue 1");
- expect(gitPrimary).not.toContain("lucide-bot");
- const completedGoalPrimary = await renderStatusPanel({
- gitSummary: null,
- gitWorktreeChangeSummary: null,
- summaryPanelVariantOverride: "mini",
- goal: goalState({ status: "verified", summaryTitle: "已完成主目标" }),
- backgroundWorks: [backgroundWork({ kind: "bash" })],
- });
- expect(completedGoalPrimary).toContain("已完成主目标");
- expect(completedGoalPrimary).not.toContain(
- "chat.summaryPanel.runningBackgroundTasksMiniValue 1",
- );
- expect(completedGoalPrimary).not.toContain("lucide-square-terminal");
- });
- it("keeps a notSatisfied goal visible in mini with its summary title", async () => {
- const html = await renderStatusPanel({
- gitSummary: null,
- gitWorktreeChangeSummary: null,
- summaryPanelVariantOverride: "mini",
- goal: goalState({
- objective: "复现用目标:总共完成 4 个 checkpoint",
- summaryTitle: "四步Checkpoint复现",
- status: "notSatisfied",
- }),
- });
- expect(html).toContain('data-state="collapsed"');
- expect(html).toContain('data-goal-status="notSatisfied"');
- expect(html).toContain("chat.summaryPanel.showPanel");
- expect(html).toContain("四步Checkpoint复现");
- expect(html).not.toContain(">复现用目标:总共完成 4 个 checkpoint<");
- });
- it("does not keep a mini capsule alive for ended Agents alone", async () => {
- const html = await renderStatusPanel({
- gitSummary: null,
- gitWorktreeChangeSummary: null,
- summaryPanelVariantOverride: "mini",
- endedSubagentCount: 3,
- parentSessionId: "parent-session",
- onOpenSubagentDirectory: vi.fn(),
- });
- expect(html).toBe("");
- });
- it("nests the ended directory row inside the Agent section", async () => {
- const html = await renderStatusPanel({
- gitSummary: null,
- gitWorktreeChangeSummary: null,
- summaryPanelVariantOverride: "panel",
- plan: planState(),
- runningSubagents: [runningSubagent()],
- endedSubagentCount: 3,
- rootSessionId: "root-session",
- parentSessionId: "parent-session",
- onOpenSubagentDirectory: vi.fn(),
- });
- const agentSectionStart = html.indexOf('data-status-section="agent"');
- const agentSectionEnd = html.indexOf("</section>", agentSectionStart);
- const endedDirectoryRow = html.indexOf("chat.statusPanel.endedAgents");
- expect(agentSectionStart).toBeGreaterThanOrEqual(0);
- expect(endedDirectoryRow).toBeGreaterThan(agentSectionStart);
- expect(endedDirectoryRow).toBeLessThan(agentSectionEnd);
- expect(html).toContain("chat.statusPanel.endedAgents");
- expect(html).toContain(">3<");
- });
- it("keeps ended-only content inside an Agent section when another summary keeps the panel", async () => {
- const html = await renderStatusPanel({
- gitSummary: null,
- gitWorktreeChangeSummary: null,
- summaryPanelVariantOverride: "panel",
- plan: planState(),
- endedSubagentCount: 3,
- rootSessionId: "root-session",
- parentSessionId: "parent-session",
- onOpenSubagentDirectory: vi.fn(),
- });
- const agentSectionStart = html.indexOf('data-status-section="agent"');
- const agentSectionEnd = html.indexOf("</section>", agentSectionStart);
- const endedDirectoryRow = html.indexOf("chat.statusPanel.endedAgents");
- expect(agentSectionStart).toBeGreaterThanOrEqual(0);
- expect(endedDirectoryRow).toBeGreaterThan(agentSectionStart);
- expect(endedDirectoryRow).toBeLessThan(agentSectionEnd);
- });
- it("renders expanded panel controls and sections", async () => {
- const html = await renderStatusPanel({
- summaryPanelVariantOverride: "panel",
- goal: goalState(),
- plan: planState(),
- runningSubagents: [runningSubagent()],
- });
- expect(html).toContain('data-state="expanded"');
- expect(html).toContain("chat.summaryPanel.displayMode");
- expect(html).toContain("chat.summaryPanel.displayModeAuto");
- expect(html).not.toContain("chat.summaryPanel.displayModeExpanded");
- expect(html).not.toContain("chat.summaryPanel.displayModeCollapsed");
- expect(html).toContain("mock-git-branch-switcher");
- expect(html).toContain("mock-git-action-menu");
- expect(html).toContain("修好状态面板");
- expect(html).toContain("复刻浮层");
- expect(html).toContain("chat.statusPanel.agents");
- expect(html).toContain('data-goal-status="active"');
- expect(html).toContain('data-goal-objective="修好状态面板"');
- expect(html).toContain('data-running-background-count="1"');
- expect(html).toContain('data-status-section="agent"');
- expect(html).toContain('data-status-section-trigger="agent"');
- });
- it("projects automatic display mode to the shell", async () => {
- const html = await renderStatusPanel({
- layoutMode: "auto",
- summaryPanelVariantOverride: null,
- });
- expect(html).toContain('data-display-mode="auto"');
- });
- it("controls the Agent section open state and forwards manual collapse", async () => {
- const onAgentSectionOpenChange = vi.fn();
- statusPanelCapture.collapsibles = [];
- const html = await renderStatusPanel({
- gitSummary: null,
- gitWorktreeChangeSummary: null,
- summaryPanelVariantOverride: "panel",
- runningSubagents: [runningSubagent()],
- agentSectionOpen: true,
- onAgentSectionOpenChange,
- });
- expect(html).toContain('data-status-section-trigger="agent"');
- expect(html).toContain('aria-expanded="true"');
- const agent = statusPanelCapture.collapsibles.find((entry) => entry.section === "agent");
- expect(agent?.open).toBe(true);
- agent?.onOpenChange?.(false);
- expect(onAgentSectionOpenChange).toHaveBeenCalledWith(false);
- });
- it("labels the Agent section count as running instead of background", async () => {
- const html = await renderStatusPanel({
- gitSummary: null,
- gitWorktreeChangeSummary: null,
- summaryPanelVariantOverride: "panel",
- runningSubagents: [
- runningSubagent({ childSessionId: "agent-1" }),
- runningSubagent({ childSessionId: "agent-2" }),
- ],
- agentSectionOpen: true,
- });
- const agentSectionStart = html.indexOf('data-status-section="agent"');
- const agentSection = html.slice(
- agentSectionStart,
- html.indexOf("</section>", agentSectionStart),
- );
- expect(agentSection).toContain("chat.statusPanel.runningAgentsValuePlural 2");
- expect(agentSection).not.toContain("chat.summaryPanel.runningBackgroundTasksMiniValuePlural 2");
- });
- it("renders active elapsed, pause control, and every iteration action/status", async () => {
- const html = await renderStatusPanel({
- gitSummary: null,
- gitWorktreeChangeSummary: null,
- summaryPanelVariantOverride: "panel",
- onPauseGoal: vi.fn(),
- goal: goalState({
- summaryTitle: "第一轮:恢复摘要",
- timeUsedSeconds: 9,
- iteration: 1,
- verifications: [
- {
- iteration: 1,
- outcome: "notSatisfied",
- at: 1_700_000_000_000,
- anchorRowId: null,
- reason: "还缺状态",
- nextAction: "第二轮:补暂停和完成态",
- },
- ],
- iterations: [
- {
- iteration: 1,
- updatedAt: 1_700_000_000_000,
- items: [{ id: "one", content: "恢复计时", status: "completed" }],
- },
- {
- iteration: 2,
- updatedAt: 1_700_000_001_000,
- items: [
- { id: "two", content: "恢复按钮", status: "inProgress" },
- { id: "three", content: "验证状态", status: "pending" },
- ],
- },
- ],
- }),
- });
- expect(html).toContain("9秒");
- expect(html).toContain('data-goal-action="pause"');
- expect(html).toContain("第一轮:恢复摘要");
- expect(html).toContain("第二轮:补暂停和完成态");
- expect(html).toContain('data-goal-iteration="1"');
- expect(html).toContain('data-goal-iteration-completed="true"');
- expect(html).toContain("0/2");
- });
- it("renders paused play and verified green check as mutually exclusive controls", async () => {
- const paused = await renderStatusPanel({
- gitSummary: null,
- gitWorktreeChangeSummary: null,
- summaryPanelVariantOverride: "panel",
- onResumeGoal: vi.fn(),
- goal: goalState({ status: "paused", timeUsedSeconds: 12 }),
- });
- expect(paused).toContain('data-goal-action="resume"');
- expect(paused).not.toContain('data-goal-action="pause"');
- const verified = await renderStatusPanel({
- gitSummary: null,
- gitWorktreeChangeSummary: null,
- summaryPanelVariantOverride: "panel",
- goal: goalState({ status: "verified", timeUsedSeconds: 18 }),
- });
- expect(verified).toContain("chat.goalVerification.complete");
- expect(verified).not.toContain("data-goal-action=");
- });
- it("does not append verifier reason cards after visible iteration actions", async () => {
- const html = await renderStatusPanel({
- gitSummary: null,
- gitWorktreeChangeSummary: null,
- summaryPanelVariantOverride: "panel",
- goal: goalState({
- iteration: 1,
- verifications: [
- {
- iteration: 1,
- outcome: "notSatisfied",
- at: 1_700_000_000_000,
- anchorRowId: null,
- reason: "这段 verifier reason 不应出现在右上角灰卡",
- nextAction: "继续第二轮 action",
- },
- ],
- }),
- });
- expect(html).toContain("继续第二轮 action");
- expect(html).not.toContain("这段 verifier reason 不应出现在右上角灰卡");
- });
- it("restores Stop only for projected Agents with an exact background control match", async () => {
- const html = await renderStatusPanel({
- gitSummary: null,
- gitWorktreeChangeSummary: null,
- summaryPanelVariantOverride: "panel",
- onCancelBackgroundWork: vi.fn(),
- backgroundWorks: [
- backgroundWork({
- workId: "bash-newer",
- kind: "bash",
- title: "启动开发服务器",
- startedAt: Date.now() - 3_000,
- cancellable: false,
- }),
- backgroundWork({
- workId: "agent-control-work",
- kind: "subagent",
- childSessionId: "agent-older",
- title: "packages结构分析",
- cancellable: true,
- }),
- backgroundWork({
- workId: "agent-disabled-work",
- kind: "subagent",
- childSessionId: "agent-disabled",
- title: "不可停止的 Agent",
- cancellable: false,
- }),
- ],
- runningSubagents: [
- runningSubagent({
- childSessionId: "agent-older",
- title: "packages结构分析",
- startedAt: Date.now() - 9_000,
- }),
- runningSubagent({
- childSessionId: "agent-disabled",
- title: "不可停止的 Agent",
- }),
- runningSubagent({
- childSessionId: "foreground-agent",
- title: "同名但无 background control",
- }),
- ],
- });
- expect(html).toContain('data-background-task-kind="bash"');
- expect(html).toContain('data-background-task-kind="agent"');
- expect(html).toContain('data-child-session-id="agent-older"');
- expect(html).toContain('data-work-id="agent-control-work"');
- expect(html).toContain('data-work-status="running"');
- expect(html).toContain('data-testid="v4-background-work-item-agent-control-work"');
- expect(html).toContain('data-status-section="terminal"');
- expect(html).toContain('data-status-section="agent"');
- expect(html).toContain("chat.statusPanel.terminals");
- expect(html).toContain("chat.statusPanel.agents");
- expect(html).toContain("lucide-bot");
- expect(html).toContain("lucide-square-terminal");
- expect(html).not.toContain("subagent · packages结构分析");
- expect(html).not.toContain("bash · 启动开发服务器");
- expect(html).toContain("chat.longRunning.elapsedSeconds 9");
- expect(html).toContain("flex-wrap");
- expect(html).toContain('data-testid="v4-background-work-cancel-agent-control-work"');
- expect(html).not.toContain('data-testid="v4-background-work-cancel-agent-older"');
- expect(html).not.toContain('data-testid="v4-background-work-cancel-agent-disabled-work"');
- expect(html).not.toContain('data-testid="v4-background-work-cancel-foreground-agent"');
- expect(html).not.toContain('data-testid="v4-background-work-cancel-bash-newer"');
- const terminalSection = html.slice(
- html.indexOf('data-status-section="terminal"'),
- html.indexOf('data-status-section="agent"'),
- );
- expect(terminalSection).toContain("启动开发服务器");
- expect(terminalSection).not.toContain("packages结构分析");
- const agentSection = html.slice(html.indexOf('data-status-section="agent"'));
- expect(agentSection).toContain("packages结构分析");
- expect(agentSection).not.toContain("启动开发服务器");
- });
- it("turns projected running Agents into child-session triggers", async () => {
- const addressableSubagent = runningSubagent({
- childSessionId: "child-addressable",
- });
- const html = await renderStatusPanel({
- gitSummary: null,
- gitWorktreeChangeSummary: null,
- summaryPanelVariantOverride: "panel",
- parentSessionId: "parent-session",
- rootSessionId: "root-session",
- onOpenSubagentSession: vi.fn(),
- runningSubagents: [
- addressableSubagent,
- runningSubagent({ childSessionId: "child-second", title: "第二个 Agent" }),
- ],
- });
- const { buildRunningSubagentOpenRequest } = await import("@/v4/ConversationStatusPanel.js");
- expect(html.match(/data-running-subagent-session-trigger="true"/g)).toHaveLength(2);
- expect(html).toContain('data-child-session-id="child-addressable"');
- expect(
- buildRunningSubagentOpenRequest({
- parentSessionId: "parent-session",
- rootSessionId: "root-session",
- subagent: addressableSubagent,
- }),
- ).toEqual({
- rootSessionId: "root-session",
- parentSessionId: "parent-session",
- childSessionId: "child-addressable",
- subagentType: "Explore",
- title: "探索渲染逻辑",
- });
- });
- it("bounds all six long status section types and keeps long Todos behind expansion", async () => {
- const todoItems = Array.from({ length: 8 }, (_, index) => ({
- id: `todo-${index + 1}`,
- content: `Todo 第 ${index + 1} 项`,
- status: index === 0 ? ("inProgress" as const) : ("pending" as const),
- }));
- const html = await renderStatusPanel({
- summaryPanelVariantOverride: "panel",
- goal: goalState({
- iterations: Array.from({ length: 8 }, (_, index) => ({
- iteration: index + 1,
- updatedAt: 1_700_000_000_000 + index,
- items: [],
- })),
- }),
- sessionPlans: Array.from({ length: 8 }, (_, index) =>
- sessionPlan(index + 1, `# 计划第 ${index + 1} 项`),
- ),
- plan: planState({ items: todoItems }),
- backgroundWorks: [
- backgroundWork({ workId: "bash-1", kind: "bash", title: "终端任务一" }),
- backgroundWork({ workId: "bash-2", kind: "bash", title: "终端任务二" }),
- backgroundWork({ workId: "dwfrun-1", kind: "workflow", title: "工作流一" }),
- ],
- workflowRuns: [workflowRunProjection()],
- runningSubagents: [
- runningSubagent({ childSessionId: "agent-1", title: "智能体一" }),
- runningSubagent({ childSessionId: "agent-2", title: "智能体二" }),
- ],
- terminalSectionOpen: true,
- workflowSectionOpen: true,
- agentSectionOpen: true,
- });
- for (const section of ["goal", "sessionPlans", "plan", "terminal", "workflow", "agent"]) {
- expect(html).toContain(`data-status-section-scroll="${section}"`);
- }
- expect(html).not.toContain('data-status-section-scroll="environment"');
- expect(html).toContain("max-h-80 min-h-0 overflow-x-hidden overflow-y-auto pr-1");
- expect(html).toContain("max-h-48 min-h-0 overflow-x-hidden overflow-y-auto pr-1");
- expect(html).toContain("max-h-[min(64dvh,32rem)]");
- expect(html).toContain(
- "min-h-0 flex-1 flex-col gap-2 overflow-x-hidden overflow-y-auto p-2 flex",
- );
- for (const item of todoItems) {
- expect(html).toContain(item.content);
- }
- expect(html).toContain('data-status-todo-preview-trigger="following"');
- expect(html).toContain('data-status-todo-preview-content="following"');
- expect(html).toContain('data-side="left"');
- expect(html).toContain('data-align="start"');
- expect(html).toContain('data-side-offset="4"');
- expect(html).toContain("flex max-h-[min(24rem,calc(100dvh-2rem))] min-w-0 flex-col");
- expect(html).toContain("min-h-0 space-y-0 overflow-y-auto pr-1");
- expect(html).toContain("chat.statusPanel.todoWaitingFold 5");
- expect(html).toContain(
- "rounded-lg px-2 text-left text-ui-base text-[var(--color-foreground-subtle)]",
- );
- expect(statusPanelCapture.hoverCards).toContainEqual(
- expect.objectContaining({
- closeDelay: 80,
- open: false,
- openDelay: 120,
- }),
- );
- });
- it("keeps a long Agent viewport bounded beside short Progress and Plans sections", async () => {
- const agents = Array.from({ length: 5 }, (_, index) =>
- runningSubagent({
- childSessionId: `mixed-agent-${index + 1}`,
- title: `Background sleep agent ${index + 1}`,
- }),
- );
- const html = await renderStatusPanel({
- gitSummary: null,
- gitWorktreeChangeSummary: null,
- summaryPanelVariantOverride: "panel",
- sessionPlans: [sessionPlan(1, "# 组合场景计划")],
- plan: planState({
- items: [{ id: "short-progress", content: "你好", status: "inProgress" }],
- }),
- runningSubagents: agents,
- agentSectionOpen: true,
- });
- for (const section of ["sessionPlans", "plan", "agent"]) {
- expect(html).toContain(`data-status-section-scroll="${section}"`);
- }
- for (const agent of agents) {
- expect(html).toContain(agent.title);
- }
- expect(html).toContain("max-h-80 min-h-0 overflow-x-hidden overflow-y-auto pr-1");
- expect(html).toContain("max-h-48 min-h-0 overflow-x-hidden overflow-y-auto pr-1");
- });
- it("maps the display mode menu back to nullable shell override", async () => {
- statusPanelCapture.radioGroups = [];
- const onVariantChange = vi.fn();
- vi.stubGlobal("window", {
- innerWidth: 1200,
- addEventListener: vi.fn(),
- removeEventListener: vi.fn(),
- });
- try {
- await renderStatusPanel({
- summaryPanelVariantOverride: null,
- onVariantChange,
- });
- } finally {
- vi.unstubAllGlobals();
- }
- expect(statusPanelCapture.radioGroups).toHaveLength(1);
- expect(statusPanelCapture.radioGroups[0]?.value).toBe("auto");
- statusPanelCapture.radioGroups[0]?.onValueChange?.("mini");
- expect(onVariantChange).toHaveBeenLastCalledWith("mini");
- statusPanelCapture.radioGroups[0]?.onValueChange?.("auto");
- expect(onVariantChange).toHaveBeenLastCalledWith(null);
- });
- });
|