| name | Playbook: Debug Failing Unit Test |
|---|---|
| description | A playbook that uses root-cause-analysis to diagnose a failing test report from Vitest and propose a minimal, correct fix. |
| tier | execution |
| schema | procedure |
| layer |
Given the source code of a failing test and the full error output from the Vitest runner, you MUST perform a root cause analysis and propose a single, minimal code change that resolves the failure.
- Ingest and State the Problem:
a. State the name of the failing test (
describeanditblock names). b. State the exact error message provided by Vitest (e.g., theExpectedvs.Receiveddiff). - Analyze the Failure:
a. Examine the error message. If it is an assertion failure (
expectfailed), identify the specific mismatch between the expected and actual values. b. If it is a runtime error (e.g.,TypeError: Cannot read properties of undefined), identify the line number and the variable that caused the error. - Apply Root Cause Analysis: Follow the
foundation/problem-solving/root-cause-analysisprocedure. a. Start with the symptom from the previous step. b. Trace the causality backward from the assertion or runtime error into the function's execution path. c. Formulate a hypothesis: Is the test's expectation incorrect, or is the source code's logic flawed? - Formulate a Solution:
a. If the source code is flawed: Propose a specific, minimal change to the source code logic to correct the behavior.
b. If the test is flawed: Propose a specific, minimal change to the test's
Arrangestep (e.g., incorrect mock setup) orAssertstep (e.g., incorrect expectation). - Provide Justification: Generate a concise, one-to-two sentence explanation of why the proposed change fixes the identified root cause.
- You MUST propose only one logical change. Do not suggest multiple alternative fixes.
- The proposed fix MUST be the minimum change required. Do not include unrelated refactoring.
- Do NOT propose changing a test's expectation to match a buggy output unless the original expectation was demonstrably incorrect based on the feature's requirements.