Repository navigation
fix: connect mobile emulator in folder workspaces - #14009
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughThe change adds environment-based emulator workspace selection and separate workspace and cleanup resolution. It introduces lease-based helper acquisition with coordinated concurrent cleanup and session retention. 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (4)
src/main/runtime/orca-runtime.ts (1)
28380-28409: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winExtract the shared selector-normalization logic to avoid a third divergent copy.
resolveFolderWorkspaceSelector(line 28381-28382) andresolveEmulatorCleanupWorkspaceId(line 28403-28404) both re-implement the sameselector.startsWith('id:') ? selector.slice(3) : selectorfollowed byparseWorkspaceKey(...). The same pattern already exists unchanged inresolveTerminalWorkspaceLaunchScope.resolveEmulatorCleanupWorkspaceIdcannot simply callresolveFolderWorkspaceSelector, because it must skip the store lookup and theselector_not_foundthrow so cleanup works for a folder workspace that no longer exists. Extract only the normalization + parse step into a small private helper (for exampleparseFolderWorkspaceSelectorId(selector): string | null), and build bothresolveFolderWorkspaceSelector(add the store lookup and throw) andresolveEmulatorCleanupWorkspaceId(skip the lookup) on top of it. This keeps the "id: stripping + parseWorkspaceKey" rule in one place so a future change to selector normalization cannot silently diverge between the workspace-resolution and cleanup-resolution paths.♻️ Proposed refactor
+ private parseFolderWorkspaceSelectorId(selector: string): string | null { + const workspaceSelector = selector.startsWith('id:') ? selector.slice(3) : selector + const parsed = parseWorkspaceKey(workspaceSelector) + return parsed?.type === 'folder' ? parsed.folderWorkspaceId : null + } + private resolveFolderWorkspaceSelector(selector: string): FolderWorkspace | null { - const workspaceSelector = selector.startsWith('id:') ? selector.slice(3) : selector - const parsed = parseWorkspaceKey(workspaceSelector) - if (parsed?.type !== 'folder') { + const folderWorkspaceId = this.parseFolderWorkspaceSelectorId(selector) + if (folderWorkspaceId === null) { return null } const workspace = this.store ?.getFolderWorkspaces?.() - .find((entry) => entry.id === parsed.folderWorkspaceId) + .find((entry) => entry.id === folderWorkspaceId) if (!workspace) { throw new Error('selector_not_found') } return workspace } private async resolveEmulatorCleanupWorkspaceId(selector: string): Promise<string> { - const workspaceSelector = selector.startsWith('id:') ? selector.slice(3) : selector - const parsed = parseWorkspaceKey(workspaceSelector) - return parsed?.type === 'folder' - ? folderWorkspaceKey(parsed.folderWorkspaceId) + const folderWorkspaceId = this.parseFolderWorkspaceSelectorId(selector) + return folderWorkspaceId !== null + ? folderWorkspaceKey(folderWorkspaceId) : this.resolveEmulatorWorkspaceId(selector) }src/cli/selectors.ts (1)
240-247: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick winNormalize
ORCA_WORKTREE_IDthe same way asORCA_WORKSPACE_ID.Line 241 tests the trimmed value but line 242 returns the raw value. A value with surrounding whitespace is forwarded to the runtime selector unchanged.
ORCA_WORKSPACE_IDis trimmed on line 244. Use one normalization rule for both variables.♻️ Proposed change
- const terminalWorktreeId = process.env.ORCA_WORKTREE_ID - if (terminalWorktreeId?.trim()) { - return terminalWorktreeId - } + const terminalWorktreeId = process.env.ORCA_WORKTREE_ID?.trim() + if (terminalWorktreeId) { + return terminalWorktreeId + }Note:
src/cli/handlers/emulator.test.tsline 114 asserts the untrimmed value, so update that expectation together with this change.src/main/emulator/emulator-bridge.test.ts (1)
460-461: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueExtract the repeated host resolver fixture.
The same two resolver mocks repeat in ten host fixtures (lines 460-461, 494-495, 529-530, 560-561, 595-596, 627-628, 649-650, 674-675, 699-700, 742-743). A small factory keeps future host-contract changes to one edit site.
♻️ Example factory
function workspaceResolvers(worktreeId = 'wt-1') { return { resolveEmulatorWorkspaceId: vi.fn(async () => worktreeId), resolveEmulatorCleanupWorkspaceId: vi.fn(async () => worktreeId) } }src/main/runtime/orca-runtime-emulator-folder-workspace.test.ts (1)
38-46: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueConsider a narrower cast than
as neverfor the stubs.
as neverdisables all structural checking. This PR splits the host contract intoresolveEmulatorWorkspaceIdandresolveEmulatorCleanupWorkspaceId. A later rename of a bridge method such asacquireHelperForDevicewill not fail typechecking in this file. APartial<EmulatorBridge> as EmulatorBridgestyle cast keeps property-name checking on the members the test does define.Also applies to: 58-59
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: c107fbd6-fa1d-4382-ae09-39a03b66e2ca
📒 Files selected for processing (11)
src/cli/handlers/emulator.test.tssrc/cli/selectors.tssrc/main/emulator/emulator-bridge.test.tssrc/main/emulator/emulator-bridge.tssrc/main/emulator/emulator-device-inventory.tssrc/main/emulator/emulator-session-registry.tssrc/main/emulator/emulator-start-lease-registry.test.tssrc/main/emulator/emulator-start-lease-registry.tssrc/main/runtime/orca-runtime-emulator-folder-workspace.test.tssrc/main/runtime/orca-runtime-emulator.tssrc/main/runtime/orca-runtime.ts
|
@coderabbitai review |
✅ Action performedReview finished.
|
Closes #13831
Problem and invariant
Successful
orca emulator attachscoped tofolder:<id>must register under that exact workspace identity and publish renderer auto-attach (plus optional focus) notifications for it.On latest main (
346e59c879adfa7c55fd22485a221a42116de1d2), the CLI discarded the folder identity and scanned for a Git worktree. Direct runtime calls then sent folder selectors through the worktree-only resolver, failing withselector_not_foundbefore the emulator helper could register.The authoritative boundary is the main-process runtime's workspace resolver, with the terminal-exported workspace identity as the CLI authority before cwd scanning.
Fix
folder:<id>key.This keeps truth at the existing runtime/session owners rather than adding renderer fallback logic or broadening the RPC wire contract.
Deterministic evidence
Byte-identical decisive oracle:
pnpm exec vitest run --config config/vitest.config.ts \ src/main/runtime/orca-runtime-emulator-folder-workspace.test.ts \ src/cli/handlers/emulator.test.ts \ --reporter=verbose346e59c879ad: red, 7 failed / 7 passed. Folder attach and cleanup threwselector_not_found; CLI attach made an extraworktree.listcall and lost terminal scope.26b2ca5fb85e: green, 14/14.Expanded lifecycle oracle: 44/44 green across folder routing, CLI scoping, shared-device ownership, Android cold boot, failed-attach cleanup, and pane-close/in-flight-attach races.
Additional validation:
pnpm typecheckpnpm lint(including type-aware checks and max-lines ratchet)git diff --checkLive proof
An isolated macOS Orca profile opened the real Mobile Emulator pane for a plain folder workspace and connected
Pixel_9_Pro_API_36. The folder-scoped runtime command returnedsdk_gphone64_arm64, and the pane showed the canonical “Plain folder” workspace as Connected with the live Android screen.Scope and remaining topology gaps
No RPC schema/opcode, persisted mobile state, Git/provider, or UI-style contract changed. This was not freshly exercised on physical Windows/WSL, direct SSH/paired runtimes, mixed client/server versions, or a live iOS simulator. Those paths do not own the reproduced selector failure; the live proof is macOS host + Android emulator.