The TDD (Test-Driven Development) blueprint is Magpie’s structured workflow for implementing new features, refactors, and integrations. It enforces a disciplined cycle:
Plan the implementation
Write tests that define expected behavior
Verify tests fail (red phase)
Implement the feature to make tests pass
Verify tests pass (green phase)
Lint for code quality
The TDD blueprint is selected automatically when Magpie classifies a task as Standard complexity.
The agent reads the repo tree and chat history, then creates a brief implementation plan:
Step { name: "plan".to_string(), kind: StepKind::Agent( AgentStep::new(format!( "You are planning how to implement a task. The file tree of the repository \ is provided as previous step output.\n\n\ Task: {}\n\n\ Create a brief plan:\n\ 1. Which files to modify or create\n\ 2. What tests to write (test names and what they verify)\n\ 3. Implementation approach (key functions/types to add or change)\n\n\ Be concise — this plan guides the next steps.", trigger.message )) .with_last_output() .with_context_from_metadata("chat_history"), ), condition: Condition::Always, continue_on_error: false,}
From crates/magpie-core/src/pipeline.rs:400-418Key details:
.with_last_output() injects the file tree from step 1
The agent writes test code ONLY based on the plan:
Step { name: "write-tests".to_string(), kind: StepKind::Agent( AgentStep::new(format!( "Based on the plan from the previous step, write ONLY test code.\n\n\ Task: {}\n\n\ Rules:\n\ - Write test functions that verify the expected behavior\n\ - Do NOT implement the actual feature yet\n\ - Tests should fail when run (the implementation doesn't exist yet)\n\ - Use the project's existing test patterns and framework\n\ - Include both happy-path and edge-case tests", trigger.message )) .with_last_output() .with_context_from_metadata("chat_history"), ), condition: Condition::Always, continue_on_error: false,}
From crates/magpie-core/src/pipeline.rs:434-452Why this matters: By writing tests first, we define the API contract before implementation. This prevents scope creep and ensures testability.
From crates/magpie-core/src/pipeline.rs:456-461Key:continue_on_error: true allows the blueprint to proceed even when tests fail. This is the red phase — we want failures here.Example output:
test auth_test::test_oauth2_token_exchange ... FAILEDtest auth_test::test_invalid_credentials ... FAILEDerror[E0433]: failed to resolve: use of undeclared type `OAuth2Client`
The agent receives the test failure output and implements the feature:
Step { name: "implement".to_string(), kind: StepKind::Agent( AgentStep::new(format!( "The tests from the previous step have been run. The output (including any \ failures or compilation errors) is provided as previous step output.\n\n\ Task: {}\n\n\ Now write the implementation to make all tests pass.\n\ - Fix any compilation errors in the tests if needed\n\ - Implement the actual feature/change\n\ - Make sure all tests pass", trigger.message )) .with_last_output() .with_context_from_metadata("chat_history"), ), condition: Condition::Always, continue_on_error: false,}
From crates/magpie-core/src/pipeline.rs:476-493The agent now:
Reads the test failure messages
Implements the minimum code to make tests pass
Fixes any compilation errors in the tests themselves
From crates/magpie-core/src/pipeline.rs:497-502Why continue_on_error: true? Even if tests fail, we want to proceed to lint and then enter the CI retry loop (see below).
Test Failures in Step 6If run-tests fails after implementation, the CI loop will retry. But if the agent keeps making the same mistake, you’ll hit max_ci_rounds and get a PartialSuccess status.Fix: Increase max_ci_rounds or provide more context in your task message.
Planning Step is CriticalIf the plan is vague or wrong, the entire flow suffers. Review the plan output in agent traces (trace_dir) to debug.