mirror of
https://github.com/eyaltoledano/claude-task-master.git
synced 2025-11-19 11:40:34 +00:00
* refactor(context): Standardize tag and projectRoot handling across all task tools This commit unifies context management by adopting a boundary-first resolution strategy. All task-scoped tools now resolve `tag` and `projectRoot` at their entry point and forward these values to the underlying direct functions. This approach centralizes context logic, ensuring consistent behavior and enhanced flexibility in multi-tag environments. * fix(tag): Clean up tag handling in task functions and sync process This commit refines the handling of the `tag` parameter across multiple functions, ensuring consistent context management. The `tag` is now passed more efficiently in `listTasksDirect`, `setTaskStatusDirect`, and `syncTasksToReadme`, improving clarity and reducing redundancy. Additionally, a TODO comment has been added in `sync-readme.js` to address future tag support enhancements. * feat(tag): Implement Boundary-First Tag Resolution for consistent tag handling This commit introduces Boundary-First Tag Resolution in the task manager, ensuring consistent and deterministic tag handling across CLI and MCP. This change resolves potential race conditions and improves the reliability of tag-specific operations. Additionally, the `expandTask` function has been updated to use the resolved tag when writing JSON, enhancing data integrity during task updates. * chore(biome): formatting * fix(expand-task): Update writeJSON call to use tag instead of resolvedTag * fix(commands): Enhance complexity report path resolution and task initialization `resolveComplexityReportPath` function to streamline output path generation based on tag context and user-defined output. - Improved clarity and maintainability of command handling by centralizing path resolution logic. * Fix: unknown currentTag * fix(task-manager): Update generateTaskFiles calls to include tag and projectRoot parameters This commit modifies the `moveTask` and `updateSubtaskById` functions to pass the `tag` and `projectRoot` parameters to the `generateTaskFiles` function. This ensures that task files are generated with the correct context when requested, enhancing consistency in task management operations. * fix(commands): Refactor tag handling and complexity report path resolution This commit updates the `registerCommands` function to utilize `taskMaster.getCurrentTag()` for consistent tag retrieval across command actions. It also enhances the initialization of `TaskMaster` by passing the tag directly, improving clarity and maintainability. The complexity report path resolution is streamlined to ensure correct file naming based on the current tag context. * fix(task-master): Update complexity report path expectations in tests This commit modifies the `initTaskMaster` test to expect a valid string for the complexity report path, ensuring it matches the expected file naming convention. This change enhances test reliability by verifying the correct output format when the path is generated. * fix(set-task-status): Enhance logging and tag resolution in task status updates This commit improves the logging output in the `registerSetTaskStatusTool` function to include the tag context when setting task statuses. It also updates the tag handling by resolving the tag using the `resolveTag` utility, ensuring that the correct tag is used when updating task statuses. Additionally, the `setTaskStatus` function is modified to remove the tag parameter from the `readJSON` and `writeJSON` calls, streamlining the data handling process. * fix(commands, expand-task, task-manager): Add complexity report option and enhance path handling This commit introduces a new `--complexity-report` option in the `registerCommands` function, allowing users to specify a custom path for the complexity report. The `expandTask` function is updated to accept the `complexityReportPath` from the context, ensuring it is utilized correctly during task expansion. Additionally, the `setTaskStatus` function now includes the `tag` parameter in the `readJSON` and `writeJSON` calls, improving task status updates with proper context. The `initTaskMaster` function is also modified to create parent directories for output paths, enhancing file handling robustness. * fix(expand-task): Add complexityReportPath to context for task expansion tests This commit updates the test for the `expandTask` function by adding the `complexityReportPath` to the context object. This change ensures that the complexity report path is correctly utilized in the test, aligning with recent enhancements to complexity report handling in the task manager. * chore: implement suggested changes * fix(parse-prd): Clarify tag parameter description for task organization Updated the documentation for the `tag` parameter in the `parse-prd.js` file to provide a clearer context on its purpose for organizing tasks into separate task lists. * Fix Inconsistent tag resolution pattern. * fix: Enhance complexity report path handling with tag support This commit updates various functions to incorporate the `tag` parameter when resolving complexity report paths. The `expandTaskDirect`, `resolveComplexityReportPath`, and related tools now utilize the current tag context, improving consistency in task management. Additionally, the complexity report path is now correctly passed through the context in the `expand-task` and `set-task-status` tools, ensuring accurate report retrieval based on the active tag. * Updated the JSDoc for the `tag` parameter in the `show-task.js` file. * Remove redundant comment on tag parameter in readJSON call * Remove unused import for getTagAwareFilePath * Add missed complexityReportPath to args for task expansion * fix(tests): Enhance research tests with tag-aware functionality This commit updates the `research.test.js` file to improve the testing of the `performResearch` function by incorporating tag-aware functionality. Key changes include mocking the `findProjectRoot` to return a valid path, enhancing the `ContextGatherer` and `FuzzyTaskSearch` mocks, and adding comprehensive tests for tag parameter handling in various scenarios. The tests now cover passing different tag values, ensuring correct behavior when tags are provided, undefined, or null, and validating the integration of tags in task discovery and context gathering processes. * Remove unused import for * fix: Refactor complexity report path handling and improve argument destructuring This commit enhances the `expandTaskDirect` function by improving the destructuring of arguments for better readability. It also updates the `analyze.js` and `analyze-task-complexity.js` files to utilize the new `resolveComplexityReportOutputPath` function, ensuring tag-aware resolution of output paths. Additionally, logging has been added to provide clarity on the report path being used. * test: Add complexity report tag isolation tests and improve path handling This commit introduces a new test file for complexity report tag isolation, ensuring that different tags maintain separate complexity reports. It enhances the existing tests in `analyze-task-complexity.test.js` by updating expectations to use `expect.stringContaining` for file paths, improving robustness against path changes. The new tests cover various scenarios, including path resolution and report generation for both master and feature tags, ensuring no cross-tag contamination occurs. * Update scripts/modules/task-manager/list-tasks.js Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * Update scripts/modules/task-manager/list-tasks.js Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * test(complexity-report): Fix tag slugification in filename expectations - Update mocks to use slugifyTagForFilePath for cross-platform compatibility - Replace raw tag values with slugified versions in expected filenames - Fix test expecting 'feature/user-auth-v2' to expect 'feature-user-auth-v2' - Align test with actual filename generation logic that sanitizes special chars --------- Co-authored-by: Ralph Khreish <35776126+Crunchyman-ralph@users.noreply.github.com> Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
592 lines
15 KiB
JavaScript
592 lines
15 KiB
JavaScript
/**
|
|
* Tests for the set-task-status.js module
|
|
*/
|
|
import { jest } from '@jest/globals';
|
|
|
|
// Mock the dependencies before importing the module under test
|
|
jest.unstable_mockModule('../../../../../scripts/modules/utils.js', () => ({
|
|
readJSON: jest.fn(),
|
|
writeJSON: jest.fn(),
|
|
log: jest.fn(),
|
|
CONFIG: {
|
|
model: 'mock-claude-model',
|
|
maxTokens: 4000,
|
|
temperature: 0.7,
|
|
debug: false
|
|
},
|
|
sanitizePrompt: jest.fn((prompt) => prompt),
|
|
truncate: jest.fn((text) => text),
|
|
isSilentMode: jest.fn(() => false),
|
|
findTaskById: jest.fn((tasks, id) =>
|
|
tasks.find((t) => t.id === parseInt(id))
|
|
),
|
|
ensureTagMetadata: jest.fn((tagObj) => tagObj),
|
|
getCurrentTag: jest.fn(() => 'master')
|
|
}));
|
|
|
|
jest.unstable_mockModule(
|
|
'../../../../../scripts/modules/task-manager/generate-task-files.js',
|
|
() => ({
|
|
default: jest.fn().mockResolvedValue()
|
|
})
|
|
);
|
|
|
|
jest.unstable_mockModule('../../../../../scripts/modules/ui.js', () => ({
|
|
formatDependenciesWithStatus: jest.fn(),
|
|
displayBanner: jest.fn(),
|
|
displayTaskList: jest.fn(),
|
|
startLoadingIndicator: jest.fn(() => ({ stop: jest.fn() })),
|
|
stopLoadingIndicator: jest.fn(),
|
|
getStatusWithColor: jest.fn((status) => status)
|
|
}));
|
|
|
|
jest.unstable_mockModule('../../../../../src/constants/task-status.js', () => ({
|
|
isValidTaskStatus: jest.fn((status) =>
|
|
[
|
|
'pending',
|
|
'done',
|
|
'in-progress',
|
|
'review',
|
|
'deferred',
|
|
'cancelled'
|
|
].includes(status)
|
|
),
|
|
TASK_STATUS_OPTIONS: [
|
|
'pending',
|
|
'done',
|
|
'in-progress',
|
|
'review',
|
|
'deferred',
|
|
'cancelled'
|
|
]
|
|
}));
|
|
|
|
jest.unstable_mockModule(
|
|
'../../../../../scripts/modules/task-manager/update-single-task-status.js',
|
|
() => ({
|
|
default: jest.fn()
|
|
})
|
|
);
|
|
|
|
jest.unstable_mockModule(
|
|
'../../../../../scripts/modules/dependency-manager.js',
|
|
() => ({
|
|
validateTaskDependencies: jest.fn()
|
|
})
|
|
);
|
|
|
|
jest.unstable_mockModule(
|
|
'../../../../../scripts/modules/config-manager.js',
|
|
() => ({
|
|
getDebugFlag: jest.fn(() => false)
|
|
})
|
|
);
|
|
|
|
// Import the mocked modules
|
|
const { readJSON, writeJSON, log, findTaskById } = await import(
|
|
'../../../../../scripts/modules/utils.js'
|
|
);
|
|
|
|
const generateTaskFiles = (
|
|
await import(
|
|
'../../../../../scripts/modules/task-manager/generate-task-files.js'
|
|
)
|
|
).default;
|
|
|
|
const updateSingleTaskStatus = (
|
|
await import(
|
|
'../../../../../scripts/modules/task-manager/update-single-task-status.js'
|
|
)
|
|
).default;
|
|
|
|
// Import the module under test
|
|
const { default: setTaskStatus } = await import(
|
|
'../../../../../scripts/modules/task-manager/set-task-status.js'
|
|
);
|
|
|
|
// Sample data for tests (from main test file) - TAGGED FORMAT
|
|
const sampleTasks = {
|
|
master: {
|
|
tasks: [
|
|
{
|
|
id: 1,
|
|
title: 'Task 1',
|
|
description: 'First task description',
|
|
status: 'pending',
|
|
dependencies: [],
|
|
priority: 'high',
|
|
details: 'Detailed information for task 1',
|
|
testStrategy: 'Test strategy for task 1'
|
|
},
|
|
{
|
|
id: 2,
|
|
title: 'Task 2',
|
|
description: 'Second task description',
|
|
status: 'pending',
|
|
dependencies: [1],
|
|
priority: 'medium',
|
|
details: 'Detailed information for task 2',
|
|
testStrategy: 'Test strategy for task 2'
|
|
},
|
|
{
|
|
id: 3,
|
|
title: 'Task with Subtasks',
|
|
description: 'Task with subtasks description',
|
|
status: 'pending',
|
|
dependencies: [1, 2],
|
|
priority: 'high',
|
|
details: 'Detailed information for task 3',
|
|
testStrategy: 'Test strategy for task 3',
|
|
subtasks: [
|
|
{
|
|
id: 1,
|
|
title: 'Subtask 1',
|
|
description: 'First subtask',
|
|
status: 'pending',
|
|
dependencies: [],
|
|
details: 'Details for subtask 1'
|
|
},
|
|
{
|
|
id: 2,
|
|
title: 'Subtask 2',
|
|
description: 'Second subtask',
|
|
status: 'pending',
|
|
dependencies: [1],
|
|
details: 'Details for subtask 2'
|
|
}
|
|
]
|
|
}
|
|
]
|
|
}
|
|
};
|
|
|
|
describe('setTaskStatus', () => {
|
|
beforeEach(() => {
|
|
jest.clearAllMocks();
|
|
|
|
// Mock console methods to suppress output
|
|
jest.spyOn(console, 'log').mockImplementation(() => {});
|
|
jest.spyOn(console, 'error').mockImplementation(() => {});
|
|
|
|
// Mock process.exit to prevent actual exit
|
|
jest.spyOn(process, 'exit').mockImplementation((code) => {
|
|
throw new Error(`process.exit: ${code}`);
|
|
});
|
|
|
|
// Set up updateSingleTaskStatus mock to actually update the data
|
|
updateSingleTaskStatus.mockImplementation(
|
|
async (tasksPath, taskId, newStatus, data) => {
|
|
// This mock now operates on the tasks array passed in the `data` object
|
|
const { tasks } = data;
|
|
// Handle subtask notation (e.g., "3.1")
|
|
if (taskId.includes('.')) {
|
|
const [parentId, subtaskId] = taskId
|
|
.split('.')
|
|
.map((id) => parseInt(id, 10));
|
|
const parentTask = tasks.find((t) => t.id === parentId);
|
|
if (!parentTask) {
|
|
throw new Error(`Parent task ${parentId} not found`);
|
|
}
|
|
if (!parentTask.subtasks) {
|
|
throw new Error(`Parent task ${parentId} has no subtasks`);
|
|
}
|
|
const subtask = parentTask.subtasks.find((st) => st.id === subtaskId);
|
|
if (!subtask) {
|
|
throw new Error(
|
|
`Subtask ${subtaskId} not found in parent task ${parentId}`
|
|
);
|
|
}
|
|
subtask.status = newStatus;
|
|
} else {
|
|
// Handle regular task
|
|
const task = tasks.find((t) => t.id === parseInt(taskId, 10));
|
|
if (!task) {
|
|
throw new Error(`Task ${taskId} not found`);
|
|
}
|
|
task.status = newStatus;
|
|
|
|
// If marking parent as done, mark all subtasks as done too
|
|
if (newStatus === 'done' && task.subtasks) {
|
|
task.subtasks.forEach((subtask) => {
|
|
subtask.status = 'done';
|
|
});
|
|
}
|
|
}
|
|
}
|
|
);
|
|
});
|
|
|
|
afterEach(() => {
|
|
// Restore console methods
|
|
jest.restoreAllMocks();
|
|
});
|
|
|
|
test('should update task status in tasks.json', async () => {
|
|
// Arrange
|
|
const testTasksData = JSON.parse(JSON.stringify(sampleTasks));
|
|
const tasksPath = '/mock/path/tasks.json';
|
|
|
|
readJSON.mockReturnValue({
|
|
...testTasksData.master,
|
|
tag: 'master',
|
|
_rawTaggedData: testTasksData
|
|
});
|
|
|
|
// Act
|
|
await setTaskStatus(tasksPath, '2', 'done', {
|
|
tag: 'master',
|
|
mcpLog: { info: jest.fn() }
|
|
});
|
|
|
|
// Assert
|
|
expect(readJSON).toHaveBeenCalledWith(tasksPath, undefined, 'master');
|
|
expect(writeJSON).toHaveBeenCalledWith(
|
|
tasksPath,
|
|
expect.objectContaining({
|
|
master: expect.objectContaining({
|
|
tasks: expect.arrayContaining([
|
|
expect.objectContaining({ id: 2, status: 'done' })
|
|
])
|
|
})
|
|
}),
|
|
undefined,
|
|
'master'
|
|
);
|
|
// expect(generateTaskFiles).toHaveBeenCalledWith(
|
|
// tasksPath,
|
|
// expect.any(String),
|
|
// expect.any(Object)
|
|
// );
|
|
});
|
|
|
|
test('should update subtask status when using dot notation', async () => {
|
|
// Arrange
|
|
const testTasksData = JSON.parse(JSON.stringify(sampleTasks));
|
|
const tasksPath = '/mock/path/tasks.json';
|
|
|
|
readJSON.mockReturnValue({
|
|
...testTasksData.master,
|
|
tag: 'master',
|
|
_rawTaggedData: testTasksData
|
|
});
|
|
|
|
// Act
|
|
await setTaskStatus(tasksPath, '3.1', 'done', {
|
|
tag: 'master',
|
|
mcpLog: { info: jest.fn() }
|
|
});
|
|
|
|
// Assert
|
|
expect(readJSON).toHaveBeenCalledWith(tasksPath, undefined, 'master');
|
|
expect(writeJSON).toHaveBeenCalledWith(
|
|
tasksPath,
|
|
expect.objectContaining({
|
|
master: expect.objectContaining({
|
|
tasks: expect.arrayContaining([
|
|
expect.objectContaining({
|
|
id: 3,
|
|
subtasks: expect.arrayContaining([
|
|
expect.objectContaining({ id: 1, status: 'done' })
|
|
])
|
|
})
|
|
])
|
|
})
|
|
}),
|
|
undefined,
|
|
'master'
|
|
);
|
|
});
|
|
|
|
test('should update multiple tasks when given comma-separated IDs', async () => {
|
|
// Arrange
|
|
const testTasksData = JSON.parse(JSON.stringify(sampleTasks));
|
|
const tasksPath = '/mock/path/tasks.json';
|
|
|
|
readJSON.mockReturnValue({
|
|
...testTasksData.master,
|
|
tag: 'master',
|
|
_rawTaggedData: testTasksData
|
|
});
|
|
|
|
// Act
|
|
await setTaskStatus(tasksPath, '1,2', 'done', {
|
|
tag: 'master',
|
|
mcpLog: { info: jest.fn() }
|
|
});
|
|
|
|
// Assert
|
|
expect(readJSON).toHaveBeenCalledWith(tasksPath, undefined, 'master');
|
|
expect(writeJSON).toHaveBeenCalledWith(
|
|
tasksPath,
|
|
expect.objectContaining({
|
|
master: expect.objectContaining({
|
|
tasks: expect.arrayContaining([
|
|
expect.objectContaining({ id: 1, status: 'done' }),
|
|
expect.objectContaining({ id: 2, status: 'done' })
|
|
])
|
|
})
|
|
}),
|
|
undefined,
|
|
'master'
|
|
);
|
|
});
|
|
|
|
test('should automatically mark subtasks as done when parent is marked done', async () => {
|
|
// Arrange
|
|
const testTasksData = JSON.parse(JSON.stringify(sampleTasks));
|
|
const tasksPath = '/mock/path/tasks.json';
|
|
|
|
readJSON.mockReturnValue({
|
|
...testTasksData.master,
|
|
tag: 'master',
|
|
_rawTaggedData: testTasksData
|
|
});
|
|
|
|
// Act
|
|
await setTaskStatus(tasksPath, '3', 'done', {
|
|
tag: 'master',
|
|
mcpLog: { info: jest.fn() }
|
|
});
|
|
|
|
// Assert
|
|
expect(writeJSON).toHaveBeenCalledWith(
|
|
tasksPath,
|
|
expect.objectContaining({
|
|
master: expect.objectContaining({
|
|
tasks: expect.arrayContaining([
|
|
expect.objectContaining({
|
|
id: 3,
|
|
status: 'done',
|
|
subtasks: expect.arrayContaining([
|
|
expect.objectContaining({ id: 1, status: 'done' }),
|
|
expect.objectContaining({ id: 2, status: 'done' })
|
|
])
|
|
})
|
|
])
|
|
})
|
|
}),
|
|
undefined,
|
|
'master'
|
|
);
|
|
});
|
|
|
|
test('should throw error for non-existent task ID', async () => {
|
|
// Arrange
|
|
const testTasksData = JSON.parse(JSON.stringify(sampleTasks));
|
|
const tasksPath = '/mock/path/tasks.json';
|
|
|
|
readJSON.mockReturnValue({
|
|
...testTasksData.master,
|
|
tag: 'master',
|
|
_rawTaggedData: testTasksData
|
|
});
|
|
|
|
// Act & Assert
|
|
await expect(
|
|
setTaskStatus(tasksPath, '99', 'done', {
|
|
tag: 'master',
|
|
mcpLog: { info: jest.fn() }
|
|
})
|
|
).rejects.toThrow('Task 99 not found');
|
|
});
|
|
|
|
test('should throw error for invalid status', async () => {
|
|
// Arrange
|
|
const testTasksData = JSON.parse(JSON.stringify(sampleTasks));
|
|
const tasksPath = '/mock/path/tasks.json';
|
|
|
|
readJSON.mockReturnValue({
|
|
...testTasksData.master,
|
|
tag: 'master',
|
|
_rawTaggedData: testTasksData
|
|
});
|
|
|
|
// Act & Assert
|
|
await expect(
|
|
setTaskStatus(tasksPath, '2', 'InvalidStatus', {
|
|
mcpLog: { info: jest.fn() }
|
|
})
|
|
).rejects.toThrow(/Invalid status value: InvalidStatus/);
|
|
});
|
|
|
|
test('should handle parent tasks without subtasks when updating subtask', async () => {
|
|
// Arrange
|
|
const testTasksData = JSON.parse(JSON.stringify(sampleTasks));
|
|
// Remove subtasks from task 3
|
|
const { subtasks, ...taskWithoutSubtasks } = testTasksData.master.tasks[2];
|
|
testTasksData.master.tasks[2] = taskWithoutSubtasks;
|
|
|
|
const tasksPath = '/mock/path/tasks.json';
|
|
readJSON.mockReturnValue({
|
|
...testTasksData.master,
|
|
tag: 'master',
|
|
_rawTaggedData: testTasksData
|
|
});
|
|
|
|
// Act & Assert
|
|
await expect(
|
|
setTaskStatus(tasksPath, '3.1', 'done', {
|
|
tag: 'master',
|
|
mcpLog: { info: jest.fn() }
|
|
})
|
|
).rejects.toThrow('has no subtasks');
|
|
});
|
|
|
|
test('should handle non-existent subtask ID', async () => {
|
|
// Arrange
|
|
const testTasksData = JSON.parse(JSON.stringify(sampleTasks));
|
|
const tasksPath = '/mock/path/tasks.json';
|
|
|
|
readJSON.mockReturnValue({
|
|
...testTasksData.master,
|
|
tag: 'master',
|
|
_rawTaggedData: testTasksData
|
|
});
|
|
|
|
// Act & Assert
|
|
await expect(
|
|
setTaskStatus(tasksPath, '3.99', 'done', {
|
|
tag: 'master',
|
|
mcpLog: { info: jest.fn() }
|
|
})
|
|
).rejects.toThrow('Subtask 99 not found');
|
|
});
|
|
|
|
test('should handle file read errors', async () => {
|
|
// Arrange
|
|
const tasksPath = 'tasks/tasks.json';
|
|
const taskId = '2';
|
|
const newStatus = 'done';
|
|
|
|
readJSON.mockImplementation(() => {
|
|
throw new Error('File not found');
|
|
});
|
|
|
|
// Act & Assert
|
|
await expect(
|
|
setTaskStatus(tasksPath, taskId, newStatus, {
|
|
mcpLog: { info: jest.fn() }
|
|
})
|
|
).rejects.toThrow('File not found');
|
|
|
|
// Verify that writeJSON was not called due to read error
|
|
expect(writeJSON).not.toHaveBeenCalled();
|
|
});
|
|
|
|
test('should handle empty task ID input', async () => {
|
|
// Arrange
|
|
const tasksPath = 'tasks/tasks.json';
|
|
const emptyTaskId = '';
|
|
const newStatus = 'done';
|
|
|
|
// Act & Assert
|
|
await expect(
|
|
setTaskStatus(tasksPath, emptyTaskId, newStatus, {
|
|
mcpLog: { info: jest.fn() }
|
|
})
|
|
).rejects.toThrow();
|
|
|
|
// Verify that updateSingleTaskStatus was not called
|
|
expect(updateSingleTaskStatus).not.toHaveBeenCalled();
|
|
});
|
|
|
|
test('should handle whitespace in comma-separated IDs', async () => {
|
|
// Arrange
|
|
const testTasksData = JSON.parse(JSON.stringify(sampleTasks));
|
|
const tasksPath = 'tasks/tasks.json';
|
|
const taskIds = ' 1 , 2 , 3 '; // IDs with whitespace
|
|
const newStatus = 'in-progress';
|
|
|
|
readJSON.mockReturnValue({
|
|
...testTasksData.master,
|
|
tag: 'master',
|
|
_rawTaggedData: testTasksData
|
|
});
|
|
|
|
// Act
|
|
const result = await setTaskStatus(tasksPath, taskIds, newStatus, {
|
|
tag: 'master',
|
|
mcpLog: { info: jest.fn() }
|
|
});
|
|
|
|
// Assert
|
|
expect(updateSingleTaskStatus).toHaveBeenCalledTimes(3);
|
|
expect(updateSingleTaskStatus).toHaveBeenCalledWith(
|
|
tasksPath,
|
|
'1',
|
|
newStatus,
|
|
expect.objectContaining({
|
|
tasks: expect.any(Array),
|
|
tag: 'master',
|
|
_rawTaggedData: expect.any(Object)
|
|
}),
|
|
false
|
|
);
|
|
expect(updateSingleTaskStatus).toHaveBeenCalledWith(
|
|
tasksPath,
|
|
'2',
|
|
newStatus,
|
|
expect.objectContaining({
|
|
tasks: expect.any(Array),
|
|
tag: 'master',
|
|
_rawTaggedData: expect.any(Object)
|
|
}),
|
|
false
|
|
);
|
|
expect(updateSingleTaskStatus).toHaveBeenCalledWith(
|
|
tasksPath,
|
|
'3',
|
|
newStatus,
|
|
expect.objectContaining({
|
|
tasks: expect.any(Array),
|
|
tag: 'master',
|
|
_rawTaggedData: expect.any(Object)
|
|
}),
|
|
false
|
|
);
|
|
expect(result).toBeDefined();
|
|
});
|
|
|
|
// Regression test to ensure tag preservation when updating in multi-tag environment
|
|
test('should preserve other tags when updating task status', async () => {
|
|
// Arrange
|
|
const multiTagData = {
|
|
master: JSON.parse(JSON.stringify(sampleTasks.master)),
|
|
'feature-branch': {
|
|
tasks: [
|
|
{ id: 10, title: 'FB Task', status: 'pending', dependencies: [] }
|
|
],
|
|
metadata: { description: 'Feature branch tasks' }
|
|
}
|
|
};
|
|
const tasksPath = '/mock/path/tasks.json';
|
|
|
|
readJSON.mockReturnValue({
|
|
...multiTagData.master, // resolved view not used
|
|
tag: 'master',
|
|
_rawTaggedData: multiTagData
|
|
});
|
|
|
|
// Act
|
|
await setTaskStatus(tasksPath, '1', 'done', {
|
|
tag: 'master',
|
|
mcpLog: { info: jest.fn() }
|
|
});
|
|
|
|
// Assert: writeJSON should be called with data containing both tags intact
|
|
const writeArgs = writeJSON.mock.calls[0];
|
|
expect(writeArgs[0]).toBe(tasksPath);
|
|
const writtenData = writeArgs[1];
|
|
expect(writtenData).toHaveProperty('master');
|
|
expect(writtenData).toHaveProperty('feature-branch');
|
|
// master task updated
|
|
const updatedTask = writtenData.master.tasks.find((t) => t.id === 1);
|
|
expect(updatedTask.status).toBe('done');
|
|
// feature-branch untouched
|
|
expect(writtenData['feature-branch'].tasks[0].status).toBe('pending');
|
|
// ensure additional args (projectRoot undefined, tag 'master') present
|
|
expect(writeArgs[2]).toBeUndefined();
|
|
expect(writeArgs[3]).toBe('master');
|
|
});
|
|
});
|