writing-tests

Enforces pytest and Vitest testing conventions for backend and frontend test authoring.

Updated Mar 30, 2026
One-click install
npx skills add https://github.com/ZaxbyHub/ragappv3 --skill writing-tests-zaxbyhub
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: writing-tests
Source: https://github.com/ZaxbyHub/ragappv3/tree/main/.opencode/skills/writing-tests
Command: npx skills add https://github.com/ZaxbyHub/ragappv3 --skill writing-tests-zaxbyhub

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Writing tests in this repository requires following strict conventions across two stacks — backend pytest/unittest with a SimpleConnectionPool dependency-override harness, and frontend Vitest with React Testing Library and jsdom — and violating them causes CI failures, vacuous regression tests, or false passes. ## Core Features & Use Cases - Backend test policy: Covers the SimpleConnectionPool + dependency_overrides harness, FK cascade seeding, CSRF bypass classification, conftest autouse fixtures, and the Python 3.11 event-loop trap. - Frontend test patterns: Provides Vitest fake-timer patterns, MemoryRouter wrapping, Radix Select and react-virtual mocks, and async reconnect-loop testing with mock sequencing. - Regression test verification: Requires stashing the source fix and confirming the new test fails on unfixed code, preventing test theater. - Use Case: When fixing a bug in a retry/backoff worker, load this Skill to learn that production code must re-check the shutdown flag after sleep, and that the test should stop the worker mid-sleep and assert queued work is dropped. ## Quick Start Load the writing-tests skill before writing or modifying any test, then follow its backend or frontend conventions for the file you are changing.

Frequently Asked Questions about writing-tests

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I write backend route tests with pytest and FastAPI dependency overrides?▼

Use the SimpleConnectionPool plus app.dependency_overrides harness: create a tempdir, run init_db and run_migrations, then override get_db, get_vector_store, get_current_active_user, and csrf_protect, restoring them in teardown. The canonical example is backend/tests/test_tags_routes.py.

How do I test async reconnect loops with Vitest fake timers?▼

Use vi.useFakeTimers with vi.advanceTimersByTimeAsync to advance past retry intervals deterministically, and prefer vi.waitFor over RTL's waitFor since it is fake-timer aware. Always call vi.useRealTimers before cleanup in afterEach.

Should this repo's frontend tests use Vitest or bun:test?▼

Use Vitest, not bun:test. Configuration lives in frontend/vite.config.ts, test files use the *.test.tsx pattern, and src/test/setup.ts mocks localStorage, confirm, and scrollTo.

Why do tests pass locally but fail in CI with missing lancedb or pyarrow?▼

CI installs requirements-ci.txt, which omits lancedb, pyarrow, and unstructured, so per-file stubs for those packages are load-bearing. Removing a stub breaks CI collection even though tests pass locally with full dependencies installed.

How do I verify a regression test is not vacuous?▼

Stash or revert only the source fix while leaving the new test in place, run it, and confirm it fails with the original bug. Then restore the fix and confirm it passes; a test passing on both versions is not a regression guard.

Why do I get 'no current event loop' errors running tests locally?▼

CI pins Python 3.11, and local Python 3.14+ fails some tests with 'RuntimeError: There is no current event loop'. This is a local artifact, not a regression; avoid manual asyncio.get_event_loop() in new tests.