test(codex): strengthen resume home snapshot contract

This commit is contained in:
Brennan Benson
2026-08-23 12:52:49 -07:00
parent ce10b304a4
commit 2fb26b6624
2 changed files with 35 additions and 7 deletions
@@ -196,6 +196,40 @@ describe('STA-4919 Codex resume home snapshot', () => {
})
})
it('propagates a still-indeterminate selected home instead of admitting or skipping it', async () => {
const { service, homeA } = await createTwoAccountService()
const markerA = join(realpathSync(homeA), '.orca-managed-home')
lstatFaults.failNext(markerA, 2)
const { ManagedCodexHomeTemporarilyUnavailableError } =
await import('../codex-accounts/host-codex-managed-home-ownership')
expect(() =>
snapshotCodexResumeHomes({
systemHomePath: getSystemCodexHomePath(),
runtimeHome: service
})
).toThrow(ManagedCodexHomeTemporarilyUnavailableError)
expect(lstatFaults.readsFor(markerA)).toBe(2)
})
it('deduplicates equivalent Windows home spellings while preserving the first path', () => {
const selectedHome = 'c:/users/brennan/.codex/'
const discoveredHome = String.raw`C:\Users\Brennan\.codex`
expect(
snapshotCodexResumeHomes({
systemHomePath: String.raw`C:\Users\System\.codex`,
runtimeHome: {
getHostCodexHomePathsForSessionDiscovery: () => [discoveredHome],
resolveSelectedHostAccountCodexHomePathForResume: () => selectedHome
}
})
).toEqual({
trustedCodexHomes: [String.raw`C:\Users\System\.codex`, discoveredHome],
selectedAccountCodexHome: selectedHome
})
})
it('still excludes a genuinely untrusted home that holds a competing alias', async () => {
const { service, homeA, store } = await createTwoAccountService()
const untrustedHome = join(testState.userDataDir, 'outside', 'account-c', 'home')
+1 -7
View File
@@ -1165,13 +1165,7 @@ async function prepareCodexSessionResumeForLaunch(args: {
const systemHomePath = getSystemCodexHomePath()
// Why: codexSessionSourceHome is import-only; treating it as CODEX_HOME would mutate history sources and bypass account auth.
const settingsStore = store
// Why: discovery omits a home whose ownership read is `indeterminate`
// (antivirus EBUSY); selection microseconds later may verify that same home.
// Snapshot both from this one call and union the verified selected home into
// the scan list, or a competing alias in another account wins (STA-4919).
// An unreadable selected home still throws rather than collapsing to "no
// selection" (STA-4422). The selected home is included only because this
// read verified it — never because verification was skipped.
// Why: include a newly verified selection when transient discovery omitted it (STA-4919).
const { trustedCodexHomes: trustedHomes, selectedAccountCodexHome } = snapshotCodexResumeHomes({
systemHomePath,
runtimeHome: codexRuntimeHome