test(web): cover the config-present branch of exa/perplexity apply
The numResults (exa) and searchRecency (perplexity) conditional spreads in apply() were only exercised on their absent side, leaving the 100% per-file branch gate red. Add plugin-registration tests that pass those config fields and assert they reach the request body.
This commit is contained in:
@@ -217,15 +217,15 @@ describe('web-search-exa plugin registration', () => {
|
||||
expect('default' in exaPlugin).toBe(false)
|
||||
})
|
||||
|
||||
it('threads searchType and highlightsPerResult config into the request', async () => {
|
||||
it('threads searchType, highlightsPerResult and numResults config into the request', async () => {
|
||||
const fetchMock = vi.fn(async () => jsonResponse({ results: [] }))
|
||||
vi.stubGlobal('fetch', fetchMock)
|
||||
const ctx = new Context()
|
||||
await ctx.plugin(WebService, { searchProvider: EXA_PROVIDER_ID })
|
||||
const fiber = await ctx.plugin(exaPlugin, { apiKey: 'exa-key', searchType: 'keyword', highlightsPerResult: 2 })
|
||||
const fiber = await ctx.plugin(exaPlugin, { apiKey: 'exa-key', searchType: 'keyword', highlightsPerResult: 2, numResults: 9 })
|
||||
await ctx.web.search({ query: 'q' })
|
||||
const [, init] = fetchMock.mock.calls[0] as unknown as [string, RequestInit]
|
||||
expect(JSON.parse(init.body as string)).toMatchObject({ type: 'keyword', contents: { highlights: { highlightsPerUrl: 2 } } })
|
||||
expect(JSON.parse(init.body as string)).toMatchObject({ type: 'keyword', contents: { highlights: { highlightsPerUrl: 2 } }, numResults: 9 })
|
||||
await fiber.dispose()
|
||||
})
|
||||
|
||||
|
||||
@@ -198,6 +198,18 @@ describe('web-search-perplexity plugin registration', () => {
|
||||
expect('default' in perplexityPlugin).toBe(false)
|
||||
})
|
||||
|
||||
it('threads maxTokens and searchRecency config into the request', async () => {
|
||||
const fetchMock = vi.fn(async () => jsonResponse({ choices: [{ message: { content: 'a' } }], citations: [] }))
|
||||
vi.stubGlobal('fetch', fetchMock)
|
||||
const ctx = new Context()
|
||||
await ctx.plugin(WebService, { searchProvider: PERPLEXITY_PROVIDER_ID })
|
||||
const fiber = await ctx.plugin(perplexityPlugin, { apiKey: 'pplx-key', maxTokens: 256, searchRecency: 'month' })
|
||||
await ctx.web.search({ query: 'q' })
|
||||
const [, init] = fetchMock.mock.calls[0] as unknown as [string, RequestInit]
|
||||
expect(JSON.parse(init.body as string)).toMatchObject({ max_tokens: 256, search_recency_filter: 'month' })
|
||||
await fiber.dispose()
|
||||
})
|
||||
|
||||
it('falls back to env key and defaults for base URL and model when config omits them', async () => {
|
||||
const prev = process.env.PERPLEXITY_API_KEY
|
||||
process.env.PERPLEXITY_API_KEY = 'env-key'
|
||||
|
||||
Reference in New Issue
Block a user