一键导入
code-integration-tests
Integration test writing for component boundaries and external dependencies
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Integration test writing for component boundaries and external dependencies
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Test failure diagnosis, source code fixes, and regression detection
Environment verification, dependency installation, baseline test verification
Contract-first single-task implementation dispatched by Coder Coordinator
Unit test writing and execution with coverage threshold enforcement
API reference documentation skill. Produces and updates API endpoint documentation from contract files in .sdd/docs/api-reference.md.
Architecture documentation skill. Produces and updates architecture overview, component diagrams, technology stack, design decisions, and directory structure in .sdd/docs/architecture.md.
| name | code-integration-tests |
| description | Integration test writing for component boundaries and external dependencies |
| argument-hint | Invoked by Coder Coordinator - do not call directly |
Phase: 4 (Integration Tests) Common contract:
.github/skills/CODER-SKILL-CONTRACT.mdSpec refs: FR-031, FR-032, FR-033
This skill is dispatched by the Coder Coordinator during Phase 4. It writes integration tests for component boundaries, uses contract schemas to generate mock responses for external dependencies, includes data setup and teardown, and reports results to the coordinator.
| # | Input | Description |
|---|---|---|
| 1 | skill_path | Path to this SKILL.md file |
| 2 | wp_path | Path to the WP file being implemented |
| 3 | contracts_dir | Path to contract files for this WP (.sdd/plans/contracts/<WP-slug>/) |
| 4 | spec_path | Path to the source spec file |
| 5 | patterns | Active code-domain patterns to avoid (from code-patterns.md) |
| 6 | target_language | Programming language (e.g., TypeScript, Python) |
| 7 | target_framework | Framework (e.g., Express, FastAPI, React) |
| 8 | task_list | Tasks with acceptance criteria and spec refs |
Report to the coordinator with these fields:
| Field | Type | Constraints | Description |
|---|---|---|---|
status | enum | success or failure | Skill outcome |
files_modified | list(string) | file paths | Files created or changed |
tasks_completed | list(string) | T-XX format | Tasks finished |
test_results | object | pass_count, fail_count, coverage_pct | Test run summary |
issues | list(string) | free text | Problems encountered |
failure_reason | string | nullable | Why the skill failed (if status is failure) |
The coordinator uses test_results.fail_count to decide whether to dispatch the debug skill (FR-010). This field MUST be present and accurate.
Before writing tests, identify all integration points within the WP's scope.
Read the implementation source files (produced by code-implementation in Phase 2) and contract files to identify:
| Boundary Type | What to Look For |
|---|---|
| Module-to-module | Function calls across source files or packages |
| Service-to-database | Database connection, query, or ORM usage |
| Service-to-external-API | HTTP client calls, SDK usage, gRPC stubs |
| Service-to-cache | Redis, Memcached, or in-memory cache interactions |
| Service-to-queue | Message publish/subscribe, job enqueue |
| Service-to-filesystem | File read/write for data persistence (not config) |
For each identified boundary, check if a corresponding contract file exists in contracts_dir:
| Contract File | Boundary It Defines |
|---|---|
api-contracts.<ext> | External API request/response schemas |
data-schemas.<ext> | Database entity schemas |
interfaces.<ext> | Module-to-module function signatures |
error-catalog.<ext> | Error responses at boundaries |
If a boundary has a contract file, use the contract to define expected inputs/outputs for the integration test. If no contract exists, derive expectations from the spec and implementation.
Test boundaries in this priority order:
Write tests that exercise real call paths across module boundaries within the WP's scope:
# GOOD: Tests real module integration
def test_order_service_creates_order_and_updates_inventory():
order_service = OrderService(inventory_repo=real_inventory_repo)
result = order_service.create_order(order_input)
assert result.status == "confirmed"
assert inventory_repo.get_stock(item_id) == original_stock - quantity
If the WP sets up data persistence, write tests against real database interactions:
# GOOD: Tests real database interaction
def test_user_repository_saves_and_retrieves():
repo = UserRepository(db=test_db)
user = repo.create(CreateUserInput(email="a@b.com", name="Test"))
retrieved = repo.get_by_id(user.id)
assert retrieved.email == "a@b.com"
assert retrieved.name == "Test"
For external dependencies, use contract files to generate mock responses that match exact schemas:
api-contracts.<ext>) for the external API# GOOD: Mock response matches the contract schema exactly
@responses.activate
def test_payment_service_processes_charge():
# Response matches api-contracts.py PaymentResponse schema
responses.add(
responses.POST,
"https://api.payment.com/charges",
json={"id": "ch_123", "status": "succeeded", "amount": 5000},
status=200,
)
result = payment_service.charge(amount=5000, currency="usd")
assert result.charge_id == "ch_123"
assert result.status == "succeeded"
Contract compliance rule: Mock responses SHALL NOT use arbitrary test data. Every mock response MUST conform to the schema defined in the contract file. If a contract defines PaymentResponse { id: string, status: string, amount: int }, the mock MUST return exactly those fields with correct types.
Every integration test SHALL include explicit data setup and teardown:
Setup (before each test):
Teardown (after each test):
Use the test framework's built-in mechanisms:
| Language | Setup/Teardown |
|---|---|
| Python (pytest) | @pytest.fixture with yield for cleanup |
| TypeScript (Jest) | beforeEach/afterEach or beforeAll/afterAll |
| Go | t.Cleanup() or TestMain |
| Rust | Custom Drop implementations or test helper functions |
Isolation rule: Each integration test SHALL be independent. Test A's data SHALL NOT leak into Test B. Use unique identifiers (UUIDs, timestamps) for test data to prevent collisions.
Test failure modes at integration boundaries:
| Failure Mode | Test Scenario |
|---|---|
| Timeout | Mock an external API to delay beyond the configured timeout. Verify the service handles the timeout gracefully (returns error, does not hang). |
| Connection refused | Mock a service that refuses connections. Verify error handling. |
| HTTP 4xx errors | Return 400, 401, 403, 404 from mocked API. Verify each is handled per spec. |
| HTTP 5xx errors | Return 500, 502, 503 from mocked API. Verify retry logic (if spec requires) or error propagation. |
| Malformed response | Return invalid JSON or missing required fields. Verify the service does not crash. |
| Database constraint violation | Attempt to insert duplicate keys or violate constraints. Verify proper error handling. |
Verify that integration points match the API contract schemas:
Place integration tests in a separate directory from unit tests:
| Language | Convention |
|---|---|
| Python | tests/integration/test_<boundary>.py |
| TypeScript | tests/integration/<boundary>.test.ts |
| Go | integration_test.go with build tag //go:build integration |
| Rust | tests/<boundary>_integration.rs (top-level tests/ directory) |
Name integration tests to describe the boundary being tested:
test_order_service_with_payment_gatewaytest_user_repo_postgres_crud_lifecycletest_integration_1test_it_works_togetherUse #tool:execute/executionSubagent for running test commands -- it filters output to relevant portions (failures, summary) and preserves context budget.
Execute integration tests separately from unit tests:
| Language | Command |
|---|---|
| Python | pytest tests/integration/ -v |
| TypeScript (Jest) | npx jest --testPathPattern=integration |
| Go | go test -tags=integration ./... |
| Rust | cargo test --test '*_integration' |
Record from the test output:
pass_count)fail_count)Include test results in the output contract:
test_results:
pass_count: <number>
fail_count: <number>
coverage_pct: <number or null>
If any tests fail:
fail_count to the exact number of failing testsissuesfail_count > 0 to trigger debug skill dispatchIntegration tests may require infrastructure that is not available in all environments.
Before running integration tests, check for required infrastructure:
| Prerequisite | Detection |
|---|---|
| Database | Check for connection string in env vars or config; try connecting |
| External service | Check for API keys/URLs in env vars or config |
| Docker | Check for docker command availability |
| Message queue | Check for connection parameters |
If a prerequisite is missing:
issues:
"Integration test for <boundary> skipped: <prerequisite> not available.
Required: <what is needed>. Setup: <how to provide it>."
status: success (missing infrastructure is not a skill failure)pytest.mark.skip, it.skip)Mock responses SHALL be derived from contract files, not invented. If api-contracts.py defines a PaymentResponse with fields {id, status, amount}, the mock SHALL return exactly those fields with correct types. Do NOT add fields not in the contract. Do NOT omit required fields.
Do NOT perform quality assessment, review checklists, or "verified implementation quality" statements. Write tests, run them, report results. The Reviewer is the sole quality gate.
Contract files in .sdd/plans/contracts/ are READ-ONLY. Do NOT modify any contract file. If a contract appears incorrect, flag it as an issue and continue.
If existing tests from a prior phase fail:
test_results