Deliver behavior changes, bug fixes, refactors, and feature work in any project with tests or explicit validation. Use when changing application behavior, updating existing tests, writing tests, reviewing missing coverage, choosing between automated and manual validation, or documenting testing gaps across backend, frontend, CLI, and database migrations.
التثبيت
التثبيت باستخدام Codex أو Claude انسخ هذا Prompt والصقه في Codex أو Claude أو مساعد آخر ليراجع صفحة Skill ويثبّتها لك.
Deliver behavior changes, bug fixes, refactors, and feature work in any project with tests or explicit validation. Use when changing application behavior, updating existing tests, writing tests, reviewing missing coverage, choosing between automated and manual validation, or documenting testing gaps across backend, frontend, CLI, and database migrations.
Test-First Delivery
Use this skill whenever a task changes application behavior, fixes a bug, or refactors existing structures.
1. Default Quality Contract
Unless explicitly directed otherwise:
Never Stop at Code Changes Alone: Every behavior-changing task is incomplete without verification.
Follow Test-First (TDD) cycle where practical: write or update failing tests before writing minimal code to make them pass.
Leave Touched Code Easy to Understand: Enforce JSDoc/docstrings on all touched functions, methods, and constructors. Include focused inline comments near complex or non-obvious logic.
Target 100% Coverage for Validated Scope: Run test suites with coverage, fixing failures and gaps iteratively.
State What Was Verified: Conclude with a clear report detailing the automated tests run, manual validation performed, and any remaining gaps.
2. The TDD Workflow (Red-Green-Refactor)
For new features or bug fixes, apply the three-phase loop:
Phase A: Red (Failing Test)
Write a failing test that defines the desired behavior or reproduces the reported bug.
Verify the test fails with a clear, expected error message before writing any application code.
Example:
describe('Feature: User password reset', () => {
it('should invalidate old tokens and create a new hashed token', async () => {
const user = awaitsetupTestUser();
const token = awaitgenerateResetToken(user.id);
expect(token).toBeDefined();
// Test fails initially because generateResetToken is not implemented
});
});
Phase B: Green (Minimal Code)
Write the simplest possible implementation that satisfies the test.
Avoid over-engineering, optimizations, or additional features. Run tests to confirm they are green.
Phase C: Refactor (Clean Code)
Improve code quality (deduplicate, clarify names, extract logic) while running tests to verify no regressions occur.
Document the implementation: add JSDoc for signatures and focused inline comments for intent.
3. Testing Strategy & Decision Tree
Before executing tests, discover the project reality (e.g. check package.json, pyproject.toml, Docker Compose config, environment setups). Use the decision tree to determine the validation path:
Does the target area already have automated tests?
Yes → Add or update tests within that suite.
No → Continue to step 2.
Did the user explicitly request no test framework changes?
Yes → Do not bootstrap. Provide a manual validation checklist and call out the automation gap.
No → Continue to step 3.
Is there an approved, lightweight framework used in adjacent code?
Yes → Use that framework to write scoped unit/component tests.
No → Continue to step 4.
Fallback to Project Defaults:
API (Backend): Use the existing Vitest/Jest runner to write unit tests.
Web (Frontend): Write unit/component tests. If Playwright infrastructure is present, update component specs.
Manual Verification Fallback:
If automation is impractical, document the manual verification checklist to prove the contract.
Doc Comments: Use the host language's standard (JSDoc for JS/TS, docstrings for Python, etc.) to document parameters, return values, thrown errors, side effects, and invariants for all touched exported functions and class members.
Inline Comments: Keep comments focused on why the logic exists, its assumptions, edge cases, caching precedence, and order of operations. Remove or rewrite comments that mechanically repeat the next line.
5. Execution Workflow (Docker Environment)
[!IMPORTANT]
Host Isolation: Since Python and Node are not installed on the host machine, run all test commands using Docker containers.
Test Scope Rule: Run unit tests only by default during AI tasks. Integration/functional tests and E2E/Playwright browser smoke tests are reserved for explicit requests.