{"id":"5969ce8c713955de","repo":"vitest-dev/vitest","slug":"test-specification-for-task-id-was-not-found","errorCode":null,"errorMessage":"Test specification for task ${id} was not found","messagePattern":"Test specification for task (.+?) was not found","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/vitest/src/node/core.ts","lineNumber":1286,"sourceCode":"      this.report('onWatcherRerun', files, trigger),\n      ...this._onUserTestsRerun.map(fn => fn(specifications)),\n    ])\n    const testResult = await this.runFiles(specifications, allTestsRun)\n\n    await this.report('onWatcherStart', this.state.getFiles(files))\n    return testResult\n  }\n\n  /** @internal */\n  async rerunTask(id: string): Promise<void> {\n    const task = this.state.idMap.get(id)\n    if (!task) {\n      throw new Error(`Task ${id} was not found`)\n    }\n\n    const reportedTask = this.state.getReportedEntityById(id)\n    if (!reportedTask) {\n      throw new Error(`Test specification for task ${id} was not found`)\n    }\n\n    const specifications = [reportedTask.toTestSpecification()]\n    await Promise.all([\n      this.report(\n        'onWatcherRerun',\n        [task.file.filepath],\n        'tasks' in task ? 'rerun suite' : 'rerun test',\n      ),\n      ...this._onUserTestsRerun.map(fn => fn(specifications)),\n    ])\n    await this.runFiles(specifications, false)\n    await this.report(\n      'onWatcherStart',\n      ['module' in reportedTask ? reportedTask.module.task : reportedTask.task],\n    )\n  }\n","sourceCodeStart":1268,"sourceCodeEnd":1304,"githubUrl":"https://github.com/vitest-dev/vitest/blob/d568f8ce3739b532d5bf2c1ee1e45e8a8a473d09/packages/vitest/src/node/core.ts#L1268-L1304","documentation":"rerunTask(id) (core.ts:1286) finds the task in idMap but state.getReportedEntityById(id) then returns null, meaning the task cannot be converted into a TestSpecification. The entity exists in the flat id map but isn't a runnable reported entity (e.g. a container/suite node without a usable spec).","triggerScenarios":"Rerunning an id that resolves to a non-test entity, or a state desync where the reported-entity map wasn't rebuilt for that id.","commonSituations":"Internal state desync after partial file reloads; rerunning a suite/container id that has no direct TestSpecification; custom watcher integrations passing non-leaf ids.","solutions":["Rerun at the file level (rerunFiles) instead of an arbitrary task id.","Rebuild state (re-discover files) before rerunning.","Filter ids to leaf test entities obtained from getReportedEntityById."],"exampleFix":"// before\nawait vitest.rerunTask(suiteId) // suite has no spec\n\n// after\nawait vitest.rerunFiles([task.file.filepath])","handlingStrategy":"validation","validationCode":"const entity = vitest.state.getReportedEntityById(id)\nif (!entity || typeof entity.toTestSpecification !== 'function') {\n  throw new Error(`No runnable spec for task ${id}; rerun at file level`)\n}\nawait vitest.rerunTask(id)","typeGuard":"function isRunnableEntity(entity: any): boolean {\n  return entity != null && typeof entity.toTestSpecification === 'function'\n}","tryCatchPattern":null,"preventionTips":["Rerun at file granularity (rerunFiles) instead of arbitrary task ids.","Filter ids to leaf entities returned by getReportedEntityById.","Rebuild state after structural file changes before rerunning."],"tags":["watch","tasks","internal","state"],"analyzedSha":"d568f8ce3739b532d5bf2c1ee1e45e8a8a473d09","analyzedAt":"2026-08-03T20:23:56.861Z","schemaVersion":2}