Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion packages/frontend/src/lib/pending-authorization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,12 @@ export function pendingAuthorizationPath(step: PendingAuthorizationStep): '/auth
/** Asks the backend; null when nothing is waiting or the question failed. */
export async function fetchPendingAuthorization(timeoutMs = 5000): Promise<PendingAuthorization | null> {
const controller = typeof AbortController === 'undefined' ? null : new AbortController();
const timer = controller ? setTimeout(() => controller.abort(), timeoutMs) : null;
// Abort with a named reason: a bare abort() rejects with "signal is aborted
// without reason", which Sentry's fetch instrumentation reported as an
// unhandled error (CLOUD-FRONTEND-Y / -10) although this function catches it.
const timer = controller
? setTimeout(() => controller.abort(new DOMException('GET /auth/pending timed out', 'TimeoutError')), timeoutMs)
: null;
try {
const response = await fetch('/auth/pending', {
headers: { Accept: 'application/json' },
Expand Down
20 changes: 20 additions & 0 deletions packages/frontend/tests/e2e/pending-authorization.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { expect, test, type Page } from '@playwright/test';
import {
CLIENT_NAME_MAX,
displayClientName,
fetchPendingAuthorization,
parsePendingAuthorization,
pendingAuthorizationPath,
signUpClientName,
Expand Down Expand Up @@ -156,6 +157,25 @@ test.describe('pending-authorization helpers', () => {
expect(Array.from(displayClientName('😀'.repeat(60))!)).toHaveLength(CLIENT_NAME_MAX);
});

test('a question that takes too long is aborted with a named reason and gives null', async () => {
const realFetch = globalThis.fetch;
let reason: unknown;
globalThis.fetch = ((_input: unknown, init?: { signal?: AbortSignal }) =>
new Promise((_resolve, reject) => {
init?.signal?.addEventListener('abort', () => {
reason = init.signal!.reason;
reject(init.signal!.reason);
});
})) as typeof fetch;
try {
expect(await fetchPendingAuthorization(10)).toBeNull();
} finally {
globalThis.fetch = realFetch;
}
expect(reason).toBeInstanceOf(DOMException);
expect((reason as DOMException).name).toBe('TimeoutError');
});

test('the sign-up names only the assistants it knows', () => {
expect(signUpClientName('claude')).toBe('Claude');
expect(signUpClientName('ChatGPT')).toBe('ChatGPT');
Expand Down
Loading