test: remove low-value settings and environment cases (#40578)

Co-authored-by: OrcaWin <293788423+OrcaWin@users.noreply.github.com>
This commit is contained in:
OrcaWin
2026-11-09 17:58:42 -08:00
committed by GitHub
co-authored by OrcaWin
parent 7777f352d8
commit e295b0d37c
9 changed files with 21 additions and 324 deletions
File diff suppressed because one or more lines are too long
@@ -1,57 +1,8 @@
import { describe, expect, it, vi } from 'vitest'
import type { BrowserWindow } from 'electron'
import type { Store } from '../../persistence/loading-store/store'
import { registerSparsePresetHandlers } from './sparse-preset-handlers'
import { describe, expect, it } from 'vitest'
import { normalizeSparsePresetDirectories } from './sparse-preset-validation'
import { mapRuntimeError } from '../../runtime/rpc/errors'
import {
InvalidSparseDirectoryError,
normalizeSparseDirectories
} from '../sparse-checkout-directories'
const { handlers } = vi.hoisted(() => ({
handlers: new Map<string, (event: unknown, args: unknown) => unknown>()
}))
vi.mock('electron', () => ({
ipcMain: {
handle: (channel: string, handler: (event: unknown, args: unknown) => unknown) =>
handlers.set(channel, handler)
}
}))
vi.mock('../../persistence/moving-wsl-projects/wsl-move-scope-guard', () => ({
assertWslMoveProjectWritable: vi.fn()
}))
describe('sparse preset validation transport', () => {
it('identifies both absolute and parent-segment directory failures by type', () => {
expect(() => normalizeSparseDirectories(['/outside'])).toThrow(InvalidSparseDirectoryError)
expect(() => normalizeSparseDirectories(['../outside'])).toThrow(InvalidSparseDirectoryError)
})
it.each([
{ name: '', directories: ['src'], code: 'name_required' },
{ name: 'a'.repeat(81), directories: ['src'], code: 'name_too_long' },
{ name: 'Preset', directories: [], code: 'directories_required' },
{ name: 'Preset', directories: ['../outside'], code: 'directories_invalid' },
{ name: 'Preset', directories: ['/outside'], code: 'directories_invalid' }
])(
'returns IPC code $code instead of saving an invalid preset',
({ name, directories, code }) => {
const saveSparsePreset = vi.fn()
// oxlint-disable-next-line typescript/consistent-type-assertions -- SAFETY: validation only reads these store methods.
const store = { getRepo: () => ({}), saveSparsePreset } as unknown as Store
// oxlint-disable-next-line typescript/consistent-type-assertions -- SAFETY: invalid input returns before the window is accessed.
registerSparsePresetHandlers({} as BrowserWindow, store)
const result = handlers.get('sparsePresets:save')?.(undefined, {
repoId: 'repo',
name,
directories
})
expect(result).toMatchObject({ errorCode: code })
expect(saveSparsePreset).not.toHaveBeenCalled()
}
)
it('keeps the validation reason in the RPC envelope', () => {
let failure: unknown
try {
@@ -1,26 +0,0 @@
import { afterEach, expect, it, vi } from 'vitest'
import { createStructuredAgentEnvironmentResolvers } from './structured-agent-shell-environment'
afterEach(() => vi.unstubAllGlobals())
it.each([
['win32', { TOKEN: 'configured', PATH: '/configured/bin', KEEP: 'keep' }],
[
'linux',
{
TOKEN: 'inherited',
PATH: '/inherited/bin',
tOKEN: 'configured',
path: '/configured/bin',
KEEP: 'keep'
}
]
] as const)('composes the effective agent environment on %s', async (platform, expected) => {
vi.stubGlobal('process', { ...process, platform })
const environment = createStructuredAgentEnvironmentResolvers({
resolveEnvironment: async () => ({ TOKEN: 'inherited', PATH: '/inherited/bin', KEEP: 'keep' }),
resolveAgentLaunchEnv: () => ({ tOKEN: 'configured', path: '/configured/bin' })
})
expect(await environment.resolveAgentEnvironment('claude')).toEqual(expected)
expect(await environment.resolveAgentEnvironment('codex')).toEqual(expected)
})
@@ -1,21 +0,0 @@
import { afterEach, expect, it, vi } from 'vitest'
import { resolveHostStructuredAgentLaunchEnvironment } from './structured-agent-launch-support'
import type * as Environment from '../environment/structured-agent-shell-environment'
vi.mock('../environment/structured-agent-shell-environment', async (importOriginal) => ({
...(await importOriginal<typeof Environment>()),
resolveHostAgentBaseEnvironment: async () => ({
TOKEN: 'inherited',
PATH: '/inherited/bin',
KEEP: 'keep'
})
}))
afterEach(() => vi.unstubAllGlobals())
it('uses the configured Windows environment for launch preflight', async () => {
vi.stubGlobal('process', { ...process, platform: 'win32' })
const env = await resolveHostStructuredAgentLaunchEnvironment('claude', {
agentDefaultEnv: { claude: { tOKEN: 'configured', path: '/configured/bin' } }
})
expect(env).toEqual({ TOKEN: 'configured', PATH: '/configured/bin', KEEP: 'keep' })
})
@@ -1,25 +0,0 @@
// @vitest-environment happy-dom
import { cleanup, fireEvent, render, screen } from '@testing-library/react'
import { afterEach, beforeEach, expect, it, vi } from 'vitest'
import { getDefaultSettings } from '../../../../../shared/constants'
import { useAppStore } from '@/store'
import { TooltipProvider } from '../../ui/tooltip'
import { ExperimentalPane } from './ExperimentalPane'
beforeEach(() => useAppStore.setState(useAppStore.getInitialState(), true))
afterEach(cleanup)
it('opens the ordinary Experimental pane and preserves its setting action', () => {
const updateSettings = vi.fn()
render(
<TooltipProvider>
<ExperimentalPane
settings={{ ...getDefaultSettings('/tmp'), experimentalPet: false }}
updateSettings={updateSettings}
/>
</TooltipProvider>
)
fireEvent.click(screen.getByRole('switch', { name: 'Pet' }))
expect(updateSettings).toHaveBeenCalledWith({ experimentalPet: true })
})
@@ -1,32 +0,0 @@
// @vitest-environment happy-dom
import { cleanup, fireEvent, render, screen } from '@testing-library/react'
import { afterEach, describe, expect, it, vi } from 'vitest'
import { createGlobalSettingsFixture } from '../../../../../shared/global-settings-test-fixture'
import { WorkspaceDirectorySetting } from './WorkspaceDirectorySetting'
vi.mock('../section-layout/SearchableSetting', () => ({
SearchableSetting: ({ children }) => children
}))
vi.mock('../../sidebar/worktree-list/controls/use-sidebar-host-scope-options', () => ({
useSidebarHostScopeOptions: () => ({ hostOptions: [] })
}))
afterEach(cleanup)
describe('WorkspaceDirectorySetting', () => {
it('shows the saved path and writes nothing when a padded copy of it is committed', () => {
const updateSettings = vi.fn()
render(
<WorkspaceDirectorySetting
settings={createGlobalSettingsFixture({ workspaceDir: '/Users/me/dev' })}
updateSettings={updateSettings}
/>
)
const input = screen.getByRole<HTMLInputElement>('textbox')
fireEvent.change(input, { target: { value: ' /Users/me/dev' } })
fireEvent.blur(input)
expect(input.value).toBe('/Users/me/dev')
expect(updateSettings).not.toHaveBeenCalled()
})
})
@@ -1,53 +0,0 @@
// @vitest-environment happy-dom
import { afterEach, expect, it, vi } from 'vitest'
import type { Repo } from '../../../../../shared/repo-types'
import { buildSettingsNavigationMetadata } from '@/hooks/useSettingsNavigationMetadata'
import { getRepositoryPaneSearchMetadata } from './repository-search'
import * as worktreeSearch from './worktrees/repository-git-worktree-search-entries'
afterEach(() => vi.restoreAllMocks())
it('builds project search indexes without constructing selected-pane groups at fleet scale', () => {
const buildWorktreeGroups = vi.spyOn(worktreeSearch, 'getRepositoryGitWorktreeSearchMetadata')
const buildNavigation = (repos: Repo[]) =>
buildSettingsNavigationMetadata({
isMac: false,
isWindows: false,
isWebClient: false,
repos
}).filter((section) => section.group === 'repositories')
for (const projectCount of [12, 120]) {
buildWorktreeGroups.mockClear()
const repos = Array.from({ length: projectCount }, (_, index): Repo => ({
id: `project-${index}`,
path: `/tmp/project-${index}`,
displayName: `Project ${index}`,
badgeColor: '',
addedAt: 0
}))
const initial = buildNavigation(repos)
expect(initial).toHaveLength(projectCount)
expect(initial.every((section) => section.searchEntries.length > 0)).toBe(true)
expect(buildWorktreeGroups).not.toHaveBeenCalled()
const changed = { ...repos[0], displayName: 'Renamed project' }
const updated = buildNavigation([changed, ...repos.slice(1)])
expect(updated).toHaveLength(projectCount)
expect(
updated
.find((section) => section.id === 'repo-project-0')
?.searchEntries.some((entry) => entry.keywords?.includes('Renamed project'))
).toBe(true)
expect(buildWorktreeGroups).not.toHaveBeenCalled()
const selectedPane = getRepositoryPaneSearchMetadata(changed)
expect(buildWorktreeGroups).toHaveBeenCalledExactlyOnceWith(changed, expect.any(Function))
expect(
selectedPane.sparsePresets.some((entry) => entry.keywords?.includes('Renamed project'))
).toBe(true)
expect(selectedPane.identity.some((entry) => entry.keywords?.includes('Renamed project'))).toBe(
true
)
}
})
@@ -1,60 +0,0 @@
// @vitest-environment happy-dom
import { cleanup, fireEvent, render, screen } from '@testing-library/react'
import { afterEach, expect, it, vi } from 'vitest'
import { getDefaultVoiceSettings } from '../../../../../shared/constants'
import type { SpeechModelManifest } from '../../../../../shared/speech-types'
import { VoiceDictationLanguageSetting } from './VoiceDictationLanguageSetting'
afterEach(cleanup)
it('searches and updates the selected dictation language', () => {
const onUpdateVoiceSettings = vi.fn()
render(
<VoiceDictationLanguageSetting
voiceSettings={{
...getDefaultVoiceSettings(),
enabled: true,
dictationLanguage: 'ko'
}}
selectedModel={undefined}
onUpdateVoiceSettings={onUpdateVoiceSettings}
/>
)
fireEvent.click(screen.getByRole('combobox', { name: /dictation language/i }))
fireEvent.change(screen.getByRole('combobox', { name: 'Search languages…' }), {
target: { value: 'spanish' }
})
fireEvent.click(screen.getByRole('option', { name: 'Spanish' }))
expect(onUpdateVoiceSettings).toHaveBeenCalledWith({ dictationLanguage: 'es' })
})
it('keeps a selected language visible when the chosen model does not support it', () => {
const selectedModel: SpeechModelManifest = {
id: 'limited',
label: 'Limited model',
type: 'whisper',
provider: 'local',
language: 'multilingual',
languages: ['en', 'es'],
sampleRate: 16000,
streaming: false,
dictationLanguages: ['en', 'es']
}
render(
<VoiceDictationLanguageSetting
voiceSettings={{
...getDefaultVoiceSettings(),
enabled: true,
dictationLanguage: 'ko'
}}
selectedModel={selectedModel}
onUpdateVoiceSettings={vi.fn()}
/>
)
fireEvent.click(screen.getByRole('combobox', { name: /dictation language/i }))
expect(screen.getByRole('option', { name: 'Korean' })).toBeTruthy()
})
@@ -1,42 +0,0 @@
import { describe, expect, it } from 'vitest'
import type { SpeechModelManifest } from '../../../../../shared/speech-types'
import { voiceSpeechModelRows } from './voice-speech-model-rows'
const model = (
id: string,
languages: string[],
extra: Partial<SpeechModelManifest> = {}
): SpeechModelManifest => ({
id,
label: id,
type: 'transducer',
provider: 'local',
language: 'multilingual',
languages,
sampleRate: 16000,
streaming: false,
...extra
})
describe('voiceSpeechModelRows', () => {
it('puts models without the language last and lists retired models only while on disk', () => {
const catalog = [
model('english-only', ['en']),
model('retired-on-disk', ['ko'], { replacedBy: 'korean' }),
model('korean', ['en', 'ko']),
model('retired-gone', ['ko'], { replacedBy: 'korean' }),
model('cloud', ['ko'], { provider: 'openai' })
]
const rows = voiceSpeechModelRows(
catalog,
[{ id: 'retired-on-disk', status: 'ready' }],
'local',
'ko'
)
expect(rows.map((row) => row.manifest.id)).toEqual([
'korean',
'english-only',
'retired-on-disk'
])
})
})