Files
deepseek-harness/packages/web/web-deepseek-api/tests/web-deepseek-api.e2e.ts
T
LegGasai 651a6ccdf0 refactor(web-deepseek-api): take Search and Fetch credentials from ctx.deepseekAuth
The plugin asked `ctx.llm.providerCredential()` for each route's credential, read `DEEPSEEK_API_KEY` and the account service itself when a route was not mounted, ordered those sources by billing, and rendered the request headers in its transport. It now names the kinds the two APIs accept and the capability's billing, and `ctx.deepseekAuth` returns the ordered credentials, each bound to its endpoint. The plugin keeps the wording of its failures; the transport sends the headers it is given.

Behavior is unchanged except in two places. A key that is blank or cannot travel in an HTTP header is reported with the error name `DeepSeekAuthError` where it named `LlmError`. A capability's own base URL that embeds credentials now leaves the provider unavailable, as one that does not parse already did; `fetch` refused such a URL before.

The package no longer depends on `dsh-llm`, `dsh-launch-environment`, or the account service. The transport's `apiKeyHeaders` request option, which only tests set, is gone, and the tests of adapters that publish the other credential kind under a DeepSeek route id went with that publication.
2026-11-15 16:21:01 +08:00

29 lines
1.7 KiB
TypeScript

import { describe, expect, it } from 'vitest'
import { DeepSeekFetchApiProvider, DeepSeekSearchApiProvider } from '@deepseek-ai/dsh-web-deepseek-api'
import { customGuidance } from './guidance.ts'
import { keyCandidate } from './sources.ts'
/** Real Search and Fetch API probes; the base names the deployment the key authenticates. */
const apiKey = process.env.DEEPSEEK_API_KEY
const baseURL = process.env.DEEPSEEK_SEARCH_API_TEST_BASE_URL ?? ''
const auth = (path: '/search' | '/fetch') => ({ sources: [keyCandidate(`${baseURL}${path}`, apiKey ?? '', 'DEEPSEEK_API_KEY')] })
const maybe = apiKey !== undefined && apiKey.length > 0 && baseURL.length > 0 ? describe : describe.skip
maybe('DeepSeek Search and Fetch real API', () => {
it('returns citeable sources from the Search API', async () => {
const provider = new DeepSeekSearchApiProvider(() => ({ auth: auth('/search'), count: 10, requestsPerSecond: 5, guidance: customGuidance('search') }))
const result = await provider.search({ query: 'DeepSeek', maxResults: 3 }, AbortSignal.timeout(30_000))
expect(result.sources.length).toBeGreaterThan(0)
expect(result.sources.length).toBeLessThanOrEqual(3)
for (const source of result.sources) expect(source.url).toMatch(/^https?:\/\//)
}, 40_000)
it('returns Markdown from the Fetch API', async () => {
const provider = new DeepSeekFetchApiProvider(() => ({ auth: auth('/fetch'), guidance: customGuidance('fetch') }))
const result = await provider.fetch({ url: 'https://example.com' }, AbortSignal.timeout(30_000))
expect(result.body.kind).toBe('text')
expect(result.body.content.length).toBeGreaterThan(0)
expect(result.statusCode).toBe(200)
}, 40_000)
})