test: remove low-value account wrapper and routing checks (#41447)

Co-authored-by: OrcaWin <293788423+OrcaWin@users.noreply.github.com>
This commit is contained in:
OrcaWin
2026-11-12 00:04:18 -08:00
committed by GitHub
co-authored by OrcaWin
parent 34bde5edd4
commit 9ee5ec9fa0
12 changed files with 23 additions and 438 deletions
File diff suppressed because one or more lines are too long
@@ -1024,7 +1024,6 @@
"src/main/browser/routing/local-host-partitions/wsl-host-browser-route-partition.test.ts": 753,
"src/main/claude-accounts/sign-in/claude-account-folder.test.ts": 153,
"src/main/claude-accounts/claude-account-service.test.ts": 1207,
"src/main/claude-accounts/sign-in/claude-command-process-windows-only.test.ts": 90,
"src/main/claude-accounts/sign-in/claude-login-session.test.ts": 1048,
"src/main/claude-accounts/sign-in/claude-pasted-code-login.test.ts": 238,
"src/main/claude-accounts/profiles/setup/claude-profile-history-windows.test.ts": 121,
@@ -1036,7 +1035,6 @@
"src/main/claude-accounts/profiles/setup/claude-profile-setup.test.ts": 405,
"src/main/claude-accounts/profiles/wsl/claude-profile-wsl-router.test.ts": 919,
"src/main/claude-accounts/sign-in/claude-sign-in-browser.test.ts": 314,
"src/main/claude-accounts/runtime-auth/claude-structured-auth-policy.test.ts": 52,
"src/main/claude-accounts/runtime-auth/keychain-config-directory-aliases.test.ts": 51,
"src/main/claude-accounts/selection/runtime-selection.test.ts": 41,
"src/main/claude-accounts/sign-in/windows-command-invocation.test.ts": 48,
@@ -1193,7 +1191,6 @@
"src/main/codex-accounts/legacy-wsl-auth-drain/legacy-wsl-runtime-auth-drain-apply-script.test.ts": 5936,
"src/main/codex-accounts/legacy-wsl-auth-drain/legacy-wsl-runtime-auth-drain-rollback-script.test.ts": 558,
"src/main/codex-accounts/credentials/managed-codex-auth-readiness.test.ts": 86,
"src/main/codex-accounts/runtime-home/routing/runtime-home-catalog-probe-prep.test.ts": 583,
"src/main/codex-accounts/runtime-home/legacy-host/runtime-home-legacy-migration.test.ts": 1147,
"src/main/codex-accounts/runtime-home/credentials/runtime-home-managed-auth-recovery.test.ts": 658,
"src/main/codex-accounts/runtime-home/credentials/runtime-home-mirror-login-copy.test.ts": 1012,
@@ -1201,7 +1198,6 @@
"src/main/codex-accounts/runtime-home/routing/runtime-home-real-home-lane-routing.test.ts": 879,
"src/main/codex-accounts/runtime-home/credentials/runtime-home-retained-auth-provenance.test.ts": 1404,
"src/main/codex-accounts/runtime-home/routing/runtime-home-service-per-account-migration.test.ts": 980,
"src/main/codex-accounts/runtime-home/routing/runtime-home-session-discovery-read-only.test.ts": 543,
"src/main/codex-accounts/runtime-home/routing/runtime-home-session-migration-pass.test.ts": 705,
"src/main/codex-accounts/runtime-home/credentials/runtime-home-system-default-mirror-readback.test.ts": 1493,
"src/main/codex-accounts/runtime-home/credentials/runtime-home-system-default-snapshot.test.ts": 1255,
@@ -5,7 +5,6 @@ import {
readFileSync,
realpathSync,
rmSync,
symlinkSync,
writeFileSync
} from 'node:fs'
import { tmpdir } from 'node:os'
@@ -115,12 +114,4 @@ describe('Claude account profile setup', () => {
runtime: 'host'
})
})
itLinks('refuses a data root linked into the default home before writing there', async () => {
const f = fixture()
mkdirSync(join(f.defaultHome, 'inner'))
symlinkSync(join(f.defaultHome, 'inner'), join(f.dataRoot, 'claude-profiles'))
expect((await f.setup()).outcome).toBe('refused')
expect(existsSync(join(f.defaultHome, 'inner', 'a'))).toBe(false)
})
})
@@ -1,58 +0,0 @@
import { describe, expect, it } from 'vitest'
import type { GlobalSettings } from '../../../shared/global-settings-types'
import type { ClaudeManagedAccount } from '../../../shared/managed-account-types'
import { isHostManagedClaudeAccount } from './environment'
import { claudeStructuredAuthPolicyForSettings } from './claude-structured-auth-policy'
const HOST_ACCOUNT = { id: 'host-a', managedAuthRuntime: 'host' } as ClaudeManagedAccount
const WSL_ACCOUNT = { id: 'wsl-b', managedAuthRuntime: 'wsl' } as ClaudeManagedAccount
const LEGACY_ACCOUNT = { id: 'legacy-c' } as ClaudeManagedAccount
function settings(
overrides: Partial<
Pick<
GlobalSettings,
| 'claudeManagedAccounts'
| 'activeClaudeManagedAccountId'
| 'activeClaudeManagedAccountIdsByRuntime'
>
>
): Parameters<typeof claudeStructuredAuthPolicyForSettings>[0] {
return {
claudeManagedAccounts: [HOST_ACCOUNT, WSL_ACCOUNT, LEGACY_ACCOUNT],
activeClaudeManagedAccountId: null,
...overrides
} as Parameters<typeof claudeStructuredAuthPolicyForSettings>[0]
}
describe('isHostManagedClaudeAccount', () => {
it('is true for a selected id no account list explains', () => {
expect(isHostManagedClaudeAccount([HOST_ACCOUNT], 'deleted-d')).toBe(true)
expect(isHostManagedClaudeAccount(undefined, 'deleted-d')).toBe(true)
expect(isHostManagedClaudeAccount([], 'deleted-d')).toBe(true)
})
})
describe('claudeStructuredAuthPolicyForSettings', () => {
it('reads the host runtime selection, not the legacy flat field alone', () => {
expect(
claudeStructuredAuthPolicyForSettings(
settings({
activeClaudeManagedAccountId: 'host-a',
activeClaudeManagedAccountIdsByRuntime: { host: null, wsl: {} }
})
)
).toEqual({ account: 'managed' })
})
it('ignores a WSL-only selection: the structured child is always a native host process', () => {
expect(
claudeStructuredAuthPolicyForSettings(
settings({
activeClaudeManagedAccountIdsByRuntime: { host: null, wsl: { Ubuntu: 'wsl-b' } }
})
)
).toEqual({ account: 'system' })
})
})
@@ -1,56 +0,0 @@
import { EventEmitter } from 'node:events'
import { PassThrough } from 'node:stream'
import { afterEach, expect, it, vi } from 'vitest'
const state = vi.hoisted(() => {
const resolved: string[] = []
const programs: string[] = []
return { resolved, programs }
})
vi.mock('@orca/process-host', () => ({
spawnProcess: (spec: { program: string }) => {
state.programs.push(spec.program)
const child = Object.assign(new EventEmitter(), {
stdin: new PassThrough(),
stdout: new PassThrough(),
stderr: new PassThrough(),
pid: undefined,
kill: vi.fn()
})
queueMicrotask(() =>
spec.program.startsWith('/proc/')
? child.emit(
'error',
Object.assign(new Error(`spawn ${spec.program} ENOENT`), { code: 'ENOENT' })
)
: child.emit('close', 0)
)
return child
}
}))
vi.mock('../../codex-cli/command', () => ({
resolveClaudeCommand: () => state.resolved.shift() ?? '/home/me/.local/bin/claude'
}))
import { runClaudeCommandProcess } from './claude-command-process'
const WINDOWS_ONLY = '/proc/orca-agent-cli-installed-only-on-windows/claude'
const config = { windowsPath: '/home/me/.claude', linuxPath: null, wslDistro: null }
const originalPlatform = process.platform
afterEach(() => {
state.resolved.length = 0
state.programs.length = 0
Object.defineProperty(process, 'platform', { value: originalPlatform })
})
it('never keeps the Windows-only answer, so a Claude installed in WSL since is used', async () => {
Object.defineProperty(process, 'platform', { value: 'linux' })
// The first lookup sees only the Windows copy; every later one finds the new WSL install.
state.resolved.push(WINDOWS_ONLY)
await expect(runClaudeCommandProcess(['auth', 'status'], config, 1000)).rejects.toThrow(
'installed only on Windows'
)
await runClaudeCommandProcess(['auth', 'status'], config, 1000)
expect(state.programs).toEqual([WINDOWS_ONLY, '/home/me/.local/bin/claude'])
})
@@ -9,10 +9,4 @@ describe('parseCodexLoginAuthUrl', () => {
expect(parseCodexLoginAuthUrl(truncated)).toBe(null)
expect(parseCodexLoginAuthUrl(`${truncated}${AUTH_URL.slice(40)}\n`)).toBe(AUTH_URL)
})
it('offers no link at all rather than an unrelated one when the notice is missing', () => {
expect(
parseCodexLoginAuthUrl('A new version of codex is available: https://openai.com/codex\n')
).toBe(null)
})
})
@@ -1,74 +0,0 @@
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { installFakeAppEnvironment } from '../../../../../config/scripts/test-runtime/environment/vitest-host-ports-setup'
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs'
import { dirname } from 'node:path'
import type * as NodeOs from 'node:os'
import { createSettings } from '../runtime-home-settings-test-fixtures'
import {
createCodexAuthJson,
createStore,
getRuntimeCodexAuthPath,
getRuntimeCodexHomePath,
getSystemCodexAuthPath,
setupRuntimeHomeTest,
teardownRuntimeHomeTest,
testState
} from '../runtime-home-service-test-harness'
import type { CodexRuntimeHomeService } from '../../runtime-home-service'
vi.mock(
'../../../codex/configuration/shared-server/codex-daemon-socket-path-guard',
async (importOriginal) => ({
...(await importOriginal<object>()),
applyCodexDaemonSocketGuard: (config: string) => config
})
)
vi.mock('electron', () => ({
app: {
getPath: () => testState.userDataDir
}
}))
beforeEach(() => installFakeAppEnvironment({ getPath: () => testState.userDataDir }))
vi.mock('node:os', async () => {
const actual = await vi.importActual<typeof NodeOs>('node:os')
return {
...actual,
homedir: () => testState.fakeHomeDir
}
})
const login = createCodexAuthJson('me@example.com', 'acct-me', 'external-login')
async function mirrorRouteService(): Promise<CodexRuntimeHomeService> {
const { CodexRuntimeHomeService } = await import('../../runtime-home-service')
// oxlint-disable-next-line typescript/consistent-type-assertions -- SAFETY: the service reads only getSettings/updateSettings, which the harness store implements.
return new CodexRuntimeHomeService(createStore(createSettings()) as never)
}
function loginInSystemHome(): void {
mkdirSync(dirname(getSystemCodexAuthPath()), { recursive: true })
writeFileSync(getSystemCodexAuthPath(), login, 'utf-8')
}
describe("the catalog probe's home prep on the mirror route", () => {
beforeEach(() => {
setupRuntimeHomeTest()
})
afterEach(() => {
teardownRuntimeHomeTest()
})
it('brings a login made in ~/.codex into the mirror before the probe reads it', async () => {
const service = await mirrorRouteService()
expect(service.prepareForCodexLaunch()).toBe(getRuntimeCodexHomePath())
expect(existsSync(getRuntimeCodexAuthPath())).toBe(false)
loginInSystemHome()
service.prepareHostCodexHomeForReadOnlyAppServer(getRuntimeCodexHomePath())
expect(readFileSync(getRuntimeCodexAuthPath(), 'utf-8')).toBe(login)
})
})
@@ -1,13 +1,12 @@
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { installFakeAppEnvironment } from '../../../../../config/scripts/test-runtime/environment/vitest-host-ports-setup'
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs'
import { existsSync, readFileSync, writeFileSync } from 'node:fs'
import { join } from 'node:path'
import { createSettings } from '../runtime-home-settings-test-fixtures'
import {
createCodexAuthJson,
createManagedAuth,
createStore,
expectResourceLinkedOrCopied,
getRuntimeCodexAuthPath,
getSystemCodexAuthPath,
getSystemCodexHomePath,
@@ -98,56 +97,6 @@ describe('CodexRuntimeHomeService', () => {
}
)
it('materializes resources and config into the per-account home on launch', async () => {
writeFileSync(getSystemCodexAuthPath(), '{"account":"system"}\n', 'utf-8')
mkdirSync(join(getSystemCodexHomePath(), 'skills', 'review'), { recursive: true })
writeFileSync(
join(getSystemCodexHomePath(), 'skills', 'review', 'SKILL.md'),
'skill\n',
'utf-8'
)
writeFileSync(
join(getSystemCodexHomePath(), 'config.toml'),
'approval_policy = "never"\n',
'utf-8'
)
const home1 = createManagedAuth(
testState.userDataDir,
'account-1',
createCodexAuthJson('one@example.com', 'acct-1', 'one')
)
const store = createStore(
createSettings({
realHomeRoutable: true,
codexManagedAccounts: [
{
id: 'account-1',
email: 'one@example.com',
managedHomePath: home1,
providerAccountId: 'acct-1',
workspaceLabel: null,
workspaceAccountId: 'acct-1',
createdAt: 1,
updatedAt: 1,
lastAuthenticatedAt: 1
}
],
activeCodexManagedAccountId: 'account-1',
activeCodexManagedAccountIdsByRuntime: { host: 'account-1', wsl: {} }
})
)
const { CodexRuntimeHomeService } = await import('../../runtime-home-service')
const service = new CodexRuntimeHomeService(store as never)
expect(service.prepareForCodexLaunch()).toBe(home1)
expectResourceLinkedOrCopied(join(home1, 'skills'), join(getSystemCodexHomePath(), 'skills'))
expect(readFileSync(join(home1, 'skills', 'review', 'SKILL.md'), 'utf-8')).toBe('skill\n')
expect(readFileSync(join(home1, 'config.toml'), 'utf-8')).toContain('approval_policy = "never"')
expect(readFileSync(getSystemCodexAuthPath(), 'utf-8')).toBe('{"account":"system"}\n')
})
it('does not read shared auth when polling observes a managed-to-real-home transition', async () => {
const runtimeAuthPath = getRuntimeCodexAuthPath()
const systemAuth = createCodexAuthJson('system@example.com', 'acct-system', 'system')
@@ -8,14 +8,12 @@ import {
createStore,
getRuntimeCodexAuthPath,
getRuntimeCodexHomePath,
getSharedRuntimeAuthProvenancePath,
getSystemCodexAuthPath,
getSystemCodexHomePath,
setRealHomeRoutableForTest,
setupRuntimeHomeTest,
teardownRuntimeHomeTest,
testState,
writePaneRegistry
testState
} from '../runtime-home-service-test-harness'
// Keep asserted config bytes independent of platform socket-path limits.
@@ -65,52 +63,6 @@ describe('CodexRuntimeHomeService', () => {
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-host/legacy-shared-config-compatibility', () => ({
syncLegacySharedCodexConfigForRetainedPanes
}))
const retainedAuth = createCodexAuthJson('system@example.com', 'acct-system', 'retained')
const currentAuth = createCodexAuthJson('system@example.com', 'acct-system', 'current')
const retainedConfig = 'model = "retained"\n'
writePaneRegistry({
'real-home-pane': {
selectionKey: 'host',
accountId: null,
homeRoute: 'real-home'
}
})
writeFileSync(getRuntimeCodexAuthPath(), retainedAuth, 'utf-8')
writeFileSync(join(getRuntimeCodexHomePath(), 'config.toml'), retainedConfig, 'utf-8')
writeFileSync(getSystemCodexAuthPath(), currentAuth, 'utf-8')
writeFileSync(join(getSystemCodexHomePath(), 'config.toml'), 'model = "current"\n', 'utf-8')
writeFileSync(
getSharedRuntimeAuthProvenancePath(),
`${JSON.stringify({ owner: 'system-default', authJson: retainedAuth })}\n`,
'utf-8'
)
const store = createStore(createSettings({ realHomeRoutable: true }))
try {
const { CodexRuntimeHomeService } = await import('../../runtime-home-service')
const service = new CodexRuntimeHomeService(store as never)
service.reconcileLegacySharedHomeForRetainedPanes()
expect(service.prepareForCodexLaunch()).toBeNull()
expect(service.prepareForRateLimitFetch()).toEqual({
kind: 'ready',
codexHomePath: getSystemCodexHomePath()
})
expect(syncLegacySharedCodexConfigForRetainedPanes).not.toHaveBeenCalled()
expect(readFileSync(getRuntimeCodexAuthPath(), 'utf-8')).toBe(retainedAuth)
expect(readFileSync(join(getRuntimeCodexHomePath(), 'config.toml'), 'utf-8')).toBe(
retainedConfig
)
} finally {
vi.doUnmock('../legacy-host/legacy-shared-config-compatibility')
}
})
it('keeps pre-rollout shared-home panes authenticated on the real-home lane', async () => {
const oldSystemAuth = createCodexAuthJson('system@example.com', 'acct-system', 'old-system')
const systemAuth = createCodexAuthJson('system@example.com', 'acct-system', 'system')
@@ -1,89 +0,0 @@
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { installFakeAppEnvironment } from '../../../../../config/scripts/test-runtime/environment/vitest-host-ports-setup'
import { existsSync, readdirSync, rmSync } from 'node:fs'
import type * as NodeOs from 'node:os'
import { join } from 'node:path'
import { createSettings } from '../runtime-home-settings-test-fixtures'
import {
createStore,
getRuntimeCodexHomePath,
setupRuntimeHomeTest,
teardownRuntimeHomeTest,
testState
} from '../runtime-home-service-test-harness'
vi.mock('electron', () => ({
app: {
getPath: () => testState.userDataDir
}
}))
beforeEach(() => installFakeAppEnvironment({ getPath: () => testState.userDataDir }))
vi.mock('node:os', async () => {
const actual = await vi.importActual<typeof NodeOs>('node:os')
return {
...actual,
homedir: () => testState.fakeHomeDir
}
})
describe('Codex session discovery on a transcript lookup miss', () => {
beforeEach(() => {
setupRuntimeHomeTest()
})
afterEach(() => {
teardownRuntimeHomeTest()
})
it('creates no directories and reads no account ownership markers', async () => {
const accountHome = join(testState.userDataDir, 'codex-accounts', 'account-1', 'home')
const store = createStore(
createSettings({
codexManagedAccounts: [
{
id: 'account-1',
email: 'user@example.com',
managedHomePath: accountHome,
providerAccountId: null,
workspaceLabel: null,
workspaceAccountId: null,
createdAt: 1,
updatedAt: 1,
lastAuthenticatedAt: 1
}
]
})
)
const { CodexRuntimeHomeService } = await import('../../runtime-home-service')
// oxlint-disable-next-line typescript/consistent-type-assertions -- SAFETY: the service reads only getSettings/updateSettings, which the harness store implements.
const service = new CodexRuntimeHomeService(store as never)
const { configureHostReadableTranscriptPathSources } =
await import('../../../native-chat/host-readable-transcript-path')
const { resolveSessionFilePath } = await import('../../../native-chat/session-file-resolver')
configureHostReadableTranscriptPathSources({
getAdditionalCodexHomePaths: () => service.getHostCodexHomePathsForSessionDiscovery()
})
rmSync(join(testState.userDataDir, 'codex-runtime-home'), { recursive: true, force: true })
rmSync(join(testState.userDataDir, 'codex-accounts'), { recursive: true, force: true })
const before = readdirSync(testState.userDataDir).sort()
const warn = vi.spyOn(console, 'warn').mockImplementation(() => {})
try {
await expect(resolveSessionFilePath('codex', 'never-written-session')).resolves.toBeNull()
await expect(resolveSessionFilePath('codex', 'never-written-session')).resolves.toBeNull()
expect(existsSync(getRuntimeCodexHomePath())).toBe(false)
expect(readdirSync(testState.userDataDir).sort()).toEqual(before)
expect(warn).not.toHaveBeenCalled()
expect(service.getHostCodexHomePathsForSessionDiscovery()).toContain(
getRuntimeCodexHomePath()
)
} finally {
warn.mockRestore()
configureHostReadableTranscriptPathSources({})
}
})
})
@@ -1,5 +1,5 @@
import { beforeEach, afterEach, describe, expect, it, vi } from 'vitest'
import { mkdirSync, readFileSync, writeFileSync } from 'node:fs'
import { mkdirSync, writeFileSync } from 'node:fs'
import type * as NodeOs from 'node:os'
import { join } from 'node:path'
import { createSettings } from '../runtime-home-settings-test-fixtures'
@@ -78,21 +78,6 @@ describe('host system default session migration pass preparation', () => {
expect(service.prepareHostSystemDefaultSessionMigrationPass()).toBe(false)
})
it('carries a full-scan demand persisted by an earlier launch into this pass', async () => {
writeBaselineMarker(CUSTOM_HISTORY_HOME, true)
const store = createStore(
createSettings({ codexSessionSourceHome: { host: CUSTOM_HISTORY_HOME, wsl: {} } })
)
const { CodexRuntimeHomeService } = await import('../../runtime-home-service')
const service = new CodexRuntimeHomeService(store as never)
expect(service.prepareHostSystemDefaultSessionMigrationPass()).toBe(true)
expect(JSON.parse(readFileSync(getMarkerPath(), 'utf-8'))).toMatchObject({
needsFullScan: true
})
})
it('still demands a full scan when the history home really moves', async () => {
writeBaselineMarker(CUSTOM_HISTORY_HOME)
const store = createStore(
@@ -51,23 +51,6 @@ describe('CodexRuntimeHomeService', () => {
teardownRuntimeHomeTest()
})
it('mirrors later system Codex config changes before launch', async () => {
const systemCodexHome = getSystemCodexHomePath()
mkdirSync(systemCodexHome, { recursive: true })
writeFileSync(join(systemCodexHome, 'config.toml'), 'model = "first"\n', 'utf-8')
const store = createStore(createSettings())
const { CodexRuntimeHomeService } = await import('../../runtime-home-service')
const service = new CodexRuntimeHomeService(store as never)
service.prepareForCodexLaunch()
writeFileSync(join(systemCodexHome, 'config.toml'), 'model = "second"\n', 'utf-8')
service.prepareForCodexLaunch()
expect(readFileSync(join(getRuntimeCodexHomePath(), 'config.toml'), 'utf-8')).toBe(
'model = "second"\n'
)
})
it('rebases the bundled marketplace onto the canonical path of a symlinked managed home', async () => {
const systemMarketplace = join(
getSystemCodexHomePath(),