From b7691d0fe2182ce61504334667679e3bfd6c7f77 Mon Sep 17 00:00:00 2001 From: Rudy Celekli Date: Sun, 27 Sep 2026 10:24:08 -0400 Subject: [PATCH 1/2] fix(tasks): align CLI assignment and listing with persisted handlers --- .../task-create-assignment-parity.test.ts | 38 +++++++++++++++++++ v3/@claude-flow/cli/src/commands/task.ts | 11 +++--- 2 files changed, 44 insertions(+), 5 deletions(-) create mode 100644 v3/@claude-flow/cli/__tests__/task-create-assignment-parity.test.ts diff --git a/v3/@claude-flow/cli/__tests__/task-create-assignment-parity.test.ts b/v3/@claude-flow/cli/__tests__/task-create-assignment-parity.test.ts new file mode 100644 index 0000000000..e78e749d02 --- /dev/null +++ b/v3/@claude-flow/cli/__tests__/task-create-assignment-parity.test.ts @@ -0,0 +1,38 @@ +import { afterEach, describe, 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 })); +vi.mock('../src/mcp-client.js', async () => { + const { taskTools } = await import('../src/mcp-tools/task-tools.js'); + return { MCPClientError: class extends Error {}, callMCPTool: async (name: string, input: any) => taskTools.find(t => t.name === name)!.handler(input) }; +}); +import { taskCommand } from '../src/commands/task.js'; +afterEach(() => { if (state.cwd) rmSync(state.cwd, { recursive: true, force: true }); }); +describe('task create CLI/MCP assignment parity', () => { + it.each(['agent-one', 'agent-one, agent-two', ''])('persists --assign %s', async (assign) => { + state.cwd = mkdtempSync(join(tmpdir(), 'ruflo-task-create-')); + const action = taskCommand.subcommands!.find(c => c.name === 'create')!.action!; + const result = await action({ args: [], flags: { _: [], type: 'implementation', description: 'Implement feature', assign }, cwd: state.cwd, interactive: false }); + expect(result.success).toBe(true); + const store = JSON.parse(readFileSync(join(state.cwd, '.claude-flow/tasks/store.json'), 'utf8')); + expect(Object.values(store.tasks)).toEqual([expect.objectContaining({ assignedTo: assign.split(',').map(s => s.trim()).filter(Boolean) })]); + }); +}); + +import { taskTools } from '../src/mcp-tools/task-tools.js'; +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 => taskTools.find(t=>t.name===name)!.handler(input) as Promise; + const active=await call('task_create',{type:'test',description:'active',assignTo:['alice']}); + const done=await call('task_create',{type:'test',description:'done',assignTo:['bob']}); + await call('task_update',{taskId:active.taskId,status:'in_progress'}); + await call('task_complete',{taskId:done.taskId}); + const action=taskCommand.subcommands!.find(c=>c.name==='list')!.action!; + const list=async(flags:any)=>{ const r=await action({args:[],flags:{_:[],format:'json',...flags},cwd:state.cwd,interactive:false});return (r.data as any).tasks; }; + expect(await list({})).toEqual([expect.objectContaining({taskId:active.taskId})]); + expect(await list({status:'running'})).toHaveLength(1); + expect(await list({all:true})).toHaveLength(2); + expect(await list({all:true,agent:'bob'})).toEqual([expect.objectContaining({taskId:done.taskId})]); +}); diff --git a/v3/@claude-flow/cli/src/commands/task.ts b/v3/@claude-flow/cli/src/commands/task.ts index 2bf55c822f..4c231035cc 100644 --- a/v3/@claude-flow/cli/src/commands/task.ts +++ b/v3/@claude-flow/cli/src/commands/task.ts @@ -177,7 +177,7 @@ const createCommand: Command = { type: taskType, description, priority: priority || 'normal', - assignedTo: ctx.flags.assign ? [ctx.flags.assign] : undefined, + assignTo: ctx.flags.assign ? String(ctx.flags.assign).split(',').map(id => id.trim()).filter(Boolean) : undefined, parentId: ctx.flags.parent, dependencies, tags, @@ -271,13 +271,14 @@ const listCommand: Command = { } ], action: async (ctx: CommandContext): Promise => { - const status = ctx.flags.all ? 'all' : (ctx.flags.status as string) || 'pending,running'; + const requestedStatus = ctx.flags.all ? 'all' : (ctx.flags.status as string) || 'pending,in_progress'; + const status = requestedStatus === 'all' ? undefined : requestedStatus.replace(/\brunning\b/g, 'in_progress'); const limit = ctx.flags.limit as number; try { const result = await callMCPTool<{ tasks: Array<{ - id: string; + taskId: string; type: string; description: string; priority: string; @@ -291,7 +292,7 @@ const listCommand: Command = { status, type: ctx.flags.type, priority: ctx.flags.priority, - agentId: ctx.flags.agent, + assignedTo: ctx.flags.agent, limit, offset: 0 }); @@ -320,7 +321,7 @@ const listCommand: Command = { { key: 'progress', header: 'Progress', width: 10 } ], data: result.tasks.map(t => ({ - id: t.id, + id: t.taskId, type: t.type, description: t.description.length > 27 ? t.description.slice(0, 27) + '...' From b4f851fd4e4104c680903d3be595815d1d0e09c0 Mon Sep 17 00:00:00 2001 From: Rudy Celekli Date: Sun, 27 Sep 2026 10:56:52 -0400 Subject: [PATCH 2/2] test(memory): register one search mock factory per case --- .../__tests__/memory-search-scores-3327.test.ts | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/v3/@claude-flow/cli/__tests__/memory-search-scores-3327.test.ts b/v3/@claude-flow/cli/__tests__/memory-search-scores-3327.test.ts index cefc6ee3a3..a28894a49f 100644 --- a/v3/@claude-flow/cli/__tests__/memory-search-scores-3327.test.ts +++ b/v3/@claude-flow/cli/__tests__/memory-search-scores-3327.test.ts @@ -25,7 +25,11 @@ interface SearchResponse { smartFallback?: string; stats?: { variantCount: number; rawCandidateCount: number }; } +let memoryModuleFactory: () => object | Promise; async function search(input: Record): Promise { + // Register once per search: two queued doMock calls for this resolved ID + // can finish out of order while Vite resolves their module IDs. + vi.doMock('/@id/@claude-flow/memory', memoryModuleFactory); const { memoryTools } = await import('../src/mcp-tools/memory-tools.js'); return memoryTools.find(t => t.name === 'memory_search')!.handler(input) as Promise; } @@ -37,7 +41,7 @@ beforeEach(() => { // are faked; this exercises the real MCP handler and its response whitelist. // The CLI's externalize-optional-deps plugin rewrites this dynamic import // to /@id/...; mock that resolved ID so Vitest 4 intercepts the import. - vi.doMock('/@id/@claude-flow/memory', async () => import('../../memory/src/smart-retrieval.js')); + memoryModuleFactory = async () => import('../../memory/src/smart-retrieval.js'); }); afterEach(() => vi.restoreAllMocks()); @@ -108,10 +112,10 @@ describe('memory_search score contract (#3327 Finding B)', () => { }); it.each(['missing export', 'import failure'])('preserves standard fallback on %s', async (reason) => { - vi.doMock('/@id/@claude-flow/memory', () => { + memoryModuleFactory = () => { if (reason === 'import failure') throw new Error('unavailable package'); return { smartSearch: undefined }; - }); + }; searchEntries.mockResolvedValue({ success: true, results: [entry('a', 0.49)] }); const result = await search({ query: 'alpha', smart: true }); expect(result.results).toEqual([{ @@ -123,14 +127,14 @@ describe('memory_search score contract (#3327 Finding B)', () => { }); it('supplies rawScore to older SmartRetrieval implementations that preserve candidate fields', async () => { - vi.doMock('/@id/@claude-flow/memory', () => ({ + memoryModuleFactory = () => ({ // The existing return projection is {...candidate, score}. This fake // deliberately does not create rawScore: the MCP adapter must supply it. smartSearch: async (rawSearch: (request: RawSearchRequest) => Promise<{ results: object[] }>) => { const raw = await rawSearch({ query: 'alpha' }); return { results: raw.results.map(r => ({ ...r, score: 0.05 })), stats: {} }; }, - })); + }); searchEntries.mockResolvedValue({ success: true, results: [entry('a', 0)] }); const result = await search({ query: 'alpha', smart: true, threshold: 0 }); expect(result.results[0].similarity).toBe(0);