{"record":{"id":"fdc0415124a853a2","repo":"ruvnet/ruflo","slug":"task-taskid-not-found-fdc041","errorCode":null,"errorMessage":"Task ${taskId} not found","messagePattern":"Task (.+?) not found","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"v3/@claude-flow/testing/src/helpers/mock-factory.ts","lineNumber":342,"sourceCode":"\n  mock.create.mockImplementation(async (definition: TaskDefinition) => {\n    const task: Task = {\n      id: `task-${++taskCounter}`,\n      name: definition.name,\n      type: definition.type,\n      status: 'pending',\n      payload: definition.payload,\n      priority: definition.priority ?? 50,\n      createdAt: new Date(),\n    };\n    tasks.set(task.id, task);\n    return task;\n  });\n\n  mock.execute.mockImplementation(async (taskId: string) => {\n    const task = tasks.get(taskId);\n    if (!task) {\n      throw new Error(`Task ${taskId} not found`);\n    }\n    task.status = 'running';\n    task.startedAt = new Date();\n\n    // Simulate execution\n    await new Promise(resolve => setTimeout(resolve, 10));\n\n    task.status = 'completed';\n    task.completedAt = new Date();\n\n    return {\n      taskId,\n      success: true,\n      duration: task.completedAt.getTime() - task.startedAt.getTime(),\n    };\n  });\n\n  mock.cancel.mockImplementation(async (taskId: string) => {","sourceCodeStart":324,"sourceCodeEnd":360,"githubUrl":"https://github.com/ruvnet/ruflo/blob/fa13ee4ad60ac2090b1480656eb233521790d640/v3/@claude-flow/testing/src/helpers/mock-factory.ts#L324-L360","documentation":"This comes from the mock task repository built by the testing mock-factory: execute(taskId) looks the id up in the mock in-memory tasks map, which is populated only by the same mock submit/create calls, and throws for unknown ids. It faithfully mimics a real repository not-found behavior.","triggerScenarios":"Calling mock.execute('task_999') without first calling the mock submit or create for that id; mixing ids from a real repository or another mock instance; a test deleting from the map and then executing.","commonSituations":"Hardcoded task ids reused across tests while the mock is reset in beforeEach; passing a task definition where the id is expected; assuming the mock accepts any id.","solutions":["Create the task through the mock first and use the id it returns","Derive ids from the created task object rather than literals","When testing the error path intentionally, wrap the call in a rejects assertion"],"exampleFix":"// before\nawait mock.execute('task_1'); // throws: never created on this mock\n\n// after\nconst task = await mock.submit(definition);\nawait mock.execute(task.id);","handlingStrategy":"validation","validationCode":"// Track ids you created on the mock\nconst createdIds = new Set<string>();\nasync function submitAndTrack(def: TaskDefinitionInput) {\n  const t = await mock.submit(def);\n  createdIds.add(t.id);\n  return t;\n}\n\nif (!createdIds.has(taskId)) {\n  throw new Error(`Unknown mock task ${taskId}; create it with mock.submit first`);\n}\nawait mock.execute(taskId);","typeGuard":"function isKnownMockTask(taskId: string, created: Set<string>): taskId is string {\n  return created.has(taskId);\n}","tryCatchPattern":"try {\n  await mock.execute(taskId);\n} catch (err) {\n  if (err instanceof Error && err.message.endsWith('not found')) {\n    const task = await mock.submit(definition); // recreate on this mock, then run\n    return mock.execute(task.id);\n  }\n  throw err;\n}","preventionTips":["Never hardcode mock task ids; always chain from the submit return value","Re-create mock state in beforeEach rather than relying on cross-test ordering","Assert intended failures with a rejects-toThrow assertion on the not-found message"],"tags":["testing","mocks","task-repository","not-found"],"backgroundTag":"entity-not-found","analyzedSha":"fa13ee4ad60ac2090b1480656eb233521790d640","analyzedAt":"2026-08-18T21:34:22.708Z","contentChangedAt":"2026-08-18T21:34:22.708Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}