mirror of
https://github.com/ruvnet/ruflo.git
synced 2026-12-04 22:41:40 +09:00
fix(cli): count cancelled tasks in task_summary so the counts add up to total (#4489)
This commit is contained in:
1 parent
d6816a4d6f
commit
99d5410b49
3 files changed
+63
-1
No files matched your search
@@ -0,0 +1,58 @@
|
||||
/**
|
||||
* task_summary counted cancelled tasks in `total` but had no field for them,
|
||||
* so the per-status counts (and the `status` Tasks table) did not add up.
|
||||
*/
|
||||
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
|
||||
import { mkdtempSync, rmSync } from 'node:fs';
|
||||
import { tmpdir } from 'node:os';
|
||||
import { join } from 'node:path';
|
||||
import { taskTools } from '../src/mcp-tools/task-tools.js';
|
||||
import { systemTools } from '../src/mcp-tools/system-tools.js';
|
||||
|
||||
const tool = (name: string) => {
|
||||
const t = [...taskTools, ...systemTools].find(t => t.name === name);
|
||||
if (!t) throw new Error(`MCP tool not registered: ${name}`);
|
||||
return t;
|
||||
};
|
||||
|
||||
type Summary = {
|
||||
total: number;
|
||||
pending: number;
|
||||
running: number;
|
||||
completed: number;
|
||||
failed: number;
|
||||
cancelled: number;
|
||||
};
|
||||
|
||||
describe('task_summary', () => {
|
||||
let dir: string;
|
||||
let prevCwd: string | undefined;
|
||||
|
||||
beforeEach(() => {
|
||||
dir = mkdtempSync(join(tmpdir(), 'ruflo-task-summary-'));
|
||||
prevCwd = process.env.CLAUDE_FLOW_CWD;
|
||||
process.env.CLAUDE_FLOW_CWD = dir;
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
if (prevCwd === undefined) delete process.env.CLAUDE_FLOW_CWD;
|
||||
else process.env.CLAUDE_FLOW_CWD = prevCwd;
|
||||
rmSync(dir, { recursive: true, force: true });
|
||||
});
|
||||
|
||||
const create = async () =>
|
||||
(await tool('task_create').handler({ type: 'feature', description: 'work' }) as { taskId: string }).taskId;
|
||||
|
||||
it('counts cancelled tasks so the per-status counts add up to total', async () => {
|
||||
await create();
|
||||
const cancelled = await create();
|
||||
const completed = await create();
|
||||
await tool('task_cancel').handler({ taskId: cancelled });
|
||||
await tool('task_complete').handler({ taskId: completed, result: {} });
|
||||
|
||||
const summary = await tool('task_summary').handler({}) as Summary;
|
||||
expect(summary).toMatchObject({ total: 3, pending: 1, completed: 1, cancelled: 1 });
|
||||
const { total, ...byStatus } = summary;
|
||||
expect(Object.values(byStatus).reduce((a, b) => a + b, 0)).toBe(total);
|
||||
});
|
||||
});
|
||||
@@ -121,6 +121,7 @@ async function getSystemStatus(): Promise<{
|
||||
running: number;
|
||||
completed: number;
|
||||
failed: number;
|
||||
cancelled: number;
|
||||
};
|
||||
performance: {
|
||||
cpuUsage: number;
|
||||
@@ -167,6 +168,7 @@ async function getSystemStatus(): Promise<{
|
||||
running: number;
|
||||
completed: number;
|
||||
failed: number;
|
||||
cancelled: number;
|
||||
}>('task_summary', {});
|
||||
|
||||
return {
|
||||
@@ -220,7 +222,7 @@ async function getSystemStatus(): Promise<{
|
||||
backend: 'none',
|
||||
performance: { searchTime: 0, cacheHitRate: 0 }
|
||||
},
|
||||
tasks: { total: 0, pending: 0, running: 0, completed: 0, failed: 0 },
|
||||
tasks: { total: 0, pending: 0, running: 0, completed: 0, failed: 0, cancelled: 0 },
|
||||
performance: {
|
||||
cpuUsage: 0,
|
||||
memoryUsage: 0,
|
||||
@@ -289,6 +291,7 @@ function displayStatus(status: Awaited<ReturnType<typeof getSystemStatus>>): voi
|
||||
{ status: 'Running', count: status.tasks.running },
|
||||
{ status: 'Completed', count: status.tasks.completed },
|
||||
{ status: 'Failed', count: status.tasks.failed },
|
||||
{ status: 'Cancelled', count: status.tasks.cancelled },
|
||||
{ status: output.bold('Total'), count: status.tasks.total }
|
||||
]
|
||||
});
|
||||
|
||||
@@ -665,6 +665,7 @@ export const systemTools: MCPTool[] = [
|
||||
running: tasks.filter(t => t.status === 'in_progress').length,
|
||||
completed: tasks.filter(t => t.status === 'completed').length,
|
||||
failed: tasks.filter(t => t.status === 'failed').length,
|
||||
cancelled: tasks.filter(t => t.status === 'cancelled').length,
|
||||
};
|
||||
},
|
||||
},
|
||||
|
||||
Reference in new issue
Block a user