agentleFS
DariuszDuszaDariuszDusza/agentic-workflow-foundry/.agents/skills/api-test-generation/SKILL.md

api-test-generation

Skill1 starsChanged 26 days agoApache-2.0View on GitHub

Use when writing or extending tests for API endpoints, whether for a new endpoint, a bug fix that needs a regression test, or a coverage gap. Produces tests that fail when the behaviour breaks, cover denial as well as success, and never carry real data or real secrets.

The file

We split this skill into the rules it gives an agent

2 rules. About 0 are common, 2 are distinctive, and 0 are 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.

  • 0

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Assert behaviour, not echo: Do not assert that the code returns what the test just told the mock to return.

    line 28
  2. Distinctive:

    Runnable alone: Every new test runs on its own by filter, so the author, the reviewer and the merger can all run exactly it.

    line 37

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

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

API test generation

Required context

  1. .agents/areas.json: the area under test and its verify command.
  2. .agents/guardrails/code-style.md: test naming and layout.
  3. .agents/guardrails/data-handling.md: what may appear in a fixture.
  4. .agents/skills/secure-api-endpoint/SKILL.md and, for tenant data, .agents/skills/tenant-safe-change/SKILL.md: the behaviours the tests must pin.
  5. The sibling test file for the nearest endpoint: its fixtures, factories and helpers.

The rules that bite

  • A test must fail when the behaviour breaks. Prove it: revert or break the line under test, run the test, see it go red, restore. A test that stays green with the change reverted proves a path production never takes.
  • Cover the three outcomes: authorization denied for the wrong caller, validation failure for bad input, and success. Most security regressions live in the first two.
  • Tenant data gets both sides: same-tenant success and cross-tenant denial, running as the application role, never a role that bypasses isolation.
  • Call the API the way clients do. Same URL prefix, same headers, same serialization. A test that calls an internal path or a different prefix tests something else.
  • Assert behaviour, not echo. Do not assert that the code returns what the test just told the mock to return. Assert on the response the client sees and the state the database holds.
  • No real data. Fixtures come from factories. Never copy a customer record, a real email or a production id into a test.
  • No real secrets, and no secret-shaped literals. A fixture that needs a key shape builds it at runtime from obviously fake parts, so the secret scanner never flags the repository.
  • Deterministic. Freeze time, seed randomness, and never call a real external service; stub it at the boundary. A flaky test is worse than a missing one, because it teaches people to re-run until green.
  • Runnable alone. Every new test runs on its own by filter, so the author, the reviewer and the merger can all run exactly it.
  • One behaviour per test, named for the behaviour, so a failure names what broke.

Verify

<the area's test runner, filtered to the new tests>   # green
<the same, with the line under test broken>           # red, then restore
make verify

Then the area's verify command exactly as .agents/areas.json declares it. A suite whose count moved needs matching assertions. Reviewer: code-reviewer (test honesty is in its lens).

Escalate when

  • The only way to reproduce a bug seems to be real customer data: ask for a redacted case.
  • A test needs network access to a real service or a shared environment.
  • You want to skip, quarantine or delete an existing failing test: that hides a signal someone relies on, and needs a person's decision and a work item.
  • A shared fixture used by many tests has to change.

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.