mirror of
https://github.com/eyaltoledano/claude-task-master.git
synced 2025-11-13 00:25:06 +00:00
* feat: enhance move command with cross-tag functionality - Updated the `move` command to allow moving tasks between different tags, including options for handling dependencies. - Added new options: `--from-tag`, `--to-tag`, `--with-dependencies`, `--ignore-dependencies`, and `--force`. - Implemented validation for cross-tag moves and dependency checks. - Introduced helper functions in the dependency manager for validating and resolving cross-tag dependencies. - Added integration and unit tests to cover new functionality and edge cases. * fix: refactor cross-tag move logic and enhance validation - Moved the import of `moveTasksBetweenTags` to the correct location in `commands.js` for better clarity. - Added new helper functions in `dependency-manager.js` to improve validation and error handling for cross-tag moves. - Enhanced existing functions to ensure proper handling of task dependencies and conflicts. - Updated tests to cover new validation scenarios and ensure robust error messaging for invalid task IDs and tags. * fix: improve task ID handling and error messaging in cross-tag moves - Refactored `moveTasksBetweenTags` to normalize task IDs for comparison, ensuring consistent handling of string and numeric IDs. - Enhanced error messages for cases where source and target tags are the same but no destination is specified. - Updated tests to validate new behavior, including handling string dependencies correctly during cross-tag moves. - Cleaned up existing code for better readability and maintainability. * test: add comprehensive tests for cross-tag move and dependency validation - Introduced new test files for `move-cross-tag` and `cross-tag-dependencies` to cover various scenarios in cross-tag task movement. - Implemented tests for handling task movement with and without dependencies, including edge cases for error handling. - Enhanced existing tests in `fix-dependencies-command` and `move-task` to ensure robust validation of task IDs and dependencies. - Mocked necessary modules and functions to isolate tests and improve reliability. - Ensured coverage for both successful and failed cross-tag move operations, validating expected outcomes and error messages. * test: refactor cross-tag move tests for better clarity and reusability - Introduced a helper function `simulateCrossTagMove` to streamline cross-tag move test cases, reducing redundancy and improving readability. - Updated existing tests to utilize the new helper function, ensuring consistent handling of expected messages and options. - Enhanced test coverage for various scenarios, including handling of dependencies and flags. * feat: add cross-tag task movement functionality - Introduced new commands for moving tasks between different tags, enhancing project organization capabilities. - Updated README with usage examples for cross-tag movement, including options for handling dependencies. - Created comprehensive documentation for cross-tag task movement, detailing usage, error handling, and best practices. - Implemented core logic for cross-tag moves, including validation for dependencies and error handling. - Added integration and unit tests to ensure robust functionality and coverage for various scenarios, including edge cases. * fix: enhance error handling and logging in cross-tag task movement - Improved logging in `moveTaskCrossTagDirect` to include detailed arguments for better traceability. - Refactored error handling to utilize structured error objects, providing clearer suggestions for resolving cross-tag dependency conflicts and subtask movement restrictions. - Updated documentation to reflect changes in error handling and provide clearer guidance on task movement options. - Added integration tests for cross-tag movement scenarios, ensuring robust validation of error handling and task movement logic. - Cleaned up existing tests for clarity and reusability, enhancing overall test coverage. * feat: enhance dependency resolution and error handling in task movement - Added recursive dependency resolution for tasks in `moveTasksBetweenTags`, improving handling of complex task relationships. - Introduced helper functions to find all dependencies and reverse dependencies, ensuring comprehensive coverage during task moves. - Enhanced error messages in `validateSubtaskMove` and `displaySubtaskMoveError` for better clarity on movement restrictions. - Updated tests to cover new functionality, including integration tests for complex cross-tag movement scenarios and edge cases. - Refactored existing code for improved readability and maintainability, ensuring consistent handling of task IDs and dependencies. * feat: unify dependency traversal and enhance task management utilities - Introduced `traverseDependencies` utility for unified forward and reverse dependency traversal, improving code reusability and clarity. - Refactored `findAllDependenciesRecursively` to leverage the new utility, streamlining dependency resolution in task management. - Added `formatTaskIdForDisplay` helper for better task ID formatting in UI, enhancing user experience during error displays. - Updated tests to cover new utility functions and ensure robust validation of dependency handling across various scenarios. - Improved overall code organization and readability, ensuring consistent handling of task dependencies and IDs. * fix: improve validation for dependency parameters in `findAllDependenciesRecursively` - Added checks to ensure `sourceTasks` and `allTasks` are arrays, throwing errors if not, to prevent runtime issues. - Updated documentation comment for clarity on the function's purpose and parameters. * fix: remove `force` option from task movement parameters - Eliminated the `force` parameter from the `moveTaskCrossTagDirect` function and related tools, simplifying the task movement logic. - Updated documentation and tests to reflect the removal of the `force` option, ensuring clarity and consistency across the codebase. - Adjusted related functions and tests to focus on `ignoreDependencies` as the primary control for handling dependency conflicts during task moves. * Add cross-tag task movement functionality - Introduced functionality for organizing tasks across different contexts by enabling cross-tag movement. - Added `formatTaskIdForDisplay` helper to improve task ID formatting in UI error messages. - Updated relevant tests to incorporate new functionality and ensure accurate error displays during task movements. * Update scripts/modules/dependency-manager.js Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * refactor(dependency-manager): Fix subtask resolution and extract helper functions 1. Fix subtask finding logic (lines 1315-1330): - Correctly locate parent task by numeric ID - Search within parent's subtasks array instead of top-level tasks - Properly handle relative subtask references 2. Extract helper functions from getDependentTaskIds (lines 1440-1636): - Move findTasksThatDependOn as module-level function - Move taskDependsOnSource as module-level function - Move subtasksDependOnSource as module-level function - Improves readability, maintainability, and testability Both fixes address architectural issues and improve code organization. * refactor(dependency-manager): Enhance subtask resolution and dependency validation - Improved subtask resolution logic to correctly find parent tasks and their subtasks, ensuring accurate identification of dependencies. - Filtered out null/undefined dependencies before processing, enhancing robustness in dependency checks. - Updated comments for clarity on the logic flow and purpose of changes, improving code maintainability. * refactor(move-task): clarify destination ID description and improve skipped task handling - Updated the description for the destination ID to clarify its usage in cross-tag moves. - Simplified the handling of skipped tasks during multiple task movements, improving readability and logging. - Enhanced the API result response to include detailed information about moved and skipped tasks, ensuring better feedback for users. * refactor(commands): remove redundant tag validation logic - Eliminated the check for identical source and target tags in the task movement logic, simplifying the code. - This change streamlines the flow for within-tag moves, enhancing readability and maintainability. * refactor(commands): enhance move command logic and error handling - Introduced helper functions for better organization of cross-tag and within-tag move logic, improving code readability and maintainability. - Enhanced error handling with structured error objects, providing clearer feedback for dependency conflicts and invalid tag combinations. - Updated move command help output to include best practices and error resolution tips, ensuring users have comprehensive guidance during task movements. - Streamlined task movement logic to handle multiple tasks more effectively, including detailed logging of successful and failed moves. * test(dependency-manager): add subtasks to task structure and mock dependency traversal - Updated `circular-dependencies.test.js` to include subtasks in task definitions, enhancing test coverage for task structures with nested dependencies. - Mocked `traverseDependencies` in `fix-dependencies-command.test.js` to ensure consistent behavior during tests, improving reliability of dependency-related tests. * refactor(dependency-manager): extract subtask finding logic into helper function - Added `findSubtaskInParent` function to encapsulate subtask resolution within a parent task's subtasks array, improving code organization and readability. - Updated `findDependencyTask` to utilize the new helper function, streamlining the logic for finding subtasks and enhancing maintainability. - Enhanced comments for clarity on the purpose and functionality of the new subtask finding logic. * refactor(ui): enhance subtask ID validation and improve error handling - Added validation for subtask ID format in `formatDependenciesWithStatus` and `taskExists`, ensuring proper handling of invalid formats. - Updated error logging in `displaySubtaskMoveError` to provide warnings for unexpected task ID formats, improving user feedback. - Converted hints to a Set in `displayDependencyValidationHints` to ensure unique hints are displayed, enhancing clarity in the UI. * test(cli): remove redundant timing check in complex cross-tag scenarios - Eliminated the timing check for task completion within 5 seconds in `complex-cross-tag-scenarios.test.js`, streamlining the test logic. - This change focuses on verifying task success without unnecessary timing constraints, enhancing test clarity and maintainability. * test(integration): enhance task movement tests with mock file system - Added integration tests for moving tasks within the same tag and between different tags using the actual `moveTask` and `moveTasksBetweenTags` functions. - Implemented `mock-fs` to simulate file system interactions, improving test isolation and reliability. - Verified task movement success and ensured proper handling of subtasks and dependencies, enhancing overall test coverage for task management functionality. - Included error handling tests for missing tags and task IDs to ensure robustness in task movement operations. * test(unit): add comprehensive tests for moveTaskCrossTagDirect functionality - Introduced new test cases to verify mock functionality, ensuring that mocks for `findTasksPath` and `readJSON` are working as expected. - Added tests for parameter validation, error handling, and function call flow, including scenarios for missing project roots and identical source/target tags. - Enhanced coverage for ID parsing and move options, ensuring robust handling of various input conditions and improving overall test reliability. * test(integration): skip tests for dependency conflict handling and withDependencies option - Marked tests for handling dependency conflicts and the withDependencies option as skipped due to issues with the mock setup. - Added TODOs to address the mock-fs setup for complex dependency scenarios, ensuring future improvements in test reliability. * test(unit): expand cross-tag move command tests with comprehensive mocks - Added extensive mocks for various modules to enhance the testing of the cross-tag move functionality in `move-cross-tag.test.js`. - Implemented detailed test cases for handling cross-tag moves, including validation for missing parameters and identical source/target tags. - Improved error handling tests to ensure robust feedback for invalid operations, enhancing overall test reliability and coverage. * test(integration): add complex dependency scenarios to task movement tests - Introduced new integration tests for handling complex dependency scenarios in task movement, utilizing the actual `moveTasksBetweenTags` function. - Added tests for circular dependencies, nested dependency chains, and cross-tag dependency resolution, enhancing coverage and reliability. - Documented limitations of the mock-fs setup for complex scenarios and provided warnings in the test output to guide future improvements. - Skipped tests for dependency conflicts and the withDependencies option due to mock setup issues, with TODOs for resolution. * test(unit): refactor move-cross-tag tests with focused mock system - Simplified mocking in `move-cross-tag.test.js` by implementing a configuration-driven mock system, reducing the number of mocked modules from 20+ to 5 core functionalities. - Introduced a reusable mock factory to streamline the creation of mocks based on configuration, enhancing maintainability and clarity. - Added documentation for the new mock system, detailing usage examples and benefits, including reduced complexity and improved test focus. - Implemented tests to validate the mock configuration, ensuring flexibility in enabling/disabling specific mocks. * test(unit): clean up mocks and improve isEmpty function in fix-dependencies-command tests - Removed the mock for `traverseDependencies` as it was unnecessary, simplifying the test setup. - Updated the `isEmpty` function to clarify its behavior regarding null and undefined values, enhancing code readability and maintainability. * test(unit): update traverseDependencies mock for consistency across tests - Standardized the mock implementation of `traverseDependencies` in both `fix-dependencies-command.test.js` and `complexity-report-tag-isolation.test.js` to accept `sourceTasks`, `allTasks`, and `options` parameters, ensuring uniformity in test setups. - This change enhances clarity and maintainability of the tests by aligning the mock behavior across different test files. * fix(core): improve task movement error handling and ID normalization - Wrapped task movement logic in a try-finally block to ensure console output is restored even on errors, enhancing reliability. - Normalized source IDs to handle mixed string/number comparisons, preventing potential issues in dependency checks. - Added tests for ID type consistency to verify that the normalization fix works correctly across various scenarios, improving test coverage and robustness. * refactor(task-manager): restructure task movement logic for improved validation and execution - Renamed and refactored `moveTasksBetweenTags` to streamline the task movement process into distinct phases: validation, data preparation, dependency resolution, execution, and finalization. - Introduced `validateMove`, `prepareTaskData`, `resolveDependencies`, `executeMoveOperation`, and `finalizeMove` functions to enhance modularity and clarity. - Updated documentation comments to reflect changes in function responsibilities and parameters. - Added comprehensive unit tests for the new structure, ensuring robust validation and error handling across various scenarios. - Improved handling of dependencies and task existence checks during the move operation, enhancing overall reliability. * fix(move-task): streamline task movement logic and improve error handling - Refactored the task movement process to enhance clarity and maintainability by replacing `forEach` with a `for...of` loop for better async handling. - Consolidated error handling and result logging to ensure consistent feedback during task moves. - Updated the logic for generating files only on the last move, improving performance and reducing unnecessary operations. - Enhanced validation for skipped tasks, ensuring accurate reporting of moved and skipped tasks in the final result. * fix(docs): update error message formatting and enhance clarity in task movement documentation - Changed code block syntax from generic to `text` for better readability in error messages related to task movement and dependency conflicts. - Ensured consistent formatting across all error message examples to improve user understanding of task movement restrictions and resolutions. - Added a newline at the end of the file for proper formatting. * Update .changeset/crazy-meals-hope.md Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * chore: improve changeset * chore: improve changeset * fix referenced bug in docs and remove docs * chore: fix format --------- Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> Co-authored-by: Ralph Khreish <35776126+Crunchyman-ralph@users.noreply.github.com>
538 lines
17 KiB
JavaScript
538 lines
17 KiB
JavaScript
import { jest } from '@jest/globals';
|
|
import path from 'path';
|
|
import mockFs from 'mock-fs';
|
|
import fs from 'fs';
|
|
import { fileURLToPath } from 'url';
|
|
|
|
// Import the actual move task functionality
|
|
import moveTask, {
|
|
moveTasksBetweenTags
|
|
} from '../../scripts/modules/task-manager/move-task.js';
|
|
import { readJSON, writeJSON } from '../../scripts/modules/utils.js';
|
|
|
|
// Mock console to avoid conflicts with mock-fs
|
|
const originalConsole = { ...console };
|
|
beforeAll(() => {
|
|
global.console = {
|
|
...console,
|
|
log: jest.fn(),
|
|
error: jest.fn(),
|
|
warn: jest.fn(),
|
|
info: jest.fn()
|
|
};
|
|
});
|
|
|
|
afterAll(() => {
|
|
global.console = originalConsole;
|
|
});
|
|
|
|
// Get __dirname equivalent for ES modules
|
|
const __filename = fileURLToPath(import.meta.url);
|
|
const __dirname = path.dirname(__filename);
|
|
|
|
describe('Cross-Tag Task Movement Simple Integration Tests', () => {
|
|
const testDataDir = path.join(__dirname, 'fixtures');
|
|
const testTasksPath = path.join(testDataDir, 'tasks.json');
|
|
|
|
// Test data structure with proper tagged format
|
|
const testData = {
|
|
backlog: {
|
|
tasks: [
|
|
{ id: 1, title: 'Task 1', dependencies: [], status: 'pending' },
|
|
{ id: 2, title: 'Task 2', dependencies: [], status: 'pending' }
|
|
]
|
|
},
|
|
'in-progress': {
|
|
tasks: [
|
|
{ id: 3, title: 'Task 3', dependencies: [], status: 'in-progress' }
|
|
]
|
|
}
|
|
};
|
|
|
|
beforeEach(() => {
|
|
// Set up mock file system with test data
|
|
mockFs({
|
|
[testDataDir]: {
|
|
'tasks.json': JSON.stringify(testData, null, 2)
|
|
}
|
|
});
|
|
});
|
|
|
|
afterEach(() => {
|
|
// Clean up mock file system
|
|
mockFs.restore();
|
|
});
|
|
|
|
describe('Real Module Integration Tests', () => {
|
|
it('should move task within same tag using actual moveTask function', async () => {
|
|
// Test moving Task 1 from position 1 to position 5 within backlog tag
|
|
const result = await moveTask(
|
|
testTasksPath,
|
|
'1',
|
|
'5',
|
|
false, // Don't generate files for this test
|
|
{ tag: 'backlog' }
|
|
);
|
|
|
|
// Verify the move operation was successful
|
|
expect(result).toBeDefined();
|
|
expect(result.message).toContain('Moved task 1 to new ID 5');
|
|
|
|
// Read the updated data to verify the move actually happened
|
|
const updatedData = readJSON(testTasksPath, null, 'backlog');
|
|
const rawData = updatedData._rawTaggedData || updatedData;
|
|
const backlogTasks = rawData.backlog.tasks;
|
|
|
|
// Verify Task 1 is no longer at position 1
|
|
const taskAtPosition1 = backlogTasks.find((t) => t.id === 1);
|
|
expect(taskAtPosition1).toBeUndefined();
|
|
|
|
// Verify Task 1 is now at position 5
|
|
const taskAtPosition5 = backlogTasks.find((t) => t.id === 5);
|
|
expect(taskAtPosition5).toBeDefined();
|
|
expect(taskAtPosition5.title).toBe('Task 1');
|
|
expect(taskAtPosition5.status).toBe('pending');
|
|
});
|
|
|
|
it('should move tasks between tags using moveTasksBetweenTags function', async () => {
|
|
// Test moving Task 1 from backlog to in-progress tag
|
|
const result = await moveTasksBetweenTags(
|
|
testTasksPath,
|
|
['1'], // Task IDs to move (as strings)
|
|
'backlog', // Source tag
|
|
'in-progress', // Target tag
|
|
{ withDependencies: false, ignoreDependencies: false },
|
|
{ projectRoot: testDataDir }
|
|
);
|
|
|
|
// Verify the cross-tag move operation was successful
|
|
expect(result).toBeDefined();
|
|
expect(result.message).toContain(
|
|
'Successfully moved 1 tasks from "backlog" to "in-progress"'
|
|
);
|
|
expect(result.movedTasks).toHaveLength(1);
|
|
expect(result.movedTasks[0].id).toBe('1');
|
|
expect(result.movedTasks[0].fromTag).toBe('backlog');
|
|
expect(result.movedTasks[0].toTag).toBe('in-progress');
|
|
|
|
// Read the updated data to verify the move actually happened
|
|
const updatedData = readJSON(testTasksPath, null, 'backlog');
|
|
// readJSON returns resolved data, so we need to access the raw tagged data
|
|
const rawData = updatedData._rawTaggedData || updatedData;
|
|
const backlogTasks = rawData.backlog?.tasks || [];
|
|
const inProgressTasks = rawData['in-progress']?.tasks || [];
|
|
|
|
// Verify Task 1 is no longer in backlog
|
|
const taskInBacklog = backlogTasks.find((t) => t.id === 1);
|
|
expect(taskInBacklog).toBeUndefined();
|
|
|
|
// Verify Task 1 is now in in-progress
|
|
const taskInProgress = inProgressTasks.find((t) => t.id === 1);
|
|
expect(taskInProgress).toBeDefined();
|
|
expect(taskInProgress.title).toBe('Task 1');
|
|
expect(taskInProgress.status).toBe('pending');
|
|
});
|
|
|
|
it('should handle subtask movement restrictions', async () => {
|
|
// Create data with subtasks
|
|
const dataWithSubtasks = {
|
|
backlog: {
|
|
tasks: [
|
|
{
|
|
id: 1,
|
|
title: 'Task 1',
|
|
dependencies: [],
|
|
status: 'pending',
|
|
subtasks: [
|
|
{ id: '1.1', title: 'Subtask 1.1', status: 'pending' },
|
|
{ id: '1.2', title: 'Subtask 1.2', status: 'pending' }
|
|
]
|
|
}
|
|
]
|
|
},
|
|
'in-progress': {
|
|
tasks: [
|
|
{ id: 2, title: 'Task 2', dependencies: [], status: 'in-progress' }
|
|
]
|
|
}
|
|
};
|
|
|
|
// Write subtask data to mock file system
|
|
mockFs({
|
|
[testDataDir]: {
|
|
'tasks.json': JSON.stringify(dataWithSubtasks, null, 2)
|
|
}
|
|
});
|
|
|
|
// Try to move a subtask directly - this should actually work (converts subtask to task)
|
|
const result = await moveTask(
|
|
testTasksPath,
|
|
'1.1', // Subtask ID
|
|
'5', // New task ID
|
|
false,
|
|
{ tag: 'backlog' }
|
|
);
|
|
|
|
// Verify the subtask was converted to a task
|
|
expect(result).toBeDefined();
|
|
expect(result.message).toContain('Converted subtask 1.1 to task 5');
|
|
|
|
// Verify the subtask was removed from the parent and converted to a standalone task
|
|
const updatedData = readJSON(testTasksPath, null, 'backlog');
|
|
const rawData = updatedData._rawTaggedData || updatedData;
|
|
const task1 = rawData.backlog?.tasks?.find((t) => t.id === 1);
|
|
const newTask5 = rawData.backlog?.tasks?.find((t) => t.id === 5);
|
|
|
|
expect(task1).toBeDefined();
|
|
expect(task1.subtasks).toHaveLength(1); // Only 1.2 remains
|
|
expect(task1.subtasks[0].id).toBe(2);
|
|
|
|
expect(newTask5).toBeDefined();
|
|
expect(newTask5.title).toBe('Subtask 1.1');
|
|
expect(newTask5.status).toBe('pending');
|
|
});
|
|
|
|
it('should handle missing source tag errors', async () => {
|
|
// Try to move from a non-existent tag
|
|
await expect(
|
|
moveTasksBetweenTags(
|
|
testTasksPath,
|
|
['1'],
|
|
'non-existent-tag', // Source tag doesn't exist
|
|
'in-progress',
|
|
{ withDependencies: false, ignoreDependencies: false },
|
|
{ projectRoot: testDataDir }
|
|
)
|
|
).rejects.toThrow();
|
|
});
|
|
|
|
it('should handle missing task ID errors', async () => {
|
|
// Try to move a non-existent task
|
|
await expect(
|
|
moveTask(
|
|
testTasksPath,
|
|
'999', // Non-existent task ID
|
|
'5',
|
|
false,
|
|
{ tag: 'backlog' }
|
|
)
|
|
).rejects.toThrow();
|
|
});
|
|
|
|
it('should handle ignoreDependencies option correctly', async () => {
|
|
// Create data with dependencies
|
|
const dataWithDependencies = {
|
|
backlog: {
|
|
tasks: [
|
|
{ id: 1, title: 'Task 1', dependencies: [2], status: 'pending' },
|
|
{ id: 2, title: 'Task 2', dependencies: [], status: 'pending' }
|
|
]
|
|
},
|
|
'in-progress': {
|
|
tasks: [
|
|
{ id: 3, title: 'Task 3', dependencies: [], status: 'in-progress' }
|
|
]
|
|
}
|
|
};
|
|
|
|
// Write dependency data to mock file system
|
|
mockFs({
|
|
[testDataDir]: {
|
|
'tasks.json': JSON.stringify(dataWithDependencies, null, 2)
|
|
}
|
|
});
|
|
|
|
// Move Task 1 while ignoring its dependencies
|
|
const result = await moveTasksBetweenTags(
|
|
testTasksPath,
|
|
['1'], // Only Task 1
|
|
'backlog',
|
|
'in-progress',
|
|
{ withDependencies: false, ignoreDependencies: true },
|
|
{ projectRoot: testDataDir }
|
|
);
|
|
|
|
expect(result).toBeDefined();
|
|
expect(result.movedTasks).toHaveLength(1);
|
|
|
|
// Verify Task 1 moved but Task 2 stayed
|
|
const updatedData = readJSON(testTasksPath, null, 'backlog');
|
|
const rawData = updatedData._rawTaggedData || updatedData;
|
|
expect(rawData.backlog.tasks).toHaveLength(1); // Task 2 remains
|
|
expect(rawData['in-progress'].tasks).toHaveLength(2); // Task 3 + Task 1
|
|
|
|
// Verify Task 1 has no dependencies (they were ignored)
|
|
const movedTask = rawData['in-progress'].tasks.find((t) => t.id === 1);
|
|
expect(movedTask.dependencies).toEqual([]);
|
|
});
|
|
});
|
|
|
|
describe('Complex Dependency Scenarios', () => {
|
|
beforeAll(() => {
|
|
// Document the mock-fs limitation for complex dependency scenarios
|
|
console.warn(
|
|
'⚠️ Complex dependency tests are skipped due to mock-fs limitations. ' +
|
|
'These tests require real filesystem operations for proper dependency resolution. ' +
|
|
'Consider using real temporary filesystem setup for these scenarios.'
|
|
);
|
|
});
|
|
|
|
it.skip('should handle dependency conflicts during cross-tag moves', async () => {
|
|
// For now, skip this test as the mock setup is not working correctly
|
|
// TODO: Fix mock-fs setup for complex dependency scenarios
|
|
});
|
|
|
|
it.skip('should handle withDependencies option correctly', async () => {
|
|
// For now, skip this test as the mock setup is not working correctly
|
|
// TODO: Fix mock-fs setup for complex dependency scenarios
|
|
});
|
|
});
|
|
|
|
describe('Complex Dependency Integration Tests with Mock-fs', () => {
|
|
const complexTestData = {
|
|
backlog: {
|
|
tasks: [
|
|
{ id: 1, title: 'Task 1', dependencies: [2, 3], status: 'pending' },
|
|
{ id: 2, title: 'Task 2', dependencies: [4], status: 'pending' },
|
|
{ id: 3, title: 'Task 3', dependencies: [], status: 'pending' },
|
|
{ id: 4, title: 'Task 4', dependencies: [], status: 'pending' }
|
|
]
|
|
},
|
|
'in-progress': {
|
|
tasks: [
|
|
{ id: 5, title: 'Task 5', dependencies: [], status: 'in-progress' }
|
|
]
|
|
}
|
|
};
|
|
|
|
beforeEach(() => {
|
|
// Set up mock file system with complex dependency data
|
|
mockFs({
|
|
[testDataDir]: {
|
|
'tasks.json': JSON.stringify(complexTestData, null, 2)
|
|
}
|
|
});
|
|
});
|
|
|
|
afterEach(() => {
|
|
// Clean up mock file system
|
|
mockFs.restore();
|
|
});
|
|
|
|
it('should handle dependency conflicts during cross-tag moves using actual move functions', async () => {
|
|
// Test moving Task 1 which has dependencies on Tasks 2 and 3
|
|
// This should fail because Task 1 depends on Tasks 2 and 3 which are in the same tag
|
|
await expect(
|
|
moveTasksBetweenTags(
|
|
testTasksPath,
|
|
['1'], // Task 1 with dependencies
|
|
'backlog',
|
|
'in-progress',
|
|
{ withDependencies: false, ignoreDependencies: false },
|
|
{ projectRoot: testDataDir }
|
|
)
|
|
).rejects.toThrow(
|
|
'Cannot move tasks: 2 cross-tag dependency conflicts found'
|
|
);
|
|
});
|
|
|
|
it('should handle withDependencies option correctly using actual move functions', async () => {
|
|
// Test moving Task 1 with its dependencies (Tasks 2 and 3)
|
|
// Task 2 also depends on Task 4, so all 4 tasks should move
|
|
const result = await moveTasksBetweenTags(
|
|
testTasksPath,
|
|
['1'], // Task 1
|
|
'backlog',
|
|
'in-progress',
|
|
{ withDependencies: true, ignoreDependencies: false },
|
|
{ projectRoot: testDataDir }
|
|
);
|
|
|
|
// Verify the move operation was successful
|
|
expect(result).toBeDefined();
|
|
expect(result.message).toContain(
|
|
'Successfully moved 4 tasks from "backlog" to "in-progress"'
|
|
);
|
|
expect(result.movedTasks).toHaveLength(4); // Task 1 + Tasks 2, 3, 4
|
|
|
|
// Read the updated data to verify all dependent tasks moved
|
|
const updatedData = readJSON(testTasksPath, null, 'backlog');
|
|
const rawData = updatedData._rawTaggedData || updatedData;
|
|
|
|
// Verify all tasks moved from backlog
|
|
expect(rawData.backlog?.tasks || []).toHaveLength(0); // All tasks moved
|
|
|
|
// Verify all tasks are now in in-progress
|
|
expect(rawData['in-progress']?.tasks || []).toHaveLength(5); // Task 5 + Tasks 1, 2, 3, 4
|
|
|
|
// Verify dependency relationships are preserved
|
|
const task1 = rawData['in-progress']?.tasks?.find((t) => t.id === 1);
|
|
const task2 = rawData['in-progress']?.tasks?.find((t) => t.id === 2);
|
|
const task3 = rawData['in-progress']?.tasks?.find((t) => t.id === 3);
|
|
const task4 = rawData['in-progress']?.tasks?.find((t) => t.id === 4);
|
|
|
|
expect(task1?.dependencies).toEqual([2, 3]);
|
|
expect(task2?.dependencies).toEqual([4]);
|
|
expect(task3?.dependencies).toEqual([]);
|
|
expect(task4?.dependencies).toEqual([]);
|
|
});
|
|
|
|
it('should handle circular dependency detection using actual move functions', async () => {
|
|
// Create data with circular dependencies
|
|
const circularData = {
|
|
backlog: {
|
|
tasks: [
|
|
{ id: 1, title: 'Task 1', dependencies: [2], status: 'pending' },
|
|
{ id: 2, title: 'Task 2', dependencies: [3], status: 'pending' },
|
|
{ id: 3, title: 'Task 3', dependencies: [1], status: 'pending' } // Circular dependency
|
|
]
|
|
},
|
|
'in-progress': {
|
|
tasks: [
|
|
{ id: 4, title: 'Task 4', dependencies: [], status: 'in-progress' }
|
|
]
|
|
}
|
|
};
|
|
|
|
// Set up mock file system with circular dependency data
|
|
mockFs({
|
|
[testDataDir]: {
|
|
'tasks.json': JSON.stringify(circularData, null, 2)
|
|
}
|
|
});
|
|
|
|
// Attempt to move Task 1 with dependencies should fail due to circular dependency
|
|
await expect(
|
|
moveTasksBetweenTags(
|
|
testTasksPath,
|
|
['1'],
|
|
'backlog',
|
|
'in-progress',
|
|
{ withDependencies: true, ignoreDependencies: false },
|
|
{ projectRoot: testDataDir }
|
|
)
|
|
).rejects.toThrow();
|
|
});
|
|
|
|
it('should handle nested dependency chains using actual move functions', async () => {
|
|
// Create data with nested dependency chains
|
|
const nestedData = {
|
|
backlog: {
|
|
tasks: [
|
|
{ id: 1, title: 'Task 1', dependencies: [2], status: 'pending' },
|
|
{ id: 2, title: 'Task 2', dependencies: [3], status: 'pending' },
|
|
{ id: 3, title: 'Task 3', dependencies: [4], status: 'pending' },
|
|
{ id: 4, title: 'Task 4', dependencies: [], status: 'pending' }
|
|
]
|
|
},
|
|
'in-progress': {
|
|
tasks: [
|
|
{ id: 5, title: 'Task 5', dependencies: [], status: 'in-progress' }
|
|
]
|
|
}
|
|
};
|
|
|
|
// Set up mock file system with nested dependency data
|
|
mockFs({
|
|
[testDataDir]: {
|
|
'tasks.json': JSON.stringify(nestedData, null, 2)
|
|
}
|
|
});
|
|
|
|
// Test moving Task 1 with all its nested dependencies
|
|
const result = await moveTasksBetweenTags(
|
|
testTasksPath,
|
|
['1'], // Task 1
|
|
'backlog',
|
|
'in-progress',
|
|
{ withDependencies: true, ignoreDependencies: false },
|
|
{ projectRoot: testDataDir }
|
|
);
|
|
|
|
// Verify the move operation was successful
|
|
expect(result).toBeDefined();
|
|
expect(result.message).toContain(
|
|
'Successfully moved 4 tasks from "backlog" to "in-progress"'
|
|
);
|
|
expect(result.movedTasks).toHaveLength(4); // Tasks 1, 2, 3, 4
|
|
|
|
// Read the updated data to verify all tasks moved
|
|
const updatedData = readJSON(testTasksPath, null, 'backlog');
|
|
const rawData = updatedData._rawTaggedData || updatedData;
|
|
|
|
// Verify all tasks moved from backlog
|
|
expect(rawData.backlog?.tasks || []).toHaveLength(0); // All tasks moved
|
|
|
|
// Verify all tasks are now in in-progress
|
|
expect(rawData['in-progress']?.tasks || []).toHaveLength(5); // Task 5 + Tasks 1, 2, 3, 4
|
|
|
|
// Verify dependency relationships are preserved
|
|
const task1 = rawData['in-progress']?.tasks?.find((t) => t.id === 1);
|
|
const task2 = rawData['in-progress']?.tasks?.find((t) => t.id === 2);
|
|
const task3 = rawData['in-progress']?.tasks?.find((t) => t.id === 3);
|
|
const task4 = rawData['in-progress']?.tasks?.find((t) => t.id === 4);
|
|
|
|
expect(task1?.dependencies).toEqual([2]);
|
|
expect(task2?.dependencies).toEqual([3]);
|
|
expect(task3?.dependencies).toEqual([4]);
|
|
expect(task4?.dependencies).toEqual([]);
|
|
});
|
|
|
|
it('should handle cross-tag dependency resolution using actual move functions', async () => {
|
|
// Create data with cross-tag dependencies
|
|
const crossTagData = {
|
|
backlog: {
|
|
tasks: [
|
|
{ id: 1, title: 'Task 1', dependencies: [5], status: 'pending' }, // Depends on task in in-progress
|
|
{ id: 2, title: 'Task 2', dependencies: [], status: 'pending' }
|
|
]
|
|
},
|
|
'in-progress': {
|
|
tasks: [
|
|
{ id: 5, title: 'Task 5', dependencies: [], status: 'in-progress' }
|
|
]
|
|
}
|
|
};
|
|
|
|
// Set up mock file system with cross-tag dependency data
|
|
mockFs({
|
|
[testDataDir]: {
|
|
'tasks.json': JSON.stringify(crossTagData, null, 2)
|
|
}
|
|
});
|
|
|
|
// Test moving Task 1 which depends on Task 5 in another tag
|
|
const result = await moveTasksBetweenTags(
|
|
testTasksPath,
|
|
['1'], // Task 1
|
|
'backlog',
|
|
'in-progress',
|
|
{ withDependencies: false, ignoreDependencies: false },
|
|
{ projectRoot: testDataDir }
|
|
);
|
|
|
|
// Verify the move operation was successful
|
|
expect(result).toBeDefined();
|
|
expect(result.message).toContain(
|
|
'Successfully moved 1 tasks from "backlog" to "in-progress"'
|
|
);
|
|
|
|
// Read the updated data to verify the move actually happened
|
|
const updatedData = readJSON(testTasksPath, null, 'backlog');
|
|
const rawData = updatedData._rawTaggedData || updatedData;
|
|
|
|
// Verify Task 1 is no longer in backlog
|
|
const taskInBacklog = rawData.backlog?.tasks?.find((t) => t.id === 1);
|
|
expect(taskInBacklog).toBeUndefined();
|
|
|
|
// Verify Task 1 is now in in-progress with its dependency preserved
|
|
const taskInProgress = rawData['in-progress']?.tasks?.find(
|
|
(t) => t.id === 1
|
|
);
|
|
expect(taskInProgress).toBeDefined();
|
|
expect(taskInProgress.title).toBe('Task 1');
|
|
expect(taskInProgress.dependencies).toEqual([5]); // Cross-tag dependency preserved
|
|
});
|
|
});
|
|
});
|