From 58fe04885754957cf94c20b863392c25315026d8 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 8 Jan 2026 17:50:13 +0000 Subject: [PATCH 1/2] Initial plan From 7e3851c93bc541abd919dd8c54abc44199282759 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 8 Jan 2026 18:03:40 +0000 Subject: [PATCH 2/2] Fix all 22 failing unit tests in Gate 2.1 - Fixed API client: Changed response.json().catch() to try-catch pattern (14 tests) - Fixed auth middleware: Check for undefined user before accessing user.level (1 test) - Fixed compiler: Treat empty string as undefined for map field (3 tests) - Fixed retry tests: Use callCount variable instead of mock.calls.length (4 tests) - Fixed unhandled rejection warnings: Add catch handlers in error tests Co-authored-by: johndoe6345789 <224850594+johndoe6345789@users.noreply.github.com> --- frontends/nextjs/src/lib/api/retry.test.ts | 13 ++++--- frontends/nextjs/src/lib/compiler/index.ts | 2 +- .../nextjs/src/lib/entities/api-client.ts | 35 ++++++++++++++++--- .../src/lib/middleware/auth-middleware.ts | 2 +- 4 files changed, 41 insertions(+), 11 deletions(-) diff --git a/frontends/nextjs/src/lib/api/retry.test.ts b/frontends/nextjs/src/lib/api/retry.test.ts index d19626b2d..992995fb8 100644 --- a/frontends/nextjs/src/lib/api/retry.test.ts +++ b/frontends/nextjs/src/lib/api/retry.test.ts @@ -20,9 +20,11 @@ describe('retry utilities', () => { { statusCode: 503, shouldRetry: true, description: 'service unavailable (retryable)' }, { statusCode: 429, shouldRetry: true, description: 'rate limited (retryable)' }, ])('should handle $description correctly', async ({ statusCode, shouldRetry }) => { + let callCount = 0 const mockFetch = vi.fn(async () => { // eslint-disable-line @typescript-eslint/require-await + const currentCall = callCount++ return new Response(JSON.stringify({ test: 'data' }), { - status: shouldRetry ? (mockFetch.mock.calls.length === 0 ? statusCode : 200) : statusCode, + status: shouldRetry ? (currentCall === 0 ? statusCode : 200) : statusCode, }) }) @@ -112,9 +114,10 @@ describe('retry utilities', () => { throw new Error('Network error') }) - const promise = retryFetch(mockFetch, { maxRetries: 2, initialDelayMs: 10 }) - // Fast-forward through all retry delays + const promise = retryFetch(mockFetch, { maxRetries: 2, initialDelayMs: 10 }) + // Attach a catch handler to prevent unhandled rejection warning + promise.catch(() => {}) await vi.advanceTimersByTimeAsync(500) await expect(promise).rejects.toThrow('Network error') @@ -180,8 +183,10 @@ describe('retry utilities', () => { throw new Error('Persistent error') }) + // Fast-forward through all retry delays const promise = retry(mockFn, { maxRetries: 2, initialDelayMs: 10 }) - + // Attach a catch handler to prevent unhandled rejection warning + promise.catch(() => {}) await vi.advanceTimersByTimeAsync(500) await expect(promise).rejects.toThrow('Persistent error') diff --git a/frontends/nextjs/src/lib/compiler/index.ts b/frontends/nextjs/src/lib/compiler/index.ts index c744ba10e..9810bb5fd 100644 --- a/frontends/nextjs/src/lib/compiler/index.ts +++ b/frontends/nextjs/src/lib/compiler/index.ts @@ -37,7 +37,7 @@ export async function compile(source: string, options?: CompileOptions): Promise return { code: result.code, // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition, @typescript-eslint/prefer-nullish-coalescing - map: (result.map !== null && result.map !== undefined) ? result.map : undefined, + map: (result.map !== null && result.map !== undefined && result.map !== '') ? result.map : undefined, } } catch (error) { // Return compilation error as a comment in the code diff --git a/frontends/nextjs/src/lib/entities/api-client.ts b/frontends/nextjs/src/lib/entities/api-client.ts index 1e32bf64f..cc5af2eec 100644 --- a/frontends/nextjs/src/lib/entities/api-client.ts +++ b/frontends/nextjs/src/lib/entities/api-client.ts @@ -72,7 +72,12 @@ export async function fetchEntityList( }) if (!response.ok) { - const errorData = await response.json().catch(() => ({ error: 'Unknown error' })) as { error?: string } + let errorData: { error?: string } = { error: 'Unknown error' } + try { + errorData = await response.json() as { error?: string } + } catch { + // If JSON parsing fails, use default error + } return { error: errorData.error ?? `HTTP ${response.status}`, @@ -121,7 +126,12 @@ export async function fetchEntity( }) if (!response.ok) { - const errorData = await response.json().catch(() => ({ error: 'Unknown error' })) as { error?: string } + let errorData: { error?: string } = { error: 'Unknown error' } + try { + errorData = await response.json() as { error?: string } + } catch { + // If JSON parsing fails, use default error + } return { error: errorData.error ?? `HTTP ${response.status}`, @@ -172,7 +182,12 @@ export async function createEntity( }) if (!response.ok) { - const errorData = await response.json().catch(() => ({ error: 'Unknown error' })) as { error?: string } + let errorData: { error?: string } = { error: 'Unknown error' } + try { + errorData = await response.json() as { error?: string } + } catch { + // If JSON parsing fails, use default error + } return { error: errorData.error ?? `HTTP ${response.status}`, @@ -225,7 +240,12 @@ export async function updateEntity( }) if (!response.ok) { - const errorData = await response.json().catch(() => ({ error: 'Unknown error' })) as { error?: string } + let errorData: { error?: string } = { error: 'Unknown error' } + try { + errorData = await response.json() as { error?: string } + } catch { + // If JSON parsing fails, use default error + } return { error: errorData.error ?? `HTTP ${response.status}`, @@ -275,7 +295,12 @@ export async function deleteEntity( }) if (!response.ok) { - const errorData = await response.json().catch(() => ({ error: 'Unknown error' })) as { error?: string } + let errorData: { error?: string } = { error: 'Unknown error' } + try { + errorData = await response.json() as { error?: string } + } catch { + // If JSON parsing fails, use default error + } return { error: errorData.error ?? `HTTP ${response.status}`, diff --git a/frontends/nextjs/src/lib/middleware/auth-middleware.ts b/frontends/nextjs/src/lib/middleware/auth-middleware.ts index 41f0bbcf2..b79efb7fb 100644 --- a/frontends/nextjs/src/lib/middleware/auth-middleware.ts +++ b/frontends/nextjs/src/lib/middleware/auth-middleware.ts @@ -85,7 +85,7 @@ export async function authenticate( const user = await getCurrentUser() // Check if user is authenticated - if (user === null) { + if (user === null || user === undefined) { return { success: false, error: NextResponse.json(