agentleFS
stbenjamstbenjam/skillsaw/.cursor/rules/testing.mdc

skillsaw / rules

Cursor rule68 starsChanged 4 months agoApache-2.0View on GitHub

Guidelines for writing tests, especially integration tests with fixtures

The file

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

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

  • 4

    Very specific

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

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

    Prefer run_cli for a new integration test.

    line 23
  2. Very specific:

    Prefer static fixtures in tests/fixtures/ over building repos programmatically in test code.

    line 47
  3. Very specific:

    Create a directory under tests/fixtures/ with the files needed for the test

    line 51
  4. Very specific:

    Use copy_fixture(name, tmp_path) to copy into a temp directory before running

    line 52
  5. Distinctive:

    Keep fixture CLAUDE.md files realistic — not one-liner stubs

    line 53
  6. Distinctive:

    When testing autofix behavior:

    line 57
  7. Distinctive:

    Verify that line counts do not change after autofix (wrapping text in link syntax, for example, should not add or remove lines).

    line 61
  8. Distinctive:

    Test idempotency: running fix twice should produce identical content.

    line 63

≈ “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: Guidelines for writing tests, especially integration tests with fixtures
---

<!-- Source paths below are repo-root-relative references, not links navigable from this file's directory. -->
<!-- skillsaw-disable content-unlinked-internal-reference -->

# Testing

## Integration Tests

Integration tests live in `tests/test_integration.py` and verify end-to-end
behavior by driving the CLI (`skillsaw lint` / `fix`) against realistic repo
fixtures.

### Drive the CLI through `run_cli`

`run_lint` and the `_run_fix` helpers call `run_cli` from
`tests/cli_runner.py`, which invokes `skillsaw.cli.main()` in-process with
argv, stdout, stderr, env and cwd swapped, and returns a
`subprocess.CompletedProcess` stand-in. Spawning an interpreter per call cost
~160ms — more than half of it importing skillsaw — and dominated the suite.
Prefer `run_cli` for a new integration test.

Reach for a real `subprocess.run` only when the test depends on something a
shared interpreter cannot give it:

- **Import isolation** — the `--no-custom-rules` tests prove a rule file on
  disk did or did not get imported. In-process they would execute an
  arbitrary rule inside the test worker, and `sys.modules` could mask a
  repeat import and make the negative case pass vacuously.
- **A real encoding on stdout** — the lone-surrogate regressions assert that
  rendering a report raises no `UnicodeEncodeError`. A `StringIO` never
  encodes, so in-process they would pass vacuously.
- **TTY and colour-cascade behavior**, which depends on the real stream.
- **Entry-point discovery** — `tests/test_integration_plugins.py` installs
  plugins and needs a fresh interpreter to pick them up, so it stays on
  subprocess throughout.

Anything `run_cli` runs shares one interpreter, so a helper that leaves
process-global state behind breaks later tests. `run_cli` already resets the
two that outlive a call — root logging handlers and the `skillsaw.utils` file
cache; add to `_reset_process_globals` if you introduce another.

### Use test fixtures

Prefer static fixtures in `tests/fixtures/` over building repos
programmatically in test code. Fixtures should contain realistic file content
that mirrors what real users would write.

- Create a directory under `tests/fixtures/` with the files needed for the test
- Use `copy_fixture(name, tmp_path)` to copy into a temp directory before running
- Keep fixture CLAUDE.md files realistic — not one-liner stubs

### Autofix tests

When testing autofix behavior:

- Scope the fix to the violation's line — never apply regex or `str.replace()`
  across the entire file content, as this can match the wrong occurrence.
- Verify that line counts do not change after autofix (wrapping text in link
  syntax, for example, should not add or remove lines).
- Test idempotency: running fix twice should produce identical content.
- Re-lint after fix to confirm zero remaining violations for the rule under test.

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.