chore: fix tests

This commit is contained in:
Ralph Khreish
2025-08-22 18:15:30 +02:00
parent fa5de356da
commit d482bee358

View File

@@ -795,7 +795,7 @@ describe('parsePRD', () => {
}); });
describe('Streaming vs Non-Streaming Modes', () => { describe('Streaming vs Non-Streaming Modes', () => {
test('should use streaming when reportProgress function is provided', async () => { test('should use non-streaming when reportProgress function is provided (streaming disabled)', async () => {
// Setup mocks to simulate normal conditions (no existing output file) // Setup mocks to simulate normal conditions (no existing output file)
fs.default.existsSync.mockImplementation((path) => { fs.default.existsSync.mockImplementation((path) => {
if (path === 'tasks/tasks.json') return false; // Output file doesn't exist if (path === 'tasks/tasks.json') return false; // Output file doesn't exist
@@ -815,23 +815,20 @@ describe('parsePRD', () => {
}; };
JSONParser.mockReturnValue(mockParser); JSONParser.mockReturnValue(mockParser);
// Call the function with reportProgress to trigger streaming path // Call the function with reportProgress - with streaming disabled, should use non-streaming
const result = await parsePRD('path/to/prd.txt', 'tasks/tasks.json', 3, { const result = await parsePRD('path/to/prd.txt', 'tasks/tasks.json', 3, {
reportProgress: mockReportProgress reportProgress: mockReportProgress
}); });
// Verify streamObjectService was called (streaming path) // With streaming disabled, should use generateObjectService instead
expect(streamObjectService).toHaveBeenCalled(); expect(generateObjectService).toHaveBeenCalled();
// Verify generateObjectService was NOT called (non-streaming path) // Verify streamObjectService was NOT called (streaming is disabled)
expect(generateObjectService).not.toHaveBeenCalled(); expect(streamObjectService).not.toHaveBeenCalled();
// Verify progress reporting was called // Verify progress reporting was still called
expect(mockReportProgress).toHaveBeenCalled(); expect(mockReportProgress).toHaveBeenCalled();
// We no longer use parseStream with streamObject
// expect(parseStream).toHaveBeenCalled();
// Verify result structure // Verify result structure
expect(result).toEqual({ expect(result).toEqual({
success: true, success: true,
@@ -840,7 +837,7 @@ describe('parsePRD', () => {
}); });
}); });
test('should fallback to non-streaming when streaming fails with specific errors', async () => { test.skip('should fallback to non-streaming when streaming fails with specific errors (streaming disabled)', async () => {
// Setup mocks to simulate normal conditions (no existing output file) // Setup mocks to simulate normal conditions (no existing output file)
fs.default.existsSync.mockImplementation((path) => { fs.default.existsSync.mockImplementation((path) => {
if (path === 'tasks/tasks.json') return false; // Output file doesn't exist if (path === 'tasks/tasks.json') return false; // Output file doesn't exist
@@ -954,7 +951,7 @@ describe('parsePRD', () => {
}); });
}); });
test('should handle research flag with streaming', async () => { test('should handle research flag with non-streaming (streaming disabled)', async () => {
// Setup mocks to simulate normal conditions // Setup mocks to simulate normal conditions
fs.default.existsSync.mockImplementation((path) => { fs.default.existsSync.mockImplementation((path) => {
if (path === 'tasks/tasks.json') return false; // Output file doesn't exist if (path === 'tasks/tasks.json') return false; // Output file doesn't exist
@@ -965,19 +962,19 @@ describe('parsePRD', () => {
// Mock progress reporting function // Mock progress reporting function
const mockReportProgress = jest.fn(() => Promise.resolve()); const mockReportProgress = jest.fn(() => Promise.resolve());
// Call with streaming + research // Call with reportProgress + research - with streaming disabled, should use non-streaming
await parsePRD('path/to/prd.txt', 'tasks/tasks.json', 3, { await parsePRD('path/to/prd.txt', 'tasks/tasks.json', 3, {
reportProgress: mockReportProgress, reportProgress: mockReportProgress,
research: true research: true
}); });
// Verify streaming path was used with research role // With streaming disabled, should use generateObjectService with research role
expect(streamObjectService).toHaveBeenCalledWith( expect(generateObjectService).toHaveBeenCalledWith(
expect.objectContaining({ expect.objectContaining({
role: 'research' role: 'research'
}) })
); );
expect(generateObjectService).not.toHaveBeenCalled(); expect(streamObjectService).not.toHaveBeenCalled();
}); });
test('should handle research flag with non-streaming', async () => { test('should handle research flag with non-streaming', async () => {
@@ -1009,7 +1006,7 @@ describe('parsePRD', () => {
expect(streamObjectService).not.toHaveBeenCalled(); expect(streamObjectService).not.toHaveBeenCalled();
}); });
test('should use streaming for CLI text mode even without reportProgress', async () => { test('should use non-streaming for CLI text mode (streaming disabled)', async () => {
// Setup mocks to simulate normal conditions // Setup mocks to simulate normal conditions
fs.default.existsSync.mockImplementation((path) => { fs.default.existsSync.mockImplementation((path) => {
if (path === 'tasks/tasks.json') return false; // Output file doesn't exist if (path === 'tasks/tasks.json') return false; // Output file doesn't exist
@@ -1020,13 +1017,12 @@ describe('parsePRD', () => {
// Call without mcpLog and without reportProgress (CLI text mode) // Call without mcpLog and without reportProgress (CLI text mode)
const result = await parsePRD('path/to/prd.txt', 'tasks/tasks.json', 3); const result = await parsePRD('path/to/prd.txt', 'tasks/tasks.json', 3);
// Verify streaming path was used (no mcpLog means CLI text mode, which should use streaming) // With streaming disabled, should use generateObjectService even in CLI text mode
expect(streamObjectService).toHaveBeenCalled(); expect(generateObjectService).toHaveBeenCalled();
expect(generateObjectService).not.toHaveBeenCalled(); expect(streamObjectService).not.toHaveBeenCalled();
// Verify progress tracker components were called for CLI mode // Progress tracker components may still be called for CLI mode display
expect(createParsePrdTracker).toHaveBeenCalled(); // but the actual parsing uses non-streaming
expect(displayParsePrdStart).toHaveBeenCalled();
expect(result).toEqual({ expect(result).toEqual({
success: true, success: true,