Skip to content

Beautiful, AI-native markdown IDE and LLM wiki

fix(ok): deliver menu actions sent before the first render (PRD-8245) (#3784)

Andrew Mikofalvya6f34df8dc61
diff --git a/.changeset/menu-action-before-first-render.md b/.changeset/menu-action-before-first-render.md
new file mode 100644
index 000000000..2581d4c38
--- /dev/null
+++ b/.changeset/menu-action-before-first-render.md
@@ -0,0 +1,7 @@
+---
+"@inkeep/open-knowledge": patch
+---
+
+A menu item chosen while a window is still opening now takes effect once the window is ready, instead of doing nothing. Toggling the terminal, the sidebar or the agent panel during launch, by menu or by keyboard shortcut, could be silently discarded: the menu bar is live from the moment the window appears, but the part of the window that listens for menu commands only starts listening after the first frame is drawn, and anything sent in between was dropped with no error and no retry. On a cold or busy machine that gap is seconds wide, which is exactly when someone reaches for a shortcut.
+
+Commands that arrive early are now held and applied the moment the window can act on them, with two deliberate limits. Pressing the same show-or-hide shortcut repeatedly during that gap counts as one request rather than several, so pressing it twice because nothing happened opens the terminal instead of opening and immediately closing it. And commands that destroy something, closing a tab or window, killing a terminal, deleting or trashing a file, are never held: what they act on is decided when they run, so applying one late would aim it at whatever happens to be selected by then rather than at what you were looking at when you pressed it.
diff --git a/packages/desktop/src/preload/index.ts b/packages/desktop/src/preload/index.ts
index 3fd702b62..a6baa7497 100644
--- a/packages/desktop/src/preload/index.ts
+++ b/packages/desktop/src/preload/index.ts
@@ -300,6 +300,146 @@ ipcRenderer.on('ok:accessibility:changed', (_event, info: { screenReaderActive:
screenReaderActive = info.screenReaderActive === true;
});
+/**
+ * Menu actions that arrive before the renderer has a listener are QUEUED, not
+ * dropped.
+ *
+ * The menu lives in main and is live from the moment the window opens, but the
+ * renderer's listener is not: `local-menu-action-bus` installs its single
+ * `onMenuAction` forwarder lazily, when the first component subscribes — which
+ * is inside a React effect, so only after the first commit. Between window
+ * open and that commit there is a real window, seconds wide on a cold or
+ * loaded machine, in which main pushes `ok:menu-action` at a renderer that has
+ * never called `ipcRenderer.on`. The event lands on no listener and is gone,
+ * so a user who hits CmdOrCtrl+J during launch watches the terminal not open.
+ *
+ * The preload runs before any renderer script, so subscribing HERE cannot miss
+ * anything; buffer until someone attaches, then replay in order.
+ *
+ * Sibling pattern, deliberately not reused: `registerPendingDelivery`
+ * (`shared/ipc-send.ts`) closes the same race for ONE-SHOT events (deep-link,
+ * share-received) by gating a single send on `dom-ready` in main. Menu actions
+ * are recurring and user-triggered, with no payload known before load, so they
+ * need a standing buffer on the renderer side rather than a deferred send.
+ *
+ * Bounded because a window type that never subscribes can still be main's
+ * chosen target (`resolveMenuActionTarget` falls back to the focused window,
+ * then the first one). Past the cap the OLDEST intent is dropped — the newest
+ * is the one the user is still waiting on.
+ */
+const MAX_BUFFERED_MENU_ACTIONS = 32;
+
+/**
+ * How each action behaves when it arrives with nobody listening.
+ *
+ * `never-buffer` DESTROYS something a second press cannot get back. What these
+ * act on is resolved when they RUN (the active tab, the selected file), so
+ * replaying one after the window finally mounts aims it at whatever is selected
+ * then rather than at what the user was looking at when they pressed. Dropping
+ * an early `kill-terminal` costs a keystroke; honoring it late can cost a
+ * session.
+ *
+ * `parity` means a FLIP rather than a count. While buffered the user gets no
+ * feedback at all, so a repeated press is the same intent restated ("open,
+ * please"), not a request to open and then close — replaying both would land
+ * the terminal shut, which is the complaint that motivated this whole fix.
+ * Collapsed only against the immediately preceding entry, so an interleaved
+ * A,B,A stays three distinct intents.
+ *
+ * `additive` keeps exact multiplicity: two presses of `new-terminal` mean two
+ * terminals.
+ *
+ * A total Record rather than a pair of Sets, because `ReadonlySet<OkMenuAction>`
+ * accepts any subset including the empty one: a new union member would compile
+ * clean and land in the replay-verbatim bucket, which is exactly what must not
+ * happen to a future destructive action. This shape fails the typecheck until
+ * someone classifies it. Same reasoning as `OK_MENU_ACTIONS`' drift guard in
+ * the app package, one step stronger — that one detects omission, this one
+ * refuses to build without a decision.
+ */
+type MenuActionBufferPolicy = 'never-buffer' | 'parity' | 'additive';
+
+const MENU_ACTION_BUFFER_POLICY: Record<OkMenuAction, MenuActionBufferPolicy> = {
+ delete: 'never-buffer',
+ 'move-to-trash': 'never-buffer',
+ 'close-active-tab-or-window': 'never-buffer',
+ 'kill-terminal': 'never-buffer',
+
+ 'toggle-sidebar': 'parity',
+ 'toggle-source': 'parity',
+ 'toggle-doc-panel': 'parity',
+ 'toggle-terminal': 'parity',
+ 'toggle-agent-panel': 'parity',
+ 'toggle-show-hidden-files': 'parity',
+ 'toggle-show-ok-folders': 'parity',
+ 'toggle-show-only-markdown-files': 'parity',
+ 'toggle-show-skills-section': 'parity',
+ 'move-terminal': 'parity',
+
+ 'new-doc': 'additive',
+ 'new-folder': 'additive',
+ 'new-project': 'additive',
+ rename: 'additive',
+ 'save-version': 'additive',
+ 'version-history': 'additive',
+ 'focus-search': 'additive',
+ 'focus-command-palette': 'additive',
+ 'navigate-back': 'additive',
+ 'navigate-forward': 'additive',
+ 'new-from-template': 'additive',
+ duplicate: 'additive',
+ 'reveal-in-finder': 'additive',
+ 'send-to-ai': 'additive',
+ 'copy-full-path': 'additive',
+ 'copy-relative-path': 'additive',
+ 'expand-all-tree': 'additive',
+ 'collapse-all-tree': 'additive',
+ 'new-terminal': 'additive',
+ 'new-worktree': 'additive',
+ 'switch-worktree': 'additive',
+ 'report-bug': 'additive',
+ 'send-feedback': 'additive',
+};
+
+const menuActionListeners = new Set<(action: OkMenuAction) => void>();
+/**
+ * Fan one action out, isolating subscriber faults. A throwing listener must not
+ * starve the ones after it, and in the replay path it must not take the rest of
+ * the batch with it — that batch is already spliced out of the queue, so an
+ * escaping throw would silently discard intents the buffer promised to deliver.
+ * Same contract the renderer-side bus keeps for its own subscribers.
+ */
+function deliverMenuAction(action: OkMenuAction): void {
+ for (const listener of menuActionListeners) {
+ try {
+ listener(action);
+ } catch (err) {
+ console.error('[preload:menu-action] listener threw during dispatch:', err);
+ }
+ }
+}
+
+const bufferedMenuActions: OkMenuAction[] = [];
+
+// biome-ignore lint/plugin/no-loosely-typed-webcontents-ipc: preload-side subscription wrapper (precedent #14)
+ipcRenderer.on('ok:menu-action', (_event, action: OkMenuAction) => {
+ if (menuActionListeners.size > 0) {
+ deliverMenuAction(action);
+ return;
+ }
+ const policy = MENU_ACTION_BUFFER_POLICY[action];
+ if (policy === 'never-buffer') {
+ // The one drop worth a trace: a user who pressed it saw nothing happen and
+ // may well report that. The parity collapse below is the designed common
+ // path and would log on every repeated keypress, so it stays quiet.
+ console.debug('[preload:menu-action] destructive action dropped, nothing listening:', action);
+ return;
+ }
+ if (policy === 'parity' && bufferedMenuActions.at(-1) === action) return;
+ if (bufferedMenuActions.length >= MAX_BUFFERED_MENU_ACTIONS) bufferedMenuActions.shift();
+ bufferedMenuActions.push(action);
+});
+
const bridge: OkDesktopBridge = {
config: readConfigFromArgv(),
@@ -313,10 +453,31 @@ const bridge: OkDesktopBridge = {
},
onMenuAction(cb: (action: OkMenuAction) => void) {
- const listener = (_event: IpcRendererEvent, action: OkMenuAction) => cb(action);
- // biome-ignore lint/plugin/no-loosely-typed-webcontents-ipc: preload-side subscription wrapper (precedent #14)
- ipcRenderer.on('ok:menu-action', listener);
- return () => ipcRenderer.removeListener('ok:menu-action', listener);
+ // The `ipcRenderer.on` for this channel is permanent and lives at module
+ // scope (see the buffering block above), so subscribing is set membership.
+ const wasUnlistened = menuActionListeners.size === 0;
+ menuActionListeners.add(cb);
+ if (wasUnlistened && bufferedMenuActions.length > 0) {
+ const replay = bufferedMenuActions.splice(0, bufferedMenuActions.length);
+ // Drained on a microtask, not inline: the caller is `subscribeLocalMenuAction`
+ // running inside a React effect, and dispatching synchronously would run
+ // subscriber handlers — which set state — before that effect has returned
+ // its cleanup.
+ queueMicrotask(() => {
+ // The set can empty again in the microtask hop (a subscriber that
+ // attaches and detaches within one turn). Put the batch back rather
+ // than dropping it: "queued or delivered, never lost" is the whole
+ // contract, and a silent loss here is the bug this block exists for.
+ if (menuActionListeners.size === 0) {
+ bufferedMenuActions.unshift(...replay);
+ return;
+ }
+ for (const action of replay) deliverMenuAction(action);
+ });
+ }
+ return () => {
+ menuActionListeners.delete(cb);
+ };
},
onUpdateDownloaded(cb: (info: OkUpdateDownloadedInfo) => void) {
diff --git a/packages/desktop/src/preload/menu-action-buffer.test.ts b/packages/desktop/src/preload/menu-action-buffer.test.ts
new file mode 100644
index 000000000..f32ac2a7e
--- /dev/null
+++ b/packages/desktop/src/preload/menu-action-buffer.test.ts
@@ -0,0 +1,274 @@
+/**
+ * Menu actions must survive the gap between window-open and first render.
+ *
+ * The menu lives in main and is live the instant the window exists. The
+ * renderer's listener is not: `local-menu-action-bus` installs its single
+ * `onMenuAction` forwarder lazily, on first subscribe, which happens inside a
+ * React effect — so only after the first commit. Between those two moments
+ * main will happily push `ok:menu-action` at a renderer that has never called
+ * `ipcRenderer.on`, and an Electron IPC event with no listener is not delayed
+ * or retried, it is gone. The user-visible shape is CmdOrCtrl+J during launch
+ * doing nothing at all.
+ *
+ * It stays invisible in the desktop smoke suite because `revealTerminalSurface`
+ * re-clicks the menu item until the panel appears, which turns a dropped action
+ * into a merely slow one. It surfaced instead in the one smoke test that cannot
+ * retry — the toggle-latency test in `terminal-dock.e2e.ts` — as a bare 5s
+ * `waitForSelector` timeout against an app that was otherwise healthy.
+ *
+ * These tests drive the preload's real `ok:menu-action` handler directly.
+ */
+
+import { beforeEach, describe, expect, it, vi } from 'vitest';
+
+type IpcListener = (event: unknown, ...args: unknown[]) => void;
+
+const exposed = new Map<string, Record<string, unknown>>();
+const channelListeners = new Map<string, Set<IpcListener>>();
+
+vi.mock('electron', () => ({
+ contextBridge: {
+ exposeInMainWorld: (key: string, value: Record<string, unknown>) => {
+ exposed.set(key, value);
+ },
+ },
+ ipcRenderer: {
+ invoke: () => Promise.resolve({ ok: true }),
+ on: (channel: string, listener: IpcListener) => {
+ const set = channelListeners.get(channel) ?? new Set<IpcListener>();
+ set.add(listener);
+ channelListeners.set(channel, set);
+ },
+ removeListener: (channel: string, listener: IpcListener) => {
+ channelListeners.get(channel)?.delete(listener);
+ },
+ send: () => {},
+ },
+ webUtils: { getPathForFile: () => '' },
+}));
+
+type MenuBridge = {
+ onMenuAction(cb: (action: string) => void): () => void;
+};
+
+async function loadBridge(): Promise<MenuBridge> {
+ exposed.clear();
+ channelListeners.clear();
+ vi.resetModules();
+ await import('./index.ts');
+ const bridge = exposed.get('okDesktop');
+ if (bridge === undefined) throw new Error('preload did not expose okDesktop');
+ return bridge as unknown as MenuBridge;
+}
+
+/** Push one `ok:menu-action` exactly as main does. */
+function pushMenuAction(action: string): void {
+ const listeners = channelListeners.get('ok:menu-action');
+ if (listeners === undefined || listeners.size === 0) {
+ throw new Error(
+ 'the preload registered no ok:menu-action listener at load — a menu action arriving before the renderer subscribes would be dropped',
+ );
+ }
+ for (const listener of listeners) listener({}, action);
+}
+
+/** Let the replay microtask run. */
+const settle = () => new Promise<void>((resolve) => queueMicrotask(resolve));
+
+beforeEach(() => {
+ exposed.clear();
+ channelListeners.clear();
+});
+
+describe('preload menu-action delivery', () => {
+ it('subscribes to the channel at load, before any renderer code runs', async () => {
+ await loadBridge();
+
+ // The whole fix: the listener exists without anyone having called
+ // `onMenuAction`. Registering it lazily is what loses the early action.
+ expect(channelListeners.get('ok:menu-action')?.size ?? 0).toBeGreaterThan(0);
+ });
+
+ it('replays an action that arrived before the renderer subscribed', async () => {
+ const bridge = await loadBridge();
+ pushMenuAction('toggle-terminal');
+
+ const seen: string[] = [];
+ bridge.onMenuAction((action) => seen.push(action));
+ // Pinned, not incidental: the drain is deferred a turn so it cannot re-enter
+ // the React effect that is still running `subscribeLocalMenuAction`. Without
+ // this line a synchronous drain would pass every other assertion here.
+ expect(seen).toEqual([]);
+ await settle();
+
+ expect(seen).toEqual(['toggle-terminal']);
+ });
+
+ it('replays several early actions in the order they arrived', async () => {
+ const bridge = await loadBridge();
+ pushMenuAction('toggle-sidebar');
+ pushMenuAction('toggle-terminal');
+ pushMenuAction('new-terminal');
+
+ const seen: string[] = [];
+ bridge.onMenuAction((action) => seen.push(action));
+ await settle();
+
+ expect(seen).toEqual(['toggle-sidebar', 'toggle-terminal', 'new-terminal']);
+ });
+
+ it('delivers live actions straight through once a subscriber is attached', async () => {
+ const bridge = await loadBridge();
+ const seen: string[] = [];
+ bridge.onMenuAction((action) => seen.push(action));
+
+ pushMenuAction('toggle-terminal');
+
+ // No queue hop for the ordinary path — a menu click must land in the same
+ // turn it arrives, exactly as it did before any buffering existed.
+ expect(seen).toEqual(['toggle-terminal']);
+ });
+
+ it('fans a live action out to every subscriber', async () => {
+ const bridge = await loadBridge();
+ const first: string[] = [];
+ const second: string[] = [];
+ bridge.onMenuAction((action) => first.push(action));
+ bridge.onMenuAction((action) => second.push(action));
+
+ pushMenuAction('toggle-doc-panel');
+
+ expect(first).toEqual(['toggle-doc-panel']);
+ expect(second).toEqual(['toggle-doc-panel']);
+ });
+
+ it('does not replay the backlog to a second subscriber', async () => {
+ const bridge = await loadBridge();
+ pushMenuAction('toggle-terminal');
+
+ const first: string[] = [];
+ bridge.onMenuAction((action) => first.push(action));
+ await settle();
+
+ const second: string[] = [];
+ bridge.onMenuAction((action) => second.push(action));
+ await settle();
+
+ // The intent was already honored. Handing it to the next component to
+ // mount would toggle the terminal back off.
+ expect(first).toEqual(['toggle-terminal']);
+ expect(second).toEqual([]);
+ });
+
+ it('stops delivering to an unsubscribed callback', async () => {
+ const bridge = await loadBridge();
+ const seen: string[] = [];
+ const unsubscribe = bridge.onMenuAction((action) => seen.push(action));
+
+ unsubscribe();
+ pushMenuAction('toggle-terminal');
+ await settle();
+
+ expect(seen).toEqual([]);
+ });
+
+ it('never queues an action that destroys something', async () => {
+ const bridge = await loadBridge();
+ // What these act on is resolved when they RUN, so a late replay aims at
+ // whatever is selected by then rather than at what the user was looking at.
+ pushMenuAction('kill-terminal');
+ pushMenuAction('close-active-tab-or-window');
+ pushMenuAction('delete');
+ pushMenuAction('move-to-trash');
+
+ const seen: string[] = [];
+ bridge.onMenuAction((action) => seen.push(action));
+ await settle();
+
+ expect(seen).toEqual([]);
+ });
+
+ it('still delivers a destructive action live', async () => {
+ const bridge = await loadBridge();
+ const seen: string[] = [];
+ bridge.onMenuAction((action) => seen.push(action));
+
+ pushMenuAction('kill-terminal');
+
+ // Only the QUEUE refuses them; a live press must still work.
+ expect(seen).toEqual(['kill-terminal']);
+ });
+
+ it('collapses a repeated parity toggle into the one intent it expresses', async () => {
+ const bridge = await loadBridge();
+ // Pressing CmdOrCtrl+J three times because nothing happened means "open",
+ // not "open, close, open". Replaying all three would leave it shut.
+ pushMenuAction('toggle-terminal');
+ pushMenuAction('toggle-terminal');
+ pushMenuAction('toggle-terminal');
+
+ const seen: string[] = [];
+ bridge.onMenuAction((action) => seen.push(action));
+ await settle();
+
+ expect(seen).toEqual(['toggle-terminal']);
+ });
+
+ it('keeps a parity toggle that is interleaved with another', async () => {
+ const bridge = await loadBridge();
+ pushMenuAction('toggle-terminal');
+ pushMenuAction('toggle-sidebar');
+ pushMenuAction('toggle-terminal');
+
+ const seen: string[] = [];
+ bridge.onMenuAction((action) => seen.push(action));
+ await settle();
+
+ // Three distinct intents: only an immediately repeated press is a restatement.
+ expect(seen).toEqual(['toggle-terminal', 'toggle-sidebar', 'toggle-terminal']);
+ });
+
+ it('keeps every repeat of an additive action', async () => {
+ const bridge = await loadBridge();
+ pushMenuAction('new-terminal');
+ pushMenuAction('new-terminal');
+
+ const seen: string[] = [];
+ bridge.onMenuAction((action) => seen.push(action));
+ await settle();
+
+ // Two presses of "new terminal" mean two terminals.
+ expect(seen).toEqual(['new-terminal', 'new-terminal']);
+ });
+
+ it('keeps the backlog when the only subscriber leaves before the replay lands', async () => {
+ const bridge = await loadBridge();
+ pushMenuAction('toggle-terminal');
+
+ // Attach and detach inside one turn: the replay microtask finds no listener.
+ bridge.onMenuAction(() => {})();
+ await settle();
+
+ const seen: string[] = [];
+ bridge.onMenuAction((action) => seen.push(action));
+ await settle();
+
+ // Queued or delivered, never lost.
+ expect(seen).toEqual(['toggle-terminal']);
+ });
+
+ it('bounds the backlog, keeping the newest intents', async () => {
+ const bridge = await loadBridge();
+ // A window type that never subscribes can still be main's chosen target,
+ // so the queue must not grow without limit.
+ for (let index = 0; index < 40; index += 1) pushMenuAction(`action-${index}`);
+
+ const seen: string[] = [];
+ bridge.onMenuAction((action) => seen.push(action));
+ await settle();
+
+ expect(seen).toHaveLength(32);
+ expect(seen.at(0)).toBe('action-8');
+ expect(seen.at(-1)).toBe('action-39');
+ });
+});
diff --git a/packages/desktop/tests/smoke/terminal-dock.e2e.ts b/packages/desktop/tests/smoke/terminal-dock.e2e.ts
index 3819fa92a..20aa0c231 100644
--- a/packages/desktop/tests/smoke/terminal-dock.e2e.ts
+++ b/packages/desktop/tests/smoke/terminal-dock.e2e.ts
@@ -195,11 +195,20 @@ async function findEditorWindow(app: ElectronApplication, timeoutMs = 25_000): P
return page;
}
+/**
+ * `editorPage` lets a caller that already holds the editor window skip the
+ * rediscovery poll. That poll is not free: it re-evaluates
+ * `window.okDesktop.config.mode` in the renderer, so it costs whatever the
+ * renderer's main thread is busy with — measured at ~400ms on a loaded CI
+ * runner. Any caller TIMING this dispatch must pass the page, or it charges
+ * the app for the harness's own round trip.
+ */
async function dispatchRendererMenuAction(
app: ElectronApplication,
action: 'move-terminal' | 'toggle-agent-panel' | 'toggle-terminal',
+ editorPage?: Page,
): Promise<void> {
- const page = await findEditorWindow(app);
+ const page = editorPage ?? (await findEditorWindow(app));
await page.evaluate(async (menuAction) => {
const menu = window.okDesktop?.menu;
if (!menu) throw new Error('renderer menu bridge is unavailable');
@@ -208,8 +217,9 @@ async function dispatchRendererMenuAction(
}
/** Click the View → Show/Hide Terminal application-menu item (real toggle path
- * on desktop — CmdOrCtrl+J is its OS-captured accelerator). Returns the item label. */
-async function clickViewTerminalItem(app: ElectronApplication): Promise<string> {
+ * on desktop — CmdOrCtrl+J is its OS-captured accelerator). Returns the item label.
+ * Pass `editorPage` when timing the toggle; see `dispatchRendererMenuAction`. */
+async function clickViewTerminalItem(app: ElectronApplication, editorPage?: Page): Promise<string> {
const label = await app.evaluate(async ({ Menu }) => {
const menu = Menu.getApplicationMenu();
if (!menu) throw new Error('application menu is unavailable');
@@ -222,7 +232,8 @@ async function clickViewTerminalItem(app: ElectronApplication): Promise<string>
if (process.platform === 'darwin') item.click();
return label;
});
- if (process.platform !== 'darwin') await dispatchRendererMenuAction(app, 'toggle-terminal');
+ if (process.platform !== 'darwin')
+ await dispatchRendererMenuAction(app, 'toggle-terminal', editorPage);
return label;
}
@@ -302,12 +313,106 @@ const terminalStatus = (page: Page) => page.locator('[data-terminal-status]');
// strict mode. Scope the claude-readiness banner by its stable test seam instead.
const readinessBanner = (page: Page) => page.getByTestId('terminal-readiness-banner');
+/**
+ * Hold until the renderer's main thread is answering promptly.
+ *
+ * `findEditorWindow` resolves as soon as PRELOAD answers, which is seconds
+ * ahead of a renderer that has committed its first render. Driving a menu
+ * action into that gap is what makes this whole family time-dependent: the
+ * dispatch, the state flip and the mount are all serviced by the one thread
+ * that is still booting. An idle renderer answers a round-trip in single-digit
+ * ms, so 100ms is slack rather than a budget; three in a row rules out
+ * catching a gap between two chunks of boot work.
+ */
+async function waitForRendererResponsive(page: Page): Promise<void> {
+ await expect(async () => {
+ for (let probe = 0; probe < 3; probe += 1) {
+ const startedAt = Date.now();
+ await page.evaluate(() => performance.now());
+ expect(Date.now() - startedAt).toBeLessThan(100);
+ }
+ // 15s: the measured worst case for a loaded CI runner to reach a settled
+ // renderer is under 5s. Past 15s the app is not slow, it is broken — and
+ // failing HERE names that, instead of surfacing as a puzzling downstream
+ // timeout.
+ }).toPass({ timeout: 15_000, intervals: [250] });
+}
+
+/**
+ * Widen the editor window and PROVE the width stuck.
+ *
+ * The rail tests below assert a layout the app only owes at the width they ask
+ * for, so the width is a precondition rather than setup. `setSize` past the
+ * display's work area is honored in the renderer for a beat and then clamped
+ * back, and a bare `innerWidth >= n` poll happily catches that beat — after
+ * which the assertions measure a narrower window and blame the app. On a 1512pt
+ * laptop that reads as the right terminal column resolving to its 324px drag
+ * floor instead of its 740px preferred width, which is CORRECT behavior for the
+ * window it actually had.
+ *
+ * So: sample until the width settles, then check it settled where it was asked
+ * to. A display that cannot hold the window SKIPS, the same way the suite skips
+ * a platform without a PTY — it is a fact about the machine, not a verdict on
+ * the app, and CI runners are wide enough that the coverage stays real. A
+ * display that COULD have held it and did not FAILS, because that is the app
+ * mis-sizing its own window and a skip would bury it.
+ */
+async function widenEditorWindow(
+ app: ElectronApplication,
+ page: Page,
+ width: number,
+ height: number,
+): Promise<void> {
+ const editorWindow = await app.browserWindow(page);
+ await editorWindow.evaluate(
+ (win: unknown, size) => {
+ (win as { setSize: (w: number, h: number, animate: boolean) => void }).setSize(
+ size.width,
+ size.height,
+ false,
+ );
+ },
+ { width, height },
+ );
+
+ let settled = 0;
+ let previous = Number.NaN;
+ await expect(async () => {
+ const inner = await page.evaluate(() => window.innerWidth);
+ settled = inner === previous ? settled + 1 : 0;
+ previous = inner;
+ expect(settled).toBeGreaterThanOrEqual(3);
+ }).toPass({ timeout: 10_000, intervals: [100] });
+
+ if (previous < width - 100) {
+ const workArea = await app.evaluate(({ screen }) => screen.getPrimaryDisplay().workAreaSize);
+ // Only a display that genuinely cannot hold the window earns a skip. On one
+ // that can, a window settling short is the app mis-sizing itself, and
+ // calling that "your display is too small" would bury a real regression
+ // under a reason that is not true.
+ if (workArea.width < width) {
+ test.skip(
+ true,
+ `Window settled at ${previous}px after asking for ${width}px. The primary display's work area is ${workArea.width}x${workArea.height} and cannot hold it, and this test asserts a layout the app only owes at ${width}px.`,
+ );
+ }
+ throw new Error(
+ `Window settled at ${previous}px after asking for ${width}px, on a display whose work area is ${workArea.width}x${workArea.height} and could have held it. That is a window-sizing bug, not a display limit.`,
+ );
+ }
+}
+
async function revealTerminalSurface(app: ElectronApplication, target: Locator): Promise<void> {
await expect(async () => {
- // A prior dispatch can land between attempts; observe first so a retry cannot hide it again.
+ // Observe before acting. A dispatch that arrived before the renderer had a
+ // listener is QUEUED by the preload and replayed on subscribe, so a retry
+ // fired while one is still in flight would land a SECOND toggle and hide
+ // the surface this call was asked to reveal. This check is the actual
+ // defence; the 5s inner window only makes a retry unlikely enough that the
+ // outer budget still has attempts left when one is genuinely needed.
if (await target.isVisible()) return;
await clickViewTerminalItem(app);
- await expect(target).toBeVisible({ timeout: 1_000 });
+ await expect(target).toBeVisible({ timeout: 5_000 });
}).toPass({ timeout: 15_000 });
}
@@ -512,12 +617,7 @@ test.describe('Docked terminal — live Electron', () => {
captureStderrFor(app, { cleanupDirs: [s.tmpHome, s.projectDir] });
const page = await findEditorWindow(app);
- const editorWindow = await app.browserWindow(page);
- await editorWindow.evaluate((win: unknown) => {
- const target = win as { setSize: (width: number, height: number, animate: boolean) => void };
- target.setSize(1900, 900, false);
- });
- await expect.poll(() => page.evaluate(() => window.innerWidth)).toBeGreaterThanOrEqual(1800);
+ await widenEditorWindow(app, page, 1900, 900);
await openTerminal(app, page);
const moveRightButton = page.getByRole('button', { name: 'Move Terminal to right' });
@@ -555,12 +655,7 @@ test.describe('Docked terminal — live Electron', () => {
captureStderrFor(app, { cleanupDirs: [s.tmpHome, s.projectDir] });
const page = await findEditorWindow(app);
- const editorWindow = await app.browserWindow(page);
- await editorWindow.evaluate((win: unknown) => {
- const target = win as { setSize: (width: number, height: number, animate: boolean) => void };
- target.setSize(1900, 900, false);
- });
- await expect.poll(() => page.evaluate(() => window.innerWidth)).toBeGreaterThanOrEqual(1800);
+ await widenEditorWindow(app, page, 1900, 900);
await openTerminal(app, page);
await clickTerminalPlacementItem(app);
await expect(page.locator('#terminal-column section[aria-label="Terminal"]')).toBeVisible({
@@ -581,6 +676,8 @@ test.describe('Docked terminal — live Electron', () => {
const columns = (await readTerminalText(page)).match(/RAIL_COLS=(\d+)/)?.[1];
expect(Number(columns)).toBeGreaterThanOrEqual(92);
+ // Shrinking always takes, so this direction needs no settle proof.
+ const editorWindow = await app.browserWindow(page);
await editorWindow.evaluate((win: unknown) => {
const target = win as { setSize: (width: number, height: number, animate: boolean) => void };
target.setSize(900, 900, false);
@@ -609,8 +706,18 @@ test.describe('Docked terminal — live Electron', () => {
captureStderrFor(app, { cleanupDirs: [s.tmpHome, s.projectDir] });
const page = await findEditorWindow(app);
+ // Boot must be OVER before the stopwatch starts, or this budget is charged
+ // for it: the dispatch and the mount are both serviced by the renderer's
+ // main thread, so a thread still booting shows up as toggle latency.
+ // Measured on a loaded Linux runner without this barrier: 1.6-2.0s of a
+ // 3.3-4.0s "toggle" was the dispatch round-trip alone.
+ await waitForRendererResponsive(page);
+
const t0 = await page.evaluate(() => performance.now());
- await clickViewTerminalItem(app);
+ // `page` is handed over so the non-darwin dispatch path does not re-discover
+ // the editor window on the clock. That rediscovery is harness cost, and it
+ // is why this budget read ~400ms higher on Linux than on macOS.
+ await clickViewTerminalItem(app, page);
// The section becomes present synchronously on the state flip.
await page.waitForSelector('section[aria-label="Terminal"]', {
state: 'attached',
diff --git a/packages/desktop/tests/smoke/terminal-movement.e2e.ts b/packages/desktop/tests/smoke/terminal-movement.e2e.ts
index 488080ce7..45e1803ae 100644
--- a/packages/desktop/tests/smoke/terminal-movement.e2e.ts
+++ b/packages/desktop/tests/smoke/terminal-movement.e2e.ts
@@ -94,11 +94,22 @@ async function findEditorWindow(app: ElectronApplication, timeoutMs = 25_000): P
return page;
}
+/**
+ * `editorPage` lets a caller that already holds the editor window skip the
+ * rediscovery poll. That poll is not free: it re-evaluates
+ * `window.okDesktop.config.mode` in the renderer, so it costs whatever the
+ * renderer's main thread is busy with, measured at ~400ms on a loaded CI
+ * runner. Any caller TIMING this dispatch must pass the page, or it charges the
+ * app for the harness's own round trip. On darwin the menu click happens inside
+ * main and never pays it at all, so leaving it in makes the same assertion mean
+ * two different things per platform.
+ */
async function dispatchRendererMenuAction(
app: ElectronApplication,
action: 'move-terminal' | 'toggle-agent-panel' | 'toggle-terminal',
+ editorPage?: Page,
): Promise<void> {
- const page = await findEditorWindow(app);
+ const page = editorPage ?? (await findEditorWindow(app));
await page.evaluate(async (menuAction) => {
const menu = window.okDesktop?.menu;
if (!menu) throw new Error('renderer menu bridge is unavailable');
@@ -136,9 +147,12 @@ async function clickViewAgentsItem(app: ElectronApplication): Promise<void> {
});
}
-async function clickTerminalPlacementItem(app: ElectronApplication): Promise<void> {
+async function clickTerminalPlacementItem(
+ app: ElectronApplication,
+ editorPage?: Page,
+): Promise<void> {
if (process.platform !== 'darwin') {
- await dispatchRendererMenuAction(app, 'move-terminal');
+ await dispatchRendererMenuAction(app, 'move-terminal', editorPage);
return;
}
await app.evaluate(async ({ Menu }) => {
@@ -154,10 +168,14 @@ async function clickTerminalPlacementItem(app: ElectronApplication): Promise<voi
async function clickTerminalPlacementItemRapidly(
app: ElectronApplication,
count: number,
+ editorPage?: Page,
): Promise<void> {
if (process.platform !== 'darwin') {
for (let index = 0; index < count; index += 1) {
- await dispatchRendererMenuAction(app, 'move-terminal');
+ // The page matters most here: without it each of these iterations pays
+ // its own rediscovery poll, and the settlement being timed spans all of
+ // them.
+ await dispatchRendererMenuAction(app, 'move-terminal', editorPage);
}
return;
}
@@ -175,13 +193,70 @@ const visibleTerminal = (page: Page) => page.locator('section[aria-label="Termin
const terminalTabs = (page: Page) =>
page.getByRole('tablist', { name: 'Terminal sessions' }).getByRole('tab');
+/**
+ * Widen the editor window and PROVE the width stuck.
+ *
+ * `setSize` past the display's work area is honored in the renderer for a beat
+ * and then clamped back, and a bare `innerWidth >= n` poll happily catches that
+ * beat. The assertions below then measure a window that has since shrunk and
+ * blame the app: a right column squeezed to its drag floor reads as a lost
+ * width, and `Math.abs(rendered - restored) < 20` fails by hundreds of pixels.
+ * Sampling until the width settles is what makes the precondition real; a
+ * display that cannot hold the window skips, the same way the suite skips a
+ * platform without a PTY.
+ */
+async function widenEditorWindow(
+ app: ElectronApplication,
+ page: Page,
+ width: number,
+ height: number,
+): Promise<void> {
+ const editorWindow = await app.browserWindow(page);
+ await editorWindow.evaluate(
+ (windowHandle: unknown, size) => {
+ (windowHandle as { setSize: (w: number, h: number, animate: boolean) => void }).setSize(
+ size.width,
+ size.height,
+ false,
+ );
+ },
+ { width, height },
+ );
+
+ let settled = 0;
+ let previous = Number.NaN;
+ await expect(async () => {
+ const inner = await page.evaluate(() => window.innerWidth);
+ settled = inner === previous ? settled + 1 : 0;
+ previous = inner;
+ expect(settled).toBeGreaterThanOrEqual(3);
+ }).toPass({ timeout: 10_000, intervals: [100] });
+
+ if (previous < width - 100) {
+ const workArea = await app.evaluate(({ screen }) => screen.getPrimaryDisplay().workAreaSize);
+ // Only a display that genuinely cannot hold the window earns a skip. On one
+ // that can, a window settling short is the app mis-sizing itself, and
+ // calling that "your display is too small" would bury a real regression
+ // under a reason that is not true.
+ if (workArea.width < width) {
+ test.skip(
+ true,
+ `Window settled at ${previous}px after asking for ${width}px. The primary display's work area is ${workArea.width}x${workArea.height} and cannot hold it, and this test asserts a layout the app only owes at ${width}px.`,
+ );
+ }
+ throw new Error(
+ `Window settled at ${previous}px after asking for ${width}px, on a display whose work area is ${workArea.width}x${workArea.height} and could have held it. That is a window-sizing bug, not a display limit.`,
+ );
+ }
+}
+
async function openTerminal(app: ElectronApplication, page: Page): Promise<void> {
const terminal = visibleTerminal(page);
await expect(async () => {
// A prior dispatch can land between attempts; observe first so a retry cannot hide it again.
if (await terminal.isVisible()) return;
await clickViewTerminalItem(app);
- await expect(terminal).toBeVisible({ timeout: 1_000 });
+ await expect(terminal).toBeVisible({ timeout: 5_000 });
}).toPass({ timeout: 15_000 });
await expect(terminal.locator('[data-terminal-status]')).toHaveAttribute(
'data-terminal-status',
@@ -219,20 +294,42 @@ async function readActiveTerminal(page: Page): Promise<string> {
});
}
-async function readScrollbackContaining(page: Page, marker: string): Promise<string> {
+/**
+ * Scroll the active terminal's scrollback until every marker is on screen at
+ * once — the proof that the lines survived whatever just happened to the panel.
+ *
+ * Reads `.xterm-rows` ONLY. The `.xterm-accessibility` node beside it is
+ * xterm's screen-reader announcement buffer, NOT scrollback: under a burst it
+ * collapses to "Too much output to announce, navigate to rows manually to read"
+ * and truncates whatever it was mid-way through, token included. Reading it as
+ * retained output is what failed this assertion on a loaded runner while the
+ * terminal itself was perfectly healthy — the sentinel was found in the
+ * announcement buffer, and the line printed right after it had been cut in
+ * half there and was not yet scrolled into the rows.
+ *
+ * Steps are deliberately shorter than one wheel-page for the same reason:
+ * markers on adjacent lines must not be able to straddle a step boundary and
+ * so never appear together.
+ */
+async function expectScrollbackRetains(page: Page, ...markers: string[]): Promise<void> {
const terminal = visibleTerminal(page).locator('.xterm');
await terminal.hover();
- for (let pageIndex = 0; pageIndex < 20; pageIndex += 1) {
- const text = await readActiveTerminal(page);
- if (text.includes(marker)) return text;
- await page.mouse.wheel(0, -1_000);
+ const readRows = () =>
+ visibleTerminal(page).evaluate(
+ (section) => section.querySelector('.xterm-rows')?.textContent ?? '',
+ );
+
+ let text = await readRows();
+ for (let step = 0; step < 40 && !markers.every((marker) => text.includes(marker)); step += 1) {
+ await page.mouse.wheel(0, -500);
await page.evaluate(
() => new Promise<void>((resolve) => requestAnimationFrame(() => resolve())),
);
+ text = await readRows();
+ }
+ for (const marker of markers) {
+ expect(text, `terminal scrollback is missing ${marker}`).toContain(marker);
}
- const text = await readActiveTerminal(page);
- if (text.includes(marker)) return text;
- throw new Error(`Terminal scrollback is missing ${marker}: ${text}`);
}
function waitForTerminalHome(page: Page, home: TerminalHome): Promise<number> {
@@ -280,19 +377,33 @@ async function moveTerminal(
home: TerminalHome,
): Promise<number> {
const settlement = waitForTerminalHome(page, home);
- await clickTerminalPlacementItem(app);
+ // The stopwatch is already running inside the renderer, so the dispatch must
+ // not re-discover the window on the clock.
+ await clickTerminalPlacementItem(app, page);
return settlement;
}
+/**
+ * The live shell's pid, read from the terminal ROWS alone.
+ *
+ * Every other reader here substring-matches a whole marker, so xterm's
+ * `.xterm-accessibility` announcement buffer can only ever delay them — a
+ * truncated prefix never satisfies a `toContain`. This one PARSES, which makes
+ * truncation dangerous rather than merely slow: a `MARKER=67818` cut short in
+ * the announcement buffer yields `67`, which clears the `toBeGreaterThan(0)`
+ * gate and then gets compared against the real pid as proof the session
+ * survived a move. Rows carry no such truncation.
+ */
async function readShellPid(page: Page, marker: string): Promise<number> {
await typeInActiveTerminal(page, `printf '${marker}=%s\\n' "$$"\r`);
let processId = 0;
await expect
.poll(
async () => {
- const matches = [
- ...(await readActiveTerminal(page)).matchAll(new RegExp(`${marker}=(\\d+)`, 'g')),
- ];
+ const rows = await visibleTerminal(page).evaluate(
+ (section) => section.querySelector('.xterm-rows')?.textContent ?? '',
+ );
+ const matches = [...rows.matchAll(new RegExp(`${marker}=(\\d+)`, 'g'))];
processId = Number(matches.at(-1)?.[1] ?? 0);
return processId;
},
@@ -341,14 +452,7 @@ test.describe('Terminal placement continuity — live Electron', () => {
const app = await launchApp(s);
captureStderrFor(app, { cleanupDirs: [s.tmpHome, s.projectDir] });
const page = await findEditorWindow(app);
- const editorWindow = await app.browserWindow(page);
- await editorWindow.evaluate((windowHandle: unknown) => {
- const target = windowHandle as {
- setSize: (width: number, height: number, animate: boolean) => void;
- };
- target.setSize(1900, 900, false);
- });
- await expect.poll(() => page.evaluate(() => window.innerWidth)).toBeGreaterThanOrEqual(1800);
+ await widenEditorWindow(app, page, 1900, 900);
await openTerminal(app, page);
await openBareTab(page);
@@ -370,7 +474,7 @@ test.describe('Terminal placement continuity — live Electron', () => {
await expect
.poll(() => readActiveTerminal(page), { timeout: 15_000 })
.toContain(`SCROLL_${token}_120`);
- expect(await readScrollbackContaining(page, sentinel)).toContain(scrollStart);
+ await expectScrollbackRetains(page, sentinel, scrollStart);
const toRightMs = await moveTerminal(app, page, 'right');
expect(toRightMs).toBeLessThan(300);
@@ -379,13 +483,13 @@ test.describe('Terminal placement continuity — live Electron', () => {
'aria-selected',
'true',
);
- expect(await readScrollbackContaining(page, sentinel)).toContain(scrollStart);
+ await expectScrollbackRetains(page, sentinel, scrollStart);
expect(await readShellPid(page, processMarker)).toBe(processId);
const rightOutput = `RIGHT_OUTPUT_${token}`;
await typeInActiveTerminal(page, `printf '${rightOutput}\\n'\r`);
await expect.poll(() => readActiveTerminal(page), { timeout: 15_000 }).toContain(rightOutput);
- expect(await readScrollbackContaining(page, sentinel)).toContain(scrollStart);
+ await expectScrollbackRetains(page, sentinel, scrollStart);
const toBottomMs = await moveTerminal(app, page, 'bottom');
expect(toBottomMs).toBeLessThan(300);
await expect(terminalTabs(page)).toHaveText(['Terminal 1', 'Terminal 2']);
@@ -393,14 +497,14 @@ test.describe('Terminal placement continuity — live Electron', () => {
'aria-selected',
'true',
);
- expect(await readScrollbackContaining(page, sentinel)).toContain(scrollStart);
+ await expectScrollbackRetains(page, sentinel, scrollStart);
expect(await readShellPid(page, processMarker)).toBe(processId);
const bottomOutput = `BOTTOM_OUTPUT_${token}`;
await typeInActiveTerminal(page, `printf '${bottomOutput}\\n'\r`);
await expect.poll(() => readActiveTerminal(page), { timeout: 15_000 }).toContain(bottomOutput);
const rapidSettlement = waitForTerminalHome(page, 'right');
- await clickTerminalPlacementItemRapidly(app, 7);
+ await clickTerminalPlacementItemRapidly(app, 7, page);
expect(await rapidSettlement).toBeLessThan(300);
await expect(page.locator('section[aria-label="Terminal"]')).toHaveCount(2);
await expect(visibleTerminal(page)).toHaveCount(1);
@@ -417,7 +521,7 @@ test.describe('Terminal placement continuity — live Electron', () => {
const rapidOutput = `RAPID_OUTPUT_${token}`;
await typeInActiveTerminal(page, `printf '${rapidOutput}\\n'\r`);
await expect.poll(() => readActiveTerminal(page), { timeout: 15_000 }).toContain(rapidOutput);
- expect(await readScrollbackContaining(page, sentinel)).toContain(scrollStart);
+ await expectScrollbackRetains(page, sentinel, scrollStart);
});
test('renderer restart restores the right layout and its live active terminal', async ({
@@ -430,14 +534,7 @@ test.describe('Terminal placement continuity — live Electron', () => {
const app = await launchApp(s);
captureStderrFor(app, { cleanupDirs: [s.tmpHome, s.projectDir] });
const page = await findEditorWindow(app);
- const editorWindow = await app.browserWindow(page);
- await editorWindow.evaluate((windowHandle: unknown) => {
- const target = windowHandle as {
- setSize: (width: number, height: number, animate: boolean) => void;
- };
- target.setSize(1900, 900, false);
- });
- await expect.poll(() => page.evaluate(() => window.innerWidth)).toBeGreaterThanOrEqual(1800);
+ await widenEditorWindow(app, page, 1900, 900);
await openTerminal(app, page);
await openBareTab(page);
@@ -498,6 +595,8 @@ test.describe('Terminal placement continuity — live Electron', () => {
await clickViewAgentsItem(app);
await expect(page.locator('#agents-column')).toBeVisible({ timeout: 10_000 });
+ // Shrinking always takes, so this direction needs no settle proof.
+ const editorWindow = await app.browserWindow(page);
await editorWindow.evaluate((windowHandle: unknown) => {
const target = windowHandle as {
setSize: (width: number, height: number, animate: boolean) => void;
diff --git a/packages/desktop/tests/smoke/terminal-process-restart.e2e.ts b/packages/desktop/tests/smoke/terminal-process-restart.e2e.ts
index 5ccac2585..2217d625d 100644
--- a/packages/desktop/tests/smoke/terminal-process-restart.e2e.ts
+++ b/packages/desktop/tests/smoke/terminal-process-restart.e2e.ts
@@ -124,7 +124,7 @@ async function openTerminal(page: Page): Promise<void> {
// A prior dispatch can land between attempts; observe first so a retry cannot hide it again.
if (await terminal.isVisible()) return;
await dispatchRendererMenuAction(page, 'toggle-terminal');
- await expect(terminal).toBeVisible({ timeout: 1_000 });
+ await expect(terminal).toBeVisible({ timeout: 5_000 });
}).toPass({ timeout: 15_000 });
await expect(terminal.locator('[data-terminal-status]')).toHaveAttribute(
'data-terminal-status',
diff --git a/packages/desktop/tests/smoke/terminal-tabs.e2e.ts b/packages/desktop/tests/smoke/terminal-tabs.e2e.ts
index e93e7e480..7ca6da8a2 100644
--- a/packages/desktop/tests/smoke/terminal-tabs.e2e.ts
+++ b/packages/desktop/tests/smoke/terminal-tabs.e2e.ts
@@ -144,7 +144,11 @@ const terminalTabs = (page: Page) =>
*/
async function openTerminal(app: ElectronApplication, page: Page): Promise<void> {
await expect(async () => {
- await clickViewTerminalItem(app);
+ // Observe before acting: a queued dispatch from a previous attempt can land
+ // between attempts, and a blind second toggle would hide the section again.
+ // Only the CLICK is conditional — the assertions below still run, so a
+ // section that came up without a live shell keeps retrying.
+ if (!(await visibleSection(page).isVisible())) await clickViewTerminalItem(app);
await expect(visibleSection(page)).toBeVisible({ timeout: 8_000 });
await expect(visibleSection(page).locator('[data-terminal-status]')).toHaveAttribute(
'data-terminal-status',
diff --git a/packages/desktop/tests/smoke/terminal-window.e2e.ts b/packages/desktop/tests/smoke/terminal-window.e2e.ts
index b4712227c..5fd3e8954 100644
--- a/packages/desktop/tests/smoke/terminal-window.e2e.ts
+++ b/packages/desktop/tests/smoke/terminal-window.e2e.ts
@@ -100,6 +100,34 @@ async function findWindowByMode(
return page;
}
+/**
+ * Hold until the renderer's main thread is answering promptly.
+ *
+ * `findWindowByMode` resolves as soon as PRELOAD answers, and main registers
+ * the window's project context only after `loadFile` settles — so between
+ * those two points the editor window exists and is drivable but main cannot
+ * yet say which project it belongs to. "New Terminal Window" invoked in that
+ * gap resolves no project and opens a HOME-cwd window with an empty
+ * `collabUrl`. A responsive renderer is strictly past load, so this closes it.
+ *
+ * An idle renderer answers a round-trip in single-digit ms; 100ms is slack
+ * rather than a budget, and three in a row rules out landing in a gap between
+ * two chunks of boot work.
+ */
+async function waitForRendererResponsive(page: Page): Promise<void> {
+ await expect(async () => {
+ for (let probe = 0; probe < 3; probe += 1) {
+ const startedAt = Date.now();
+ await page.evaluate(() => performance.now());
+ expect(Date.now() - startedAt).toBeLessThan(100);
+ }
+ // 15s: the measured worst case for a loaded CI runner to reach a settled
+ // renderer is under 5s. Past 15s the app is not slow, it is broken — and
+ // failing HERE names that, instead of surfacing as a puzzling downstream
+ // timeout.
+ }).toPass({ timeout: 15_000, intervals: [250] });
+}
+
async function clickNewTerminalWindow(
app: ElectronApplication,
sourceWebContentsId?: number,
@@ -169,6 +197,8 @@ test.describe('Standalone terminal window — live Electron', () => {
captureStderrFor(app, { cleanupDirs: [s.tmpHome, s.projectDir] });
// The main-process command inherits project context from the source editor.
const editor = await findWindowByMode(app, 'editor');
+ // …but only once main HAS that context; see `waitForRendererResponsive`.
+ await waitForRendererResponsive(editor);
const editorWindow = await app.browserWindow(editor);
const editorWebContentsId = await editorWindow.evaluate(
(win: unknown) => (win as { webContents: { id: number } }).webContents.id,
@@ -216,7 +246,7 @@ test.describe('Standalone terminal window — live Electron', () => {
track(s.tmpHome, s.projectDir);
const app = await launchApp(s);
captureStderrFor(app, { cleanupDirs: [s.tmpHome, s.projectDir] });
- await findWindowByMode(app, 'editor');
+ await waitForRendererResponsive(await findWindowByMode(app, 'editor'));
expect(await clickNewTerminalWindow(app)).toBe(true);
await findWindowByMode(app, 'terminal');