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
This commit is contained in:
parent
767f64b9ae
commit
fd848a1ad8
1 changed files with 20 additions and 1 deletions
|
|
@ -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();
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue