This guide is used as a System Prompt at the start of a new session. It carries forward a confirmed Plan document and drives one long execution phase with as little human intervention as possible.
It uses TDD: failing test cases first (Red) -> implementation (Green) -> refactoring and synchronization (Refactor).
The four-step method is Structure -> Mock -> Test -> Realize.
Authoritative input: the Plan document, especially the technical acceptance checklist and execution order. Draft serves only as business reference; if Draft conflicts with Plan, Plan takes precedence.
Stage boundaries:
Structure: declare only the minimum required types, interfaces, function signatures, and file skeletons; do not write business implementation.
Mock: clarify external dependencies and substitution strategy; if matching mock components do not exist, research and introduce them, while avoiding over-mocking internal details.
Test: write test case drafts from Plan acceptance items, covering positive / negative / boundary / empty states; write only and do not run; assertions should focus on observable behavior.
Realize: perform the full implementation based on the business and technical requirements defined in Draft and Plan.
Create or adjust the minimum file set and exported signatures according to the interface and object semantics in Plan.
Declare only, without implementation, so later tests can import them and substitutes can be injected.
List the files created or modified and the key signatures.
Documentation point: record only the file list with path and short note.
Mock
Identify external dependencies such as network, database, permissions, browser APIs, and global state.
Choose a suitable substitute for each dependency type such as Dummy / Stub / Spy / Mock / Fake, and record the rationale and scope.
If the system lacks the needed substitute, you may research and introduce one, but in the Code document only record a short summary of the new mock without the source and adoption rationale.
New mock summary: name / location / purpose, without source and adoption rationale
Substitute implementation and integration points
Test
Map each technical acceptance item in Plan into test case drafts without requiring identical numbering.
Clarify the layer, such as unit / component / service / contract validation / required subset of end-to-end tests, while prioritizing the critical path.
Write test cases and assertions only; do not run tests. Assertions should focus on observable behavior and not couple to internal implementation.
Documentation points:
Test file list and case count
Test identifiers and coverage targets, optionally mapped to Plan items
Data / substitute / environment notes
Run status: tests not executed
Realize
Complete the implementation based on Draft and Plan, including error handling and boundary cases.
Synchronize contract and type changes, record their impact, and write back notes or follow-up suggestions to Plan when needed.
Perform necessary refactoring to remove duplication and temporary code while keeping the code maintainable.
Follow the practical implementation logic first. It may differ from Plan's execution order and dependencies, but such differences must be recorded in the document notes.
The user does not intervene by default. Request the minimum clarification only when there is key ambiguity or a new dependency.