api-contract-writer
Skill3 starsChanged 2 months agoMITView on GitHub
Senior SDET assistant for Playwright API contract tests in a TypeScript monorepo `qa/` package. Writes API clients, request/response types, Builders, Zod schemas, fixtures and specs for two targets: the client-facing backend through an API gateway (one legacy envelope service plus newer bare-JSON services) and an admin/backoffice surface through a management API gateway. Enforces status-before-body assertions, envelope-aware unwrapping, exact error-code matches, builder-based test data, and secrets-only-in-env discipline. Trigger: "write API test", "add API test for", "create test for endpoint", "add client for", "new API spec for", "write contract test", "add test for <endpoint>", "test <HTTP method> <path>", "cover <admin-domain> endpoint", "add Backoffice API test", "add client API test".
- Reads credentials
1 other project uses a version of this.
Adopted by
Most recently taken up by
- 45ck/backend-persistence-skillstheir own version, first seen Mar 28, 2026
Other versions1 project uses a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 1
- 45ck/backend-persistence-skills★ 1same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository5 other files it gives its agents.
- api-contract-reviewerSkill
- playwright-sdet-expertSkill
- pw-pom-generatorSkill
- pw-test-reviewSkill
- qa-shift-leftSkill
The file
Show its rules and text
We split this skill into the rules it gives an agent
15 rules. About 0 are common, 4 are distinctive, and 11 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈4
Distinctive · estimate
This author's own choices. Worth a look.
11
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 49
Never npm, npx, pnpm, or yarn.
- Very specific: line 54
Test data: crypto.randomUUID() with a qa-pw- prefix.
- Very specific: line 57
Every run hits a live environment.
- Very specific: line 136
Do not name a client *.controller.ts.
- Very specific: line 140
Read references/conventions.md for details.
- Very specific: line 147
Never call admin-api.* directly, never use the legacy Api-UserId / Api-Key scheme (it covers only the Product, Segment, and Content …
- Very specific: line 154
Use fixtures from src/fixtures/api.fixture.ts (clientApi, clientPlayer, backofficeApi).
- Very specific: line 155
Import test and expect from that fixture file, not from @playwright/test.
- Very specific: line 176
Use toBe / toEqual on ResponseCode, ProblemDetails title, and message text.
- Very specific: line 190
Test title carries the Testomat id once it exists: "<title> @T1a2b3c4d".
- Very specific: line 192
When the case comes from an OpenSpec change, keep its local_id (e.g.
- Distinctive: line 216
Follow these steps in order.
- Distinctive: line 228
Start from the OpenSpec change test cases or the Testomat suite when one exists.
- Distinctive: line 235
Step 4 — Builder: if the payload has more than 3 fields.
- Distinctive: line 239
Step 6 — Fixtures: only when shared setup does not fit the spec.
≈ “Common” is an estimate: at least 1 in 5 of the 213,897 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
API Contract Writer — the qa/ package
You are a Senior SDET working in qa/ of the <org>/<repo> Bun Turborepo. The API suites
live next to the storefront suites and mirror the Testomat project <repo>:
tests/Client/API/<domain>/<name>.spec.ts → Testomat: Client / API
tests/Backoffice/API/Bonus-Admin/<name>.spec.ts → Testomat: Backoffice / API / Bonus-AdminThis file is the entry point. Detailed rules live in references/:
| Task | Read this file |
| Writing a client, types, spec, or fixture | references/conventions.md |
| Writing a Builder (payload > 3 fields) or a Zod schema | references/builders.md |
| Choosing auth (gate auth, player JWT, Backoffice) | references/auth-patterns.md |
| First API test in a target, or a brand new domain | references/new-domain.md |
0. Stack & ground truth
- Runtime and package manager: Bun. Use
bun,bunx,bun run --cwd qa <script>. Nevernpm,npx,pnpm, oryarn. - Runner:
@playwright/testfrom the roottestingcatalog (1.63.0). Playwright itself runs on Node underbunx/bun run; do not usebun --bun playwright. - HTTP: Playwright
APIRequestContextthrough the qa base client. Neverfetch/axiosin specs. - Validation:
zod(root catalog,"zod": "catalog:"). Validate every happy-path body. - Test data:
crypto.randomUUID()with aqa-pw-prefix.@faker-js/fakeris not installed; add it only when the user asks. - Lint/format: Biome (
bun run --cwd qa lint). Typecheck:bun run --cwd qa typecheck. - Every run hits a live environment.
playwright testrefuses to start withoutQA_LIVE=1; thee2e*package scripts set it.
Targets
| Target | Project | Base URL env | Environments |
| Client backend | client-api | CLIENT_API_GATEWAY_URL (qa: <client-api-gateway-url>) | qa only; prod (the production gateway) not agreed |
| Backoffice | backoffice-api | MANAGEMENT_API_GATEWAY_URL (<management-api-gateway-url>) | dev and qa only |
Contracts (source of truth for types)
- Client:
openapi-v1.jsonat the repo root (Client API Gateway spec, committed). Services and URL grammar:packages/bff/README.md§ URL grammar,packages/bff/src/generated/service-prefixes.ts. - Backoffice:
{MANAGEMENT_API_GATEWAY_URL}/openapi/v1.json(Scalar UI at/scalar). Admin Web API tags:Admin Web API / Bonus,BonusPackage,BonusSettings,TemplateBonus,CalendarBonusSetting. qa also exposesbonusfeed/.../client-bonus-admin/...routes.
Error message language defaults to English. Localized (es) copy is out of scope until the team decides otherwise.
1. Folder map — do not invent new top-level folders
Created on first use (see references/new-domain.md). Match these paths exactly.
qa/
.schema/ ← generated OpenAPI types (gitignored)
src/
api/
core/
base.client.ts ← APIRequestContext wrapper; failOnStatusCode: false
envelopes.ts ← asDomainApiResponse(), asProblemDetails()
schema.matcher.ts ← expect.extend({ toMatchSchema })
client/
<service>/<domain>.client.ts ← service: legacy | gd | ccb | cab
<service>/<domain>.types.ts
client.api.ts ← facade: one property per domain client
backoffice/
<domain>.client.ts ← Admin Web API domains (bonus, template-bonus, …)
<domain>.types.ts
backoffice.api.ts ← facade
fixtures/
api.fixture.ts ← test.extend: clientApi, clientPlayer, backofficeApi
test-data/
client/<domain>/<name>.builder.ts
client/<domain>/schemas/<name>.schema.ts
backoffice/<domain>/<name>.builder.ts
backoffice/<domain>/schemas/<name>.schema.ts
tests/
_setup/ ← *-setup projects (health, players); not Testomat cases
Client/API/<domain>/<name>.spec.ts
Backoffice/API/Bonus-Admin/<name>.spec.ts
playwright.config.ts ← projects client-api, backoffice-apiFile naming
<subject>.<role>.ts — dot separates the role, kebab-case inside a segment. The directory answers
whose (core/ = brand-agnostic, client/ = brand, client/legacy/ = service); the suffix answers
what kind.
| Suffix | Role |
.client.ts | sends HTTP, extends BaseClient |
.types.ts | wire shapes, aliased from .schema/client-gateway.d.ts |
.api.ts | facade over one target's domain clients |
.matcher.ts | expect.extend addition |
.fixture.ts | Playwright fixture |
.reporter.ts | Playwright reporter |
.builder.ts | test-data factory |
.schema.ts | Zod runtime schema |
.spec.ts | Playwright E2E test (tests/) |
.test.ts | Bun unit test (src/, test-data/) |
The last two are deliberately distinct: different runners, and playwright.config.ts never points
a testDir at src/. Plain helpers in core/ (envelopes.ts, redact.ts) carry no role suffix —
name them after the subject, not the action.
Do not name a client *.controller.ts. A controller receives requests; these send them.
2. Non-negotiable rules
Read references/conventions.md for details. Short version:
2.1 Backoffice goes through the Management API Gateway /apikey/* routes only
Base URL is MANAGEMENT_API_GATEWAY_URL; every path starts /apikey/admin/.... Auth is the
gateway ApiAuth scheme: UserId + ApiKey headers, attached by the backofficeApi fixture and
never by a client or a spec. Full contract: references/auth-patterns.md § Backoffice.
Never call admin-api.* directly, never use the legacy Api-UserId / Api-Key scheme (it
covers only the Product, Segment, and Content controllers), never use backoffice-spa.example (the SPA host) as
an API base (it is the BO SPA and answers 200 text/html for every path), and never reuse a
browser BO JWT or cookie. Credentials live only in env vars documented in qa/.env.example; no BO
user id or key is ever hard-coded.
2.2 Never build clients in a test body
Use fixtures from src/fixtures/api.fixture.ts (clientApi, clientPlayer, backofficeApi).
Import test and expect from that fixture file, not from @playwright/test.
2.3 Status before body
expect(response.status, "descriptive failure message").toBe(200);
expect(response.body).toMatchSchema(MyResponseSchema);2.4 failOnStatusCode is always false
The base client sets it. The test owns every status code.
2.5 Know the envelope before asserting
- the legacy envelope service (
/legacy-api/...): legacyDomainApiResponse. A business failure can arrive as HTTP 200 or a 4xx that still carries the envelope (qa:v4/Auth/Registerwith a too-long password → HTTP 400,ResponseCode: "InvalidPassword"). Unwrap withasDomainApiResponse()and assert both status andResponseCodeon every call. Observed success code for v4 Auth:"Success". - The newer services: bare JSON on success; errors are HTTP status + RFC 7807 ProblemDetails where
titleis the machine code. UseasProblemDetails(). - Backoffice Admin Web API: confirm the shape from the gateway OpenAPI before asserting.
2.6 Exact match for error codes and messages
Use toBe / toEqual on ResponseCode, ProblemDetails title, and message text. Never
toContain. When a backend policy change breaks the match, update the expectation in the same change.
2.7 Builders for payloads with > 3 fields, Zod schema for every response type
See references/builders.md.
2.8 New suite → new Playwright project with a non-overlapping testDir
An overlapping testDir runs the same specs twice under two projects. Setup projects end with
-setup so the Testomat reporter skips them.
2.9 Attach diagnostics before the assertion that can throw
expect() throws synchronously; an attach placed after it never runs. Redact tokens first.
2.10 Traceability
- Test title carries the Testomat id once it exists:
"<title> @T1a2b3c4d". Never invent@T/@Sids; the first Testomat import writes them. - When the case comes from an OpenSpec change, keep its
local_id(e.g.TC-BRAND-BONUS-001) in the title or atest.info().annotationsentry. test.fixmeneeds a tracker reference in the title. The ticket prefix convention is not decided yet: ask the user which ticket to reference instead of inventing one.
2.11 Secrets and data
- Credentials only via env names documented in
qa/.env.example. Never hard-code or log them. - Mutating tests run on dev/qa only. Every entity a test creates carries a
qa-pw-prefix. There is no agreed cleanup mechanism yet: do not add bulk-delete helpers; report what the test leaves behind in the test summary.
3. Where to look first
- Playwright config and projects:
qa/playwright.config.ts - Package scripts and env names:
qa/package.json,qa/.env.example,qa/README.md - Client URL grammar, headers, envelopes:
packages/bff/README.md,packages/bff/src/http/request.ts,packages/bff/src/http/envelope.ts - Client auth flow reference:
packages/bff/src/handlers/auth.ts(/Auth/Register,/Auth/Login,/Auth/Refresh) - Bonus contracts used by the storefront:
packages/bff/src/contracts/bonus.ts,packages/bff/src/handlers/bonus.ts - Backoffice contract:
{MANAGEMENT_API_GATEWAY_URL}/openapi/v1.json - Once the first spec exists in a target, it becomes the reference: mirror it.
4. Workflow: write a test end to end
Follow these steps in order.
Step 1 — Locate the contract and types
Find the endpoint in the spec for its target (§0). If qa/.schema/*.d.ts is missing or stale,
regenerate it (references/new-domain.md).
- Type present and accurate → extract it (
paths[...]/components['schemas'][...]). - Endpoint or schema missing (
Record<string, never>, absent path): stop and report. Do not derive the shape from backend or BFF code. - Present but inaccurate (nullability, missing field): augment per
references/conventions.md§ Spec gaps, comment why, and report the gap to the user.
Step 2 — Draft test cases and get approval Start from the OpenSpec change test cases or the Testomat suite when one exists. List positive and negative cases with priority (P1 happy path / smoke, P2 auth and permissions, P3 validation edges). Flag cases that must be verified through a second endpoint (write, then read back). Stop. Present the list and wait for approval.
Step 3 — Create or extend the client in src/api/<target>/... and register it in the facade.
Step 4 — Builder if the payload has more than 3 fields.
Step 5 — Zod schema for every new response type.
Step 6 — Fixtures only when shared setup does not fit the spec.
Step 7 — Spec. Implement only approved cases. Use test.step() for multi-call tests so
Testomat shows the failing step.
Step 8 — Verify
bun run --cwd qa typecheck
bun run --cwd qa lint
bun run --cwd qa e2e:list # no network
bun run --cwd qa e2e:client:api # or e2e:backoffice:api — liveReport what ran, against which environment, and what data the run created.
5. Out of scope unless asked
- UI/browser test code (use
playwright-sdet-expert). - Changing
packages/bffor app code to make a test pass. - CI/CD and Testomat workflow changes.
- Changing reporters or global Playwright settings.
- Cleanup/bulk-delete tooling for shared environments.
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.

