agentleFS
Igorsolop0Igorsolop0/qa-claude-skills/skills/api-contract-writer/SKILL.md

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

  • Other versions1 project uses a version of this.

    Word for word · 0

    None found.

    Edited · 0

    None found.

    Wrote their own version · 1

    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.

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
  1. Very specific:

    Never npm, npx, pnpm, or yarn.

    line 49
  2. Very specific:

    Test data: crypto.randomUUID() with a qa-pw- prefix.

    line 54
  3. Very specific:

    Every run hits a live environment.

    line 57
  4. Very specific:

    Do not name a client *.controller.ts.

    line 136
  5. Very specific:

    Read references/conventions.md for details.

    line 140
  6. Very specific:

    Never call admin-api.* directly, never use the legacy Api-UserId / Api-Key scheme (it covers only the Product, Segment, and Content …

    line 147
  7. Very specific:

    Use fixtures from src/fixtures/api.fixture.ts (clientApi, clientPlayer, backofficeApi).

    line 154
  8. Very specific:

    Import test and expect from that fixture file, not from @playwright/test.

    line 155
  9. Very specific:

    Use toBe / toEqual on ResponseCode, ProblemDetails title, and message text.

    line 176
  10. Very specific:

    Test title carries the Testomat id once it exists: "<title> @T1a2b3c4d".

    line 190
  11. Very specific:

    When the case comes from an OpenSpec change, keep its local_id (e.g.

    line 192
  12. Distinctive:

    Follow these steps in order.

    line 216
  13. Distinctive:

    Start from the OpenSpec change test cases or the Testomat suite when one exists.

    line 228
  14. Distinctive:

    Step 4 — Builder: if the payload has more than 3 fields.

    line 235
  15. Distinctive:

    Step 6 — Fixtures: only when shared setup does not fit the spec.

    line 239

≈ “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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

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-Admin

This file is the entry point. Detailed rules live in references/:

TaskRead this file
Writing a client, types, spec, or fixturereferences/conventions.md
Writing a Builder (payload > 3 fields) or a Zod schemareferences/builders.md
Choosing auth (gate auth, player JWT, Backoffice)references/auth-patterns.md
First API test in a target, or a brand new domainreferences/new-domain.md

0. Stack & ground truth

  • Runtime and package manager: Bun. Use bun, bunx, bun run --cwd qa <script>. Never npm, npx, pnpm, or yarn.
  • Runner: @playwright/test from the root testing catalog (1.63.0). Playwright itself runs on Node under bunx/bun run; do not use bun --bun playwright.
  • HTTP: Playwright APIRequestContext through the qa base client. Never fetch/axios in specs.
  • Validation: zod (root catalog, "zod": "catalog:"). Validate every happy-path body.
  • Test data: crypto.randomUUID() with a qa-pw- prefix. @faker-js/faker is 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 test refuses to start without QA_LIVE=1; the e2e* package scripts set it.

Targets

TargetProjectBase URL envEnvironments
Client backendclient-apiCLIENT_API_GATEWAY_URL (qa: <client-api-gateway-url>)qa only; prod (the production gateway) not agreed
Backofficebackoffice-apiMANAGEMENT_API_GATEWAY_URL (<management-api-gateway-url>)dev and qa only

Contracts (source of truth for types)

  • Client: openapi-v1.json at 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 exposes bonusfeed/.../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-api

File 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.

SuffixRole
.client.tssends HTTP, extends BaseClient
.types.tswire shapes, aliased from .schema/client-gateway.d.ts
.api.tsfacade over one target's domain clients
.matcher.tsexpect.extend addition
.fixture.tsPlaywright fixture
.reporter.tsPlaywright reporter
.builder.tstest-data factory
.schema.tsZod runtime schema
.spec.tsPlaywright E2E test (tests/)
.test.tsBun 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/...): legacy DomainApiResponse. A business failure can arrive as HTTP 200 or a 4xx that still carries the envelope (qa: v4/Auth/Register with a too-long password → HTTP 400, ResponseCode: "InvalidPassword"). Unwrap with asDomainApiResponse() and assert both status and ResponseCode on every call. Observed success code for v4 Auth: "Success".
  • The newer services: bare JSON on success; errors are HTTP status + RFC 7807 ProblemDetails where title is the machine code. Use asProblemDetails().
  • 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/@S ids; 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 a test.info().annotations entry.
  • test.fixme needs 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 — live

Report 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/bff or 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.

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.