Use when the user asks to implement an approved SPEC SDD using test-driven development.
---
name: execute-specs
license: MIT
description: "Use when the user asks to implement an approved SPEC SDD using test-driven development."
metadata:
version: "1.4.0"
visibility: public
author: afonsoft
url: https://github.com/afonsoft/skills
---
# Execute TDD from SPEC
Test-driven development guided by the approved SPEC SDD. The SPEC is the single source of truth. Every test is derived from a numbered requirement or acceptance criterion.
Internal reasoning and commands are in English. All questions and explanations to the user are in **Portuguese (pt-BR)**.
## When to Use
- A `.specs/SPEC-{YYYYMMDD}-{feature}.md` exists with `Status: Approved`.
- The user asks to implement a feature, change, or bugfix.
- The user asks to execute or run a SPEC (e.g., "execute the spec", "run the spec", "run TDD from the spec").
- O usuário pede para executar ou rodar um SPEC (ex.: "executar o spec", "rodar o spec", "fazer TDD a partir do spec").
- Before writing implementation code.
## When NOT to Use
- Do not use when the SPEC is missing or still in `Draft`.
- Do not use when the user only wants a code review or fix without tests.
- Do not use when the SPEC explicitly declines a requirement (marked `[A DEFINIR]`).
## Core Principles
1. **The SPEC is the oracle.** Every test must map to a requirement or acceptance criterion.
2. **One vertical slice at a time.** One failing test, one passing test, one refactor.
3. **No speculative code.** Write only the minimum code to make the current test pass.
4. **No refactor in RED.** Refactor only when the suite is green.
5. **Re-validate after every change.** Run the full suite before moving to the next slice.
## Process
### 1. Read the SPEC
Load `.specs/SPEC-{YYYYMMDD}-{feature}.md` and identify:
- Section 4 — numbered requirements (`RF-001`, `RF-002`, ...).
- Section 6 — acceptance criteria in BDD `Given...when...then`.
- Section 7 — task plan and validation strategy.
- Section 3 — files to create or modify.
- Section 0 — the `Ticket` field: resolve the linked GitHub Issue number (e.g. `#123`) if present.
If the SPEC is not approved, stop and invoke `/write-specs`.
### 2. Slice the work
Order the work by the task plan (Section 7). Each slice is one requirement or one acceptance criterion. Never write all tests upfront.
When the first slice starts, set the SPEC `Status` to `In implementation` and sync the linked Issue to `in_progress` (see GitHub Issue Status Sync).
### 3. Red-Green-Refactor loop
For each slice:
```text
RED → Write one test that exercises a public seam and fails.
GREEN → Write the minimum code that passes the test.
REFACTOR → Clean duplication, improve names, respect SOLID while green.
```
### 4. Test at the public seam
Test behavior through public interfaces (API, function, component), not internal implementation. Tests must survive internal refactors. See [references/tests.md](references/tests.md) for examples and [references/mocking.md](references/mocking.md) for mock rules.
### 5. Mapping to the SPEC
For each test, include a comment or description pointing to the source requirement:
```python
# Covers RF-003: order total must include tax
# Covers AC-02: Given an empty cart, when checking out, then the system returns 422
```
### 6. Re-validate and report
After every slice:
1. Run the full test suite for the affected stack.
2. Run lint / type check.
3. Confirm the SPEC requirement is satisfied.
Report progress to the user in Portuguese and continue automatically to the next slice. Do not ask for approval between slices; the approved SPEC is the source of truth.
```text
Slice concluido: [RF-XXX / AC-YYY]
- Teste: [PASS/FAIL]
- Build: [PASS/FAIL]
- Lint: [PASS/FAIL]
Avançando para o proximo slice: [PROXIMO].
```
### 7. Closure
When all slices are green:
- Run the full suite (unit, integration, relevant E2E).
- Run the validation strategy from the SPEC (Section 7.1).
- Update `docs/qa/test-plan-<feature>.md` or equivalent if it exists.
- Sync the linked Issue to `in_review` (see GitHub Issue Status Sync).
- Invoke `/qa-analyst` for the mandatory pre-PR review.
- Do not open the PR until QA approves.
- When the PR opens, sync the Issue to `in_pullrequest`. When the PR merges and delivery is finalized, sync to `done`, set the SPEC `Status` to `Done`, and close the Issue if GitHub did not close it automatically.
## GitHub Issue Status Sync
When the SPEC's `Ticket` field points to a GitHub Issue, keep its status label in sync with execution, per the Label Contract in `create-issues`. Status labels are exclusive — always remove the previous one when applying the next. If `gh` is unavailable or the SPEC has no linked Issue, skip the sync and continue — never let label management block TDD.
| Moment | Action |
| --- | --- |
| Implementation starts (first slice) | Swap current status label → `in_progress`; set SPEC `Status: In implementation` |
| All slices green (before the QA gate) | Swap → `in_review` |
| PR opened | Swap → `in_pullrequest` |
| PR merged and delivery finalized | Swap → `done`; set SPEC `Status: Done`; close the Issue if still open |
| SPEC canceled at any point | Swap → `canceled` + pt-BR comment with the reason; set SPEC `Status: Canceled` |
**Blockers** — PR merge conflict, failing CI that cannot be resolved in the slice, missing dependency, unanswered question, or any other impediment: keep the current status label, add `blocked`, and post a pt-BR comment describing the blocker. When the blocker clears, remove `blocked` and comment the resolution.
```bash
# status transition (exclusive)
gh issue edit 123 --remove-label todo --add-label in_progress
# flag a blocker
gh issue edit 123 --add-label blocked
gh issue comment 123 --body "Bloqueio: conflito de merge no PR #45 em src/foo.ts. Aguardando resolução."
# blocker cleared
gh issue edit 123 --remove-label blocked
gh issue comment 123 --body "Bloqueio resolvido: conflito do PR #45 resolvido no merge com develop."
```
After flagging a blocker, report it to the user in Portuguese and pause that work item — do not mark the slice as done while `blocked`.
## Anti-Patterns
- ❌ Writing all tests before any implementation.
- ❌ Testing private methods or internal state.
- ❌ Mismatched expectations in mocks (see [references/mocking.md](references/mocking.md)).
- ❌ Refactoring while a test is red.
- ❌ Skipping the validation strategy from the SPEC.
## Common Mistakes
| Mistake | Fix |
| --- | --- |
| Implementing before the test | Write the failing test first. |
| The test does not map to the SPEC | Link every test to `RF-###` or `AC-###`. |
| Slice too large | Break the slice until one behavior is tested. |
| Not running the full suite after a green test | Re-validate before moving on. |
| Leaving the Issue status label stale | Sync the label at every transition (`in_progress` → `in_review` → `in_pullrequest` → `done`). |
| Hiding a blocker | Add `blocked` + a pt-BR comment on the Issue and report to the user; never silently stall. |
## References
- `write-specs` — for producing the SPEC SDD
- `qa-analyst` — for the mandatory pre-PR review
- `diagnose` — when a test fails unexpectedly and the cause is unclear
- `references/tests.md` — test examples and patterns
- `references/mocking.md` — mocking rules
- `references/refactoring.md` — refactoring guidance
- `references/deep-modules.md` — deep module design
- `references/interface-design.md` — interface design patterns
don't have the plugin yet? install it then click "run inline in claude" again.
extracted original procedure into numbered steps with explicit inputs/outputs, clarified decision logic (spec validation, github issue sync optionality, blocker handling), documented all inputs including git/github-cli, added edge cases (gh unavailable, oversized slices, unlinked tests), preserved author attribution and portuguese user interactions.
---
name: execute-specs
slug: execute-specs
license: MIT
description: "implement an approved spec sdd using test-driven development"
metadata:
version: "1.4.0"
visibility: public
author: afonsoft
source: https://github.com/afonsoft/skills
credits: "original author afonsoft"
---
## intent
execute a feature, bugfix, or change by running test-driven development guided by an approved SPEC SDD. the spec is the single source of truth. every test derives from a numbered requirement (RF-###) or acceptance criterion (AC-###). use this skill when a `.specs/SPEC-{YYYYMMDD}-{feature}.md` file exists with `Status: Approved` and the user asks to implement, execute, or run the spec. all internal reasoning is in english. all user-facing questions and reports are in portuguese (pt-BR).
## inputs
- **SPEC file**: `.specs/SPEC-{YYYYMMDD}-{feature}.md` with `Status: Approved`. must contain sections for requirements (RF-###), acceptance criteria (AC-###), files to modify, and task plan.
- **GitHub Issue (optional)**: if the SPEC's `Ticket` field links to an issue (e.g., `#123`), you can sync status labels via the `gh` CLI.
- **Test framework**: unit test framework appropriate to the codebase (pytest, jest, vitest, golang testing, etc.).
- **Lint / type checker**: eslint, mypy, go fmt, or equivalent for the target stack.
- **git**: access to the repository to read the SPEC, create branches, and commit.
- **GitHub CLI (optional)**: `gh` command-line tool for issue label syncing. if unavailable, skip label syncing and continue; never let it block TDD.
## procedure
1. **read and validate the spec**
- load `.specs/SPEC-{YYYYMMDD}-{feature}.md`.
- confirm `Status: Approved`. if `Status: Draft` or missing, stop and invoke `/write-specs`.
- extract section 4 (numbered requirements RF-001, RF-002, ...).
- extract section 6 (acceptance criteria in BDD `Given...when...then` format).
- extract section 7 (task plan and validation strategy).
- extract section 3 (list of files to create or modify).
- note the `Ticket` field if present (github issue number).
- output: validated spec document with sections indexed.
2. **order work by task plan**
- follow the task plan from SPEC section 7.
- slice work into one requirement or one acceptance criterion per slice.
- never write all tests upfront; build one vertical slice at a time.
- output: ordered list of slices (RF-### or AC-### identifiers).
3. **begin implementation and sync github issue (if applicable)**
- when the first slice starts, update the SPEC file: set `Status: In implementation`.
- if the SPEC's `Ticket` field references a github issue, run `gh issue edit <number> --remove-label <old-status> --add-label in_progress`.
- output: SPEC file updated locally and github issue synced (or skipped if no issue or gh unavailable).
4. **red-green-refactor loop for each slice**
**red phase**:
- write one test that exercises a public seam (api endpoint, function, component interface, not internal state) and fails.
- include a comment linking the test to the SPEC: `# covers RF-003: order total must include tax` or `# covers AC-02: given an empty cart, when checking out, then 422`.
- run the test suite. confirm the test fails and no other tests regress.
- output: failing test file and test run report showing red status.
**green phase**:
- write the minimum code to make the test pass. do not speculate. do not refactor yet.
- run the test suite. confirm the new test passes and no existing tests regress.
- output: implementation code and passing test run report.
**refactor phase**:
- only refactor while the suite is green. remove duplication, improve names, apply solid principles.
- run the test suite. confirm all tests still pass.
- run lint and type checker. fix any warnings.
- output: refactored code and clean lint/type-check report.
5. **re-validate after every slice**
- run the full test suite for the affected stack (unit, integration, relevant e2e).
- run lint and type checker.
- confirm the SPEC requirement or acceptance criterion is satisfied.
- output: test run report (all green), lint report (clean), and verification note.
6. **report progress to user in portuguese**
- after each slice completes, post a report:
Slice concluido: [RF-XXX / AC-YYY]
Avançando para o proximo slice: [PROXIMO].
- do not ask for approval between slices. the approved spec is the source of truth. continue automatically.
- output: user-facing progress report in pt-BR.
7. **repeat steps 4-6 until all slices are green**
- output: all slices completed with passing tests and clean builds.
8. **final validation and qa gate**
- run the full test suite (unit, integration, e2e as applicable).
- execute the validation strategy from SPEC section 7.1.
- update or create `docs/qa/test-plan-<feature>.md` if it exists.
- sync github issue to `in_review` via `gh issue edit <number> --remove-label in_progress --add-label in_review`.
- invoke `/qa-analyst` for the mandatory pre-pr review. do not open a pr until qa approves.
- output: full test suite report (green), validation strategy report, and qa invocation.
9. **merge and close**
- when qa approves, open the pull request.
- sync github issue to `in_pullrequest` via `gh issue edit <number> --remove-label in_review --add-label in_pullrequest`.
- when the pr merges and delivery is finalized:
- sync github issue to `done` via `gh issue edit <number> --remove-label in_pullrequest --add-label done`.
- close the github issue if it is still open: `gh issue close <number>`.
- update the SPEC file: set `Status: Done`.
- output: merged pr, closed github issue, and updated spec file.
## decision points
- **if the spec is not approved** (Status is Draft or missing), stop immediately and invoke `/write-specs`. do not proceed.
- **if the spec has no linked github issue**, skip all label syncing and continue. github issue tracking is optional. never let missing or unavailable gh cli block tdd.
- **if gh cli is unavailable**, skip label syncing. log the reason (gh not installed, auth failed, network timeout) and continue. the spec is the source of truth; labels are a convenience.
- **if a test fails unexpectedly and the root cause is unclear**, invoke `/diagnose` to investigate. do not guess. do not skip the failing test.
- **if a blocker arises** (merge conflict, failing ci that cannot be resolved in the slice, missing dependency, unanswered question), do the following:
- keep the current github issue status label (do not advance to the next status).
- add the `blocked` label via `gh issue edit <number> --add-label blocked`.
- post a pt-BR comment describing the blocker: `gh issue comment <number> --body "Bloqueio: descricao do problema. Aguardando resolucao."`.
- report the blocker to the user in pt-BR and pause that work item. do not mark the slice as done.
- when the blocker clears, remove the `blocked` label: `gh issue edit <number> --remove-label blocked`.
- post a pt-BR comment describing the resolution: `gh issue comment <number> --body "Bloqueio resolvido: descricao da resolucao."`.
- resume tdd.
- **if the slice is too large** (more than one behavior per test), break it down. one test per public seam interaction.
- **if a test does not map to a spec requirement**, reject it. every test must link to `RF-###` or `AC-###` in a comment.
## output contract
success means:
- all tests in the affected stack pass (unit, integration, e2e).
- lint and type checker output is clean.
- every test includes a comment linking it to `RF-###` or `AC-###`.
- the SPEC file is updated: `Status: Done`.
- the linked github issue (if present) is labeled `done` and closed.
- the pr is merged into the target branch.
- a final report is posted to the user in pt-BR confirming delivery.
test files are co-located with implementation or in a standard `tests/` or `__tests__/` directory. commit messages reference the RF-### and AC-### identifiers: "feat: implement RF-003 and AC-02".
## outcome signal
the user knows the skill worked when:
- all slices report green (test, build, lint).
- the final report in pt-BR confirms all requirements and acceptance criteria are satisfied.
- the linked github issue (if present) is labeled `done` and closed.
- the pr is merged and visible in the main branch history.
- the SPEC file shows `Status: Done`.
- the user can run the test suite locally and see all tests pass.