Beautiful, AI-native markdown IDE and LLM wiki
TypeScript 2nd-brainagent-skillsclaudecodexcompany-braindocsknowledge-knowledge-baseknowledge-managementllmllm-wikillm-wiki-karpathymarkdownmarkdown-editormdmdxnotespkmsecond-brainskills
test: pin Editor focus reveal producers (#6753)
Nick Gomez20ab669ccf76
diff --git a/packages/app/src/components/EditorPane.agents-panel-reload-visibility.dom.test.tsx b/packages/app/src/components/EditorPane.agents-panel-reload-visibility.dom.test.tsxindex b94ca3cf1..47629f211 100644--- a/packages/app/src/components/EditorPane.agents-panel-reload-visibility.dom.test.tsx+++ b/packages/app/src/components/EditorPane.agents-panel-reload-visibility.dom.test.tsx@@ -17,11 +17,13 @@ import {__resetPaneVisibilityStoreForTests,paneVisibilityStore,} from '@/lib/pane-visibility-store';+import { withUsableEditorHeader } from './editor-pane-focus.test-helper';let openThreads: ThreadInfo[] = [];let connectionStatus: 'idle' | 'connecting' | 'open' | 'closed' = 'open';let rosterThreadIds: ReadonlySet<string> | null = null;const storeListeners = new Set<() => void>();+let attachSessionHosts = false;function notifyStore() {for (const listener of storeListeners) listener();@@ -185,6 +187,14 @@ vi.doMock('./EditorArea', () => ({editorRegion: document.createElement('div'),});}, [agentsContainer, terminalContainer, agentsVisible, onSessionPlacements]);+ useEffect(() => {+ if (!attachSessionHosts) return;+ document.body.append(agentsContainer, terminalContainer);+ return () => {+ agentsContainer.remove();+ terminalContainer.remove();+ };+ }, [agentsContainer, terminalContainer]);if (agentsVisible)return (<div data-testid="agents-column">@@ -318,6 +328,7 @@ describe('EditorPane agents-panel reload visibility', () => {afterEach(() => {cleanup();+ attachSessionHosts = false;delete (window as { okDesktop?: unknown }).okDesktop;__resetPaneVisibilityStoreForTests();});@@ -502,6 +513,30 @@ describe('EditorPane agents-panel reload visibility', () => {expect(readPersistedAgentsPanelLevel()).toBe(false);});+ test('web: a user reveal request focuses the empty Agents action from the Editor header', async () => {+ attachSessionHosts = true;+ await renderPane(3);++ await withUsableEditorHeader(async () => {+ act(() => paneVisibilityStore.request('agents', true, 'user'));++ const action = await screen.findByRole('button', { name: 'Start an agent' });+ await waitFor(() => expect(document.activeElement).toBe(action));+ });+ });++ test('web: the Agents menu toggle focuses the empty Agents action from the Editor header', async () => {+ attachSessionHosts = true;+ await renderPane(3);++ await withUsableEditorHeader(async () => {+ act(() => emitLocalMenuAction('toggle-agent-panel'));++ const action = await screen.findByRole('button', { name: 'Start an agent' });+ await waitFor(() => expect(document.activeElement).toBe(action));+ });+ });+test('desktop: a header show during a pending dock restore reads closed first and survives settlement', async () => {const pendingDockState = deferredDockState();const viewMenuStates: Array<Record<string, unknown>> = [];diff --git a/packages/app/src/components/SessionsHost.agents.dom.test.tsx b/packages/app/src/components/SessionsHost.agents.dom.test.tsxindex 9e90afaf6..99b545c51 100644--- a/packages/app/src/components/SessionsHost.agents.dom.test.tsx+++ b/packages/app/src/components/SessionsHost.agents.dom.test.tsx@@ -20,6 +20,7 @@ import type { ThreadRenderModel } from '@/lib/acp/thread-event-model';import type { OkDesktopBridge } from '@/lib/desktop-bridge-types';import { IN_APP_THREAD_ID, saveStickyAgent, terminalCliId } from '@/lib/unified-agent-store';import type { ThreadLaunchIntent } from './EditorPane';+import { withUsableEditorHeader } from './editor-pane-focus.test-helper';import { requestPreferredSession } from './handoff/preferred-session-events';import { requestActiveTerminalInput } from './handoff/terminal-input-events';import { subscribeToTerminalLaunchRequests } from './handoff/terminal-launch-events';@@ -278,17 +279,6 @@ function agentsDockWrites(setDockState: ReturnType<typeof vi.fn>) {);}-function makeUsableEditorHeader(): HTMLButtonElement {- const button = document.body.appendChild(document.createElement('button'));- button.type = 'button';- button.setAttribute('data-header-pane-button', 'editor');- Object.defineProperty(button, 'getClientRects', {- configurable: true,- value: () => [{ width: 1, height: 1 }],- });- return button;-}-function makeTerminalBridge(): OkDesktopBridge {return {terminal: {@@ -1904,18 +1894,13 @@ describe('SessionsHost — agents panel (web / no bridge)', () => {render(<Harness initialVisible initialShowing={false} control={control} />);await screen.findByTestId('sessions-dock-empty');- const outside = makeUsableEditorHeader();- try {- outside.focus();+ await withUsableEditorHeader(async (outside) => {expect(document.activeElement).toBe(outside);-act(() => control.current?.setShowing(true));await act(async () => {});expect(document.activeElement).toBe(outside);- } finally {- outside.remove();- }+ });});test('a user reveal requested before the host mounts still focuses the empty Agents surface', async () => {@@ -1930,36 +1915,31 @@ describe('SessionsHost — agents panel (web / no bridge)', () => {/>,);const action = await screen.findByRole('button', { name: 'Configure agents' });- const outside = makeUsableEditorHeader();- try {- outside.focus();+ await withUsableEditorHeader(async () => {act(() => control.current?.setShowing(true));await waitFor(() => expect(document.activeElement).toBe(action));- } finally {- outside.remove();- }+ });});test('an empty reveal keeps the Editor pane header focused when a session arrives later', async () => {vi.useFakeTimers();const control = makeControl();render(<Harness initialVisible={false} control={control} />);- const outside = makeUsableEditorHeader();try {- outside.focus();- act(() => control.current?.setVisible(true));- expect(screen.getByTestId('sessions-dock-empty')).toBeDefined();- expect(document.activeElement).toBe(outside);+ await withUsableEditorHeader(async (outside) => {+ act(() => control.current?.setVisible(true));+ expect(screen.getByTestId('sessions-dock-empty')).toBeDefined();+ expect(document.activeElement).toBe(outside);- act(() => setOpenThreads([makeThread({ threadId: 'arrived', title: 'Arrived' })]));+ act(() => setOpenThreads([makeThread({ threadId: 'arrived', title: 'Arrived' })]));- expect(screen.getByRole('tab', { name: /Arrived/ })).toBeDefined();- await act(async () => {});- act(() => vi.advanceTimersByTime(5_000));- await act(async () => {});- expect(document.activeElement).toBe(outside);+ expect(screen.getByRole('tab', { name: /Arrived/ })).toBeDefined();+ await act(async () => {});+ act(() => vi.advanceTimersByTime(5_000));+ await act(async () => {});+ expect(document.activeElement).toBe(outside);+ });} finally {- outside.remove();vi.useRealTimers();}});diff --git a/packages/app/src/components/editor-pane-focus.test-helper.ts b/packages/app/src/components/editor-pane-focus.test-helper.tsnew file mode 100644index 000000000..d1297bd64--- /dev/null+++ b/packages/app/src/components/editor-pane-focus.test-helper.ts@@ -0,0 +1,17 @@+export async function withUsableEditorHeader(+ callback: (button: HTMLButtonElement) => void | Promise<void>,+): Promise<void> {+ const button = document.body.appendChild(document.createElement('button'));+ button.type = 'button';+ button.setAttribute('data-header-pane-button', 'editor');+ Object.defineProperty(button, 'getClientRects', {+ configurable: true,+ value: () => [{ width: 1, height: 1 }],+ });+ button.focus();+ try {+ await callback(button);+ } finally {+ button.remove();+ }+}diff --git a/packages/app/tests/stress/header-pane-buttons.e2e.ts b/packages/app/tests/stress/header-pane-buttons.e2e.tsindex ddcc77557..143b2535b 100644--- a/packages/app/tests/stress/header-pane-buttons.e2e.ts+++ b/packages/app/tests/stress/header-pane-buttons.e2e.ts@@ -480,6 +480,23 @@ test.describe('the Agents button follows every chat show/hide path on the web',await expectPaneKeepingFocus(page, 'agents', 'hidden');});+ test('Cmd/Ctrl+L from the narrow Editor header focuses the empty Agents surface', async ({+ page,+ api,+ }) => {+ await openWeb(page, api, 'narrow-keyboard-agents-focus');+ await page.setViewportSize({ width: 767, height: 800 });++ const editorHeader = headerPaneButton(page, 'editor');+ await editorHeader.focus();+ await expect(editorHeader).toBeFocused();++ await page.keyboard.press('ControlOrMeta+l');++ await expectPane(page, 'agents', 'shown');+ await waitForFocusInPane(page, 'agents');+ });+test('Shift+Cmd/Ctrl+J reveals chat and leaves an open chat open', async ({ page, api }) => {await openWeb(page, api, 'new-session');const agentSettings = page.getByTestId('settings-dialog');