This commit is contained in:
r committed 2026-11-05 09:54:31 -05:00
commit 52ec160d5a
3 files changed
+73 -4

No files matched your search

@@ -1,7 +1,9 @@
import { afterEach, describe, expect, it, vi } from 'vitest';
import { mkdtempSync, readFileSync, rmSync } from 'node:fs';
import { mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
import { tmpdir } from 'node:os';
import { join } from 'node:path';
import { resolveTargetCommand } from '../src/command-resolution.js';
import { CommandParser } from '../src/parser.js';
const state = vi.hoisted(() => ({ cwd: '' }));
vi.mock('../src/mcp-tools/types.js', () => ({ getProjectCwd: () => state.cwd }));
vi.mock('../src/mcp-client.js', async () => {
@@ -22,6 +24,65 @@ describe('task create CLI/MCP assignment parity', () => {
});
import { taskTools } from '../src/mcp-tools/task-tools.js';
describe('task retry CLI/MCP state parity (#4723)', () => {
it.each([
{ label: 'explicit retain', options: ['--no-reset-state'], reset: false },
{ label: 'CLI default', options: [], reset: false },
{ label: 'explicit reset', options: ['--reset-state'], reset: true },
{ label: 'MCP default', options: null, reset: true },
])('persists the new task and synchronizes assignees with $label', async ({ options, reset }) => {
state.cwd = mkdtempSync(join(tmpdir(), 'ruflo-task-retry-'));
const flowDir = join(state.cwd, '.claude-flow');
mkdirSync(join(flowDir, 'agents'), { recursive: true });
const agentPaths = [join(flowDir, 'agents', 'store.json'), join(flowDir, 'agents.json')];
for (const path of agentPaths) {
writeFileSync(path, JSON.stringify({ agents: { coder: { status: 'idle', currentTask: null } } }));
}
const readAgent = (path: string) => JSON.parse(readFileSync(path, 'utf8')).agents.coder;
const readTasks = () => JSON.parse(readFileSync(join(flowDir, 'tasks', 'store.json'), 'utf8')).tasks;
const call = async (name: string, input: Record<string, unknown>) => {
const tool = taskTools.find(candidate => candidate.name === name)!;
return await tool.handler(input) as { taskId: string; newTaskId: string };
};
const { taskId } = await call('task_create', {
type: 'test', description: 'Persist retry state', assignTo: ['coder'], tags: ['fixture'],
});
const savedResult = { partial: 'fixture result' };
await call('task_update', { taskId, status: 'failed', progress: 42, result: savedResult });
const original = readTasks()[taskId];
for (const path of agentPaths) expect(readAgent(path)).toMatchObject({ status: 'idle', currentTask: null });
let newTaskId: string;
if (options === null) {
({ newTaskId } = await call('task_retry', { taskId }));
} else {
const parser = new CommandParser();
parser.registerCommand(taskCommand);
const { command, flags, positional } = parser.parse(['task', 'retry', taskId, ...options]);
const { target, args } = resolveTargetCommand(taskCommand, command, positional);
expect(parser.validateFlags(flags, target)).toEqual([]);
const result = await target.action!({ args, flags, cwd: state.cwd, interactive: false });
expect(result).toMatchObject({ success: true });
({ newTaskId } = result.data as { newTaskId: string });
}
const tasks = readTasks();
expect(newTaskId).not.toBe(taskId);
expect(tasks[taskId]).toEqual(original);
expect(tasks[newTaskId]).toMatchObject({
status: 'pending', progress: reset ? 0 : 42, startedAt: null, completedAt: null,
assignedTo: ['coder'], tags: ['fixture', 'retry-of:' + taskId],
});
expect(tasks[newTaskId].result).toEqual(reset ? undefined : savedResult);
for (const path of agentPaths) {
expect(readAgent(path)).toMatchObject({ status: 'busy', currentTask: newTaskId });
}
await call('task_cancel', { taskId: newTaskId });
for (const path of agentPaths) expect(readAgent(path)).toMatchObject({ status: 'idle', currentTask: null });
});
});
it('lists all, running and agent-filtered tasks using the persisted handler contract', async () => {
state.cwd = mkdtempSync(join(tmpdir(), 'ruflo-task-list-'));
const call = (name: string, input: any): Promise<any> => taskTools.find(t=>t.name===name)!.handler(input) as Promise<any>;
+1 -1
View File
@@ -765,7 +765,7 @@ const retryCommand: Command = {
],
action: async (ctx: CommandContext): Promise<CommandResult> => {
const taskId = ctx.args[0];
const resetState = ctx.flags['reset-state'] as boolean;
const resetState = (ctx.flags.resetState ?? ctx.flags['reset-state']) as boolean | undefined;
if (!taskId) {
output.printError('Task ID is required');
@@ -682,22 +682,30 @@ export const taskTools: MCPTool[] = [
const original = store.tasks[taskId];
if (!original) return { success: false, taskId, error: 'Task not found' };
const retainState = input.resetState === false;
const newTaskId = `task-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
store.tasks[newTaskId] = {
const retry: TaskRecord = {
taskId: newTaskId,
type: original.type,
description: original.description,
priority: original.priority,
status: 'pending',
progress: 0,
progress: retainState ? original.progress ?? 0 : 0,
assignedTo: [...original.assignedTo],
tags: [...original.tags, 'retry-of:' + taskId],
createdAt: new Date().toISOString(),
startedAt: null,
completedAt: null,
};
if (retainState && original.result !== undefined) retry.result = original.result;
store.tasks[newTaskId] = retry;
saveTaskStore(store);
updateAgents(retry.assignedTo, (agent) => {
agent.status = 'busy';
agent.currentTask = newTaskId;
});
return {
taskId,
newTaskId,