fix: abort model retries immediately on user cancellation
This commit is contained in:
@@ -476,6 +476,38 @@ describe('setClient and labels', () => {
|
||||
expect(router.isTierStrict('default')).toBe(true);
|
||||
});
|
||||
|
||||
it('requestAbort interrupts retry loop before fallback chain', async () => {
|
||||
const primary = {
|
||||
chat: vi.fn().mockRejectedValue(new Error('temporary failure')),
|
||||
} as unknown as ModelClient;
|
||||
const fallback = {
|
||||
chat: vi.fn().mockResolvedValue({
|
||||
content: 'fallback',
|
||||
stopReason: 'end_turn',
|
||||
usage: { inputTokens: 1, outputTokens: 1 },
|
||||
}),
|
||||
} as unknown as ModelClient;
|
||||
|
||||
const router = new ModelRouter({
|
||||
default: primary,
|
||||
fallbackChain: [fallback],
|
||||
retryConfig: {
|
||||
maxRetries: 3,
|
||||
initialDelayMs: 80,
|
||||
backoffMultiplier: 1,
|
||||
maxDelayMs: 80,
|
||||
nonRetryablePatterns: [],
|
||||
},
|
||||
});
|
||||
|
||||
const run = router.chat({ messages: [{ role: 'user', content: 'hi' }] });
|
||||
setTimeout(() => router.requestAbort(), 10);
|
||||
|
||||
await expect(run).rejects.toMatchObject({ name: 'AbortError' });
|
||||
expect(primary.chat).toHaveBeenCalledTimes(1);
|
||||
expect(fallback.chat).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('setOnTierChange does not replace existing listeners', () => {
|
||||
const router = new ModelRouter({
|
||||
default: { chat: vi.fn() } as unknown as ModelClient,
|
||||
|
||||
Reference in New Issue
Block a user