Skip to content

Local-first AI coding agent desktop: Electron + Rust host core + pi Agent Harness + user-installable plugins

23.3 KB
Raw Blame
import { readAppSource } from "./helpers/source-contracts.mjs";
import assert from "node:assert/strict";
import { readFile } from "node:fs/promises";
import test from "node:test";
import { loadStyles } from "./helpers/styles.mjs";

const sidebarSource = await readFile(
  new URL("../src/components/Sidebar.tsx", import.meta.url),
  "utf8",
);
const hoverSource = await readFile(
  new URL("../src/features/sessions/SessionHoverCard.tsx", import.meta.url),
  "utf8",
);
const hoverHookSource = await readFile(
  new URL("../src/features/sessions/useSessionHoverCard.ts", import.meta.url),
  "utf8",
);
const globalStyles = await loadStyles();
const appSource = await readAppSource();
const panelSource = await readFile(
  new URL("../src/components/workpanel/WorkPanel.tsx", import.meta.url),
  "utf8",
);
const shortcutSource = await readFile(
  new URL("../../../packages/shared/src/keyboard-shortcuts.ts", import.meta.url),
  "utf8",
);
test("home sidebar exposes only the supported destination entries", async () => {
  const navigationSource = await readFile(
    new URL("../src/components/SidebarNavigation.tsx", import.meta.url),
    "utf8",
  );
  assert.match(sidebarSource, /data-nav="home"/);
  assert.match(sidebarSource, /<SidebarPrimaryNav onNewTask=\{onNewTask\}/);
  assert.match(sidebarSource, /<SidebarFooter \/>/);
  // Top: new task, scheduled, plugin market. Footer: settings + version only.
  const primary = navigationSource.slice(
    navigationSource.indexOf("export function SidebarPrimaryNav"),
    navigationSource.indexOf("export function SidebarFooter"),
  );
  const footer = navigationSource.slice(navigationSource.indexOf("export function SidebarFooter"));
  assert.deepEqual(
    [...primary.matchAll(/data-nav="([^"]+)"/g)].map((match) => match[1]),
    ["new-task", "scheduled", "plugins"],
  );
  assert.deepEqual(
    [...footer.matchAll(/data-nav="([^"]+)"/g)].map((match) => match[1]),
    ["settings", "build"],
  );
  assert.match(primary, /t\("nav\.pluginMarket"\)/);
  assert.match(primary, /usePluginBrowseState\.getState\(\)\.setTab\("market"\)/);
  assert.match(primary, /settings\?\.scheduledTasksEnabled !== false/);
  assert.doesNotMatch(sidebarSource + navigationSource, /data-nav="projects"/);
  assert.doesNotMatch(sidebarSource + navigationSource, /t\("nav\.scheduled"\)/);
});

test("sidebar brand returns to the chat home", () => {
  const brandButton = sidebarSource.match(
    /<TooltipButton\s+type="button"\s+className="brand no-drag"[\s\S]*?<\/TooltipButton>/,
  )?.[0] ?? "";

  assert.match(brandButton, /data-nav="home"/);
  assert.match(brandButton, /ariaLabel=\{t\("nav\.home"\)\}/);
  assert.match(brandButton, /onClick=\{\(\) => setPage\("chat"\)\}/);
  assert.match(brandButton, /<BrandLogo size=\{20\}/);
  assert.match(brandButton, /t\("app\.shellName"\)/);
});

test("sidebar header retains non-mac branding and collapse without a search control", () => {
  const header = sidebarSource.match(
    /<div className="sidebar-header">[\s\S]*?<\/div>\s*<\/div>/,
  )?.[0] ?? "";

  assert.match(header, /className="brand no-drag"/);
  assert.match(header, /className="sidebar-header-actions no-drag"/);
  assert.doesNotMatch(header, /IconSearch/);
  assert.match(header, /<IconSidebar/);
  assert.match(header, /data-nav="toggle-sidebar"/);
  assert.doesNotMatch(appSource, /IconChevronLeft|IconChevronRight/);
});

test("work panel collapse control is the viewport-fixed shell toggle", () => {
  assert.match(appSource, /className="app-work-panel-toggle no-drag"/);
  assert.match(appSource, /collapseWorkPanel\(\)/);
  assert.doesNotMatch(panelSource, /onCollapse/);
  assert.doesNotMatch(panelSource, /work-panel-toolbar-collapse/);
  assert.doesNotMatch(panelSource, /work-panel-collapse/);
  assert.doesNotMatch(panelSource, /collapsePanel/);
  assert.match(
    globalStyles,
    /\.main-titlebar\.work-panel-open\s*\{[^}]*padding-right:\s*0;/s,
  );
  assert.match(
    globalStyles,
    /:root\[data-platform="win32"\] \.main-titlebar\.work-panel-open,[\s\S]*:root\[data-platform="linux"\] \.main-titlebar\.work-panel-open\s*\{[^}]*right:\s*0;/,
  );
  // The reservation is platform-scoped; the base header rule stays neutral.
  assert.doesNotMatch(
    globalStyles,
    /^\.work-panel-header\s*\{[^}]*margin-right:/ms,
  );
});

test("macOS hides sidebar branding and keeps header actions beside traffic lights", () => {
  assert.doesNotMatch(sidebarSource, /sidebar-macos-drag-row/);
  assert.match(
    globalStyles,
    /:root\[data-platform="darwin"\] \.sidebar-header\s*\{[^}]*padding-left:\s*var\(--ds-window-lead-inset\);/s,
  );
  assert.match(
    globalStyles,
    /:root\[data-platform="darwin"\] \.sidebar-header > \.brand\s*\{[^}]*display:\s*none;/s,
  );
  assert.match(
    globalStyles,
    /\.sidebar-header-actions\s*\{[^}]*margin-left:\s*auto;/s,
  );
});

test("destination history is available through shortcuts without titlebar buttons", () => {
  assert.match(shortcutSource, /id: "navigateBack"[\s\S]*?"Mod\+BracketLeft"/);
  assert.match(appSource, /case "navigateBack"/);
  assert.match(appSource, /useAppStore\.getState\(\)\.navBack\(\)/);
  assert.match(shortcutSource, /id: "navigateForward"[\s\S]*?"Mod\+BracketRight"/);
  assert.match(appSource, /case "navigateForward"/);
  assert.match(appSource, /useAppStore\.getState\(\)\.navForward\(\)/);
  assert.doesNotMatch(appSource, /title=\{t\("nav\.(?:back|forward)"\)\}/);
});

test("sidebar shows a bounded Recent session list before retained projects", () => {
  const newProjectAction = sidebarSource.match(
    /<div[\s\S]*?className="sidebar-list-toolbar"[\s\S]*?data-action="new-project"[\s\S]*?<\/div>/,
  )?.[0] ?? "";
  const standaloneSessions = sidebarSource.match(
    /data-sidebar-session-section="temporary"[\s\S]*?<\/section>/,
  )?.[0] ?? "";

  assert.match(newProjectAction, /t\("nav\.projects"\)/);
  assert.match(newProjectAction, /<IconNewProject/);
  assert.match(newProjectAction, /openProjectPicker\(\)/);
  assert.match(standaloneSessions, /t\("nav\.recentSessions"\)/);
  assert.match(standaloneSessions, /data-action="new-standalone-session"/);
  assert.match(standaloneSessions, /createSession\(\{ projectPath: null \}\)/);
  assert.match(standaloneSessions, /renderSessionRows\(visibleRecentSessions, \{ global: true, recent: true \}\)/);
  assert.match(standaloneSessions, /data-action="recent-sessions-load-more"/);
  assert.ok(
    sidebarSource.indexOf('data-sidebar-session-section="temporary"') <
      sidebarSource.indexOf('data-action="new-project"'),
  );
  assert.match(
    globalStyles,
    // `[^}]*`, not `[\s\S]*?`: the assertion must read this block, not a
    // `max-height` in some later partial of the concatenated stylesheet.
    /\.sidebar-session-group-body\.standalone\s*\{[^}]*max-height:\s*291px;[^}]*overflow-x:\s*hidden;[^}]*overflow-y:\s*auto;/,
  );
  assert.doesNotMatch(sidebarSource, /data-sidebar-project-group="temporary"/);
});

test("Recent project labels keep their width ahead of long session titles", () => {
  const recentRows = sidebarSource.match(
    /renderSessionRows\(visibleRecentSessions, \{[^}]*\}\)/,
  )?.[0] ?? "";
  const rowClass = sidebarSource.match(
    /className=\{`thread-item \$\{active[\s\S]*?\n        data-sidebar-session-row/,
  )?.[0] ?? "";
  const projectLabel = sidebarSource.match(
    /<span\s+className="thread-item-project"\s+title=\{options\?\.recent && normalizedProjectPath \? owningProject : undefined\}/,
  )?.[0] ?? "";

  assert.match(recentRows, /recent:\s*true/);
  assert.match(rowClass, /options\?\.recent && normalizedProjectPath/);
  assert.match(projectLabel, /title=\{options\?\.recent && normalizedProjectPath \? owningProject : undefined\}/);
  assert.match(
    globalStyles,
    /\.thread-item\.recent-project-session \.thread-item-project\s*\{[^}]*flex:\s*0 0 auto;/,
  );
  assert.match(
    sidebarSource,
    /renderSessionRows\(pinnedSessions, \{ global: true \}\)/,
    "pinned rows keep their existing presentation path",
  );
  assert.doesNotMatch(recentRows, /temporary:\s*false/);
});

test("sidebar project and session lists stay coordinated with the global type scale", () => {
  assert.match(
    globalStyles,
    /\.thread-item-title\s*\{[^}]*font-size:\s*var\(--text-md\);/s,
  );
  assert.match(
    globalStyles,
    /\.sidebar-session-group-title\s*\{[^}]*font-size:\s*var\(--text-md\);/s,
  );
  assert.match(
    globalStyles,
    /\.sidebar-session-empty\s*\{[^}]*font-size:\s*var\(--text-md\);/s,
  );
});

test("pinned project rows replace the folder glyph with a filled star", () => {
  assert.match(
    sidebarSource,
    /entry\.meta\.pinned \? \([\s\S]*?<IconStar\s+size=\{13\}\s+fill="currentColor"[\s\S]*?className="sidebar-project-pin"[\s\S]*?\) : \([\s\S]*?<IconFolder size=\{13\} aria-hidden \/>/,
  );
  assert.match(
    globalStyles,
    /\.sidebar-project-pin\s*\{[^}]*flex:\s*0 0 auto;[^}]*color:\s*var\(--ds-accent\);/s,
  );
});

test("sidebar section toolbars open create actions from context menus", () => {
  assert.match(sidebarSource, /data-sidebar-section=\"sessions\"/);
  assert.match(sidebarSource, /data-sidebar-section=\"projects\"/);
  assert.match(sidebarSource, /openSectionMenu\(\"sessions\"/);
  assert.match(sidebarSource, /openSectionMenu\(\"projects\"/);
  assert.match(sidebarSource, /className="sidebar-section-menu"/);
  assert.doesNotMatch(sidebarSource, /data-sidebar-section-menu=\{sectionMenu\}/);
  assert.match(sidebarSource, /e\.button === 2/);
  assert.match(sidebarSource, /addEventListener\("pointerdown"/);
});

test("sidebar floating menus stay anchored to triggers and pointer positions", () => {
  const triggerPlacement = sidebarSource.match(
    /const placeMenu = useCallback\([\s\S]*?\n  }, \[\]\);/,
  )?.[0] ?? "";
  const pointPlacement = sidebarSource.match(
    /const placeMenuAtPoint = useCallback\([\s\S]*?\n  }, \[\]\);/,
  )?.[0] ?? "";
  assert.match(sidebarSource, /return portalToBody\(/);
  assert.match(sidebarSource, /<SidebarMenuPanel/);
  assert.match(triggerPlacement, /placeSidebarFloatingMenuTop\(/);
  assert.match(triggerPlacement, /left:\s*Math\.max\(/);
  assert.match(triggerPlacement, /rect\.right \+ 4/);
  assert.match(pointPlacement, /const anchor = \{ top: y, bottom: y \}/);
  assert.match(pointPlacement, /placeSidebarFloatingMenuTop\(/);
  assert.match(pointPlacement, /x \+ 4/);
  assert.match(sidebarSource, /placeMenuAtPoint\(event\.clientX, event\.clientY\)/);
  /* One panel owns every menu, so exactly one surface is ref'd per open. */
  assert.equal((sidebarSource.match(/ref=\{floatingMenuRef\}/g) ?? []).length, 0);
  assert.equal((sidebarSource.match(/menuRef=\{floatingMenuRef\}/g) ?? []).length, 4);
  assert.match(sidebarSource, /new ResizeObserver\(reposition\)/);
  assert.match(sidebarSource, /const position = \{ top: menuPosition\.top, left: menuPosition\.left \}/);
  assert.equal((sidebarSource.match(/position=\{position\}/g) ?? []).length, 4);
});

/*
  The row menus had grown into long flat lists; these assertions keep related
  actions behind hover-opened second-level menus while leaving common actions
  one click away and destructive actions isolated.
*/
test("sidebar row menus expose hover submenus for related actions", () => {
  const sessionMenu = sidebarSource.match(
    /const sessionMenuContent = useCallback\([\s\S]*?\n    \[\n[\s\S]*?\n    \],\n  \);/,
  )?.[0] ?? "";
  const projectMenu = sidebarSource.match(
    /const projectMenuContent = useCallback\([\s\S]*?\n    \[\n[\s\S]*?\n    \],\n  \);/,
  )?.[0] ?? "";
  const sortMenu = sidebarSource.match(
    /const sortMenuContent = useMemo\([\s\S]*?\n    \[displaySessionSort[\s\S]*?\n  \);/,
  )?.[0] ?? "";

  assert.ok(sessionMenu, "session menu content must exist");
  assert.ok(projectMenu, "project menu content must exist");
  assert.ok(sortMenu, "sort menu content must exist");

  /* Destructive actions are nested instead of sharing the root menu. */
  assert.match(sessionMenu, /sidebarMenuSubmenu\(\{[\s\S]*?id: "session-danger"[\s\S]*?id: "delete-session"/);
  assert.match(projectMenu, /sidebarMenuSubmenu\(\{[\s\S]*?id: "project-danger"[\s\S]*?id: "delete-project"/);
  assert.match(sidebarSource, /sidebarMenuSubmenu\(\{[\s\S]*?id: "batch-danger"[\s\S]*?id: "batch-delete"/);
  assert.match(sessionMenu, /id: "batch-archive"|id: "copy-session-link"/);

  /* Related actions open as real second-level menus. */
  assert.match(sessionMenu, /sidebarMenuSubmenu\(\{[\s\S]*?id: "session-git"[\s\S]*?items: gitItems/);
  assert.match(sessionMenu, /id: "session-copy"[\s\S]*?id: "copy-conversation-id"[\s\S]*?id: "copy-session-path"[\s\S]*?id: "copy-session-link"/);
  assert.match(sidebarSource, /api\.getSessionScratchPath\(session\.id\)/);
  assert.match(sessionMenu, /id: "open-session-path"/);
  assert.match(projectMenu, /sidebarMenuSubmenu\(\{[\s\S]*?id: "project-git"[\s\S]*?items: projectIsolationItems/);
  assert.match(projectMenu, /id: "project-copy"[\s\S]*?id: "copy-project-name"[\s\S]*?id: "copy-project-path"/);
  assert.match(projectMenu, /sidebarMenuAction\(\{\s*id: "copy-project-name",\s*label: t\("project\.copyName"\),\s*icon: <IconCopy size=\{14\} \/>,/);
  assert.match(projectMenu, /id: "project-git"[\s\S]*?icon: <IconBranch size=\{14\} \/>/);
  assert.match(projectMenu, /copyTextToClipboard\(entry\.displayPath \?\? entry\.path\)/);

  /* The sort popover is two labelled groups instead of a title plus loose rows. */
  assert.match(sortMenu, /id: "sort"/);
  assert.match(sortMenu, /id: "view"/);
  assert.doesNotMatch(sidebarSource, /className="sidebar-popover-title"/);
  assert.doesNotMatch(sidebarSource, /className="sidebar-popover-divider"/);
});
test("portaled sort menu does not stretch to the viewport edge", () => {
  const basePopoverRule = globalStyles.match(
    /\.sidebar-row-menu,\n\.sidebar-popover\s*\{[^}]*\}/s,
  )?.[0] ?? "";
  const floatingPopoverRule =
    globalStyles.match(/\.sidebar-popover\.sidebar-floating-menu\s*\{[^}]*\}/s)?.[0] ?? "";

  assert.match(basePopoverRule, /position:\s*fixed;/);
  assert.doesNotMatch(basePopoverRule, /position:\s*absolute;/);
  assert.match(basePopoverRule, /max-height:\s*min\(360px,\s*calc\(100vh - 16px\)\);/);
  assert.match(basePopoverRule, /overflow-y:\s*auto;/);
  assert.match(floatingPopoverRule, /top:\s*auto;/);
  assert.match(floatingPopoverRule, /right:\s*auto;/);
  assert.match(globalStyles, /\.sidebar-floating-menu\s*\{[^}]*width:\s*max-content;/s);
  assert.match(globalStyles, /\.sidebar-floating-menu\s*\{[^}]*max-width:\s*calc\(100vw - 16px\);/s);
});

test("sessions toolbar puts sorting before new-session creation", () => {
  const sortIndex = sidebarSource.indexOf('data-action="session-sort"');
  const newSessionIndex = sidebarSource.indexOf('data-action="new-standalone-session"');

  assert.ok(sortIndex >= 0);
  assert.ok(newSessionIndex >= 0);
  assert.ok(sortIndex < newSessionIndex);
});

test("sidebar action icons stay quiet until their toolbar or row is hovered", () => {
  const toolbarButton = globalStyles.match(
    /\.sidebar-toolbar-button\s*\{[^}]+\}/s,
  )?.[0] ?? "";
  assert.match(toolbarButton, /opacity:\s*0/);
  assert.match(
    globalStyles,
    /\.sidebar-list-toolbar:hover \.sidebar-toolbar-button,[\s\S]*?\.sidebar-list-toolbar:focus-within \.sidebar-toolbar-button,[\s\S]*?opacity:\s*1;/,
  );
  assert.match(globalStyles, /\.thread-item:hover \.thread-item-more,/);
  assert.match(
    globalStyles,
    /\.sidebar-session-group-header:hover \.thread-item-more,[\s\S]*?\.sidebar-session-group-header:focus-within \.thread-item-more,/,
  );
  assert.match(
    globalStyles,
    /\.sidebar-session-group-header:hover \.sidebar-session-group-add,[\s\S]*?\.sidebar-session-group-header:focus-within \.sidebar-session-group-add,[\s\S]*?opacity:\s*1;/,
  );
});

test("project rows expose folder actions and full-path hover", () => {
  assert.match(sidebarSource, /id: "open-project-folder"/);
  assert.match(sidebarSource, /api\.openProjectFolder\(entry\.path\)/);
  assert.doesNotMatch(sidebarSource, /data-action="edit-project-instructions"/);
  assert.doesNotMatch(sidebarSource, /<ProjectInstructionsDialog/);
  assert.doesNotMatch(sidebarSource, /data-action="open-session-folder"/);
  assert.doesNotMatch(sidebarSource, /api\.openSessionFolder\(/);
  assert.match(
    sidebarSource,
    /className="sidebar-session-group-title project-toggle"[\s\S]*?tooltip=\{entry\.displayPath \?\? entry\.path\}[\s\S]*?tooltipDelayMs=\{500\}[\s\S]*?aria-describedby=\{`\$\{projectId\}-path-description`\}/,
  );
  assert.match(sidebarSource, /<TooltipButton/);
  assert.match(globalStyles, /\.ui-tooltip-path\s*\{[^}]*width:\s*max-content/);
  assert.match(globalStyles, /\.ui-tooltip-path\s*\{[^}]*max-width:\s*min\(420px,\s*calc\(100vw - 16px\)\)/);
  // The hover text and its accessible description name the path the project
  // really lives at: the remote workspace path for a remote project.
  assert.match(sidebarSource, /className="sr-only">\s*\{entry\.displayPath \?\? entry\.path\}/);
});

test("sidebar row menus omit project reassignment and switching actions", () => {
  assert.doesNotMatch(sidebarSource, /data-action="move-session-to-project"/);
  assert.doesNotMatch(sidebarSource, /t\("nav\.moveToProject"/);
  assert.doesNotMatch(sidebarSource, /t\("project\.switch"/);
  assert.match(
    sidebarSource,
    /if \(!entry\.active && !\(await selectProject\(entry\.path\)\)\) return;/,
  );
});

test("session title buttons use hover cards without native title tooltips", () => {
  const sessionMainStart = sidebarSource.indexOf('className="thread-item-main"');
  const sessionMainEnd = sidebarSource.indexOf(">\n          {sessionPinned", sessionMainStart);
  const sessionMain = sessionMainStart >= 0 && sessionMainEnd >= 0
    ? sidebarSource.slice(sessionMainStart, sessionMainEnd)
    : "";

  assert.match(sessionMain, /showSessionHoverCard\(/);
  assert.doesNotMatch(sessionMain, /\btitle=\{/);
  assert.match(hoverSource, /className="sidebar-session-hover-card selectable"/);
  assert.match(hoverSource, /className="sidebar-session-hover-card-title"/);
  assert.match(sessionMain, /onFocusCapture=/);
  assert.match(sessionMain, /aria-describedby=/);
  assert.match(hoverHookSource, /\}, 500\)/);
  assert.match(hoverHookSource, /event\.key === "Escape"/);
  assert.match(hoverHookSource, /addEventListener\("scroll", hide, true\)/);
  assert.match(hoverHookSource, /addEventListener\("visibilitychange", onVisibility\)/);
});

test("session hover cards expose readable models and keyboard-navigable session links", () => {
  assert.match(hoverSource, /role="dialog"/);
  assert.match(hoverSource, /summary\?\.modelName \|\| summary\?\.providerName/);
  assert.doesNotMatch(hoverSource, /modelKey\?\.includes\("\/"\)/);
  assert.doesNotMatch(hoverSource, /sidebar-session-hover-card-id/);
  assert.doesNotMatch(hoverSource, /sessionCollaboration\.checkedAt/);
  assert.doesNotMatch(hoverSource, /sessionCollaboration\.provider/);
  assert.doesNotMatch(hoverSource, /nav\.hoverCardLocalTask/);
  assert.match(hoverSource, /data-session-link=\{summary\.createdBySession\.sessionId\}/);
  assert.match(hoverSource, /summary\.createdSessions\.slice\(0, 8\)/);
  assert.match(hoverSource, /type="button"/);
  assert.match(hoverSource, /onClick=\{\(\) => openSessionReference/);
  assert.match(hoverSource, /useHoverCardSelection\(elementRef, keepVisible, scheduleHide, registerDismissGuard\)/);
  assert.match(hoverHookSource, /setTimeout\(\(\) => \{[\s\S]*?hide\(\);[\s\S]*?\}, 160\)/);
  assert.match(globalStyles, /\.sidebar-session-hover-card\s*\{[\s\S]*?pointer-events:\s*auto;/);
  assert.match(globalStyles, /\.sidebar-session-hover-card-session-link:focus-visible\s*\{[\s\S]*?outline:/);
});

test("related session links show only active running state", () => {
  assert.match(sidebarSource, /<SessionHoverCard[\s\S]*?runningSessions=\{runningSessions\}/);
  assert.match(sidebarSource, /<SessionHoverCard[\s\S]*?pendingPermissions=\{pendingPermissions\}/);
  assert.match(hoverSource, /sessionReferenceIsRunning\(reference, runningSessions, pendingPermissions\)/);
  assert.match(hoverSource, /data-session-running="true"/);
  assert.match(globalStyles, /\.sidebar-session-hover-card-session-link-status\s*\{[\s\S]*?--ds-warning/);
  assert.match(globalStyles, /\.sidebar-session-hover-card-session-link-status::before\s*\{[\s\S]*?sidebar-status-breathe/);
});

test("hidden row actions stay out of the row's click path", () => {
  // Resting state: the invisible control is not a pointer target at all.
  assert.match(
    globalStyles,
    /\.thread-item-more\s*\{[^}]*opacity:\s*0;[^}]*pointer-events:\s*none;[^}]*\}/s,
  );
  assert.match(
    globalStyles,
    /\.thread-item:hover \.thread-item-more,\s*\n\.thread-item:focus-within \.thread-item-more,[\s\S]*?\{[^}]*pointer-events:\s*auto;/s,
  );
  assert.match(
    globalStyles,
    /\.thread-item-more:focus-visible\s*\{[^}]*opacity:\s*1;[^}]*pointer-events:\s*auto;/s,
  );
  // Without hover there is no reveal, so a no-hover pointer gets the controls
  // visible and tappable instead of an invisible gutter.
  assert.match(
    globalStyles,
    /@media \(hover: none\)\s*\{[\s\S]*?\.thread-item-meta \.thread-item-more,[\s\S]*?opacity:\s*1;\s*\n\s*pointer-events:\s*auto;/,
  );
  // The row itself stays clickable where the hidden control used to swallow
  // the click, and spelled-out controls never double-fire the row.
  assert.match(sidebarSource, /if \(target\?\.closest\("button, \[data-action\]"\)\) return;/);
  assert.match(sidebarSource, /className=\{`thread-item[\s\S]*?onClick=\{\(event\) => \{/);
});

test("a blurred window releases latched row hover and actions", () => {
  assert.match(sidebarSource, /const \[windowFocused, setWindowFocused\] = useState\(true\)/);
  assert.match(sidebarSource, /window\.addEventListener\("focus", onWindowFocus\)/);
  assert.match(sidebarSource, /window\.addEventListener\("blur", onWindowBlur\)/);
  assert.match(sidebarSource, /data-window-blur=\{windowFocused \? undefined : "true"\}/);
  assert.match(
    globalStyles,
    /\.sidebar\[data-window-blur="true"\] \.thread-item:hover:not\(\.active\),\s*\.sidebar\[data-window-blur="true"\] \.project-group:not\(\.is-drop-target\) > \.sidebar-session-group-header:hover\s*\{[^}]*background:\s*transparent;/s,
  );
  assert.match(
    globalStyles,
    /\.sidebar\[data-window-blur="true"\] \.thread-item:hover \.thread-item-more:not\(\[aria-expanded="true"\]\),[\s\S]*?opacity:\s*0;\s*\n\s*pointer-events:\s*none;/,
  );
});

test("sidebar rows share one hover surface and workspace context never paints selection", () => {
  assert.match(
    globalStyles,
    /\.thread-item,\s*\.sidebar-session-group-header\s*\{[^}]*border-radius:\s*var\(--radius-sm\);[^}]*transition:/,
  );
  assert.match(
    globalStyles,
    /\.thread-item:hover,\s*\.thread-item.active,\s*\.project-group > \.sidebar-session-group-header:hover\s*\{[^}]*background:\s*var\(--ds-bg-hover\);/,
  );
  assert.match(globalStyles, /\.thread-item.active\s*\{[^}]*background:\s*var\(--ds-bg-active\);/);
  assert.match(globalStyles, /\.sidebar-session-group-title\s*\{[^}]*background:\s*transparent;[^}]*color:\s*inherit;/);
  assert.doesNotMatch(globalStyles, /\.project-group\.active/);
  assert.doesNotMatch(globalStyles, /\.sidebar-session-group-title\.project-toggle:hover/);
  assert.match(sidebarSource, /data-current-workspace=\{entry\.active \? "true" : undefined\}/);
  assert.match(globalStyles, /:focus-visible\s*\{[^}]*outline:\s*1\.5px solid/);
  assert.match(globalStyles, /\.project-group\.is-drop-target > \.sidebar-session-group-header\s*\{[^}]*outline:[^}]*background:/);
  assert.match(globalStyles, /@media \(prefers-reduced-motion: reduce\)\s*\{[\s\S]*?\.thread-item,\s*\.sidebar-session-group-header\s*\{\s*transition-duration:\s*0\.01ms !important;/);
});