agentleFS
AndreiBanu1AndreiBanu1/playwright-suite-skills/skills/write-api-test/SKILL.md

write-api-test

Skill1 starsChanged 3 months agoMITView on GitHub

Use when adding a Playwright test that exercises an HTTP endpoint directly with no browser — REST or GraphQL — including response-shape validation, error paths, and cleanup after writes. Reads conventions from .claude/test-profile.md and mirrors the existing request specs. Not for tests that drive a page.

The file

We split this skill into the rules it gives an agent

11 rules. About 0 are common, 9 are distinctive, and 2 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈9

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 2

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Add one request-level spec: no browser, no DOM, just a call and what came back.

    line 8
  2. Distinctive:

    If the profile names an endpoint-client layer, use it.

    line 31
  3. Very specific:

    If the profile says none, calls go through whatever the request group already uses, and you leave the architecture alone.

    line 35
  4. Distinctive:

    Shape validation: If the repo validates response shape against schemas, add or reuse a schema alongside the spec the way the neighbours do.

    line 52
  5. Very specific:

    Run the spec alone with the profile's run one command, then run it a second time.

    line 71
  6. Distinctive:

    Run lint and typecheck if the profile lists them.

    line 75
  7. Distinctive:

    Never hardcode a base URL, token, tenant, or account identifier.

    line 79
  8. Distinctive:

    Never assert on a raw secret's value, and never log a response that contains one.

    line 81
  9. Distinctive:

    Never widen an assertion or a schema to clear a failure.

    line 82
  10. Distinctive:

    Do not add a retry to hide a race.

    line 83
  11. Distinctive:

    If the endpoint needs a fixture the repo has no pattern for (an impersonated user, a seeded tenant), stop and ask.

    line 84

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

Skill: write-api-test

Add one request-level spec: no browser, no DOM, just a call and what came back.

These tests are cheap and fast, which makes them the ones most often written carelessly. The two failure modes to avoid are asserting so little that the test cannot fail (status < 500, toBeTruthy()) and asserting so much that every unrelated field change turns it red.

Preconditions

  1. .claude/test-profile.md exists and lists a request group. If not, run probe-conventions first.
  2. You know the endpoint, the method, and what the call is supposed to prove. If the ask is "add tests for the orders API", use clarify-scope — that is a backlog, not a test.

Procedure

1. Read two existing request specs

Record: the verbatim import line, how the call is made (a shared client, a domain-specific client, the raw request context), how credentials are obtained, how the response is unwrapped, and whether response shape is validated against a schema or asserted field by field. Copy all of it.

2. Route the call the way the repo routes calls

If the profile names an endpoint-client layer, use it. If the endpoint has no client method yet, add one with write-api-client rather than reaching around the layer — one spec bypassing the client is how the layer stops being true.

If the profile says none, calls go through whatever the request group already uses, and you leave the architecture alone.

3. Write the spec

<the profile's verbatim request import line>

test('<the behaviour, not the endpoint>', async ({ <fixtures from the profile> }) => {
  // arrange — request inputs, sourced the way the profile says data is sourced
  // act     — the call, through the repo's client layer
  // assert  — status, then shape, then the one or two values that carry the meaning
});

Assert in that order and stop there. Status alone is not a test. Every field is not a test either.

Shape validation. If the repo validates response shape against schemas, add or reuse a schema alongside the spec the way the neighbours do. Treat a schema as a contract: when a response stops matching, the first question is whether the contract changed intentionally. Only then does the schema get updated. Loosening a schema to clear a red run destroys the only thing it was protecting.

GraphQL. A 200 with a populated errors array is a failure — assert on the absence of errors explicitly, since the transport status will not tell you. Send variables as variables; never string-interpolate values into a query document.

Error paths. For every write endpoint, one negative case is worth more than three more happy paths: rejected input, missing record, or unauthenticated. Assert the status and the error body's shape — a 400 with an HTML error page is not the same as a 400 with the documented error object.

Writes clean up after themselves. Anything created gets removed in teardown, and teardown must survive the spec having failed halfway. Then read the resource back — a write endpoint that returns 201 while persisting nothing is a real bug class, and only the read-back finds it.

4. Verify

Run the spec alone with the profile's run one command, then run it a second time. Request specs that pass once and fail on the rerun are leaking state, and that is far easier to fix now than after it lands in CI.

Run lint and typecheck if the profile lists them.

Guardrails

  • Never hardcode a base URL, token, tenant, or account identifier. Those come from the repo's data source, and a spec with an embedded token is a leak the moment it is pushed.
  • Never assert on a raw secret's value, and never log a response that contains one.
  • Never widen an assertion or a schema to clear a failure. Report the disagreement instead.
  • Do not add a retry to hide a race. Find what you should have waited for.
  • If the endpoint needs a fixture the repo has no pattern for (an impersonated user, a seeded tenant), stop and ask.

Done when

The spec passes twice consecutively in isolation, asserts status and shape and meaning, cleans up anything it created, and you have reported the path, the target, and any client method or schema you added.

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.