fix(conversion): improve stream failures and diagnostic exports

This commit is contained in:
elky
2026-09-08 21:04:22 +08:00
parent 17d01d7fe0
commit 99f6499b2b
19 changed files with 1378 additions and 66 deletions
@@ -4,6 +4,7 @@ const { getMock } = vi.hoisted(() => ({ getMock: vi.fn() }))
vi.mock('@/api/client', () => ({ default: { get: getMock } }))
import { dashboardApi } from '@/api/dashboard'
import { requestTraceApi } from '@/api/requestTrace'
import { cache } from '@/utils/cache'
beforeEach(() => {
@@ -13,6 +14,20 @@ beforeEach(() => {
})
describe('dashboard body loading', () => {
it('reports download progress so diagnostic exports can abort oversized bodies', async () => {
const onProgress = vi.fn()
getMock.mockResolvedValue({ data: new ArrayBuffer(0), headers: { 'x-aether-body-encoding': 'json', 'x-aether-usage-id': 'usage-1', 'x-aether-body-field': 'response_body' } })
await dashboardApi.getRequestBody('usage-1', 'response_body', undefined, onProgress)
getMock.mock.calls[0][1].onDownloadProgress({ loaded: 2 * 1024 * 1024 })
expect(onProgress).toHaveBeenCalledWith(2 * 1024 * 1024)
})
it('records the gateway version at export without confusing it with failure-time metadata', async () => {
getMock.mockResolvedValue({ data: { request_id: 'request-1', candidates: [] }, headers: { 'x-aether-build-version': 'test-build' } })
expect(await requestTraceApi.getRequestTrace('request-1')).toMatchObject({ gateway_version: 'test-build' })
getMock.mockResolvedValue({ data: { request_id: 'request-1', candidates: [] } })
expect(await requestTraceApi.getRequestTrace('request-1')).toMatchObject({ gateway_version: null })
})
it('requests opaque body bytes, outside the JSON detail cache', async () => {
const bytes = new ArrayBuffer(20)
const controller = new AbortController()