fix(codex): compare retained pane routes

This commit is contained in:
Brennan Benson
2026-07-31 17:59:31 -07:00
parent 42bb474009
commit 0c4d69e28a
3 changed files with 19 additions and 151 deletions
@@ -226,7 +226,7 @@ describe('listStaleCodexPanes', () => {
).toEqual([])
})
it('reports a retained pane after its process CODEX_HOME changes', () => {
it('does not report a custom-home spelling change that keeps the shared route', () => {
recordCodexPaneAccount('pty-1', {
selectionKey: 'host',
accountId: null,
@@ -238,20 +238,9 @@ describe('listStaleCodexPanes', () => {
listStaleCodexPanes({
ptyIds: ['pty-1'],
settings: settingsWithSelection(null),
activeHostHomeRoute: 'shared-home',
activeHostCustomHomeOverride: {
source: 'environment',
context: { codexHome: '/custom/codex-b' }
}
activeHostHomeRoute: 'shared-home'
})
).toEqual([
{
ptyId: 'pty-1',
launchAccountId: null,
activeAccountId: null,
reason: 'home-route-change'
}
])
).toEqual([])
})
it('leaves a retained pane alone while its process CODEX_HOME is unchanged', () => {
@@ -266,58 +255,33 @@ describe('listStaleCodexPanes', () => {
listStaleCodexPanes({
ptyIds: ['pty-1'],
settings: settingsWithSelection(null),
activeHostHomeRoute: 'shared-home',
activeHostCustomHomeOverride: {
source: 'environment',
context: { codexHome: '/custom/codex-home' }
}
activeHostHomeRoute: 'shared-home'
})
).toEqual([])
})
it.each([
[
'environment to shell startup',
{ environmentHomeOverride: { codexHome: '/custom/codex-home' } },
{
source: 'shell-startup' as const,
context: {
home: '/custom',
shell: '/bin/zsh',
codexHome: '/custom/codex-home'
}
}
],
[
'shell startup to environment',
{
shellStartupHomeOverride: {
home: '/custom',
shell: '/bin/zsh',
codexHome: '/custom/codex-home'
}
},
{
source: 'environment' as const,
context: { codexHome: '/custom/codex-home' }
}
]
])('does not report a same-path %s change', (_label, provenance, activeOverride) => {
it('reports when removing a custom home changes the resolved route', () => {
recordCodexPaneAccount('pty-1', {
selectionKey: 'host',
accountId: null,
homeRoute: 'shared-home',
...provenance
environmentHomeOverride: { codexHome: '/custom/codex-home' }
})
expect(
listStaleCodexPanes({
ptyIds: ['pty-1'],
settings: settingsWithSelection(null),
activeHostHomeRoute: 'shared-home',
activeHostCustomHomeOverride: activeOverride
activeHostHomeRoute: 'real-home'
})
).toEqual([])
).toEqual([
{
ptyId: 'pty-1',
launchAccountId: null,
activeAccountId: null,
reason: 'home-route-change'
}
])
})
it.skipIf(process.platform === 'win32')(
@@ -343,7 +307,7 @@ describe('listStaleCodexPanes', () => {
listStaleCodexPanes({
ptyIds: ['pty-1'],
settings: settingsWithSelection(null),
activeHostHomeRoute: 'real-home'
activeHostHomeRoute: 'shared-home'
})
).toEqual([])
@@ -366,42 +330,6 @@ describe('listStaleCodexPanes', () => {
}
)
it.skipIf(process.platform === 'win32')(
'reports a retained pane when the replacement launch context changes',
() => {
const paneHome = join(userDataPath, 'pane-home')
mkdirSync(paneHome, { recursive: true })
const customHome = join(paneHome, 'custom-codex-home')
writeFileSync(join(paneHome, '.zshrc'), 'export CODEX_HOME="$HOME/custom-codex-home"\n')
recordCodexPaneAccount('pty-1', {
selectionKey: 'host',
accountId: null,
homeRoute: 'shared-home',
shellStartupHomeOverride: {
home: paneHome,
shell: '/bin/zsh',
codexHome: customHome
}
})
expect(
listStaleCodexPanes({
ptyIds: ['pty-1'],
settings: settingsWithSelection(null),
activeHostHomeRoute: 'real-home',
activeHostCustomHomeOverride: null
})
).toEqual([
{
ptyId: 'pty-1',
launchAccountId: null,
activeAccountId: null,
reason: 'home-route-change'
}
])
}
)
it('never reports an unrecorded PTY, so an upgrade cannot invent a prompt', () => {
expect(
listStaleCodexPanes({ ptyIds: ['pty-unknown'], settings: settingsWithSelection('account-b') })
+2 -60
View File
@@ -5,14 +5,6 @@ import {
getCodexPaneAccount,
type CodexPaneHomeRoute
} from './codex-pane-account-registry'
import {
environmentCodexHomeOverrideContextsEqual,
getCustomCodexHomeOverrideForLaunch,
shellStartupCodexHomeOverrideMatches,
type CustomCodexHomeOverrideForLaunch,
type CodexEnvironmentHomeOverride,
type CodexShellStartupHomeOverride
} from './codex-real-home-path'
export type StaleCodexPane = {
ptyId: string
@@ -29,7 +21,6 @@ export function listStaleCodexPanes(args: {
ptyIds: readonly string[]
settings: GlobalSettings
activeHostHomeRoute?: CodexPaneHomeRoute
activeHostCustomHomeOverride?: CustomCodexHomeOverrideForLaunch | null
}): StaleCodexPane[] {
const stalePanes: StaleCodexPane[] = []
for (const ptyId of args.ptyIds) {
@@ -41,16 +32,11 @@ export function listStaleCodexPanes(args: {
args.settings,
parseSelectionLaneKey(record.selectionKey)
)
const customHomeChanged = getCustomHomeChanged(record, args)
const hasCustomHomeProvenance =
record.shellStartupHomeOverride !== undefined || record.environmentHomeOverride !== undefined
const homeRouteChanged =
record.selectionKey === 'host' &&
record.homeRoute !== undefined &&
(customHomeChanged ||
(!hasCustomHomeProvenance &&
args.activeHostHomeRoute !== undefined &&
record.homeRoute !== args.activeHostHomeRoute))
args.activeHostHomeRoute !== undefined &&
record.homeRoute !== args.activeHostHomeRoute
const accountChanged = record.accountId !== activeAccountId
if (accountChanged || homeRouteChanged) {
stalePanes.push({
@@ -64,50 +50,6 @@ export function listStaleCodexPanes(args: {
return stalePanes
}
function getCustomHomeChanged(
record: {
shellStartupHomeOverride?: CodexShellStartupHomeOverride
environmentHomeOverride?: CodexEnvironmentHomeOverride
},
args: {
activeHostCustomHomeOverride?: CustomCodexHomeOverrideForLaunch | null
}
): boolean {
if (record.shellStartupHomeOverride) {
if (!Object.prototype.hasOwnProperty.call(args, 'activeHostCustomHomeOverride')) {
const currentProcessOverride = getCustomCodexHomeOverrideForLaunch()
return currentProcessOverride
? customHomeOverrideChanged(record.shellStartupHomeOverride.codexHome, {
activeHostCustomHomeOverride: currentProcessOverride
})
: !shellStartupCodexHomeOverrideMatches(record.shellStartupHomeOverride)
}
return customHomeOverrideChanged(record.shellStartupHomeOverride.codexHome, args)
}
if (!record.environmentHomeOverride) {
return false
}
return customHomeOverrideChanged(record.environmentHomeOverride.codexHome, args)
}
function customHomeOverrideChanged(
recordedCodexHome: string,
args: {
activeHostCustomHomeOverride?: CustomCodexHomeOverrideForLaunch | null
}
): boolean {
const currentOverride = Object.prototype.hasOwnProperty.call(args, 'activeHostCustomHomeOverride')
? args.activeHostCustomHomeOverride
: getCustomCodexHomeOverrideForLaunch()
return (
!currentOverride ||
!environmentCodexHomeOverrideContextsEqual(
{ codexHome: recordedCodexHome },
{ codexHome: currentOverride.context.codexHome }
)
)
}
/**
* Drops the launch record for panes the user chose to keep on the old account.
*
+1 -3
View File
@@ -3,7 +3,6 @@ import type { CodexAccountAddTarget, CodexAccountService } from '../codex-accoun
import type { CodexAccountSelectionTarget } from '../codex-accounts/runtime-selection'
import { listRecordedCodexPaneLanes } from '../codex/codex-pane-account-registry'
import { forgetStaleCodexPanes, listStaleCodexPanes } from '../codex/codex-stale-pane-accounts'
import { getCustomCodexHomeOverrideForLaunch } from '../codex/codex-real-home-path'
import type { GlobalSettings } from '../../shared/types'
export function registerCodexAccountHandlers(
@@ -18,8 +17,7 @@ export function registerCodexAccountHandlers(
return listStaleCodexPanes({
ptyIds: args.ptyIds.filter((ptyId): ptyId is string => typeof ptyId === 'string'),
settings,
activeHostHomeRoute: codexAccounts.runtimeHomeService.getSelectedHostCodexHomeRoute(),
activeHostCustomHomeOverride: getCustomCodexHomeOverrideForLaunch()
activeHostHomeRoute: codexAccounts.runtimeHomeService.getSelectedHostCodexHomeRoute()
})
})
ipcMain.handle('codexAccounts:listRecordedPaneLanes', (_event, args: { ptyIds?: unknown }) => {