mirror of
https://github.com/claude-code-best/claude-code.git
synced 2026-06-15 12:55:51 +00:00
71 lines
2.0 KiB
TypeScript
71 lines
2.0 KiB
TypeScript
import { afterEach, describe, expect, mock, test } from 'bun:test'
|
|
|
|
let isFirstPartyBaseUrl = true
|
|
|
|
mock.module('../adapters/apiAdapter.js', () => ({
|
|
ApiSearchAdapter: class ApiSearchAdapter {},
|
|
}))
|
|
|
|
mock.module('../adapters/bingAdapter.js', () => ({
|
|
BingSearchAdapter: class BingSearchAdapter {},
|
|
}))
|
|
|
|
mock.module('../adapters/braveAdapter.js', () => ({
|
|
BraveSearchAdapter: class BraveSearchAdapter {},
|
|
}))
|
|
|
|
mock.module('../../../utils/model/providers.js', () => ({
|
|
isFirstPartyAnthropicBaseUrl: () => isFirstPartyBaseUrl,
|
|
}))
|
|
|
|
const { createAdapter } = await import('../adapters/index')
|
|
|
|
const originalWebSearchAdapter = process.env.WEB_SEARCH_ADAPTER
|
|
|
|
afterEach(() => {
|
|
isFirstPartyBaseUrl = true
|
|
|
|
if (originalWebSearchAdapter === undefined) {
|
|
delete process.env.WEB_SEARCH_ADAPTER
|
|
} else {
|
|
process.env.WEB_SEARCH_ADAPTER = originalWebSearchAdapter
|
|
}
|
|
})
|
|
|
|
describe('createAdapter', () => {
|
|
test('reuses the same instance when the selected backend does not change', () => {
|
|
process.env.WEB_SEARCH_ADAPTER = 'brave'
|
|
|
|
const firstAdapter = createAdapter()
|
|
const secondAdapter = createAdapter()
|
|
|
|
expect(firstAdapter).toBe(secondAdapter)
|
|
expect(firstAdapter.constructor.name).toBe('BraveSearchAdapter')
|
|
})
|
|
|
|
test('rebuilds the adapter when WEB_SEARCH_ADAPTER changes', () => {
|
|
process.env.WEB_SEARCH_ADAPTER = 'brave'
|
|
const braveAdapter = createAdapter()
|
|
|
|
process.env.WEB_SEARCH_ADAPTER = 'bing'
|
|
const bingAdapter = createAdapter()
|
|
|
|
expect(bingAdapter).not.toBe(braveAdapter)
|
|
expect(bingAdapter.constructor.name).toBe('BingSearchAdapter')
|
|
})
|
|
|
|
test('selects the API adapter for first-party Anthropic URLs', () => {
|
|
delete process.env.WEB_SEARCH_ADAPTER
|
|
isFirstPartyBaseUrl = true
|
|
|
|
expect(createAdapter().constructor.name).toBe('ApiSearchAdapter')
|
|
})
|
|
|
|
test('selects the Bing adapter for third-party Anthropic base URLs', () => {
|
|
delete process.env.WEB_SEARCH_ADAPTER
|
|
isFirstPartyBaseUrl = false
|
|
|
|
expect(createAdapter().constructor.name).toBe('BingSearchAdapter')
|
|
})
|
|
})
|