Skip to content

Fix 6 e2e test flakes: worktree teardown, window focus, and terminal cleanup - #9625

Merged
AmethystLiang merged 3 commits into
mainfrom
fix-e2e-tests-2
Jul 21, 2026
Merged

AmethystLiang merged 3 commits into
mainfrom
fix-e2e-tests-2

Conversation

@AmethystLiang

Copy link
Copy Markdown
Contributor

Summary

Fixes six e2e test flakes across worktree lifecycle, window management, terminal cleanup, scroll anchoring, and CI diagnostics:

  1. Worktree teardown — Tolerate selector_not_found errors when tearing down just-created/removed worktrees that haven't resolved in the runtime graph yet
  2. Window focus retry — Add exponential backoff retry logic for transient window open failures during second-instance activation
  3. Terminal split collapse — Fix parked tab exit handler to properly collapse dead split leaves when a stale primary handler also observes the exit
  4. Scroll anchor drift — Account for Chromium's native scroll anchoring when content height changes in diff view
  5. Headless diagnostics — Forward Electron process logs when ORCA_E2E_FORWARD_APP_LOGS=1 for CI failure investigation
  6. Terminal persistence — Fix assertion to validate specific closed tab identity instead of total tab count

Screenshots

No visual change.

Testing

  • pnpm lint
  • pnpm typecheck
  • pnpm test
  • pnpm build
  • Added high-quality tests that catch regressions: unresolved runtime selector, window retry/race/exhaustion, dead split leaf collapse, conditional scroll assertion, tab identity validation

AI Review Report

Changes focus on defensive error handling and race condition mitigation in lifecycle-critical paths. All additions tolerate transient state changes and missing resources. Cross-platform verified: window focus uses platform-agnostic setTimeout, terminal handlers work across all shell backends, scroll fix applies uniformly to Chromium rendering, e2e improvements are CI-neutral.

Security Audit

No security concerns. Changes affect only error handling and test assertions: safe resource tolerance (worktree teardown), Electron-only APIs (window retry), pure state mutations (terminal handlers), env-gated log output (e2e forwarding).

Notes

Window focus retry caps at 3 attempts with 300ms delay; terminal handler reordering fixes multi-pane collapse since destroyed parked PaneManager cannot modify persisted layout; scroll anchor check is conservative—only caps assertion when height stable since Chromium's native anchoring is legitimate on height changes.

Tolerate selector_not_found during destructive worktree removal, retry transient
window reopens with bounded attempts, collapse dead split leaves in parked tabs,
stabilize tab-close persistence and diff-scroll assertions, and forward app logs
for visibility into failures. Each fix addresses a root cause—not a test workaround
—and includes a verification pass confirming no regressions. Fixes identified in
shard-10 CI failure (oracle #29710852934).
This smoke-evidence file was used to track adversarial verification of the 6 e2e fixes during development. Now that the fixes are committed and tested, the temporary verification notes can be removed.
@coderabbitai

coderabbitai Bot commented Jul 21, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 5639e0b0-9d5a-49de-96b5-032b8d04d7e2

📥 Commits

Reviewing files that changed from the base of the PR and between 3e8b548 and de272b3.

📒 Files selected for processing (2)
  • src/main/window/focus-existing-window.test.ts
  • src/main/window/focus-existing-window.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/main/window/focus-existing-window.ts
  • src/main/window/focus-existing-window.test.ts

📝 Walkthrough

Walkthrough

The changes make destructive worktree teardown tolerate unresolved runtime selectors, add bounded main-window reopen retries, and prioritize dead split-leaf cleanup for parked terminal watchers. E2E coverage is updated for timer behavior, window retries, watcher cleanup, scroll-height changes, activation-process logging, and durable split-tab closure after restart. Shared Electron log forwarding is exported for reuse by the activation test.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately summarizes the main change: fixing multiple e2e flakes across teardown, focus, and cleanup.
Description check ✅ Passed All required sections are present and mostly complete, with summary, screenshots, testing, AI review, security audit, and notes filled in.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
src/main/window/focus-existing-window.test.ts (1)

232-256: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Test doesn't actually prove "no 4th attempt" after exhaustion.

The inline comment claims "a further run() call must not schedule or fire a 4th attempt," but the test only calls timer.run(300) twice before asserting. Since the exhausted attempt returns without scheduling a new timer, the assertions currently pass without ever confirming that a third run(300) call fires nothing — a boundary regression (e.g. attempt > REOPEN_MAX_ATTEMPTS instead of >=) that adds one extra scheduled retry wouldn't be caught here.

✅ Suggested addition
     timer.run(300)
     timer.run(300)
     // Why: REOPEN_MAX_ATTEMPTS caps total tries at 3 (1 initial + 2 retries);
     // a further run() call must not schedule or fire a 4th attempt.
     expect(openWindow).toHaveBeenCalledTimes(3)
     expect(warn).toHaveBeenCalledTimes(3)
+    timer.run(300)
+    expect(openWindow).toHaveBeenCalledTimes(3)
+    expect(warn).toHaveBeenCalledTimes(3)
   })

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 7da071e8-d180-49c3-99d4-8bdcd8419e9a

📥 Commits

Reviewing files that changed from the base of the PR and between bf7fbdd and 3e8b548.

📒 Files selected for processing (10)
  • src/main/runtime/worktree-teardown.test.ts
  • src/main/runtime/worktree-teardown.ts
  • src/main/window/focus-existing-window.test.ts
  • src/main/window/focus-existing-window.ts
  • src/renderer/src/components/terminal-pane/terminal-parked-tab-watchers.test.ts
  • src/renderer/src/components/terminal-pane/terminal-parked-tab-watchers.ts
  • tests/e2e/combined-diff-scroll-restore.spec.ts
  • tests/e2e/headless-serve-desktop-activation.spec.ts
  • tests/e2e/helpers/orca-app.ts
  • tests/e2e/terminal-tab-close-restart-persistence.spec.ts

Extract activateWindow to prevent drift between sync and async
paths on win32 reinforcement (moveTop, pulseAlwaysOnTop, retry
focus). Adds test coverage for window recovery on retry.
@AmethystLiang
AmethystLiang merged commit 5786513 into main Jul 21, 2026
5 checks passed
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…cleanup (stablyai#9625)

* Fix 6 e2e flakes: worktree teardown, window focus, and terminal cleanup

Tolerate selector_not_found during destructive worktree removal, retry transient
window reopens with bounded attempts, collapse dead split leaves in parked tabs,
stabilize tab-close persistence and diff-scroll assertions, and forward app logs
for visibility into failures. Each fix addresses a root cause—not a test workaround
—and includes a verification pass confirming no regressions. Fixes identified in
shard-10 CI failure (oracle #29710852934).

* Remove E2E fix verification document

This smoke-evidence file was used to track adversarial verification of the 6 e2e fixes during development. Now that the fixes are committed and tested, the temporary verification notes can be removed.

* Unify win32 window activation for sync and retry paths

Extract activateWindow to prevent drift between sync and async
paths on win32 reinforcement (moveTop, pulseAlwaysOnTop, retry
focus). Adds test coverage for window recovery on retry.
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