Files
metapi/src/server/services/proxyRetryPolicy.test.ts
T
cita 4e22b379a8 feat: Add support for OpenAI Responses endpoint and enhance proxy retry logic
- Updated proxyRetryPolicy to retry on all 4xx and 5xx status codes.
- Introduced 'responses' target format in TestChatRequestPayload.
- Implemented extractResponsesContent function to handle responses format in ModelTester.
- Enhanced ModelTester to support responses target format and display appropriate labels.
- Updated ProxyLogs to extract and display upstream paths from error messages.
- Added tests to ensure responses target format is preserved during payload sync.
- Created responses proxy route to handle requests to the new OpenAI Responses endpoint.
- Updated upstreamEndpoint logic to include responses endpoint handling.
- Added modelService tests to validate token route rebuilding logic.
2026-03-01 15:21:16 +08:00

41 lines
1.5 KiB
TypeScript

import { describe, expect, it } from 'vitest';
import { shouldRetryProxyRequest } from './proxyRetryPolicy.js';
describe('proxyRetryPolicy', () => {
it('retries on rate limit and server errors', () => {
expect(shouldRetryProxyRequest(429, 'rate limit')).toBe(true);
expect(shouldRetryProxyRequest(500, 'internal error')).toBe(true);
expect(shouldRetryProxyRequest(503, 'service unavailable')).toBe(true);
});
it('retries on model unsupported messages from upstream', () => {
expect(
shouldRetryProxyRequest(400, '{"error":"当前 API 不支持所选模型 claude-sonnet-4-5-20250929","type":"error"}'),
).toBe(true);
expect(
shouldRetryProxyRequest(400, '{"error":{"message":"unsupported model: claude-3"}}'),
).toBe(true);
expect(
shouldRetryProxyRequest(404, '{"error":{"message":"The model `gpt-4.1` does not exist"}}'),
).toBe(true);
});
it('retries on generic client request errors for cross-channel fallback', () => {
expect(
shouldRetryProxyRequest(400, '{"error":{"message":"invalid request body"}}'),
).toBe(true);
expect(
shouldRetryProxyRequest(401, '{"error":{"message":"invalid access token"}}'),
).toBe(true);
expect(
shouldRetryProxyRequest(403, '{"error":{"message":"forbidden"}}'),
).toBe(true);
expect(
shouldRetryProxyRequest(404, '{"error":{"message":"not found"}}'),
).toBe(true);
expect(
shouldRetryProxyRequest(422, '{"error":{"message":"unprocessable"}}'),
).toBe(true);
});
});