Skip to content

test(layout-owner): adversarial unit and e2e tests against PR #51934 - #52167

Merged
Jinwoo-H merged 1 commit into
layout-owner-launch-drafts-through-mainfrom
test/pr-51934-adversarial-coverage
Nov 29, 2026
Merged

Jinwoo-H merged 1 commit into
layout-owner-launch-drafts-through-mainfrom
test/pr-51934-adversarial-coverage

Conversation

@Jinwoo-H

@Jinwoo-H Jinwoo-H commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

ELI5

Tests-only PR targeting PR #51934 (layout-owner-launch-drafts-through-main, head 52b685804e7). No product code is changed. It exercises every tricky lifecycle case for window tabs whose terminals start in main under ORCA_LAYOUT_OWNER=main (in-place restart, multi-tab daemon restart, reload during planning and right after start, refused creates, exit-before-view across reload, two desktop windows on one workspace, and a phone client opening the same tab) and pins three remaining bugs before the next review round.

Files Added Deleted Net
Test 7 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​1795 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​1795
Prod 0 0 0 0

Before / After

  • Before: PR fix(layout-owner): window tabs that launch an agent or carry a draft start through main #51934 had unit/E2E coverage for happy-path window starts, remounts, account-switch launch count, single-tab post-reload daemon restart, and parsePaneAttachRequest, leaving died-pane Restart, multi-tab daemon restart without reload, reload with delayed draft readiness + agentLaunch planning, two desktop windows on one workspace, and phone client interactions untested.
  • After: Adds 4 unit test files (9 tests) and 2 E2E spec files + shared harness (7 tests). On head 52b685804e7, 11 pass (proving those paths hold) and 5 fail for 3 distinct real bugs.

Mechanism (Pass / Fail Summary on 52b685804e7)

Failing tests (3 real bugs exposed)

  1. Died-pane Restart on a main-started tab never sends restartPane — FAIL (Unit)

    • src/renderer/src/components/terminal-pane/pty-connection/attach/main-pane-attach-lifecycle.test.ts (routes a died-pane Restart (after transport exited and cleared ptyId) through main restartPane)
    • Why: After a process dies, ipc-pty-transport's markExited() sets ptyId = null. When usePaneProcessRestart calls releasePaneTransportForRestart(transport), replacesPtyId is null, so session.pendingReplacedPtyId is null. runDeferredSessionAttach only routes to restartMainStartedPane when session.pendingReplacedPtyId is truthy, so died-pane Restart falls into attachMainStartedPane, receives { state: 'exited' }, and leaves the tab dead with no terminal.
  2. PaneStarter.ensureStarted ignores consumed, so a phone opening an exited main-started tab re-runs its command — FAIL (Unit + E2E)

    • Unit: src/main/runtime/terminal/recovery/pane-starter-consumed-and-restart.test.ts (does not re-start a consumed exited pane on ensureStarted (e.g. phone open), until forget())
    • E2E: tests/layout-owner-e2e/window-tab-main-start-multi-client.spec.ts (a phone client opening an exited main-started tab does not re-run its command)
    • Why: perform-mobile-session-pty-records-refresh.ts:203 calls this.ensureRestoredPaneStarted(pane, trigger) directly when a phone activates a non-ready tab. Unlike the startPane layout reducer, PaneStarter.ensureStarted (restored-pane-start.ts:93) clears this.consumed.delete(key) and launches a second agent process (launches.length === 2 instead of 1).
  3. Two-RPC tab-create gap (createTerminalTab → terminal.create { windowTab }): a second desktop window or phone steals the unstarted tab and drops its startup — FAIL (2 E2E tests)

    • E2E: tests/layout-owner-e2e/window-tab-main-start-multi-client.spec.ts (two desktop windows on one workspace and a phone client opening a live or planning tab share one start with its startup intact)
    • E2E: tests/layout-owner-e2e/window-tab-main-start-multi-client.spec.ts (a phone activating a new window tab during the createTerminalTab-to-terminal.create gap does not steal its startup)
    • Why: recordCreatedTerminalTabInLayoutOwner sends layout.apply createTerminalTab first, then sends terminal.create { windowTab: true } on reply. Main publishes the new unbound, unstarted tab in a layout frame / session.tabs.list during that gap. A paired desktop window already viewing the workspace (without any artificial delay) or a phone activating the tab triggers a generic ensureRestoredPaneStarted before terminal.create { windowTab: true } reaches startWith, launching opencode with empty argv: [] and silently dropping --model test/fake-model (and any agentLaunch/draftPrompt).

Passing tests (11 passing, proving these cases are covered on 52b685804e7)

  • Unit (7/9 pass):
    • main-pane-attach-lifecycle.test.ts: live account-switch restart routes through main restartPane (never startFreshSpawn); onPaneAttachMiss re-attaches once without looping when the binding frame already landed before unstarted/unknown; held with NEWER_DAEMON_HOLD_ERROR opens the Reopen card instead of a raw error toast.
    • terminal-tab-create-refusal.test.ts: refused createTerminalTab closes the tab without settling the owner latch to 'window' or invoking terminal.create.
    • pane-starter-consumed-and-restart.test.ts: PaneLaunchStatuses stays visible while bound to the started terminal and expires once rebound after restart.
    • attach-pane-states.test.ts: attachPaneView awaits an in-flight start in main and unhides a hidden-started PTY on visible attach with attachOnlyView: true (no start fields); held returns { state: 'held', reason } without invoking runPtyIpcSpawn.
  • E2E (window-tab-main-start-lifecycle.spec.ts, 4/4 pass):
    • In-place account-switch restart stops the old terminal process (isPidAlive === false), binds a new ptyId !== before.ptyId, accepts interactive input, 0 window pty:spawns, 0 error toasts.
    • Live daemon restart (window.api.pty.management.restart()) with active agent tab + hidden draft tab + initial shell tab open (no prior reload): every tab gets a live interactive terminal, draft is pasted only once, 0 error toasts.
    • Window reload during agentLaunch planning (slow --version probe) and right after start (delayed draft readiness): 1 start each, 1 draft paste, initialAgentStatus re-seeded for both tabs, 0 window pty:spawns.
    • Refused creates (agent+draft tab and OpenCode model tab) start 0 terminals anywhere (pty:spawn, terminal.create, terminal.createAgentSession all 0), and commands exiting before view attach (both background and active untouched) keep their tabs open even across reload with 1 launch each and 0 error toasts.

How It Was Tested

All runs executed in the foreground with ORCA_LAYOUT_OWNER=main (and ORCA_SERVER_LAYOUT_OWNER=main, ORCA_BACKGROUND_LAUNCH=1 for E2E):

  • Unit tests (pnpm test ... --maxWorkers=2): 7 passed, 2 failed (the 2 real unit bugs above).
  • E2E tests (pnpm exec playwright test tests/layout-owner-e2e/window-tab-main-start-lifecycle.spec.ts tests/layout-owner-e2e/window-tab-main-start-multi-client.spec.ts --config tests/layout-owner-playwright.config.ts --project electron-headless --workers=1 --reporter=list): 4 passed, 3 failed (the 2 real multi-client/phone E2E bugs above).
  • oxfmt, oxlint: 0 warnings, 0 errors across all 7 files.
  • pnpm run typecheck:ci: 0 errors. pnpm run typecheck:e2e: 0 errors in tests/.

Visible Changes

None (tests only).

@greptile-apps

greptile-apps Bot commented Nov 29, 2026 •

Copy link
Copy Markdown

Confidence Score: 4/5 · The tests-only PR has no newly identified blocking defect, but two test checks should be strengthened.RetriggerView in GreptileConfidence Score: 4/5

[Low impact] The PR reaches test coverage for main-owned terminal starts, not shipped runtime behavior.

The tests-only PR has no newly identified blocking defect, but two test checks should be strengthened.

Findings

  1. P2 Refused phone opens go unnoticed ▶
  2. P2 Phone can miss the gap ▶

Summary

Adds unit and E2E coverage for main-owned terminal starts.

  • Main-owned terminal tests cover restarts and pane attachment.
  • Lifecycle tests cover reloads, refused tabs, and early exits.
  • Client tests cover shared terminal starts across windows and phones.

Reviews (1) · Last reviewed commit: "test(layout-owner): add unit and e2e tes..." · Reviewed by Greptile

Comment on lines +274 to +280
await phone.request('session.tabs.activate', {
worktree: `id:${worktreeId}`,
tabId: exitedSurface!.id,
notifyClients: false,
navigation: 'caller',
intent: 'user'
})

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Refused phone opens go unnoticed

The exited-tab test ignores the reply from phone.request('session.tabs.activate', ...). request returns failed replies without throwing, so the test can pass when the server refuses to open the tab: no second command runs, but the phone never reaches the behavior being tested.

Use phone.call or assert that the reply has ok: true. The planning-tab and create-gap tests also discard activation replies.

phone = pairMobileClient(mobileOffer)

const gapPrefix = 'gap-race-'
await delayWindowTabTerminalCreate(hostApp, gapPrefix, 800)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Phone can miss the gap

The test delays terminal.create for only 800 ms, then makes several phone requests before activation. Nothing checks that the delay is still running when activation arrives. On a slow run, the create can finish first and the model assertion can pass without testing the race.

Hold the create request behind an explicit gate until the phone activation reaches the server, then release it.

Jinwoo-H added a commit that referenced this pull request Nov 29, 2026
…umed start stays consumed

- One-call tab create (design step 6): the window's terminal.create carries its createTerminalTab;
  main writes the tab as the first step of the pane's start, under the start gate. No window or
  phone finds the tab recorded but unstarted, so none starts it without its --model or startup.
  A refusal or failed start answers with the call's frame; host_not_owned still records the tab
  alone and the window starts it, as before.
- PaneStarter.ensureStarted refuses a consumed pane instead of clearing it: a phone opening an
  exited main-started tab no longer runs its command again. A stop (forget) or a layout command's
  start (byLayoutCommand: startPane with a resume record, wake, restartPane) still starts it.
- A died pane's Restart reaches main's restartPane: the connect is marked as a restart, since the
  exited transport no longer names its terminal.
- Tests from #52167 merged; refusal stubs follow the one call, my spec imports the shared harness.
@Jinwoo-H
Jinwoo-H merged commit d71938a into layout-owner-launch-drafts-through-main Nov 29, 2026
50 of 55 checks passed
Jinwoo-H added a commit that referenced this pull request Nov 29, 2026
…start through main (#51934)

* fix(layout-owner): window tabs that launch an agent or carry a draft start through main

* test(layout-owner): read the recorded window spawns without a cast

* test(layout-owner): type the recorded window spawns as a declared global

* test(layout-owner): count only terminals the window's own spawn starts

* fix(layout-owner): main-started window tabs never start twice, seed status on every attach, typed launch refusals, safe draft paste

* test(layout-owner): type the seeded tab options instead of casting

* fix(layout-owner): a main-started pane's late connect may only attach to main's terminal

* fix(layout-owner): a window tab's failed agent launch shows one typed outcome, none for a closed pane

Main's create asks the launch what a failed pane shows before either failure writer
publishes, so no raw start failure reaches the window first. Exited-during-start
shows the launch refusal, as the pane's own spawn does. Main-started view facts are
dropped on a failed create and when the tab closes. The draft cap counts sanitised
UTF-8 bytes.

* fix(layout-owner): a window tab main starts only attaches; one starter per pane in main

The window asks main once who starts a new tab's first terminal (asking, then main or
window) before the pane connects. A pane main starts sends pty:attachPane, built from
an allow-list, which awaits main's in-flight start and answers a typed state instead of
an error, so it never starts a terminal or feeds remount recovery. Main runs the window
tab's start under the same per-pane gate as every other start and marks it consumed, so
a later startPane never re-runs it from tab facts. Main hands the launch's view facts
back with the attach. The window's starting mark, startup hand-off and give-back
remount, and the main-started view map are gone.

* test(layout-owner): prove a pane main starts is started once, by one owner

A lane-wide oracle fails any switch-on spec whose window starts a terminal in a pane
main started. The window-tab spec adds a command that exits before its view, remounts
during main's start, and a slow decline remounted while the window is still asking.
Unit tests pin the per-pane starter, the consumed startPane rule, the one-way owner
latch and the attach request's allow-list.

* test(layout-owner): withhold main's window-tab starts in the default-tabs crash spec

Main now starts default tabs that carry startup fields, through the window's
terminal.create, so stalling only pty:spawn no longer keeps every terminal from
starting before the crash. The exited-before-view case no longer assumes the tab
closes: it stayed open on Linux and closed on macOS.

* fix(layout-owner): main owns a window tab's start through restart, daemon restart and reload

- Restart (account switch, died-pane Restart) of a main-started pane goes through main's
  restartPane: main stops the terminal and starts the pane again through the same starter.
- A daemon restart forgets the consumed start, so main's startPane runs again.
- Main publishes 'starting' when it takes a start, and the launch status per terminal, so a
  reloaded window waits on main and re-seeds the agent status instead of starting a shell.
- A refused create only closes the tab.
- Attach replies: closed/owner-changed races map to states, an exited registration is 'exited',
  'held' shows the newer-daemon card; an already-present binding is attached at once.
- An exited-before-view tab stays open: main notes the spawn commit before the binding save,
  and the window treats main's first start as its fresh spawn.

* test(layout-owner): the layout.apply reply contract covers the window's restartPane

* test(layout-owner): add unit and e2e tests against PR #51934 main-started window tabs

* fix(layout-owner): one call writes a window tab and starts it; a consumed start stays consumed

- One-call tab create (design step 6): the window's terminal.create carries its createTerminalTab;
  main writes the tab as the first step of the pane's start, under the start gate. No window or
  phone finds the tab recorded but unstarted, so none starts it without its --model or startup.
  A refusal or failed start answers with the call's frame; host_not_owned still records the tab
  alone and the window starts it, as before.
- PaneStarter.ensureStarted refuses a consumed pane instead of clearing it: a phone opening an
  exited main-started tab no longer runs its command again. A stop (forget) or a layout command's
  start (byLayoutCommand: startPane with a resume record, wake, restartPane) still starts it.
- A died pane's Restart reaches main's restartPane: the connect is marked as a restart, since the
  exited transport no longer names its terminal.
- Tests from #52167 merged; refusal stubs follow the one call, my spec imports the shared harness.

* fix(layout-owner): a window tab's start is spent only when its terminal ends on its own

- Replace the pane-level 'consumed' flag with a fact about the start's terminal: a window-tab
  start is spent once the terminal it ran ends on its own (main's existing ended-on-its-own exit
  verdict), no later terminal holds the pane, and the pane keeps no resume record. Sleep, Restart,
  a daemon replacing the terminal and a held pane are not that, so wake, mailbox/CLI wake, a phone
  opening a slept tab and held Reopen start again with no forget call; the daemon-restart forget
  is gone. A failed start stays spent; a refused tab records nothing.
- createTab publishes the first terminal's cwd with the tab, and the terminal bridge passes its
  startup command into createTab, so the one-call create carries both (nothing is queued after).
- host_not_owned from the one call answers as layout.apply would (a twin's start goes to the
  window, a local refusal closes the tab), with no second layout.apply.
- A held pane's Reopen asks main to start it, then attaches.
- The switch-on window lane runs the two new window-tab specs.

* test(layout-owner): window tabs main starts in one call wake from sleep, reopen held, survive restarts and keep their inputs

- Slept window agent and draft tabs wake once, through main, from the sidebar and from a phone.
- A held window tab's Reopen after a newer terminal service gets a live terminal from main.
- A daemon restart after the tab was viewed, opened on a phone and reloaded gives it a live terminal.
- A repeated one-call create runs nothing new and leaves the pane startable.
- ui:createTerminal's startup command and a subfolder project's first terminal run in the right cwd.
- The spawn oracle no longer counts a refused or reattached one-call create as a main start.

* fix(layout-owner): a workspace woken or opened while its sleep is still settling wakes its slept tabs

Main finishes a sleep before the window commits it. Opening the workspace or one of its tabs in that gap saw
terminals that were still listed, so nothing woke the slept tabs:
- the window remounts the tabs when the sleep ends on a workspace that was already reopened
- attach answers `sleeping` for a pane main keeps a resume record for, so the view asks main to wake it
- a phone open waits for a sleep that is still running, then trusts main's resume record over the window's stale `ready`

Also adds an e2e for an Agent Sleep woken by a terminal send to its handle.

* fix(layout-owner): a tab removed during tab creation drops its queued starting directory

* fix(layout-owner): a frame binds a layout whose last terminal binding cleared, as the full build does
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant