Skip to content

Commit fd1171f

Browse files
authored
refactor(ui): heal chat-pane max-lines and markdown-tables mock isolation (#125766)
* refactor(ui): extract chat pane rail state chat-pane-render.ts sits at 702/700 effective max-lines on main, latently failing the lint lane for any change that pulls it into scope. Extract the rail/sidebar-slot model building into chat-pane-rails.ts (behavior-neutral) to heal it without a suppression. * test(ui): isolate markdown-tables from shared module graph The shared UI runner reuses its module graph across jsdom registries; when another worker file evaluates markdown-tables.ts unmocked first, this file's clipboard vi.mock can bind to a stale instance and the copy spy records zero calls (checks-ui failures on PR #125668). The test belongs on the canonical singleton-sensitive list, which exists for exactly this class.
1 parent d95d591 commit fd1171f

3 files changed

Lines changed: 91 additions & 57 deletions

File tree

‎test/vitest/vitest.ui-isolated-paths.mjs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export const uiIsolatedTestFiles = [
55
"ui/src/app/app-host.server-prefs.test.ts",
66
"ui/src/app/bootstrap.test.ts",
77
"ui/src/app/router-outlet.test.ts",
8+
"ui/src/components/markdown-tables.test.ts",
89
"ui/src/components/resizable-divider.test.ts",
910
"ui/src/components/sidebar-update-card.test.ts",
1011
"ui/src/components/viewer-facepile.test.ts",
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
import { isDesktopPanelAvailable } from "../../app/app-shell-chrome.ts";
2+
import type { ChatPageHost } from "./chat-state-host.ts";
3+
import { createBackgroundTasksProps } from "./components/chat-background-tasks.ts";
4+
import { openTaskDetailId } from "./components/chat-detail-slot.ts";
5+
import { createSessionWorkspaceProps } from "./components/chat-session-workspace.ts";
6+
import {
7+
SIDEBAR_NARROW_BREAKPOINT_PX,
8+
closeSlot,
9+
isSidebarSlotVisible,
10+
openSlot,
11+
type SidebarSlotId,
12+
} from "./sidebar-layout.ts";
13+
14+
type ChatPaneSidebarLayout = Parameters<typeof isSidebarSlotVisible>[0];
15+
type ChatPaneGatewaySnapshot = Parameters<typeof isDesktopPanelAvailable>[0];
16+
17+
/** Builds the two rail models and their shared sidebar slot controls. */
18+
export function createChatPaneRails(params: {
19+
state: ChatPageHost;
20+
sidebarLayout: ChatPaneSidebarLayout;
21+
paneWidth: number;
22+
presentationId: string;
23+
gatewaySnapshot: ChatPaneGatewaySnapshot;
24+
setObserverVisibility: (visible: boolean) => void;
25+
}) {
26+
const { state, sidebarLayout } = params;
27+
const hasPanelSlot = (slot: SidebarSlotId) =>
28+
sidebarLayout.columns[0]?.panels.some((panel) => panel.slot === slot) === true;
29+
const openPanelSlot = (slot: SidebarSlotId) => {
30+
state.updateSidebarLayout(openSlot(state.sidebarLayout, slot));
31+
if (slot === "companion") {
32+
params.setObserverVisibility(true);
33+
}
34+
};
35+
const closePanelSlot = (slot: SidebarSlotId) => {
36+
if (slot === "companion") {
37+
params.setObserverVisibility(false);
38+
}
39+
state.updateSidebarLayout(closeSlot(state.sidebarLayout, slot));
40+
};
41+
const togglePanelSlot = (slot: SidebarSlotId) =>
42+
hasPanelSlot(slot) ? closePanelSlot(slot) : openPanelSlot(slot);
43+
const sessionWorkspaceBase = createSessionWorkspaceProps(state, {
44+
draftScope: params.presentationId,
45+
expanded: hasPanelSlot("workspace"),
46+
narrowLayout: false,
47+
});
48+
const sessionWorkspace = {
49+
...sessionWorkspaceBase,
50+
collapsed: !hasPanelSlot("workspace"),
51+
narrowLayout: false,
52+
onToggleCollapsed: () => togglePanelSlot("workspace"),
53+
onToggleTerminal: state.terminalAvailable ? () => togglePanelSlot("terminal") : undefined,
54+
onToggleBrowser: state.browserPanelAvailable ? () => togglePanelSlot("browser") : undefined,
55+
onToggleDesktop: isDesktopPanelAvailable(params.gatewaySnapshot)
56+
? () => togglePanelSlot("desktop")
57+
: undefined,
58+
};
59+
const backgroundTasksBase = createBackgroundTasksProps(state, {
60+
narrowLayout: false,
61+
openTaskId: openTaskDetailId(state.sidebarContent, sidebarLayout),
62+
onOpenTaskDetail: (task) => state.handleOpenSidebar({ kind: "task", taskId: task.id }),
63+
});
64+
const backgroundTasks = {
65+
...backgroundTasksBase,
66+
collapsed: !hasPanelSlot("tasks"),
67+
narrowLayout: false,
68+
onToggleCollapsed: () => togglePanelSlot("tasks"),
69+
};
70+
const progressCardInRail =
71+
params.paneWidth >= SIDEBAR_NARROW_BREAKPOINT_PX &&
72+
isSidebarSlotVisible(sidebarLayout, "companion");
73+
return {
74+
backgroundTasks,
75+
closePanelSlot,
76+
openPanelSlot,
77+
progressCardInRail,
78+
sessionWorkspace,
79+
};
80+
}

‎ui/src/pages/chat/chat-pane-render.ts‎

Lines changed: 10 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { html, nothing } from "lit";
2-
import { isDesktopPanelAvailable } from "../../app/app-shell-chrome.ts";
32
import { findInlineApproval } from "../../app/approval-presentation.ts";
43
import { hasOperatorAdminAccess, hasOperatorWriteAccess } from "../../app/operator-access.ts";
54
import { cancelQuestionPrompt, submitQuestionPrompt } from "../../app/question-prompt.ts";
@@ -23,6 +22,7 @@ import { clearChatHistory } from "./chat-history.ts";
2322
import { resolveChatMessageAccess } from "./chat-message-access.ts";
2423
import { requiresChatModelSetup } from "./chat-model-setup.ts";
2524
import { ChatPaneLayoutRender } from "./chat-pane-layout-render.ts";
25+
import { createChatPaneRails } from "./chat-pane-rails.ts";
2626
import {
2727
createChatPaneSessionActionCallbacks,
2828
readChatPaneMutationAccess,
@@ -44,24 +44,14 @@ import {
4444
selectedChatSessionRow,
4545
} from "./chat-state-route.ts";
4646
import type { ChatProps } from "./chat-view.ts";
47-
import { createBackgroundTasksProps } from "./components/chat-background-tasks.ts";
48-
import { openTaskDetailId } from "./components/chat-detail-slot.ts";
4947
import { chatPullRequestId, createPullRequestBranch } from "./components/chat-pull-requests.ts";
5048
import {
51-
createSessionWorkspaceProps,
5249
openSessionWorkspaceFile,
5350
revealSessionWorkspaceFile,
5451
} from "./components/chat-session-workspace.ts";
5552
import { activeQueuedMessageEdit } from "./queued-message-edit.ts";
5653
import { hasAbortableSessionRun } from "./run-lifecycle.ts";
5754
import { scheduleChatScroll } from "./scroll.ts";
58-
import {
59-
SIDEBAR_NARROW_BREAKPOINT_PX,
60-
closeSlot,
61-
isSidebarSlotVisible,
62-
openSlot,
63-
type SidebarSlotId,
64-
} from "./sidebar-layout.ts";
6555
import { resolveActiveRunOutputTokens, resolveChatProjectionRunId } from "./tool-stream.ts";
6656
import { configureToolTitleFetcher } from "./tool-titles.ts";
6757
import { workspaceResultConflictFromPlacement } from "./workspace-conflict.ts";
@@ -111,25 +101,6 @@ export class ChatPane extends ChatPaneLayoutRender {
111101
layout: state.sidebarLayout,
112102
paneWidth: this.paneWidth,
113103
});
114-
const hasPanelSlot = (slot: SidebarSlotId) =>
115-
sidebarLayout.columns[0]?.panels.some((panel) => panel.slot === slot) === true;
116-
const progressCardInRail =
117-
this.paneWidth >= SIDEBAR_NARROW_BREAKPOINT_PX &&
118-
isSidebarSlotVisible(sidebarLayout, "companion");
119-
const openPanelSlot = (slot: SidebarSlotId) => {
120-
state.updateSidebarLayout(openSlot(state.sidebarLayout, slot));
121-
if (slot === "companion") {
122-
this.setSessionObserverVisibility(true);
123-
}
124-
};
125-
const closePanelSlot = (slot: SidebarSlotId) => {
126-
if (slot === "companion") {
127-
this.setSessionObserverVisibility(false);
128-
}
129-
state.updateSidebarLayout(closeSlot(state.sidebarLayout, slot));
130-
};
131-
const togglePanelSlot = (slot: SidebarSlotId) =>
132-
hasPanelSlot(slot) ? closePanelSlot(slot) : openPanelSlot(slot);
133104
state.chatFollowUpMode = resolveControlUiFollowUpMode(
134105
state.settings.chatFollowUpMode,
135106
resolveControlUiServerQueueMode(
@@ -223,33 +194,15 @@ export class ChatPane extends ChatPaneLayoutRender {
223194
? t("chat.catalog.remoteViewOnly")
224195
: t("chat.catalog.unsupportedViewOnly")
225196
: null;
226-
const sessionWorkspaceBase = createSessionWorkspaceProps(state, {
227-
draftScope: this.presentationId,
228-
expanded: hasPanelSlot("workspace"),
229-
narrowLayout: false,
230-
});
231-
const sessionWorkspace = {
232-
...sessionWorkspaceBase,
233-
collapsed: !hasPanelSlot("workspace"),
234-
narrowLayout: false,
235-
onToggleCollapsed: () => togglePanelSlot("workspace"),
236-
onToggleTerminal: state.terminalAvailable ? () => togglePanelSlot("terminal") : undefined,
237-
onToggleBrowser: state.browserPanelAvailable ? () => togglePanelSlot("browser") : undefined,
238-
onToggleDesktop: isDesktopPanelAvailable(gatewaySnapshot)
239-
? () => togglePanelSlot("desktop")
240-
: undefined,
241-
};
242-
const backgroundTasksBase = createBackgroundTasksProps(state, {
243-
narrowLayout: false,
244-
openTaskId: openTaskDetailId(state.sidebarContent, sidebarLayout),
245-
onOpenTaskDetail: (task) => state.handleOpenSidebar({ kind: "task", taskId: task.id }),
246-
});
247-
const backgroundTasks = {
248-
...backgroundTasksBase,
249-
collapsed: !hasPanelSlot("tasks"),
250-
narrowLayout: false,
251-
onToggleCollapsed: () => togglePanelSlot("tasks"),
252-
};
197+
const { backgroundTasks, closePanelSlot, openPanelSlot, progressCardInRail, sessionWorkspace } =
198+
createChatPaneRails({
199+
state,
200+
sidebarLayout,
201+
paneWidth: this.paneWidth,
202+
presentationId: this.presentationId,
203+
gatewaySnapshot,
204+
setObserverVisibility: this.setSessionObserverVisibility,
205+
});
253206
const selfUser = resolveCurrentSelfUser({
254207
snapshotUser: gatewaySnapshot.selfUser,
255208
presenceEntries: readPresenceEntries(gatewaySnapshot.hello?.snapshot),

0 commit comments

Comments
 (0)