From fd848a1ad8d95ac95fa175c804e8bfa48f58cafd Mon Sep 17 00:00:00 2001 From: Chad Metcalf Date: Sun, 3 Aug 2025 16:01:38 -0700 Subject: [PATCH] test: fix CI failure by forcing headless mode in services tests The services/index.test.ts was failing in CI because it triggers the onboarding flow which uses readlineSync, but CI environments don't have TTY access. These tests are specifically for testing mode conversion logic (plan/auto/normal to readonly/auto flags), not onboarding functionality. Onboarding is properly tested in the dedicated onboarding.test.ts file. - Add headless: true flag to all initializeServices() calls in tests - This skips the onboarding flow and focuses on the actual logic being tested - Maintains proper test coverage while fixing CI compatibility --- src/services/index.test.ts | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/services/index.test.ts b/src/services/index.test.ts index 9b0d422ba..446b50b77 100644 --- a/src/services/index.test.ts +++ b/src/services/index.test.ts @@ -2,9 +2,11 @@ import { jest } from '@jest/globals'; import { initializeServices } from './index.js'; import { modeService } from './ModeService.js'; +import { serviceContainer } from './ServiceContainer.js'; describe('initializeServices', () => { let mockModeService: any; + let mockServiceContainer: any; beforeEach(() => { // Reset all mocks @@ -16,9 +18,22 @@ describe('initializeServices', () => { getCurrentMode: jest.fn() }; + // Create mock service container to prevent actual service registration + mockServiceContainer = { + register: jest.fn(), + get: jest.fn(), + set: jest.fn(), + reload: jest.fn(), + isReady: jest.fn(), + getServiceStates: jest.fn() + }; + // Set up modeService mock (modeService as any).initialize = mockModeService.initialize; (modeService as any).getCurrentMode = mockModeService.getCurrentMode; + + // Set up serviceContainer mock to prevent actual service initialization + (serviceContainer as any).register = mockServiceContainer.register; }); afterEach(() => { @@ -28,6 +43,7 @@ describe('initializeServices', () => { describe('mode conversion', () => { it('should pass only readonly flag for plan mode', async () => { await initializeServices({ + headless: true, // Force headless mode to skip onboarding toolPermissionOverrides: { mode: 'plan', allow: ['tool1'], @@ -47,6 +63,7 @@ describe('initializeServices', () => { it('should pass only auto flag for auto mode', async () => { await initializeServices({ + headless: true, // Force headless mode to skip onboarding toolPermissionOverrides: { mode: 'auto', allow: ['tool1'], @@ -66,6 +83,7 @@ describe('initializeServices', () => { it('should pass no mode flags for normal mode', async () => { await initializeServices({ + headless: true, // Force headless mode to skip onboarding toolPermissionOverrides: { mode: 'normal', allow: ['tool1'], @@ -84,6 +102,7 @@ describe('initializeServices', () => { it('should pass no mode flags when mode is undefined', async () => { await initializeServices({ + headless: true, // Force headless mode to skip onboarding toolPermissionOverrides: { allow: ['tool1'], ask: ['tool2'], @@ -100,7 +119,7 @@ describe('initializeServices', () => { }); it('should not call initialize when no toolPermissionOverrides provided', async () => { - await initializeServices({}); + await initializeServices({ headless: true }); // Force headless mode to skip onboarding expect(mockModeService.initialize).not.toHaveBeenCalled(); });