test: stabilize rebased PR 385 checks
This commit is contained in:
@@ -27,6 +27,21 @@ async function flushClipboardCopy(): Promise<void> {
|
|||||||
await new Promise(resolve => setTimeout(resolve, 0))
|
await new Promise(resolve => setTimeout(resolve, 0))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function waitForExecCall(
|
||||||
|
command: string,
|
||||||
|
attempts = 20,
|
||||||
|
): Promise<(typeof execFileNoThrowMock.mock.calls)[number] | undefined> {
|
||||||
|
for (let attempt = 0; attempt < attempts; attempt++) {
|
||||||
|
const call = execFileNoThrowMock.mock.calls.find(([cmd]) => cmd === command)
|
||||||
|
if (call) {
|
||||||
|
return call
|
||||||
|
}
|
||||||
|
await flushClipboardCopy()
|
||||||
|
}
|
||||||
|
|
||||||
|
return undefined
|
||||||
|
}
|
||||||
|
|
||||||
describe('Windows clipboard fallback', () => {
|
describe('Windows clipboard fallback', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
execFileNoThrowMock.mockClear()
|
execFileNoThrowMock.mockClear()
|
||||||
@@ -62,9 +77,7 @@ describe('Windows clipboard fallback', () => {
|
|||||||
await setClipboard('Привет мир')
|
await setClipboard('Привет мир')
|
||||||
await flushClipboardCopy()
|
await flushClipboardCopy()
|
||||||
|
|
||||||
const windowsCall = execFileNoThrowMock.mock.calls.find(
|
const windowsCall = await waitForExecCall('powershell')
|
||||||
([cmd]) => cmd === 'powershell',
|
|
||||||
)
|
|
||||||
|
|
||||||
expect(windowsCall?.[2]).toMatchObject({
|
expect(windowsCall?.[2]).toMatchObject({
|
||||||
stdin: 'ignore',
|
stdin: 'ignore',
|
||||||
|
|||||||
@@ -1,7 +1,17 @@
|
|||||||
import { afterEach, expect, mock, test } from 'bun:test'
|
import { afterEach, beforeEach, expect, mock, test } from 'bun:test'
|
||||||
|
|
||||||
|
import { resetModelStringsForTestingOnly } from '../../bootstrap/state.js'
|
||||||
import { saveGlobalConfig } from '../config.js'
|
import { saveGlobalConfig } from '../config.js'
|
||||||
|
|
||||||
|
async function importFreshModelOptionsModule() {
|
||||||
|
mock.restore()
|
||||||
|
mock.module('./providers.js', () => ({
|
||||||
|
getAPIProvider: () => 'github',
|
||||||
|
}))
|
||||||
|
const nonce = `${Date.now()}-${Math.random()}`
|
||||||
|
return import(`./modelOptions.js?ts=${nonce}`)
|
||||||
|
}
|
||||||
|
|
||||||
const originalEnv = {
|
const originalEnv = {
|
||||||
CLAUDE_CODE_USE_GITHUB: process.env.CLAUDE_CODE_USE_GITHUB,
|
CLAUDE_CODE_USE_GITHUB: process.env.CLAUDE_CODE_USE_GITHUB,
|
||||||
CLAUDE_CODE_USE_OPENAI: process.env.CLAUDE_CODE_USE_OPENAI,
|
CLAUDE_CODE_USE_OPENAI: process.env.CLAUDE_CODE_USE_OPENAI,
|
||||||
@@ -14,6 +24,20 @@ const originalEnv = {
|
|||||||
ANTHROPIC_CUSTOM_MODEL_OPTION: process.env.ANTHROPIC_CUSTOM_MODEL_OPTION,
|
ANTHROPIC_CUSTOM_MODEL_OPTION: process.env.ANTHROPIC_CUSTOM_MODEL_OPTION,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
mock.restore()
|
||||||
|
delete process.env.CLAUDE_CODE_USE_GITHUB
|
||||||
|
delete process.env.CLAUDE_CODE_USE_OPENAI
|
||||||
|
delete process.env.CLAUDE_CODE_USE_GEMINI
|
||||||
|
delete process.env.CLAUDE_CODE_USE_BEDROCK
|
||||||
|
delete process.env.CLAUDE_CODE_USE_VERTEX
|
||||||
|
delete process.env.CLAUDE_CODE_USE_FOUNDRY
|
||||||
|
delete process.env.OPENAI_MODEL
|
||||||
|
delete process.env.OPENAI_BASE_URL
|
||||||
|
delete process.env.ANTHROPIC_CUSTOM_MODEL_OPTION
|
||||||
|
resetModelStringsForTestingOnly()
|
||||||
|
})
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
process.env.CLAUDE_CODE_USE_GITHUB = originalEnv.CLAUDE_CODE_USE_GITHUB
|
process.env.CLAUDE_CODE_USE_GITHUB = originalEnv.CLAUDE_CODE_USE_GITHUB
|
||||||
process.env.CLAUDE_CODE_USE_OPENAI = originalEnv.CLAUDE_CODE_USE_OPENAI
|
process.env.CLAUDE_CODE_USE_OPENAI = originalEnv.CLAUDE_CODE_USE_OPENAI
|
||||||
@@ -34,17 +58,9 @@ afterEach(() => {
|
|||||||
providerProfiles: [],
|
providerProfiles: [],
|
||||||
activeProviderProfileId: undefined,
|
activeProviderProfileId: undefined,
|
||||||
}))
|
}))
|
||||||
|
resetModelStringsForTestingOnly()
|
||||||
})
|
})
|
||||||
|
|
||||||
async function importFreshModelOptionsModule() {
|
|
||||||
mock.restore()
|
|
||||||
mock.module('./providers.js', () => ({
|
|
||||||
getAPIProvider: () => 'github',
|
|
||||||
}))
|
|
||||||
const nonce = `${Date.now()}-${Math.random()}`
|
|
||||||
return import(`./modelOptions.js?ts=${nonce}`)
|
|
||||||
}
|
|
||||||
|
|
||||||
test('GitHub provider exposes only default + GitHub model in /model options', async () => {
|
test('GitHub provider exposes only default + GitHub model in /model options', async () => {
|
||||||
process.env.CLAUDE_CODE_USE_GITHUB = '1'
|
process.env.CLAUDE_CODE_USE_GITHUB = '1'
|
||||||
delete process.env.CLAUDE_CODE_USE_OPENAI
|
delete process.env.CLAUDE_CODE_USE_OPENAI
|
||||||
@@ -58,7 +74,9 @@ test('GitHub provider exposes only default + GitHub model in /model options', as
|
|||||||
|
|
||||||
const { getModelOptions } = await importFreshModelOptionsModule()
|
const { getModelOptions } = await importFreshModelOptionsModule()
|
||||||
const options = getModelOptions(false)
|
const options = getModelOptions(false)
|
||||||
const nonDefault = options.filter(option => option.value !== null)
|
const nonDefault = options.filter(
|
||||||
|
(option: { value: unknown }) => option.value !== null,
|
||||||
|
)
|
||||||
|
|
||||||
expect(nonDefault.length).toBe(1)
|
expect(nonDefault.length).toBe(1)
|
||||||
expect(nonDefault[0]?.value).toBe('github:copilot')
|
expect(nonDefault[0]?.value).toBe('github:copilot')
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { describe, expect, test, afterEach } from 'bun:test'
|
import { afterEach, beforeEach, describe, expect, test } from 'bun:test'
|
||||||
import {
|
import {
|
||||||
parseProviderFlag,
|
parseProviderFlag,
|
||||||
applyProviderFlag,
|
applyProviderFlag,
|
||||||
@@ -8,18 +8,26 @@ import {
|
|||||||
|
|
||||||
const originalEnv = { ...process.env }
|
const originalEnv = { ...process.env }
|
||||||
|
|
||||||
|
const RESET_KEYS = [
|
||||||
|
'CLAUDE_CODE_USE_OPENAI',
|
||||||
|
'CLAUDE_CODE_USE_GEMINI',
|
||||||
|
'CLAUDE_CODE_USE_GITHUB',
|
||||||
|
'CLAUDE_CODE_USE_BEDROCK',
|
||||||
|
'CLAUDE_CODE_USE_VERTEX',
|
||||||
|
'OPENAI_BASE_URL',
|
||||||
|
'OPENAI_API_KEY',
|
||||||
|
'OPENAI_MODEL',
|
||||||
|
'GEMINI_MODEL',
|
||||||
|
] as const
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
for (const key of RESET_KEYS) {
|
||||||
|
delete process.env[key]
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
for (const key of [
|
for (const key of RESET_KEYS) {
|
||||||
'CLAUDE_CODE_USE_OPENAI',
|
|
||||||
'CLAUDE_CODE_USE_GEMINI',
|
|
||||||
'CLAUDE_CODE_USE_GITHUB',
|
|
||||||
'CLAUDE_CODE_USE_BEDROCK',
|
|
||||||
'CLAUDE_CODE_USE_VERTEX',
|
|
||||||
'OPENAI_BASE_URL',
|
|
||||||
'OPENAI_API_KEY',
|
|
||||||
'OPENAI_MODEL',
|
|
||||||
'GEMINI_MODEL',
|
|
||||||
]) {
|
|
||||||
if (originalEnv[key] === undefined) delete process.env[key]
|
if (originalEnv[key] === undefined) delete process.env[key]
|
||||||
else process.env[key] = originalEnv[key]
|
else process.env[key] = originalEnv[key]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -105,7 +105,7 @@ describe('applyProviderProfileToProcessEnv', () => {
|
|||||||
|
|
||||||
expect(process.env.CLAUDE_CODE_USE_GEMINI).toBeUndefined()
|
expect(process.env.CLAUDE_CODE_USE_GEMINI).toBeUndefined()
|
||||||
expect(process.env.CLAUDE_CODE_USE_GITHUB).toBeUndefined()
|
expect(process.env.CLAUDE_CODE_USE_GITHUB).toBeUndefined()
|
||||||
expect(process.env.CLAUDE_CODE_USE_OPENAI).toBe('1')
|
expect(String(process.env.CLAUDE_CODE_USE_OPENAI)).toBe('1')
|
||||||
expect(process.env.CLAUDE_CODE_PROVIDER_PROFILE_ENV_APPLIED_ID).toBe(
|
expect(process.env.CLAUDE_CODE_PROVIDER_PROFILE_ENV_APPLIED_ID).toBe(
|
||||||
'provider_test',
|
'provider_test',
|
||||||
)
|
)
|
||||||
@@ -177,7 +177,7 @@ describe('applyActiveProviderProfileFromConfig', () => {
|
|||||||
} as any)
|
} as any)
|
||||||
|
|
||||||
expect(applied).toBeUndefined()
|
expect(applied).toBeUndefined()
|
||||||
expect(process.env.CLAUDE_CODE_USE_OPENAI).toBe('1')
|
expect(String(process.env.CLAUDE_CODE_USE_OPENAI)).toBe('1')
|
||||||
expect(process.env.OPENAI_BASE_URL).toBe('http://localhost:11434/v1')
|
expect(process.env.OPENAI_BASE_URL).toBe('http://localhost:11434/v1')
|
||||||
expect(process.env.OPENAI_MODEL).toBe('qwen2.5:3b')
|
expect(process.env.OPENAI_MODEL).toBe('qwen2.5:3b')
|
||||||
})
|
})
|
||||||
@@ -267,7 +267,7 @@ describe('applyActiveProviderProfileFromConfig', () => {
|
|||||||
} as any)
|
} as any)
|
||||||
|
|
||||||
expect(applied?.id).toBe('saved_openai')
|
expect(applied?.id).toBe('saved_openai')
|
||||||
expect(process.env.CLAUDE_CODE_USE_OPENAI).toBe('1')
|
expect(String(process.env.CLAUDE_CODE_USE_OPENAI)).toBe('1')
|
||||||
expect(process.env.OPENAI_BASE_URL).toBe('https://api.openai.com/v1')
|
expect(process.env.OPENAI_BASE_URL).toBe('https://api.openai.com/v1')
|
||||||
expect(process.env.OPENAI_MODEL).toBe('gpt-4o')
|
expect(process.env.OPENAI_MODEL).toBe('gpt-4o')
|
||||||
})
|
})
|
||||||
@@ -286,10 +286,10 @@ describe('persistActiveProviderProfileModel', () => {
|
|||||||
model: 'kimi-k2.5:cloud',
|
model: 'kimi-k2.5:cloud',
|
||||||
})
|
})
|
||||||
|
|
||||||
saveMockGlobalConfig(current => ({
|
saveMockGlobalConfig(current => ({
|
||||||
...current,
|
...current,
|
||||||
providerProfiles: [activeProfile],
|
providerProfiles: [activeProfile],
|
||||||
activeProviderProfileId: activeProfile.id,
|
activeProviderProfileId: activeProfile.id,
|
||||||
}))
|
}))
|
||||||
applyProviderProfileToProcessEnv(activeProfile)
|
applyProviderProfileToProcessEnv(activeProfile)
|
||||||
|
|
||||||
@@ -303,7 +303,7 @@ describe('persistActiveProviderProfileModel', () => {
|
|||||||
)
|
)
|
||||||
|
|
||||||
const saved = getProviderProfiles().find(
|
const saved = getProviderProfiles().find(
|
||||||
profile => profile.id === activeProfile.id,
|
(profile: ProviderProfile) => profile.id === activeProfile.id,
|
||||||
)
|
)
|
||||||
expect(saved?.model).toBe('minimax-m2.5:cloud')
|
expect(saved?.model).toBe('minimax-m2.5:cloud')
|
||||||
})
|
})
|
||||||
@@ -333,7 +333,7 @@ describe('persistActiveProviderProfileModel', () => {
|
|||||||
|
|
||||||
expect(process.env.OPENAI_MODEL).toBe('cli-model')
|
expect(process.env.OPENAI_MODEL).toBe('cli-model')
|
||||||
const saved = getProviderProfiles().find(
|
const saved = getProviderProfiles().find(
|
||||||
profile => profile.id === activeProfile.id,
|
(profile: ProviderProfile) => profile.id === activeProfile.id,
|
||||||
)
|
)
|
||||||
expect(saved?.model).toBe('minimax-m2.5:cloud')
|
expect(saved?.model).toBe('minimax-m2.5:cloud')
|
||||||
})
|
})
|
||||||
@@ -414,7 +414,7 @@ describe('deleteProviderProfile', () => {
|
|||||||
expect(result.activeProfileId).toBeUndefined()
|
expect(result.activeProfileId).toBeUndefined()
|
||||||
|
|
||||||
expect(process.env.CLAUDE_CODE_PROVIDER_PROFILE_ENV_APPLIED).toBeUndefined()
|
expect(process.env.CLAUDE_CODE_PROVIDER_PROFILE_ENV_APPLIED).toBeUndefined()
|
||||||
expect(process.env.CLAUDE_CODE_USE_OPENAI).toBe('1')
|
expect(String(process.env.CLAUDE_CODE_USE_OPENAI)).toBe('1')
|
||||||
expect(process.env.OPENAI_BASE_URL).toBe('http://localhost:11434/v1')
|
expect(process.env.OPENAI_BASE_URL).toBe('http://localhost:11434/v1')
|
||||||
expect(process.env.OPENAI_MODEL).toBe('qwen2.5:3b')
|
expect(process.env.OPENAI_MODEL).toBe('qwen2.5:3b')
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user