From 5e2718f8b2f479fc158df2d06b4d42cdb5e6d99f Mon Sep 17 00:00:00 2001 From: Test User Date: Mon, 22 Dec 2025 02:18:31 -0500 Subject: [PATCH] test: enhance agent-service tests with context loading mock - Added a mock for the `loadContextFiles` function to return an empty context by default, improving test reliability. - Updated the agent-service test suite to ensure proper initialization of the `AgentService` with mocked dependencies. These changes aim to enhance the test coverage and stability of the agent-service functionality. --- .../server/tests/unit/services/agent-service.test.ts | 8 +++++++- apps/ui/tests/utils/navigation/views.ts | 12 ++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/apps/server/tests/unit/services/agent-service.test.ts b/apps/server/tests/unit/services/agent-service.test.ts index 8b125f8c..ef2a5e0d 100644 --- a/apps/server/tests/unit/services/agent-service.test.ts +++ b/apps/server/tests/unit/services/agent-service.test.ts @@ -4,12 +4,12 @@ import { ProviderFactory } from '@/providers/provider-factory.js'; import * as fs from 'fs/promises'; import * as imageHandler from '@automaker/utils'; import * as promptBuilder from '@automaker/utils'; +import * as contextLoader from '@automaker/utils'; import { collectAsyncGenerator } from '../../utils/helpers.js'; vi.mock('fs/promises'); vi.mock('@/providers/provider-factory.js'); vi.mock('@automaker/utils'); -vi.mock('@automaker/utils'); describe('agent-service.ts', () => { let service: AgentService; @@ -21,6 +21,12 @@ describe('agent-service.ts', () => { beforeEach(() => { vi.clearAllMocks(); service = new AgentService('/test/data', mockEvents as any); + + // Mock loadContextFiles to return empty context by default + vi.mocked(contextLoader.loadContextFiles).mockResolvedValue({ + files: [], + formattedPrompt: '', + }); }); describe('initialize', () => { diff --git a/apps/ui/tests/utils/navigation/views.ts b/apps/ui/tests/utils/navigation/views.ts index 9ed62db8..459810d8 100644 --- a/apps/ui/tests/utils/navigation/views.ts +++ b/apps/ui/tests/utils/navigation/views.ts @@ -24,6 +24,18 @@ export async function navigateToContext(page: Page): Promise { await page.goto('/context'); await page.waitForLoadState('networkidle'); + // Wait for loading to complete (if present) + const loadingElement = page.locator('[data-testid="context-view-loading"]'); + try { + const loadingVisible = await loadingElement.isVisible({ timeout: 2000 }); + if (loadingVisible) { + // Wait for loading to disappear (context view will appear) + await loadingElement.waitFor({ state: 'hidden', timeout: 10000 }); + } + } catch { + // Loading element not found or already hidden, continue + } + // Wait for the context view to be visible await waitForElement(page, 'context-view', { timeout: 10000 }); }