Files
magpie/internal/gateway/testdata/clinepass_stream.sse
T
yetone fc78eb5f6b gateway: ClinePass's upstream is read from provider_metadata.gateway.routing.finalProvider (#2847, smart-lty)
ClinePass (api.cline.bot) names the provider that answered only in a
Chat choice's provider_metadata.gateway.routing.finalProvider: under
delta in a stream chunk, and under message in a single body. upstreamOf
read only a top-level provider, message.provider and response.provider,
so the Routing page's 上游 column, the request log and the usage ledger
showed nothing for ClinePass.

upstreamOf now also reads finalProvider at those two places, and nowhere
else. A choice's content belongs to the model. providerAttempts inside
routing lists every provider that was tried, not the one that answered.
The cheap pre-check now passes a chunk that carries only
"finalProvider".

Tests:
- TestUpstreamOfClinePass checks:
  - the real chunk gives deepseek;
  - the same chunk as one body (message) gives deepseek;
  - content, tool_call arguments, providerAttempts alone and an
    object-valued finalProvider give "";
  - a top-level provider still wins.
- TestClinePassUpstreamRecorded serves the real stream through the
  Handler on /v1/chat/completions and on /v1/messages (translated). It
  checks that the route, the try, Recent() and the usage ledger all say
  deepseek.

The fixture testdata/clinepass_stream.sse is a real ClinePass stream:
api.cline.bot, deepseek/deepseek-v4.1-flash, captured 2026-10-02 in the
MIT-licensed wkeking/clinepass-channel-monitor
(internal/channellog/testdata/plain_success.log). It is not the
reporter's own bytes; #2847 has none.

What was run at 1a3b92688 + this change, on macOS (Go 1.26.8):
- gofmt -l: clean.
- go vet: darwin, linux (-tags nogui) and windows.
- Builds: darwin, linux (nogui) and windows.
- go test -run 'TestUpstream|TestClinePass|TestServed' ./internal/gateway: ok.
- Broken by hand: with the old upstream.go put back, both new tests go
  red ("real ClinePass chunk: upstreamOf = \"\"; want deepseek", plus the
  route, request-log and usage assertions on both paths).
- go test -timeout 45m ./... at load average 420-460 (several sessions'
  suites at once). agent, davsync, gateway, library, plugin and provider
  ran past the 45m timeout. gui was red on load reds that are already
  filed:
  - TestSetAnswersWhileDevinAndProvidersHang: #1375.
  - TestTrayCellClickReleasedPanel: #2645.
  - TestClaudeAccountsSpentFallBackToCodex: #2859, also #2858.
  - TestHostOnBunLackingLibsSaysWhich and TestGatewayHookMixedPiPackage:
    #2865.
  - The package timeouts: #2869.
  Every other package was ok.

Not tried: a live ClinePass account in the real app.
2026-10-19 07:38:46 +08:00

4 lines
2.3 KiB
Plaintext

data: {"id":"gen_01M3YFPP549JB6EP8D4RCXD6EH","object":"chat.completion.chunk","created":1790950726,"model":"deepseek/deepseek-v4.1-flash","choices":[{"index":0,"delta":{"role":"assistant"},"logprobs":null,"finish_reason":null}],"system_fingerprint":"fp_jgawxng80g"}
data: {"choices":[{"delta":{"provider_metadata":{"deepseek":{"choiceIndex":0,"messageRole":"assistant","promptCacheHitTokens":0,"promptCacheMissTokens":37,"responseObject":"chat.completion.chunk","systemFingerprint":"aeb56401ca74e127821c4f9126dcb669"},"gateway":{"cost":"0.00001515","gatewayCost":"0.00001515","generationId":"gen_01M3YFPP549JB6EP8D4RCXD6EH","inferenceCost":"0.00001515","inputInferenceCost":"0.00000555","marketCost":"0.00001515","outputInferenceCost":"0.0000096","routing":{"affinity":{"outcome":"confirmed","pinnedProvider":"deepseek"},"canonicalSlug":"deepseek/deepseek-v4.1-flash","clientSessionId":"sess-ed01ce273d78b615f19287b8325e4aee","clientSessionIdSource":"explicit","fallbacksAvailable":[],"finalProvider":"deepseek","modelAttemptCount":1,"modelAttempts":[{"canonicalSlug":"deepseek/deepseek-v4.1-flash","providerAttemptCount":1,"providerAttempts":[{"credentialType":"system","endTime":1790950726481,"provider":"deepseek","providerRequestId":"4ae0eeb4ebc6bcc03390f31ec70cc26a","providerResponseId":"00b1015b-004f-4132-9223-649fed188560","startTime":1790950725813,"statusCode":200,"success":true}],"success":true}],"originalModelId":"deepseek/deepseek-v4.1-flash","planningReasoning":"Provider set restricted to: deepseek. System credentials planned for: deepseek. Total execution order: deepseek(system)","resolvedProvider":"deepseek","totalProviderAttemptCount":1},"surchargeCost":"0"}}},"finish_reason":"length","index":0,"logprobs":null}],"created":1790950726,"generationId":"gen_01M3YFPP549JB6EP8D4RCXD6EH","id":"gen_01M3YFPP549JB6EP8D4RCXD6EH","model":"deepseek/deepseek-v4.1-flash","object":"chat.completion.chunk","system_fingerprint":"fp_jgawxng80g","usage":{"cache_creation_input_tokens":0,"completion_tokens":16,"completion_tokens_details":{"image_tokens":0,"reasoning_tokens":16},"cost":0.00001515,"cost_details":null,"gateway_cost":0.00001515,"is_byok":false,"market_cost":0.00001515,"prompt_tokens":37,"prompt_tokens_details":{"audio_tokens":0,"cached_tokens":0,"video_tokens":0},"total_tokens":53}}
data: [DONE]