dev-api-integration-testing
Skill2 starsChanged 7 months agoMITView on GitHub
Use when authoring or running integration tests for a backend slice, especially Phase 5 against a live dev API. Payload conventions, side-effect verification (DB / queue / file), dev-data fixture hygiene, idempotency, real dependencies for the system under test -- mock only the truly external or non-deterministic.
In this repository64 other files it gives its agents.
- CLAUDE.mdCLAUDE.md
- openspec-apply-changeSkill
- openspec-archive-changeSkill
- openspec-exploreSkill
- openspec-proposeSkill
- api-design-from-frontendSkill
- architect-team-pipelineSkill
- bug-fix-pipelineSkill
- cartographer-teamSkill
- claude-design-importSkill
- claude-md-efficiencySkill
- closeoutSkill
- common-pipeline-conventionsSkill
- contract-first-parallelismSkill
- coverage-mappingSkill
- ct6-agent-coreSkill
- data-annotationsSkill
- data-dictionarySkill
- data-engineering-explorationSkill
- data-eng-pipelineSkill
- data-lineage-mappingSkill
- delivery-manifestSkill
- design-fidelity-mappingSkill
- diagnostic-research-teamSkill
- documentation-currencySkill
- domain-research-teamSkill
- dynamic-value-discoverySkill
- editability-completenessSkill
- email-testingSkill
- endpoint-trace-mappingSkill
- expensive-verification-debuggingSkill
- frontend-route-mappingSkill
- helpdeskSkill
- intake-and-mappingSkill
- interaction-completenessSkill
- interaction-intuitionSkill
- interactive-mockup-discoverySkill
- intuition-map-lifecycleSkill
- mcp-output-contract-designSkill
- mempalace-integrationSkill
- mini-architect-team-pipelineSkill
- page-publishingSkill
- phenotype-absorptionSkill
- phenotypesSkill
- playwright-suite-builderSkill
- playwright-user-flowsSkill
- project-homepageSkill
- project-principlesSkill
- proposal-refinerSkill
- readme-stylingSkill
- reuse-first-designSkill
- root-cause-test-failuresSkill
- structure-optimizationSkill
- team-spawning-and-review-gatesSkill
- test-prod-safety-classifierSkill
- test-run-monitorSkill
- token-compressionSkill
- ux-test-builderSkill
- verification-planningSkill
- verified-agent-outputSkill
- The first 60 shown.
The file
We split this skill into the rules it gives an agent
3 rules. About 0 are common, 2 are distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈2
Distinctive · estimate
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 41
Create dev data with a per-test prefix (e.g., it-<test_name>-<uuid>) to make cleanup automatic and prevent cross-test contamination.
- Distinctive: line 66
If the test wrote to an external service that doesn't honor prefixes, register the resource with the cleanup registry so a periodic sweep …
- Distinctive: line 70
Every test must be runnable twice in a row without failing on the second run.
≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Dev-API Integration Testing
Before choosing WHERE to verify (v3.66.0): apply the
verification-planningskill — enumerate local run / dev environment / replay / seeded fixture / production, prove which venue each claim depends on, run the cheapest faithful venue first, and record theverification_plan. The local-then-live sequence below is the venue order for the integration gate; it is never a reason to skip a cheaper faithful check of a claim, and never a reason to wait for an environment the run can provide itself.
Backend tests that pass against mocks and fail against the live system are the most expensive bugs to discover. This skill enforces the discipline that integration tests run against the real dev API with real dev data, and verify real side effects.
Where connection details live
The OpenSpec design.md for the change must include a ## Dev Environment section with:
- Base URL of the dev API.
- Auth strategy (test user creds, service token, signed JWT).
- Database connection (read-only? read-write? which schema?).
- Queue / cache / object store endpoints.
- Cleanup strategy (test data prefix, transactional rollback, scheduled sweep).
Tests read these from the design artifact — never hard-code in test files.
What "integration" means here
- The system under test (the backend service / module) runs against its REAL dependencies in the dev environment: real DB, real queues, real cache, real auth.
- Mock ONLY:
- Truly external third parties (payment processors, email providers) — and only when the dev env doesn't have a sandbox.
- Non-deterministic inputs (time, randomness, cloud-region routing) when assertion would otherwise flake.
- Everything else is real.
Full-run enumeration — the whole dev suite
The full run against dev is SELECTED, not exhaustive (v4.0.0): python "${CLAUDE_PLUGIN_ROOT}/scripts/test_index/cli.py" select --workspace <ws> --phase 5 --baseline <sha> --json names the integration tests whose files, endpoints or elements the change set reaches, plus the human always_run pins and every unknown mapping; run those against live dev and cite the selection record in the evidence file. The manifest (<e2e-dir>/suite-manifest.json, whose contract playwright-suite-builder owns) is still enumerated -- the selector reads it -- but the whole dev project runs ONCE, at Phase 8 (or the lane's merge boundary, select --phase 8), before the merge to main. This reverses the v3.65.0 whole-suite rule; the full text and the reasoning are in skills/common-pipeline-conventions/references/test-selection.md. A slice run wearing a full run's name is still forbidden: the Phase 8 full run is not selectable. The pins (tests.always_run / tests.full_suite_at in the human-owned .architect-team-deploy.json) are read, never narrowed, by an agent — wanting one changed is a question for the user. Absent a suite manifest, behavior is unchanged.
Test structure
Setup phase
- Create dev data with a per-test prefix (e.g.,
it-<test_name>-<uuid>) to make cleanup automatic and prevent cross-test contamination. - Authenticate using the dev environment's test-user mechanism (NOT the production auth flow).
Action phase
- One HTTP request per assertion when possible. Use
httpx(or the project's existing async client). - Capture the full request (method, URL, headers minus secrets, body) and response (status, headers, body) on failure for debug.
Assertion phase
Four layers, all required for any state-changing endpoint:
- Response shape (the write echo). Status code + response body matches the schema in the design artifact. Use a schema validator (pydantic, marshmallow, zod-equivalent) — don't assert one field at a time.
- API read-back. For any written value that is subsequently readable, GET the resource back through the public API and assert the written value returns. This layer is required, not optional polish: a write echo can be assembled from the request the caller just sent while the serializer, the response schema, or the read query drops the field entirely — the write succeeds, the read returns nothing, and every other layer is green. For an update endpoint the full chain is required — POST-echo → GET → PUT-echo → GET-after-PUT — because the create path and the update path can diverge in exactly the serializer that hides the bug. Assert the value the API RETURNS, never the value you sent.
- Side-effect verification (necessary, and not sufficient). The action actually changed the system:
- DB row exists / updated / deleted (query directly).
- Queue message published (consume from the queue or query the broker's API).
- File written (read from the object store).
- Cache entry set/invalidated. This layer proves the write PERSISTED; it does not prove the value is RETRIEVABLE. A row the API never returns is a blank field to the user. A direct-DB assertion is never a substitute for layer 2 — it is the corroboration that layer 2's read-back reflects real stored state rather than a cache or a request echo.
- Audit/log effect where applicable (audit trail row, log line, metric increment).
Teardown phase
- Clean up the per-test prefix.
- If the test wrote to an external service that doesn't honor prefixes, register the resource with the cleanup registry so a periodic sweep removes it.
Idempotency
Every test must be runnable twice in a row without failing on the second run. If the first run created data, the second run's setup must either reuse-or-recreate, or the teardown must have removed it.
This is non-negotiable — flaky tests rot the whole suite.
Per-test expectations & failure handling
For every integration test (local OR live-dev), write a per-step expectation file BEFORE running the test, per root-cause-test-failures. The expectation file (<test-output-dir>/expectations/<test-id>.json) captures the request payload, response assertions (status / shape / values), API read-back assertions (the value a subsequent GET must return — the full POST-echo → GET → PUT-echo → GET-after-PUT chain for update endpoints), side-effect assertions (DB rows, queue messages, files), and audit-log assertions — all four assertion layers mandated above. The read-back leg is the one most easily dropped here, and dropping it is exactly how a green suite ships a field the API never returns: this file is written BEFORE the test runs and decides what the test asserts. On any failure, do NOT propose a fix until the 3-pass root-cause loop has run and produced an evidence-backed rca/<test-id>-<ts>.json artifact. "It's probably flaky" is forbidden — either identify the race / fixture / env trigger with evidence and document the fix in-loop, OR (when the verdict is product-bug) escalate via the RCA handoff AND write a solution requirement to <cwd>/.architect-team/solution-requirements/SR-<test-id>-<ts>.json per team-spawning-and-review-gates's ## Solution Requirements section. The SR auto-spawns a fix team via the orchestrator; the loop re-enters Phase 2 with the failing integration test as the convergence check.
Test naming
- Pattern:
test_<endpoint>_<scenario>(e.g.,test_post_projects_creates_with_owner,test_post_projects_401_when_unauthenticated). - One scenario per test. Don't bundle happy-path and error cases in one function.
Error path coverage
Cover EVERY error response the endpoint can return, drawn from the OpenSpec design artifact's response catalog:
- 400 / 422 validation errors (one test per failing validation rule).
- 401 unauthenticated.
- 403 unauthorized (right user, wrong role / missing permission).
- 404 not-found.
- 409 conflict.
- 429 rate-limited.
- 5xx via fault injection where possible.
Anti-pattern rationalizations to reject
| Rationalization | Rebuttal |
| "I'll mock the DB to make the test fast" | Mocking the DB tests your assumptions about the ORM, not your code. Use the real DB in dev. |
| "The error responses are obvious — happy path is enough" | Error paths break production. Coverage of every documented error response is the bar. |
| "I'll skip side-effect verification — the 200 is enough" | A 200 with no side effect is a silent data-loss bug. Verify the row, the message, the file — AND read the value back through the API. The side-effect layer corroborates the read-back; it never replaces it. |
| "The DB row proves it persisted" | Persisted is not retrievable. The user reads through the API; assert there. A green DB assertion beside a serializer that drops the field is exactly the shape of a "fixed" bug the user still sees. |
| "Test data leaks are fine — dev gets reset" | Cross-test contamination causes flaky tests. Use the prefix discipline. |
| "I'll hard-code the dev URL" | The design artifact is the source. Read from it, so changing environments doesn't require a code edit. |
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

