mirror of
https://github.com/ruvnet/ruflo.git
synced 2026-12-04 06:21:59 +09:00
Merge pull request #4935 from kevin9327/fix/task-update-reopen-completed-at
fix(tasks): clear completedAt when task_update reopens a finished task
This commit is contained in:
2 files changed
+48
No files matched your search
@@ -0,0 +1,43 @@
|
||||
import { afterEach, beforeEach, expect, it, vi } from 'vitest';
|
||||
import { mkdtempSync, readFileSync, rmSync } from 'node:fs';
|
||||
import { tmpdir } from 'node:os';
|
||||
import { join } from 'node:path';
|
||||
const state = vi.hoisted(() => ({ cwd: '' }));
|
||||
vi.mock('../src/mcp-tools/types.js', () => ({ getProjectCwd: () => state.cwd }));
|
||||
import { taskTools } from '../src/mcp-tools/task-tools.js';
|
||||
const call = (name: string, input: any): Promise<any> => taskTools.find(t => t.name === name)!.handler(input) as Promise<any>;
|
||||
const stored = (id: string) => JSON.parse(readFileSync(join(state.cwd, '.claude-flow/tasks/store.json'), 'utf8')).tasks[id];
|
||||
beforeEach(() => { state.cwd = mkdtempSync(join(tmpdir(), 'ruflo-task-reopen-')); });
|
||||
afterEach(() => rmSync(state.cwd, { recursive: true, force: true }));
|
||||
|
||||
it.each([
|
||||
['completed', 'pending'],
|
||||
['completed', 'in_progress'],
|
||||
['failed', 'in_progress'],
|
||||
['cancelled', 'pending'],
|
||||
])('reopening a %s task as %s clears completedAt', async (finished, reopened) => {
|
||||
const { taskId } = await call('task_create', { type: 'test', description: 'task' });
|
||||
await call('task_update', { taskId, status: finished });
|
||||
expect(stored(taskId).completedAt).toEqual(expect.any(String));
|
||||
|
||||
await call('task_update', { taskId, status: reopened });
|
||||
expect(stored(taskId)).toMatchObject({ status: reopened, completedAt: null });
|
||||
expect((await call('task_status', { taskId })).completedAt).toBeNull();
|
||||
});
|
||||
|
||||
it('finishing the reopened task records a new completedAt', async () => {
|
||||
const { taskId } = await call('task_create', { type: 'test', description: 'task' });
|
||||
await call('task_update', { taskId, status: 'completed' });
|
||||
await call('task_update', { taskId, status: 'pending' });
|
||||
await call('task_update', { taskId, status: 'completed' });
|
||||
expect(stored(taskId)).toMatchObject({ status: 'completed', progress: 100 });
|
||||
expect(stored(taskId).completedAt).toEqual(expect.any(String));
|
||||
});
|
||||
|
||||
it('a progress-only update leaves a finished task completedAt alone', async () => {
|
||||
const { taskId } = await call('task_create', { type: 'test', description: 'task' });
|
||||
await call('task_update', { taskId, status: 'failed' });
|
||||
const { completedAt } = stored(taskId);
|
||||
await call('task_update', { taskId, progress: 30 });
|
||||
expect(stored(taskId).completedAt).toBe(completedAt);
|
||||
});
|
||||
@@ -443,6 +443,11 @@ export const taskTools: MCPTool[] = [
|
||||
if (newStatus === 'in_progress' && !task.startedAt) {
|
||||
task.startedAt = new Date().toISOString();
|
||||
}
|
||||
// Reopening a finished task (completed/failed/cancelled -> pending/in_progress) makes it unfinished
|
||||
// again, so it must not keep reporting the completedAt of the run that was undone.
|
||||
if (newStatus === 'pending' || newStatus === 'in_progress') {
|
||||
task.completedAt = null;
|
||||
}
|
||||
// A finished task frees its workers, as task_complete and task_cancel do; otherwise a worker
|
||||
// whose task was finished through task_update stays `busy` forever, and a later task_complete
|
||||
// returns early because the status already reads completed.
|
||||
|
||||
Reference in new issue
Block a user