chore: prettier formatting

This commit is contained in:
Eyal Toledano
2025-04-09 18:20:47 -04:00
parent 12519946b4
commit 4f68bf3b47
7 changed files with 487 additions and 376 deletions

View File

@@ -50,13 +50,16 @@ export async function addTaskDirect(args, log, context = {}) {
// Check required parameters // Check required parameters
if (!args.prompt && !isManualCreation) { if (!args.prompt && !isManualCreation) {
log.error('Missing required parameters: either prompt or title+description must be provided'); log.error(
'Missing required parameters: either prompt or title+description must be provided'
);
disableSilentMode(); disableSilentMode();
return { return {
success: false, success: false,
error: { error: {
code: 'MISSING_PARAMETER', code: 'MISSING_PARAMETER',
message: 'Either the prompt parameter or both title and description parameters are required for adding a task' message:
'Either the prompt parameter or both title and description parameters are required for adding a task'
} }
}; };
} }

View File

@@ -22,11 +22,28 @@ export function registerAddTaskTool(server) {
name: 'add_task', name: 'add_task',
description: 'Add a new task using AI', description: 'Add a new task using AI',
parameters: z.object({ parameters: z.object({
prompt: z.string().optional().describe('Description of the task to add (required if not using manual fields)'), prompt: z
title: z.string().optional().describe('Task title (for manual task creation)'), .string()
description: z.string().optional().describe('Task description (for manual task creation)'), .optional()
details: z.string().optional().describe('Implementation details (for manual task creation)'), .describe(
testStrategy: z.string().optional().describe('Test strategy (for manual task creation)'), 'Description of the task to add (required if not using manual fields)'
),
title: z
.string()
.optional()
.describe('Task title (for manual task creation)'),
description: z
.string()
.optional()
.describe('Task description (for manual task creation)'),
details: z
.string()
.optional()
.describe('Implementation details (for manual task creation)'),
testStrategy: z
.string()
.optional()
.describe('Test strategy (for manual task creation)'),
dependencies: z dependencies: z
.string() .string()
.optional() .optional()
@@ -35,11 +52,16 @@ export function registerAddTaskTool(server) {
.string() .string()
.optional() .optional()
.describe('Task priority (high, medium, low)'), .describe('Task priority (high, medium, low)'),
file: z.string().optional().describe('Path to the tasks file (default: tasks/tasks.json)'), file: z
.string()
.optional()
.describe('Path to the tasks file (default: tasks/tasks.json)'),
projectRoot: z projectRoot: z
.string() .string()
.optional() .optional()
.describe('Root directory of the project (default: current working directory)'), .describe(
'Root directory of the project (default: current working directory)'
),
research: z research: z
.boolean() .boolean()
.optional() .optional()

View File

@@ -791,20 +791,46 @@ function registerCommands(programInstance) {
.command('add-task') .command('add-task')
.description('Add a new task using AI or manual input') .description('Add a new task using AI or manual input')
.option('-f, --file <file>', 'Path to the tasks file', 'tasks/tasks.json') .option('-f, --file <file>', 'Path to the tasks file', 'tasks/tasks.json')
.option('-p, --prompt <prompt>', 'Description of the task to add (required if not using manual fields)') .option(
'-p, --prompt <prompt>',
'Description of the task to add (required if not using manual fields)'
)
.option('-t, --title <title>', 'Task title (for manual task creation)') .option('-t, --title <title>', 'Task title (for manual task creation)')
.option('-d, --description <description>', 'Task description (for manual task creation)') .option(
.option('--details <details>', 'Implementation details (for manual task creation)') '-d, --description <description>',
.option('--test-strategy <testStrategy>', 'Test strategy (for manual task creation)') 'Task description (for manual task creation)'
.option('--dependencies <dependencies>', 'Comma-separated list of task IDs this task depends on') )
.option('--priority <priority>', 'Task priority (high, medium, low)', 'medium') .option(
.option('-r, --research', 'Whether to use research capabilities for task creation') '--details <details>',
'Implementation details (for manual task creation)'
)
.option(
'--test-strategy <testStrategy>',
'Test strategy (for manual task creation)'
)
.option(
'--dependencies <dependencies>',
'Comma-separated list of task IDs this task depends on'
)
.option(
'--priority <priority>',
'Task priority (high, medium, low)',
'medium'
)
.option(
'-r, --research',
'Whether to use research capabilities for task creation'
)
.action(async (options) => { .action(async (options) => {
const isManualCreation = options.title && options.description; const isManualCreation = options.title && options.description;
// Validate that either prompt or title+description are provided // Validate that either prompt or title+description are provided
if (!options.prompt && !isManualCreation) { if (!options.prompt && !isManualCreation) {
console.error(chalk.red('Error: Either --prompt or both --title and --description must be provided')); console.error(
chalk.red(
'Error: Either --prompt or both --title and --description must be provided'
)
);
process.exit(1); process.exit(1);
} }
@@ -812,7 +838,9 @@ function registerCommands(programInstance) {
// Prepare dependencies if provided // Prepare dependencies if provided
let dependencies = []; let dependencies = [];
if (options.dependencies) { if (options.dependencies) {
dependencies = options.dependencies.split(',').map(id => parseInt(id.trim(), 10)); dependencies = options.dependencies
.split(',')
.map((id) => parseInt(id.trim(), 10));
} }
// Create manual task data if title and description are provided // Create manual task data if title and description are provided
@@ -825,17 +853,27 @@ function registerCommands(programInstance) {
testStrategy: options.testStrategy || '' testStrategy: options.testStrategy || ''
}; };
console.log(chalk.blue(`Creating task manually with title: "${options.title}"`)); console.log(
chalk.blue(`Creating task manually with title: "${options.title}"`)
);
if (dependencies.length > 0) { if (dependencies.length > 0) {
console.log(chalk.blue(`Dependencies: [${dependencies.join(', ')}]`)); console.log(
chalk.blue(`Dependencies: [${dependencies.join(', ')}]`)
);
} }
if (options.priority) { if (options.priority) {
console.log(chalk.blue(`Priority: ${options.priority}`)); console.log(chalk.blue(`Priority: ${options.priority}`));
} }
} else { } else {
console.log(chalk.blue(`Creating task with AI using prompt: "${options.prompt}"`)); console.log(
chalk.blue(
`Creating task with AI using prompt: "${options.prompt}"`
)
);
if (dependencies.length > 0) { if (dependencies.length > 0) {
console.log(chalk.blue(`Dependencies: [${dependencies.join(', ')}]`)); console.log(
chalk.blue(`Dependencies: [${dependencies.join(', ')}]`)
);
} }
if (options.priority) { if (options.priority) {
console.log(chalk.blue(`Priority: ${options.priority}`)); console.log(chalk.blue(`Priority: ${options.priority}`));

View File

@@ -3506,7 +3506,9 @@ async function addTask(
'\n' + '\n' +
chalk.white(`Status: ${getStatusWithColor(newTask.status)}`) + chalk.white(`Status: ${getStatusWithColor(newTask.status)}`) +
'\n' + '\n' +
chalk.white(`Priority: ${chalk.keyword(getPriorityColor(newTask.priority))(newTask.priority)}`) + chalk.white(
`Priority: ${chalk.keyword(getPriorityColor(newTask.priority))(newTask.priority)}`
) +
'\n' + '\n' +
(dependencies.length > 0 (dependencies.length > 0
? chalk.white(`Dependencies: ${dependencies.join(', ')}`) + '\n' ? chalk.white(`Dependencies: ${dependencies.join(', ')}`) + '\n'
@@ -3514,11 +3516,17 @@ async function addTask(
'\n' + '\n' +
chalk.white.bold('Next Steps:') + chalk.white.bold('Next Steps:') +
'\n' + '\n' +
chalk.cyan(`1. Run ${chalk.yellow(`task-master show ${newTaskId}`)} to see complete task details`) + chalk.cyan(
`1. Run ${chalk.yellow(`task-master show ${newTaskId}`)} to see complete task details`
) +
'\n' + '\n' +
chalk.cyan(`2. Run ${chalk.yellow(`task-master set-status --id=${newTaskId} --status=in-progress`)} to start working on it`) + chalk.cyan(
`2. Run ${chalk.yellow(`task-master set-status --id=${newTaskId} --status=in-progress`)} to start working on it`
) +
'\n' + '\n' +
chalk.cyan(`3. Run ${chalk.yellow(`task-master expand --id=${newTaskId}`)} to break it down into subtasks`), chalk.cyan(
`3. Run ${chalk.yellow(`task-master expand --id=${newTaskId}`)} to break it down into subtasks`
),
{ padding: 1, borderColor: 'green', borderStyle: 'round' } { padding: 1, borderColor: 'green', borderStyle: 'round' }
) )
); );

View File

@@ -1,14 +1,14 @@
{ {
"tasks": [ "tasks": [
{ {
"id": 1, "id": 1,
"dependencies": [], "dependencies": [],
"subtasks": [ "subtasks": [
{ {
"id": 1, "id": 1,
"dependencies": [] "dependencies": []
} }
] ]
} }
] ]
} }

View File

@@ -3,7 +3,10 @@
*/ */
import { jest } from '@jest/globals'; import { jest } from '@jest/globals';
import { sampleTasks, emptySampleTasks } from '../../tests/fixtures/sample-tasks.js'; import {
sampleTasks,
emptySampleTasks
} from '../../tests/fixtures/sample-tasks.js';
// Mock functions that need jest.fn methods // Mock functions that need jest.fn methods
const mockParsePRD = jest.fn().mockResolvedValue(undefined); const mockParsePRD = jest.fn().mockResolvedValue(undefined);
@@ -658,11 +661,24 @@ describe('Commands Module', () => {
// Create a mock task manager with an addTask function that resolves to taskId 5 // Create a mock task manager with an addTask function that resolves to taskId 5
mockTaskManager = { mockTaskManager = {
addTask: jest.fn().mockImplementation((file, prompt, dependencies, priority, session, research, generateFiles, manualTaskData) => { addTask: jest
// Return the next ID after the last one in sample tasks .fn()
const newId = sampleTasks.tasks.length + 1; .mockImplementation(
return Promise.resolve(newId.toString()); (
}) file,
prompt,
dependencies,
priority,
session,
research,
generateFiles,
manualTaskData
) => {
// Return the next ID after the last one in sample tasks
const newId = sampleTasks.tasks.length + 1;
return Promise.resolve(newId.toString());
}
)
}; };
// Create a simplified version of the add-task action function for testing // Create a simplified version of the add-task action function for testing
@@ -676,13 +692,15 @@ describe('Commands Module', () => {
// Validate that either prompt or title+description are provided // Validate that either prompt or title+description are provided
if (!prompt && !isManualCreation) { if (!prompt && !isManualCreation) {
throw new Error('Either --prompt or both --title and --description must be provided'); throw new Error(
'Either --prompt or both --title and --description must be provided'
);
} }
// Prepare dependencies if provided // Prepare dependencies if provided
let dependencies = []; let dependencies = [];
if (options.dependencies) { if (options.dependencies) {
dependencies = options.dependencies.split(',').map(id => id.trim()); dependencies = options.dependencies.split(',').map((id) => id.trim());
} }
// Create manual task data if title and description are provided // Create manual task data if title and description are provided
@@ -716,7 +734,9 @@ describe('Commands Module', () => {
await expect(async () => { await expect(async () => {
await addTaskAction(undefined, options); await addTaskAction(undefined, options);
}).rejects.toThrow('Either --prompt or both --title and --description must be provided'); }).rejects.toThrow(
'Either --prompt or both --title and --description must be provided'
);
}); });
test('should handle short-hand flag -p for prompt', async () => { test('should handle short-hand flag -p for prompt', async () => {
@@ -737,7 +757,7 @@ describe('Commands Module', () => {
{ session: process.env }, { session: process.env },
false, // Research flag false, // Research flag
null, // Generate files parameter null, // Generate files parameter
null // Manual task data null // Manual task data
); );
}); });
@@ -759,7 +779,7 @@ describe('Commands Module', () => {
{ session: process.env }, { session: process.env },
true, // Research flag should be true true, // Research flag should be true
null, // Generate files parameter null, // Generate files parameter
null // Manual task data null // Manual task data
); );
}); });
@@ -782,7 +802,8 @@ describe('Commands Module', () => {
{ session: process.env }, { session: process.env },
false, false,
null, // Generate files parameter null, // Generate files parameter
{ // Manual task data {
// Manual task data
title: 'Login Component', title: 'Login Component',
description: 'Create a reusable login form', description: 'Create a reusable login form',
details: 'Implementation details here', details: 'Implementation details here',
@@ -809,7 +830,7 @@ describe('Commands Module', () => {
{ session: process.env }, { session: process.env },
false, false,
null, // Generate files parameter null, // Generate files parameter
null // Manual task data null // Manual task data
); );
}); });
@@ -831,7 +852,7 @@ describe('Commands Module', () => {
{ session: process.env }, { session: process.env },
false, false,
null, // Generate files parameter null, // Generate files parameter
null // Manual task data null // Manual task data
); );
}); });
@@ -852,7 +873,7 @@ describe('Commands Module', () => {
{ session: process.env }, { session: process.env },
false, // Research is false by default false, // Research is false by default
null, // Generate files parameter null, // Generate files parameter
null // Manual task data null // Manual task data
); );
}); });
}); });

View File

@@ -10,317 +10,336 @@
*/ */
import { jest } from '@jest/globals'; import { jest } from '@jest/globals';
import { sampleTasks, emptySampleTasks } from '../../../fixtures/sample-tasks.js'; import {
sampleTasks,
emptySampleTasks
} from '../../../fixtures/sample-tasks.js';
// Mock EVERYTHING // Mock EVERYTHING
const mockAddTaskDirect = jest.fn(); const mockAddTaskDirect = jest.fn();
jest.mock('../../../../mcp-server/src/core/task-master-core.js', () => ({ jest.mock('../../../../mcp-server/src/core/task-master-core.js', () => ({
addTaskDirect: mockAddTaskDirect addTaskDirect: mockAddTaskDirect
})); }));
const mockHandleApiResult = jest.fn(result => result); const mockHandleApiResult = jest.fn((result) => result);
const mockGetProjectRootFromSession = jest.fn(() => '/mock/project/root'); const mockGetProjectRootFromSession = jest.fn(() => '/mock/project/root');
const mockCreateErrorResponse = jest.fn(msg => ({ const mockCreateErrorResponse = jest.fn((msg) => ({
success: false, success: false,
error: { code: 'ERROR', message: msg } error: { code: 'ERROR', message: msg }
})); }));
jest.mock('../../../../mcp-server/src/tools/utils.js', () => ({ jest.mock('../../../../mcp-server/src/tools/utils.js', () => ({
getProjectRootFromSession: mockGetProjectRootFromSession, getProjectRootFromSession: mockGetProjectRootFromSession,
handleApiResult: mockHandleApiResult, handleApiResult: mockHandleApiResult,
createErrorResponse: mockCreateErrorResponse, createErrorResponse: mockCreateErrorResponse,
createContentResponse: jest.fn(content => ({ success: true, data: content })), createContentResponse: jest.fn((content) => ({
executeTaskMasterCommand: jest.fn() success: true,
data: content
})),
executeTaskMasterCommand: jest.fn()
})); }));
// Mock the z object from zod // Mock the z object from zod
const mockZod = { const mockZod = {
object: jest.fn(() => mockZod), object: jest.fn(() => mockZod),
string: jest.fn(() => mockZod), string: jest.fn(() => mockZod),
boolean: jest.fn(() => mockZod), boolean: jest.fn(() => mockZod),
optional: jest.fn(() => mockZod), optional: jest.fn(() => mockZod),
describe: jest.fn(() => mockZod), describe: jest.fn(() => mockZod),
_def: { shape: () => ({ _def: {
prompt: {}, shape: () => ({
dependencies: {}, prompt: {},
priority: {}, dependencies: {},
research: {}, priority: {},
file: {}, research: {},
projectRoot: {} file: {},
})} projectRoot: {}
})
}
}; };
jest.mock('zod', () => ({ jest.mock('zod', () => ({
z: mockZod z: mockZod
})); }));
// DO NOT import the real module - create a fake implementation // DO NOT import the real module - create a fake implementation
// This is the fake implementation of registerAddTaskTool // This is the fake implementation of registerAddTaskTool
const registerAddTaskTool = (server) => { const registerAddTaskTool = (server) => {
// Create simplified version of the tool config // Create simplified version of the tool config
const toolConfig = { const toolConfig = {
name: 'add_task', name: 'add_task',
description: 'Add a new task using AI', description: 'Add a new task using AI',
parameters: mockZod, parameters: mockZod,
// Create a simplified mock of the execute function // Create a simplified mock of the execute function
execute: (args, context) => { execute: (args, context) => {
const { log, reportProgress, session } = context; const { log, reportProgress, session } = context;
try { try {
log.info && log.info(`Starting add-task with args: ${JSON.stringify(args)}`); log.info &&
log.info(`Starting add-task with args: ${JSON.stringify(args)}`);
// Get project root // Get project root
const rootFolder = mockGetProjectRootFromSession(session, log); const rootFolder = mockGetProjectRootFromSession(session, log);
// Call addTaskDirect // Call addTaskDirect
const result = mockAddTaskDirect({ const result = mockAddTaskDirect(
...args, {
projectRoot: rootFolder ...args,
}, log, { reportProgress, session }); projectRoot: rootFolder
},
log,
{ reportProgress, session }
);
// Handle result // Handle result
return mockHandleApiResult(result, log); return mockHandleApiResult(result, log);
} catch (error) { } catch (error) {
log.error && log.error(`Error in add-task tool: ${error.message}`); log.error && log.error(`Error in add-task tool: ${error.message}`);
return mockCreateErrorResponse(error.message); return mockCreateErrorResponse(error.message);
} }
} }
}; };
// Register the tool with the server // Register the tool with the server
server.addTool(toolConfig); server.addTool(toolConfig);
}; };
describe('MCP Tool: add-task', () => { describe('MCP Tool: add-task', () => {
// Create mock server // Create mock server
let mockServer; let mockServer;
let executeFunction; let executeFunction;
// Create mock logger // Create mock logger
const mockLogger = { const mockLogger = {
debug: jest.fn(), debug: jest.fn(),
info: jest.fn(), info: jest.fn(),
warn: jest.fn(), warn: jest.fn(),
error: jest.fn() error: jest.fn()
}; };
// Test data // Test data
const validArgs = { const validArgs = {
prompt: 'Create a new task', prompt: 'Create a new task',
dependencies: '1,2', dependencies: '1,2',
priority: 'high', priority: 'high',
research: true research: true
}; };
// Standard responses // Standard responses
const successResponse = { const successResponse = {
success: true, success: true,
data: { data: {
taskId: '5', taskId: '5',
message: 'Successfully added new task #5' message: 'Successfully added new task #5'
} }
}; };
const errorResponse = { const errorResponse = {
success: false, success: false,
error: { error: {
code: 'ADD_TASK_ERROR', code: 'ADD_TASK_ERROR',
message: 'Failed to add task' message: 'Failed to add task'
} }
}; };
beforeEach(() => { beforeEach(() => {
// Reset all mocks // Reset all mocks
jest.clearAllMocks(); jest.clearAllMocks();
// Create mock server // Create mock server
mockServer = { mockServer = {
addTool: jest.fn(config => { addTool: jest.fn((config) => {
executeFunction = config.execute; executeFunction = config.execute;
}) })
}; };
// Setup default successful response // Setup default successful response
mockAddTaskDirect.mockReturnValue(successResponse); mockAddTaskDirect.mockReturnValue(successResponse);
// Register the tool // Register the tool
registerAddTaskTool(mockServer); registerAddTaskTool(mockServer);
}); });
test('should register the tool correctly', () => { test('should register the tool correctly', () => {
// Verify tool was registered // Verify tool was registered
expect(mockServer.addTool).toHaveBeenCalledWith( expect(mockServer.addTool).toHaveBeenCalledWith(
expect.objectContaining({ expect.objectContaining({
name: 'add_task', name: 'add_task',
description: 'Add a new task using AI', description: 'Add a new task using AI',
parameters: expect.any(Object), parameters: expect.any(Object),
execute: expect.any(Function) execute: expect.any(Function)
}) })
); );
// Verify the tool config was passed // Verify the tool config was passed
const toolConfig = mockServer.addTool.mock.calls[0][0]; const toolConfig = mockServer.addTool.mock.calls[0][0];
expect(toolConfig).toHaveProperty('parameters'); expect(toolConfig).toHaveProperty('parameters');
expect(toolConfig).toHaveProperty('execute'); expect(toolConfig).toHaveProperty('execute');
}); });
test('should execute the tool with valid parameters', () => { test('should execute the tool with valid parameters', () => {
// Setup context // Setup context
const mockContext = { const mockContext = {
log: mockLogger, log: mockLogger,
reportProgress: jest.fn(), reportProgress: jest.fn(),
session: { workingDirectory: '/mock/dir' } session: { workingDirectory: '/mock/dir' }
}; };
// Execute the function // Execute the function
executeFunction(validArgs, mockContext); executeFunction(validArgs, mockContext);
// Verify getProjectRootFromSession was called // Verify getProjectRootFromSession was called
expect(mockGetProjectRootFromSession).toHaveBeenCalledWith( expect(mockGetProjectRootFromSession).toHaveBeenCalledWith(
mockContext.session, mockContext.session,
mockLogger mockLogger
); );
// Verify addTaskDirect was called with correct arguments // Verify addTaskDirect was called with correct arguments
expect(mockAddTaskDirect).toHaveBeenCalledWith( expect(mockAddTaskDirect).toHaveBeenCalledWith(
expect.objectContaining({ expect.objectContaining({
...validArgs, ...validArgs,
projectRoot: '/mock/project/root' projectRoot: '/mock/project/root'
}), }),
mockLogger, mockLogger,
{ {
reportProgress: mockContext.reportProgress, reportProgress: mockContext.reportProgress,
session: mockContext.session session: mockContext.session
} }
); );
// Verify handleApiResult was called // Verify handleApiResult was called
expect(mockHandleApiResult).toHaveBeenCalledWith( expect(mockHandleApiResult).toHaveBeenCalledWith(
successResponse, successResponse,
mockLogger mockLogger
); );
}); });
test('should handle errors from addTaskDirect', () => { test('should handle errors from addTaskDirect', () => {
// Setup error response // Setup error response
mockAddTaskDirect.mockReturnValueOnce(errorResponse); mockAddTaskDirect.mockReturnValueOnce(errorResponse);
// Setup context // Setup context
const mockContext = { const mockContext = {
log: mockLogger, log: mockLogger,
reportProgress: jest.fn(), reportProgress: jest.fn(),
session: { workingDirectory: '/mock/dir' } session: { workingDirectory: '/mock/dir' }
}; };
// Execute the function // Execute the function
executeFunction(validArgs, mockContext); executeFunction(validArgs, mockContext);
// Verify addTaskDirect was called // Verify addTaskDirect was called
expect(mockAddTaskDirect).toHaveBeenCalled(); expect(mockAddTaskDirect).toHaveBeenCalled();
// Verify handleApiResult was called with error response // Verify handleApiResult was called with error response
expect(mockHandleApiResult).toHaveBeenCalledWith( expect(mockHandleApiResult).toHaveBeenCalledWith(errorResponse, mockLogger);
errorResponse, });
mockLogger
);
});
test('should handle unexpected errors', () => { test('should handle unexpected errors', () => {
// Setup error // Setup error
const testError = new Error('Unexpected error'); const testError = new Error('Unexpected error');
mockAddTaskDirect.mockImplementationOnce(() => { mockAddTaskDirect.mockImplementationOnce(() => {
throw testError; throw testError;
}); });
// Setup context // Setup context
const mockContext = { const mockContext = {
log: mockLogger, log: mockLogger,
reportProgress: jest.fn(), reportProgress: jest.fn(),
session: { workingDirectory: '/mock/dir' } session: { workingDirectory: '/mock/dir' }
}; };
// Execute the function // Execute the function
executeFunction(validArgs, mockContext); executeFunction(validArgs, mockContext);
// Verify error was logged // Verify error was logged
expect(mockLogger.error).toHaveBeenCalledWith( expect(mockLogger.error).toHaveBeenCalledWith(
'Error in add-task tool: Unexpected error' 'Error in add-task tool: Unexpected error'
); );
// Verify error response was created // Verify error response was created
expect(mockCreateErrorResponse).toHaveBeenCalledWith('Unexpected error'); expect(mockCreateErrorResponse).toHaveBeenCalledWith('Unexpected error');
}); });
test('should pass research parameter correctly', () => { test('should pass research parameter correctly', () => {
// Setup context // Setup context
const mockContext = { const mockContext = {
log: mockLogger, log: mockLogger,
reportProgress: jest.fn(), reportProgress: jest.fn(),
session: { workingDirectory: '/mock/dir' } session: { workingDirectory: '/mock/dir' }
}; };
// Test with research=true // Test with research=true
executeFunction({ executeFunction(
...validArgs, {
research: true ...validArgs,
}, mockContext); research: true
},
mockContext
);
// Verify addTaskDirect was called with research=true // Verify addTaskDirect was called with research=true
expect(mockAddTaskDirect).toHaveBeenCalledWith( expect(mockAddTaskDirect).toHaveBeenCalledWith(
expect.objectContaining({ expect.objectContaining({
research: true research: true
}), }),
expect.any(Object), expect.any(Object),
expect.any(Object) expect.any(Object)
); );
// Reset mocks // Reset mocks
jest.clearAllMocks(); jest.clearAllMocks();
// Test with research=false // Test with research=false
executeFunction({ executeFunction(
...validArgs, {
research: false ...validArgs,
}, mockContext); research: false
},
mockContext
);
// Verify addTaskDirect was called with research=false // Verify addTaskDirect was called with research=false
expect(mockAddTaskDirect).toHaveBeenCalledWith( expect(mockAddTaskDirect).toHaveBeenCalledWith(
expect.objectContaining({ expect.objectContaining({
research: false research: false
}), }),
expect.any(Object), expect.any(Object),
expect.any(Object) expect.any(Object)
); );
}); });
test('should pass priority parameter correctly', () => { test('should pass priority parameter correctly', () => {
// Setup context // Setup context
const mockContext = { const mockContext = {
log: mockLogger, log: mockLogger,
reportProgress: jest.fn(), reportProgress: jest.fn(),
session: { workingDirectory: '/mock/dir' } session: { workingDirectory: '/mock/dir' }
}; };
// Test different priority values // Test different priority values
['high', 'medium', 'low'].forEach(priority => { ['high', 'medium', 'low'].forEach((priority) => {
// Reset mocks // Reset mocks
jest.clearAllMocks(); jest.clearAllMocks();
// Execute with specific priority // Execute with specific priority
executeFunction({ executeFunction(
...validArgs, {
priority ...validArgs,
}, mockContext); priority
},
mockContext
);
// Verify addTaskDirect was called with correct priority // Verify addTaskDirect was called with correct priority
expect(mockAddTaskDirect).toHaveBeenCalledWith( expect(mockAddTaskDirect).toHaveBeenCalledWith(
expect.objectContaining({ expect.objectContaining({
priority priority
}), }),
expect.any(Object), expect.any(Object),
expect.any(Object) expect.any(Object)
); );
}); });
}); });
}); });