Specx tests

From maksimzayats/specx · View interactive version

Specx tests is an AI agent skill from the GitHub repository maksimzayats/specx. Add or refine tests for specx Python services. Use when creating unit tests for use cases/services, integration tests for FastAPI controllers or infrastructure adapters, e2e smoke tests, architecture import guardrails, DI override tests, pytest fixtures, or coverage and boundary checks.

How to use this skill

Skill file

specx Tests

Use this skill when behavior, wiring, or architecture boundaries need tests.

Read references/testing.md before creating test files.

Test Layers

helpers only. This is not a test suite and does not hold project-specific

doubles.

fresh application container returned by the project's get_container().

tests call resolved use cases against the transactional DB; delivery

integration tests exercise HTTP mapping; migrations prove Alembic behavior.

specx.testing.architecture.assert_specx_architecture wrappers for genuinely

project-specific extra rules. Standard packaged rules run through

uv run specx check.

Rules

and capabilities.

tests/unit/core/tasks/services/test_title_service.py.

target harnesses.

tests and any project-wide test overrides. tests/integration/conftest.py

owns the transactional DB-backed container fixture for integration tests.

before resolution, then call container.resolve(Target).

module-local container fixture may register it before returning the

container.

them. When the same double is reused by multiple unit modules, put it in a

mirrored

tests/unit/core/<scope>/{capabilities,gateways,repositories}/fake_<source_module>.py

file.

_scenarios.py, fake modules outside those mirrored unit port/capability

packages, or double classes in conftest.py.

behavior needs to be changed for that scenario. Prefer autospeccing when

call signatures matter and spec_set when unexpected attributes must fail.

and framework resources with local doubles or inline mocks.

cases, services, or capabilities; stub only external systems when needed.

use cases that inject a UoW manager; delivery tests should own HTTP mapping,

not be the only persistence proof.

dialect behavior matters. A rollback harness may not replace isolated

commit-visible tests for locking, concurrency, isolation, or after-commit

behavior.

services and use cases.

Delivery probe tests cover /healthz and /readyz as operational endpoints,

not versioned business API routes. /healthz must prove a lightweight

process response only; /readyz must prove required infrastructure readiness,

including a real bounded DB check for SQLAlchemy services.

503, probe routes are excluded from OpenAPI, and legacy /api/v1/health is

absent when replacing old generated health endpoints.

monkeypatching logging.config.dictConfig, and asserting the generated

stdlib config. Use caplog only when a log record is meaningful behavior.

resources and asserting shutdown order. Route integration helpers must run

ASGI lifespan explicitly.

tests. Enter LifespanManager, then pass the yielded manager's manager.app

to ASGITransport so request scopes receive lifespan state.

constants, not raw integer literals.

when the resolved use case has an async execute(...); use

await container.aresolve(...) only when DI construction itself has async

providers.

under test. Do not bundle unrelated mocks in a dict or class-keyed fixture.

diwire.integrations.pytest_plugin, and do not use Injected[...]

parameters in tests.

graph is asyncio-specific, override the top-level anyio_backend fixture to

return "asyncio"; leave it unpinned only when the suite intentionally

supports every installed backend.

returns an instance.

from the container; local test doubles may be instantiated in the test module

before registration.

boundaries such as docstrings, use-case inputs, UoW injection, route paths,

direct persistence dependency rejection in use cases, container imports,

and AGENTS.md command coverage.

[tool.specx].ignore and a project reason recorded beside the configuration.

enable technology-specific families explicitly with

[tool.specx].extend-select; FastAPI projects select fastapi.

built-in SpecxRuleId; use the programmatic wrapper for those projects.

references/render_architecture_guardrails.py to render the tiny wrapper.

Code Style

Use blank lines as logical separators in all code. Keep related statements

together, but separate independent setup, action, assertion, response, branch,

and transformation groups so long blocks stay readable.

References

and architecture guardrail snippets.

the tiny specx architecture wrapper.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.