{"record":{"id":"47708c04c8af4ace","repo":"eyaltoledano/claude-task-master","slug":"test-results-required-for-red-phase-transition","errorCode":null,"errorMessage":"Test results required for RED phase transition","messagePattern":"Test results required for RED phase transition","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/tm-core/src/modules/workflow/orchestrators/workflow-orchestrator.ts","lineNumber":165,"sourceCode":"\t}\n\n\t/**\n\t * Handle TDD phase transitions (RED -> GREEN -> COMMIT)\n\t */\n\tprivate async handleTDDPhaseTransition(event: WorkflowEvent): Promise<void> {\n\t\tconst currentTDD = this.context.currentTDDPhase || 'RED';\n\n\t\tswitch (event.type) {\n\t\t\tcase 'RED_PHASE_COMPLETE':\n\t\t\t\tif (currentTDD !== 'RED') {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t'Invalid transition: RED_PHASE_COMPLETE from non-RED phase'\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\t// Validate test results are provided\n\t\t\t\tif (!event.testResults) {\n\t\t\t\t\tthrow new Error('Test results required for RED phase transition');\n\t\t\t\t}\n\n\t\t\t\t// Store test results in context\n\t\t\t\tthis.context.lastTestResults = event.testResults;\n\n\t\t\t\t// Special case: All tests passing in RED phase means feature already implemented\n\t\t\t\tif (event.testResults.failed === 0) {\n\t\t\t\t\tthis.emit('tdd:red:completed');\n\t\t\t\t\tthis.emit('tdd:feature-already-implemented', {\n\t\t\t\t\t\tsubtaskId: this.getCurrentSubtaskId(),\n\t\t\t\t\t\ttestResults: event.testResults\n\t\t\t\t\t});\n\n\t\t\t\t\t// Mark subtask as complete and move to next one\n\t\t\t\t\tconst subtask =\n\t\t\t\t\t\tthis.context.subtasks[this.context.currentSubtaskIndex];\n\t\t\t\t\tif (subtask) {\n\t\t\t\t\t\tsubtask.status = 'completed';","sourceCodeStart":147,"sourceCodeEnd":183,"githubUrl":"https://github.com/eyaltoledano/claude-task-master/blob/c0c98d367c55296bfe69e65680625b6db437af02/packages/tm-core/src/modules/workflow/orchestrators/workflow-orchestrator.ts#L147-L183","documentation":"A RED_PHASE_COMPLETE event signals the end of the RED (write failing tests) phase, so the orchestrator requires the event to carry testResults proving the tests ran. Dispatching RED_PHASE_COMPLETE without testResults throws this error — the transition cannot proceed without evidence.","triggerScenarios":"transition({ type: 'RED_PHASE_COMPLETE' }) with testResults undefined or omitted while currentTDDPhase is RED, e.g. signaling phase completion before the test suite has executed.","commonSituations":"Hooking phase advancement to file-save instead of test-run completion; a test runner that crashed and produced no results object; calling the transition manually in scripts without constructing the full event payload.","solutions":["Always attach testResults to the RED_PHASE_COMPLETE event: { type: 'RED_PHASE_COMPLETE', testResults: results }.","Ensure the test suite actually runs and returns a results object before signaling completion.","If the runner failed, dispatch the ERROR event instead of faking a RED completion.","Add a pre-dispatch check: if (!event.testResults) run the suite first."],"exampleFix":"// before\nawait orchestrator.transition({ type: 'RED_PHASE_COMPLETE' });\n// after\nconst results = await runTests();\nawait orchestrator.transition({ type: 'RED_PHASE_COMPLETE', testResults: results });","handlingStrategy":"validation","validationCode":"function assertTestResults(event) {\n  if (event.type === 'RED_PHASE_COMPLETE' && !event.testResults) {\n    throw new TypeError('RED_PHASE_COMPLETE requires testResults');\n  }\n}\nassertTestResults(event);\nawait orchestrator.transition(event);","typeGuard":"function hasTestResults(e) {\n  return e.type !== 'RED_PHASE_COMPLETE'\n    || (typeof e.testResults === 'object' && e.testResults !== null);\n}","tryCatchPattern":"try {\n  await orchestrator.transition(event);\n} catch (e) {\n  if (e.message === 'Test results required for RED phase transition') {\n    const results = await runTests();\n    await orchestrator.transition({ ...event, testResults: results });\n  } else throw e;\n}","preventionTips":["Always build RED_PHASE_COMPLETE events with testResults from a real test run","Advance phases from test-runner completion hooks, not file-save events","On runner failure, dispatch ERROR rather than an empty completion","Add a payload validator for all WorkflowEvent types at dispatch boundaries"],"tags":["tdd","validation","workflow"],"backgroundTag":"missing-required-payload","analyzedSha":"c0c98d367c55296bfe69e65680625b6db437af02","analyzedAt":"2026-08-29T02:56:26.071Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}