lens-testing
Skill132 starsChanged 3 months agoMITView on GitHub
Use when a Lens change needs backend HTTP contract coverage. Keep tests risk-based, drive them through the API fixtures, and use the repository's uv-managed checks.
In this repositoryOne other file it gives its agents.
- AGENTS.mdAGENTS.md
The file
We split this skill into the rules it gives an agent
8 rules. About 0 are common, 5 are distinctive, and 3 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈5
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
- Distinctive: line 12
Do not automatically add frontend tests or direct tests of units, services, helpers, converters, or repositories.
- Distinctive: line 14
Delete a test once the behavior it guarded is covered elsewhere, or once the field or option it pinned has been removed or derived.
- Distinctive: line 20
If coverage is justified, add the smallest request-and-response behavior test.
- Distinctive: line 22
Run frontend lint, type check, or build only when frontend files or the requested verification require them.
- Very specific: line 34
Do not restate what the framework already guarantees.
- Very specific: line 35
Do not write per-endpoint 401 tests.
- Very specific: line 39
Call every backend tool through uv run --no-sync from the repository root, so it comes from the dev dependency group instead of a global …
- Distinctive: line 48
Do not add another test runner or a custom parallel harness.
≈ “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.
Files
Lens Testing
Scope
Cover only critical, high-risk backend HTTP contracts: authentication and authorization, data persistence or loss, gateway protocol compatibility, and routing or failover behavior. A new route or reproducible bug alone does not justify a test; the affected HTTP contract must warrant the coverage.
Do not automatically add frontend tests or direct tests of units, services, helpers, converters, or repositories. Follow explicit user instructions when they change the scope.
Delete a test once the behavior it guarded is covered elsewhere, or once the field or option it pinned has been removed or derived.
Workflow
- Trace the affected HTTP path and decide whether it is a contract worth protecting.
- Reuse the nearest area file under
backend/tests/api/, plus fixtures and helpers inbackend/tests/conftest.py. - If coverage is justified, add the smallest request-and-response behavior test.
- Format touched files and run the smallest relevant check. For backend contract changes, run the API suite in parallel; narrow to one file only while debugging.
- Run frontend lint, type check, or build only when frontend files or the requested verification require them; CI remains the full repository check.
Conventions
One file per area, named backend/tests/api/test_<area>_api.py. Name each test after the behavior it asserts, and separate arrange, act, and assert with blank lines.
- Drive every test through the
clientfixture. A test that bypasses HTTP, by calling a service function directly or by hand-building aRequest, is testing an implementation detail. - Build state through the admin API with the shared fixtures
admin_headers,create_site,create_model_group,create_gateway_key, andcreate_site_group_and_key. Import helpers withfrom conftest import ...:valid_site_payload,gateway_headers,openai_chat_channel_id,seed_request_log,assert_error, andjson_response. - Stub only at the network edge, by monkeypatching
proxy_upstream._send_upstreamor by injecting anhttpx.MockTransportclient, so the gateway path under test still runs end to end. Never monkeypatch the function under test and then assert on its own return value. - Assert one invariant per test, and express variants with
pytest.mark.parametrizeandpytest.param(..., id=...)rather than copied test bodies. For schema rejection cases, parametrize a mutator that edits an otherwise valid payload. - Assert only what the HTTP contract promises. Response item order is not a contract unless the endpoint documents it; compare sorted values or sets instead.
- For protocol and streaming coverage, keep the upstream frames literal in the test, then assert both the converted client-visible body and the persisted request log.
- Do not restate what the framework already guarantees. Request and backup models inherit
StrictBaseModel(extra="forbid"), so one representative case per schema family covers rejected extra fields and missing required fields; do not add a case per field. - Do not write per-endpoint 401 tests.
test_every_admin_route_rejects_missing_tokenwalksapp.routesand covers the whole admin surface; when a new admin route is intentionally public, add it to_UNAUTHENTICATED_ADMIN_ROUTESin the same change.
Commands
Call every backend tool through uv run --no-sync from the repository root, so it comes from the dev dependency group instead of a global install.
- Format and lint touched files:
uv run --no-sync ruff format <paths>thenuv run --no-sync ruff check --fix <paths> - Backend suite:
uv run --no-sync python -m pytest backend/tests/api -q --confcutdir=backend/tests -n auto --dist worksteal - One file, while debugging:
uv run --no-sync python -m pytest backend/tests/api/test_<area>_api.py -q --confcutdir=backend/tests - Frontend checks, from
frontend/:pnpm lint,pnpm exec tsc --noEmit, andpnpm build
pytest-xdist and ruff ship in the dev dependency group; install them with uv sync --locked. With a package index mirror configured, --locked misreports lockfile drift, so use uv sync --frozen.
Do not add another test runner or a custom parallel harness.
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
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.

