diff --git a/apps/server/tests/unit/lib/enhancement-prompts.test.ts b/apps/server/tests/unit/lib/enhancement-prompts.test.ts index ab139861..13d61555 100644 --- a/apps/server/tests/unit/lib/enhancement-prompts.test.ts +++ b/apps/server/tests/unit/lib/enhancement-prompts.test.ts @@ -17,6 +17,14 @@ import { type EnhancementMode, } from '@/lib/enhancement-prompts.js'; +const ENHANCEMENT_MODES: EnhancementMode[] = [ + 'improve', + 'technical', + 'simplify', + 'acceptance', + 'ux-reviewer', +]; + describe('enhancement-prompts.ts', () => { describe('System Prompt Constants', () => { it('should have non-empty improve system prompt', () => { @@ -184,8 +192,7 @@ describe('enhancement-prompts.ts', () => { }); it('should work with all enhancement modes', () => { - const modes: EnhancementMode[] = ['improve', 'technical', 'simplify', 'acceptance']; - modes.forEach((mode) => { + ENHANCEMENT_MODES.forEach((mode) => { const prompt = buildUserPrompt(mode, testText); expect(prompt).toContain(testText); expect(prompt.length).toBeGreaterThan(100); @@ -205,6 +212,7 @@ describe('enhancement-prompts.ts', () => { expect(isValidEnhancementMode('technical')).toBe(true); expect(isValidEnhancementMode('simplify')).toBe(true); expect(isValidEnhancementMode('acceptance')).toBe(true); + expect(isValidEnhancementMode('ux-reviewer')).toBe(true); }); it('should return false for invalid modes', () => { @@ -216,13 +224,12 @@ describe('enhancement-prompts.ts', () => { }); describe('getAvailableEnhancementModes', () => { - it('should return all four enhancement modes', () => { + it('should return all enhancement modes', () => { const modes = getAvailableEnhancementModes(); - expect(modes).toHaveLength(4); - expect(modes).toContain('improve'); - expect(modes).toContain('technical'); - expect(modes).toContain('simplify'); - expect(modes).toContain('acceptance'); + expect(modes).toHaveLength(ENHANCEMENT_MODES.length); + ENHANCEMENT_MODES.forEach((mode) => { + expect(modes).toContain(mode); + }); }); it('should return an array', () => { diff --git a/apps/server/tests/unit/routes/app-spec/common.test.ts b/apps/server/tests/unit/routes/app-spec/common.test.ts index aeaf8ea5..a348a2aa 100644 --- a/apps/server/tests/unit/routes/app-spec/common.test.ts +++ b/apps/server/tests/unit/routes/app-spec/common.test.ts @@ -5,59 +5,61 @@ import { getSpecRegenerationStatus, } from '@/routes/app-spec/common.js'; +const TEST_PROJECT_PATH = '/tmp/automaker-test-project'; + describe('app-spec/common.ts', () => { beforeEach(() => { // Reset state before each test - setRunningState(false, null); + setRunningState(TEST_PROJECT_PATH, false, null); }); describe('setRunningState', () => { it('should set isRunning to true when running is true', () => { - setRunningState(true); - expect(getSpecRegenerationStatus().isRunning).toBe(true); + setRunningState(TEST_PROJECT_PATH, true); + expect(getSpecRegenerationStatus(TEST_PROJECT_PATH).isRunning).toBe(true); }); it('should set isRunning to false when running is false', () => { - setRunningState(true); - setRunningState(false); - expect(getSpecRegenerationStatus().isRunning).toBe(false); + setRunningState(TEST_PROJECT_PATH, true); + setRunningState(TEST_PROJECT_PATH, false); + expect(getSpecRegenerationStatus(TEST_PROJECT_PATH).isRunning).toBe(false); }); it('should set currentAbortController when provided', () => { const controller = new AbortController(); - setRunningState(true, controller); - expect(getSpecRegenerationStatus().currentAbortController).toBe(controller); + setRunningState(TEST_PROJECT_PATH, true, controller); + expect(getSpecRegenerationStatus(TEST_PROJECT_PATH).currentAbortController).toBe(controller); }); it('should set currentAbortController to null when not provided', () => { const controller = new AbortController(); - setRunningState(true, controller); - setRunningState(false); - expect(getSpecRegenerationStatus().currentAbortController).toBe(null); + setRunningState(TEST_PROJECT_PATH, true, controller); + setRunningState(TEST_PROJECT_PATH, false); + expect(getSpecRegenerationStatus(TEST_PROJECT_PATH).currentAbortController).toBe(null); }); - it('should set currentAbortController to null when explicitly passed null', () => { + it('should keep currentAbortController when explicitly passed null while running', () => { const controller = new AbortController(); - setRunningState(true, controller); - setRunningState(true, null); - expect(getSpecRegenerationStatus().currentAbortController).toBe(null); + setRunningState(TEST_PROJECT_PATH, true, controller); + setRunningState(TEST_PROJECT_PATH, true, null); + expect(getSpecRegenerationStatus(TEST_PROJECT_PATH).currentAbortController).toBe(controller); }); it('should update state multiple times correctly', () => { const controller1 = new AbortController(); const controller2 = new AbortController(); - setRunningState(true, controller1); - expect(getSpecRegenerationStatus().isRunning).toBe(true); - expect(getSpecRegenerationStatus().currentAbortController).toBe(controller1); + setRunningState(TEST_PROJECT_PATH, true, controller1); + expect(getSpecRegenerationStatus(TEST_PROJECT_PATH).isRunning).toBe(true); + expect(getSpecRegenerationStatus(TEST_PROJECT_PATH).currentAbortController).toBe(controller1); - setRunningState(true, controller2); - expect(getSpecRegenerationStatus().isRunning).toBe(true); - expect(getSpecRegenerationStatus().currentAbortController).toBe(controller2); + setRunningState(TEST_PROJECT_PATH, true, controller2); + expect(getSpecRegenerationStatus(TEST_PROJECT_PATH).isRunning).toBe(true); + expect(getSpecRegenerationStatus(TEST_PROJECT_PATH).currentAbortController).toBe(controller2); - setRunningState(false, null); - expect(getSpecRegenerationStatus().isRunning).toBe(false); - expect(getSpecRegenerationStatus().currentAbortController).toBe(null); + setRunningState(TEST_PROJECT_PATH, false, null); + expect(getSpecRegenerationStatus(TEST_PROJECT_PATH).isRunning).toBe(false); + expect(getSpecRegenerationStatus(TEST_PROJECT_PATH).currentAbortController).toBe(null); }); }); diff --git a/apps/server/tests/unit/services/dev-server-service.test.ts b/apps/server/tests/unit/services/dev-server-service.test.ts index b6bae863..03d3d01c 100644 --- a/apps/server/tests/unit/services/dev-server-service.test.ts +++ b/apps/server/tests/unit/services/dev-server-service.test.ts @@ -8,6 +8,7 @@ import fs from 'fs/promises'; vi.mock('child_process', () => ({ spawn: vi.fn(), execSync: vi.fn(), + execFile: vi.fn(), })); // Mock secure-fs