fix(codex): seed pane override fallbacks

This commit is contained in:
Brennan Benson
2026-07-31 18:09:49 -07:00
parent a0d2085c69
commit 4f6d50a08c
6 changed files with 49 additions and 6 deletions
@@ -1133,6 +1133,20 @@ describe('CodexRuntimeHomeService', () => {
}
})
it('seeds shared auth for a pane-local custom home on the real-home lane', async () => {
const systemAuth = createCodexAuthJson('system@example.com', 'acct-system', 'system-token')
writeFileSync(getSystemCodexAuthPath(), systemAuth, 'utf-8')
const store = createStore(createSettings({ codexSystemDefaultRealHomeEnabled: true }))
const { CodexRuntimeHomeService } = await import('./runtime-home-service')
const service = new CodexRuntimeHomeService(store as never)
const customHome = join(testState.fakeHomeDir, 'pane-custom-codex-home')
expect(service.prepareForCodexLaunch(undefined, { CODEX_HOME: customHome })).toBe(
getRuntimeCodexHomePath()
)
expect(readFileSync(getRuntimeCodexAuthPath(), 'utf-8')).toBe(systemAuth)
})
it('skips retired-home reconciliation when no retained host pane can use it', async () => {
const syncLegacySharedCodexConfigForRetainedPanes = vi.fn()
vi.doMock('./legacy-shared-config-compatibility', () => ({
@@ -240,7 +240,7 @@ export class CodexRuntimeHomeService {
return null
}
this.invalidateBackfillAfterManagedSystemDefaultLaunch(launchEnv)
this.syncForCurrentSelection()
this.syncForCurrentSelection(target, launchEnv)
syncSystemCodexResourcesIntoManagedHome()
syncSystemConfigIntoManagedCodexHome()
// Why: sessions can be large; bridge them after launch so starting a fresh TUI never waits on a full tree walk.
@@ -615,7 +615,10 @@ export class CodexRuntimeHomeService {
return this.getRuntimeHomePath()
}
syncForCurrentSelection(target?: CodexAccountSelectionTarget): void {
syncForCurrentSelection(
target?: CodexAccountSelectionTarget,
launchEnv?: NodeJS.ProcessEnv
): void {
if (target?.runtime === 'wsl') {
this.syncWslRuntimeForCurrentSelection(target)
return
@@ -636,11 +639,11 @@ export class CodexRuntimeHomeService {
this.lastHostAccountUsedSelfContainedHome = false
this.lastSyncedAccountId = null
this.lastWrittenAuthJson = null
if (this.isHostSystemDefaultRealHome()) {
if (this.isHostSystemDefaultRealHome(launchEnv)) {
return
}
}
if (this.isHostSystemDefaultRealHome()) {
if (this.isHostSystemDefaultRealHome(launchEnv)) {
// Why: retained daemon panes may own shared auth from a managed launch;
// compatibility reconciliation runs later with durable provenance.
if (this.lastSyncedAccountId !== null) {
@@ -250,7 +250,9 @@ export function hasRecordedLegacySharedCodexPane(): boolean {
return Object.values(readRegistry().panes).some(
(record) =>
record.selectionKey === 'host' &&
(record.homeRoute === undefined || record.homeRoute === 'shared-home')
(record.homeRoute === undefined ||
record.homeRoute === 'shared-home' ||
record.homeRoute === 'custom-home')
)
}
@@ -87,6 +87,21 @@ describe('resolveCodexPaneLaunchAccount', () => {
).toEqual({ selectionKey: 'host', accountId: null, homeRoute: 'custom-home' })
})
it('keeps an account-owned route comparable when a pane override is ignored', () => {
const accounts = [managedAccount({ id: 'account-a' })]
expect(
resolveCodexPaneLaunchAccount({
pinnedByResume: false,
launchCodexHomePath: '/data/codex-accounts/account-a/home',
recordComparableHomeRoute: false,
systemCodexHomePath: SYSTEM_HOME,
settings: settings({ host: 'account-a', accounts }),
target: { runtime: 'host' }
})
).toEqual({ selectionKey: 'host', accountId: 'account-a', homeRoute: 'account-home' })
})
it('records the same account a resume pinned to when it is already selected', () => {
const accounts = [managedAccount({ id: 'account-a' })]
+4 -1
View File
@@ -40,8 +40,11 @@ export function resolveCodexPaneLaunchAccount(args: {
target: CodexAccountSelectionTarget
}): CodexPaneAccountRecord | null {
const selectionKey = getCodexSelectionLaneKey(args.target)
const resolvedHomeRoute = resolveCodexPaneHomeRoute(args)
const homeRoute =
args.recordComparableHomeRoute === false ? 'custom-home' : resolveCodexPaneHomeRoute(args)
args.recordComparableHomeRoute === false && resolvedHomeRoute === 'shared-home'
? 'custom-home'
: resolvedHomeRoute
if (!args.pinnedByResume) {
return {
selectionKey,
@@ -102,12 +102,18 @@ describe('codex pane account registry', () => {
accountId: null,
homeRoute: 'wsl-home'
})
expect(hasRecordedLegacySharedCodexPane()).toBe(false)
recordCodexPaneAccount('pty-custom', {
selectionKey: 'host',
accountId: null,
homeRoute: 'custom-home'
})
expect(hasRecordedLegacySharedCodexPane()).toBe(true)
forgetCodexPaneAccount('pty-custom')
expect(hasRecordedLegacySharedCodexPane()).toBe(false)
recordCodexPaneAccount('pty-shared', {