Skip to content

Commit 5f364b8

Browse files
committed
test: clarify distinction between UI display and auto-retry
Added tests that explicitly demonstrate the key distinction: - hasInterruptedStream = Should RetryBarrier UI be shown? - isEligibleForAutoRetry = Should system auto-retry? For non-retryable errors (authentication, quota): - hasInterruptedStream returns true (show UI) - isEligibleForAutoRetry returns false (don't auto-retry) - Result: User sees manual Retry button, not 'Retrying...' For retryable errors (network, server): - Both return true - Result: User sees 'Retrying...' with countdown and exponential backoff This prevents confusion about why we have two similar-sounding functions.
1 parent ad532e8 commit 5f364b8

File tree

1 file changed

+108
-0
lines changed

1 file changed

+108
-0
lines changed

src/utils/messages/retryEligibility.test.ts

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,114 @@ describe("hasInterruptedStream", () => {
286286
});
287287

288288
describe("isEligibleForAutoRetry", () => {
289+
describe("hasInterruptedStream vs isEligibleForAutoRetry distinction", () => {
290+
// These tests demonstrate the key distinction in our retry system:
291+
// - hasInterruptedStream: Should UI show retry barrier? (YES for all errors)
292+
// - isEligibleForAutoRetry: Should system auto-retry? (NO for non-retryable errors)
293+
294+
describe("authentication errors", () => {
295+
const messages: DisplayedMessage[] = [
296+
{
297+
type: "user",
298+
id: "user-1",
299+
historyId: "user-1",
300+
content: "Hello",
301+
historySequence: 1,
302+
},
303+
{
304+
type: "stream-error",
305+
id: "error-1",
306+
historyId: "assistant-1",
307+
error: "Invalid API key",
308+
errorType: "authentication",
309+
historySequence: 2,
310+
},
311+
];
312+
313+
it("hasInterruptedStream returns true (show UI)", () => {
314+
expect(hasInterruptedStream(messages)).toBe(true);
315+
});
316+
317+
it("isEligibleForAutoRetry returns false (don't auto-retry)", () => {
318+
expect(isEligibleForAutoRetry(messages)).toBe(false);
319+
});
320+
321+
it("behavior: UI shows Retry button, not 'Retrying...'", () => {
322+
// This combination means:
323+
// - User sees RetryBarrier with manual "Retry" button
324+
// - System does NOT auto-retry (infinite loop prevention)
325+
// - User can manually retry after fixing API key
326+
expect(hasInterruptedStream(messages)).toBe(true);
327+
expect(isEligibleForAutoRetry(messages)).toBe(false);
328+
});
329+
});
330+
331+
describe("quota errors", () => {
332+
const messages: DisplayedMessage[] = [
333+
{
334+
type: "user",
335+
id: "user-1",
336+
historyId: "user-1",
337+
content: "Hello",
338+
historySequence: 1,
339+
},
340+
{
341+
type: "stream-error",
342+
id: "error-1",
343+
historyId: "assistant-1",
344+
error: "Usage quota exceeded",
345+
errorType: "quota",
346+
historySequence: 2,
347+
},
348+
];
349+
350+
it("hasInterruptedStream returns true (show UI)", () => {
351+
expect(hasInterruptedStream(messages)).toBe(true);
352+
});
353+
354+
it("isEligibleForAutoRetry returns false (don't auto-retry)", () => {
355+
expect(isEligibleForAutoRetry(messages)).toBe(false);
356+
});
357+
});
358+
359+
describe("network errors (retryable)", () => {
360+
const messages: DisplayedMessage[] = [
361+
{
362+
type: "user",
363+
id: "user-1",
364+
historyId: "user-1",
365+
content: "Hello",
366+
historySequence: 1,
367+
},
368+
{
369+
type: "stream-error",
370+
id: "error-1",
371+
historyId: "assistant-1",
372+
error: "Network connection failed",
373+
errorType: "network",
374+
historySequence: 2,
375+
},
376+
];
377+
378+
it("hasInterruptedStream returns true (show UI)", () => {
379+
expect(hasInterruptedStream(messages)).toBe(true);
380+
});
381+
382+
it("isEligibleForAutoRetry returns true (auto-retry with backoff)", () => {
383+
expect(isEligibleForAutoRetry(messages)).toBe(true);
384+
});
385+
386+
it("behavior: UI shows 'Retrying...' with countdown", () => {
387+
// This combination means:
388+
// - User sees RetryBarrier with "Retrying... (attempt N)"
389+
// - System auto-retries with exponential backoff
390+
// - User can stop with Ctrl+C
391+
expect(hasInterruptedStream(messages)).toBe(true);
392+
expect(isEligibleForAutoRetry(messages)).toBe(true);
393+
});
394+
});
395+
});
396+
289397
it("returns false for empty messages", () => {
290398
expect(isEligibleForAutoRetry([])).toBe(false);
291399
});

0 commit comments

Comments
 (0)