Files

3.3 KiB

Tests must be written before implementation — write failing tests, see them fail (Red), implement, see pass (Green)

  1. Write Failing Tests (Red Phase):

    • Pre-Delegation Checkpoint: Before spawning a worker for dangerous or non-trivial changes, ensure your current progress is staged (git add .) or committed. This prevents losing iterations if a sub-agent incorrectly uses git restore.
    • Zero-Assertion Ban: You MUST NOT write tests that contain only pass or lack meaningful assertions. A test is only valid if it contains assertions that explicitly test the behavioral change and verify the failure condition.
    • Code Style: ALWAYS explicitly mention "Use exactly 1-space indentation for Python code" when prompting a sub-agent.
    • Delegate Test Creation: Do NOT write test code directly. Spawn a Tier 3 Worker via the OpenCode Task tool with subagent_type: "tier3-worker" and a surgical prompt specifying WHERE (file:line range), WHAT (test to create), HOW (which assertions/fixtures to use), and SAFETY (thread constraints if applicable). Example: "Write tests in tests/test_cost_tracker.py for cost_tracker.py:estimate_cost(). Test all model patterns in MODEL_PRICING dict. Assert unknown model returns 0. Use 1-space indentation." (If repeating due to failures, set the subagent's failure_count higher to switch to a more capable model.) Note: the legacy python scripts/mma_exec.py --role tier3-worker invocation is DEPRECATED (see §"Conductor Token Firewalling" below); use the OpenCode Task tool instead.
    • Take the code generated by the Worker and apply it.
    • CRITICAL: Run the tests and confirm that they fail as expected. This is the "Red" phase of TDD. Do not proceed until you have failing tests.
  2. Implement to Pass Tests (Green Phase):

    • Pre-Delegation Checkpoint: Ensure current progress is staged or committed before delegating.
    • Code Style: ALWAYS explicitly mention "Use exactly 1-space indentation for Python code" when prompting a sub-agent.
    • Delegate Implementation: Do NOT write the implementation code directly. Spawn a Tier 3 Worker via the OpenCode Task tool (subagent_type: "tier3-worker") with a surgical prompt specifying WHERE (file:line range to modify), WHAT (the specific change), HOW (which API calls, data structures, or patterns to use), and SAFETY (thread-safety constraints). Example: "In gui_2.py _render_mma_dashboard (lines 2685-2699), extend the token usage table from 3 to 5 columns by adding 'Model' and 'Est. Cost'. Use imgui.table_setup_column(). Import cost_tracker. Call cost_tracker.estimate_cost(model, input_tokens, output_tokens). Use 1-space indentation." (If repeating due to failures, set failure_count higher to switch to a more capable model.) Note: the legacy python scripts/mma_exec.py --role tier3-worker invocation is DEPRECATED; use the OpenCode Task tool.
    • Take the code generated by the Worker and apply it.
    • Run the test suite again and confirm that all tests now pass. This is the "Green" phase.
  3. Refactor (Optional but Recommended):

    • With the safety of passing tests, refactor the implementation code and the test code to improve clarity, remove duplication, and enhance performance without changing the external behavior.
    • Rerun tests to ensure they still pass after refactoring.