agentleFS
EvilFreelancerEvilFreelancer/openapi-to-cli/.cursor/rules/testing.mdc

openapi-to-cli / rules

Cursor rule263 starsChanged 3 months agoMITView on GitHub

Test conventions for openapi-to-cli (Jest)

The file

We split this testing.mdc into the rules it gives an agent

4 rules. About 0 are common, 1 is distinctive, and 3 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈1

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 3

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    All tests live in tests/ alongside the matching src/ module.

    line 13
  2. Very specific:

    Test files: tests/<module>.test.ts (one per src/<module>.ts).

    line 14
  3. Very specific:

    Test names: it("does X when Y", ...) - describe behavior, not implementation.

    line 21
  4. Distinctive:

    Add new spec fixtures only when an existing one cannot reproduce the case.

    line 51

≈ “Common” is an estimate: at least 1 in 5 of the 3,030 Cursor rule 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
testing.mdc
---
description: Test conventions for openapi-to-cli (Jest)
globs: tests/**/*.ts
alwaysApply: true
---

# Test conventions (Jest)

Applies when editing or adding files under `tests/`.

## Layout

- All tests live in `tests/` alongside the matching `src/` module.
- Test files: `tests/<module>.test.ts` (one per `src/<module>.ts`).
- Shared inputs in `tests/fixtures/` (OpenAPI/Swagger documents, sample profiles). Recorded outputs in `tests/results/`.
- `github-api.test.ts` and `box-api-yaml.test.ts` are large real-spec regression tests - do not hand-edit their fixtures.

## Structure

- Group with `describe(<moduleName>, ...)`; one nested `describe` per public method or scenario.
- Test names: `it("does X when Y", ...)` - describe behavior, not implementation.
- Arrange / Act / Assert order inside each `it`. Blank lines between the three sections are encouraged.

## Isolation

- Each `it` is independent. Use `beforeEach`/`afterEach` for setup and teardown, not module-level mutable state.
- Mock `fs` and `axios` (`HttpClient`) through the constructor options the modules expose. Do **not** monkey-patch the real `fs`/`axios` modules in tests.
- For `.ocli/` fixtures, use `fs.mkdtempSync(os.tmpdir() + "/...")` and clean up in `afterEach`.

## Running

```bash
npm test                                # full Jest suite
npx jest tests/<file>.test.ts           # one file
npx jest tests/<file>.test.ts -t "X"    # one test by name
```

## What to assert

- Public behavior visible at the module boundary - return values, written files, requests issued via the mocked `HttpClient`, captured `stdout`.
- For BM25 / `command-search` - assert ranking order and matched commands, not internal scores.
- For `openapi-to-commands` - assert the resulting `CliCommand[]` structure (names, options, body schema), not intermediate spec normalization.

## What not to assert

- Internal helper signatures, private state, exact log strings - those are implementation details.
- Floating-point BM25 scores beyond ranking order.

## Fixtures

- Add new spec fixtures only when an existing one cannot reproduce the case. Keep them minimal: one path, one operation, only the fields needed for the test.
- For tests covering spec features (OAS 3 `requestBody`, Swagger 2 `formData`, multi-file `$ref`, header/cookie params), name the fixture after the feature, e.g. `tests/fixtures/swagger2-formdata.yaml`.

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.