Repository navigation
fix(updater): keep macOS Orca open when background instances block updates #24952
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
3355580
fix(updater): guard macOS installs against running app instances
OrcaWin 86de153
fix(updater): match native app blockers and preserve quit lifecycle
OrcaWin 5b552d6
fix(updater): keep ordinary macOS quit on Squirrel's install-on-exit …
1e5540c
fix(updater): preserve quit intent through macOS staging
OrcaWin 39ac2aa
Merge main and repair Claude retention test fixture
OrcaWin e7ebe20
test(native-chat): explicitly model legacy published tab ownership
OrcaWin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
src/main/macos-update-running-instances.integration.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| import { copyFileSync, mkdirSync, mkdtempSync, rmSync } from 'node:fs' | ||
| import { once } from 'node:events' | ||
| import { tmpdir } from 'node:os' | ||
| import path from 'node:path' | ||
| import { expect, it, vi } from 'vitest' | ||
| import { spawnProcess } from '../shared/child-process/run-process' | ||
| import { getMacUpdateRunningInstances } from './macos-update-running-instances' | ||
|
|
||
| it.runIf(process.platform === 'darwin')( | ||
| 'detects real sibling processes with spaces in the bundle path and clears after they exit', | ||
| async () => { | ||
| const root = mkdtempSync(path.join(tmpdir(), 'orca-update-instances-')) | ||
| const executable = path.join(root, 'Orca Test.app', 'Contents', 'MacOS', 'Orca Test') | ||
| mkdirSync(path.dirname(executable), { recursive: true }) | ||
| copyFileSync('/bin/sleep', executable) | ||
| const self = spawnProcess({ program: executable, args: ['30'] }) | ||
| const sibling = spawnProcess({ program: executable, args: ['30'] }) | ||
| const selfClosed = once(self, 'close') | ||
| const siblingClosed = once(sibling, 'close') | ||
| try { | ||
| expect(self.pid).toBeTypeOf('number') | ||
| expect(sibling.pid).toBeTypeOf('number') | ||
| await vi.waitFor(async () => { | ||
| expect(await getMacUpdateRunningInstances(executable, self.pid)).toEqual([sibling.pid]) | ||
| }) | ||
| sibling.kill('SIGTERM') | ||
| await siblingClosed | ||
| expect(await getMacUpdateRunningInstances(executable, self.pid)).toEqual([]) | ||
| } finally { | ||
| self.kill('SIGTERM') | ||
| sibling.kill('SIGTERM') | ||
| await Promise.all([selfClosed, siblingClosed]) | ||
| rmSync(root, { recursive: true, force: true }) | ||
| } | ||
| } | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| import { beforeEach, describe, expect, it, vi } from 'vitest' | ||
| import { | ||
| getMacUpdateRunningInstances, | ||
| parseMacUpdateRunningInstances | ||
| } from './macos-update-running-instances' | ||
|
|
||
| const { runProcessMock } = vi.hoisted(() => ({ runProcessMock: vi.fn() })) | ||
| vi.mock('../shared/child-process/run-process', () => ({ runProcess: runProcessMock })) | ||
|
|
||
| const executable = '/Applications/Orca Test.app/Contents/MacOS/Orca Test' | ||
|
|
||
| describe('macOS update running instances', () => { | ||
| beforeEach(() => { | ||
| runProcessMock.mockReset() | ||
| }) | ||
|
|
||
| it('finds sibling main processes while excluding self, helpers, unrelated commands and other app copies', () => { | ||
| expect( | ||
| parseMacUpdateRunningInstances( | ||
| [ | ||
| ` 100 ${executable}`, | ||
| ` 101 ${executable}`, | ||
| ` 102 ${executable}`, | ||
| ' 103 /Applications/Orca Test.app/Contents/Frameworks/Orca Helper.app/Contents/MacOS/Orca Helper', | ||
| ' 104 /tmp/Orca Test.app/Contents/MacOS/Orca Test', | ||
| ` 105 /bin/zsh -c ${executable}`, | ||
| ' 106 /usr/bin/login', | ||
| '' | ||
| ].join('\n'), | ||
| executable, | ||
| 100 | ||
| ) | ||
| ).toEqual([101, 102]) | ||
| }) | ||
|
|
||
| it('rejects malformed process output instead of assuming no blockers', () => { | ||
| expect(() => parseMacUpdateRunningInstances('not a process row', executable, 100)).toThrow() | ||
| }) | ||
|
|
||
| it('skips development runtimes without probing the host', async () => { | ||
| expect(await getMacUpdateRunningInstances('/usr/local/bin/node')).toEqual([]) | ||
| expect(runProcessMock).not.toHaveBeenCalled() | ||
| }) | ||
|
|
||
| it.each(['linux', 'win32'])('does not probe on %s', async (platform) => { | ||
| vi.stubGlobal('process', { ...process, platform }) | ||
| try { | ||
| expect(await getMacUpdateRunningInstances(executable)).toEqual([]) | ||
| expect(runProcessMock).not.toHaveBeenCalled() | ||
| } finally { | ||
| vi.unstubAllGlobals() | ||
| } | ||
| }) | ||
|
|
||
| it.runIf(process.platform === 'darwin')( | ||
| 'uses a bounded same-user process query and preserves paths with spaces', | ||
| async () => { | ||
| runProcessMock.mockResolvedValue({ | ||
| code: 0, | ||
| stdout: `100 ${executable}\n101 ${executable}\n`, | ||
| timedOut: false | ||
| }) | ||
| expect(await getMacUpdateRunningInstances(executable, 100)).toEqual([101]) | ||
| expect(runProcessMock).toHaveBeenCalledWith( | ||
| expect.objectContaining({ | ||
| program: '/bin/ps', | ||
| args: ['-U', String(process.getuid?.()), '-ww', '-o', 'pid=,comm='], | ||
| timeoutMs: 5000, | ||
| killOnOutputLimit: true | ||
| }) | ||
| ) | ||
| } | ||
| ) | ||
|
|
||
| it.runIf(process.platform === 'darwin').each([ | ||
| { code: 1, timedOut: false }, | ||
| { code: null, timedOut: true }, | ||
| { code: 0, timedOut: false, outputTruncated: true } | ||
| ])('fails closed for incomplete query results: %j', async (result) => { | ||
| runProcessMock.mockResolvedValue({ stdout: '', ...result }) | ||
| await expect(getMacUpdateRunningInstances(executable)).rejects.toThrow('Could not check') | ||
| }) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| import path from 'node:path' | ||
| import { runProcess } from '../shared/child-process/run-process' | ||
|
|
||
| /** Squirrel waits for every main application process from the target bundle. */ | ||
| export async function getMacUpdateRunningInstances( | ||
| executable = process.execPath, | ||
| currentPid = process.pid | ||
| ): Promise<number[]> { | ||
| if (process.platform !== 'darwin' || !executable.includes('.app/Contents/MacOS/')) { | ||
| return [] | ||
| } | ||
| const result = await runProcess({ | ||
| program: '/bin/ps', | ||
| args: ['-U', String(process.getuid?.()), '-ww', '-o', 'pid=,comm='], | ||
| timeoutMs: 5_000, | ||
| maxOutputBytes: 2 * 1024 * 1024, | ||
| killOnOutputLimit: true | ||
| }) | ||
| if (result.code !== 0 || result.timedOut || result.outputTruncated) { | ||
| throw new Error('Could not check running Orca instances') | ||
| } | ||
| return parseMacUpdateRunningInstances(result.stdout, executable, currentPid) | ||
| } | ||
|
|
||
| export function parseMacUpdateRunningInstances( | ||
| listing: string, | ||
| executable: string, | ||
| currentPid: number | ||
| ): number[] { | ||
| const pids: number[] = [] | ||
| for (const line of listing.split('\n')) { | ||
| if (!line.trim()) { | ||
| continue | ||
| } | ||
| const row = /^\s*(\d+)\s+(.+)$/.exec(line) | ||
| if (!row) { | ||
| throw new Error('Invalid macOS process listing') | ||
| } | ||
| const pid = Number(row[1]) | ||
| if (pid !== currentPid && path.normalize(row[2]) === path.normalize(executable)) { | ||
| pids.push(pid) | ||
| } | ||
| } | ||
| return pids | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.