Testing & quality
ContentsVision has one firm, non-negotiable rule, written at the top of the repo's CLAUDE.md:
Run the full test suite after any change to the app, and all tests must pass before the work is considered done. A change with no test is incomplete.
This page explains how to run the suite and why it is built the way it is.
Running the tests
One command, from the repo root:
./run_tests.sh # run everything
./run_tests.sh -k billing # only tests matching "billing"
./run_tests.sh -x # stop at the first failure
run_tests.sh activates the backend virtualenv, installs the test-only dependencies once (pytest, pytest-asyncio), and runs pytest from backend/. Any extra arguments pass straight through to pytest.
Offline by design
The suite must stay fast, offline, and safe to run anytime. Three guarantees make that true (backend/tests/conftest.py):
- A throwaway in-memory database.
DATABASE_URLis forced tosqlite+aiosqlite:///:memory:before the app is imported, and each test gets a fresh engine. The real dev database atstorage/inventory.dbis never opened. - No third-party calls. The suite never reaches the AI on OpenRouter, transcription on Deepgram, the Adjust Square API, Contents Estimation, Contents Capture, PostHog, or Sentry. Anything that needs an external service mocks that layer. PostHog analytics is simply off in tests (no key is set), so
core/analytics.pyno-ops without even importing the SDK.conftest.pyalso blanksSENTRY_DSNandCONTENTS_CAPTURE_API_BASE_URLbefore the app is imported, so a developer's.envcannot initialise a real Sentry SDK or point the suite at Capture, and blanksLOCAL_AUTH_USER_EMAILso the local auth bypass cannot skip real token validation. The one test that does touch the network is the opt-in Contents Estimation wire check (below), skipped unless you set its variables. - A developer's real credentials cannot leak in.
conftest.pysetsCONTENTSVISION_IGNORE_MACHINE_ENV=1, which drops~/.contentsvision/local.envfrom the settings sources entirely (see where a value comes from), and separately blanksMAILGUN_API_KEY,MAILGUN_WEBHOOK_SIGNING_KEY, andSLACK_WEBHOOK_URLas real environment variables, which outrank both.envlayers.
The machine-wide file exists so a developer can set a shared local credential once. The first time a working Mailgun sending key was put in it, ./run_tests.sh picked it up and a test run sent live email through the team's Mailgun account, because test_the_adjuster_invites_the_insured exercises the real send path and had until then only ever seen an unconfigured one.
Opting out of the whole file is deliberate, rather than blanking known keys one at a time: it also covers every credential added to that file in future. test_settings_layering.py guards both halves, and asserts directly that insured_email.email_enabled() and support_email.support_email_enabled() are false inside the suite.
The rule this incident illustrates: a test that exercises a real sender must not depend on the sender being unconfigured by accident. If you add an outbound channel, switch it off in conftest.py in the same change.
The test client (conftest.py) seeds a team and a user and mints a valid AdjustSquare-format token with make_test_token, so auth-protected endpoints work without hitting real SSO. The get_db dependency is overridden to share the in-memory engine, so data seeded directly is visible to API calls.
What the suite covers
The backend/tests/ directory has broad coverage: claim and room APIs, the inventory API, uploads (chunked and batched photo), jobs and job recovery, billing (unit, API, and the external prepaid service), auth and the local auth bypass, cross-tenant scoping (test_tenant_scoping.py), the admin pages, auto-approve, numbering, the Adjust Square client and submissions, Contents Estimation (payloads, API, billing, SSO hand-off), Contents Capture (import, webhook, provisioning, automatic processing, claim creator), the Enterprise product access push and its enforcement (test_product_access.py), the insured inventory link and its email, PDF import, observability, telemetry and Sentry (test_sentry.py, plus test_frontend_sentry_issues.py for the browser side), PostHog analytics, Slack notifications, prompt settings, the settings layering, the activity log and service, audio and video helpers, audio chunking, an end-to-end pipeline test with the AI layer mocked, the hierarchy config resolver and hierarchy API (test_config_resolver.py, test_hierarchy_api.py), access profiles (test_access_profiles.py), claim assignment (test_claim_assignment.py), saved views and tags (test_saved_views_and_tags.py), custom dashboards (test_custom_dashboards.py), training (test_training_api.py, test_training_modules.py, test_training_basic_module.py, plus frontend checks for the builder and training windows), test_customer_content_no_customer_names.py (the Help Center and customer changelog must not name a customer), and the Help Center (test_help_guides.py: playable guide step logic and content validation via node --test, every guide target existing as a data-guide attribute, and screenshot resolution) plus test_help_screenshots.py, which fails when an article references an image the screenshot job does not produce, or public/help holds an image no article uses. Some frontend logic is unit tested with node --test (frontend/src/lib/*.test.mjs) and run from pytest, skipping when Node is absent. test_frontend_typecheck.py runs tsc --noEmit on the whole frontend whenever frontend/node_modules is installed (skipping otherwise): next build on the Forge deploy runs the same check and fails the deploy on one type error, and no pipeline step checks it first. test_frontend_typecheck.py also pins the specific Sentry breadcrumb typing that once broke a stage deploy. Tests are configured in pytest.ini (async auto-mode, verbose one-line-per-test output driven by each test's docstring).
The opt-in Contents Estimation wire check
Every other test mocks app.services.contents_estimation, so nothing in the default run proves the two apps still agree on URLs, fields and status codes. test_contents_estimation_live.py does, against a real, local Contents Estimation. It is skipped unless both CE_LIVE_BASE_URL and CE_LIVE_KEY (that instance's per-team intake key) are set, so ./run_tests.sh alone never runs it. It creates a claim on the other side, so never aim it at production.
CE_LIVE_BASE_URL=http://127.0.0.1:8099 CE_LIVE_KEY='cek_...' \
./run_tests.sh tests/test_contents_estimation_live.py
A skip is easy to miss in a summary line, so any run that skips it prints a banner naming what did not run (tests/wire_check.py, printed from conftest.py). Setting CE_LIVE_REQUIRED=1 turns the skip into a failure, which is the gate to run before promoting stage to main. test_wire_check_gate.py covers those rules.
Conventions
- Add or update tests with every change. A feature or fix includes its test.
- Show real failures. If a test fails, show the actual failing output. Never claim green when it is red.
- Keep the default suite offline. Anything that needs a real external service must be mocked, or gated behind an explicit opt-in marker so
./run_tests.shnever touches the network.
Mocking the external layers
Because the pipeline and Adjust Square client are isolated services, tests mock at their boundaries:
- The AI analyzer functions (
claude_analyzer) are patched to return canned items, so the pipeline can be exercised end to end without a real model call. - The Adjust Square client functions are patched to capture the arguments they are called with (for example, asserting the right bearer token and adjuster id are passed) and to return fake responses.
This keeps tests deterministic and instant while still covering the real control flow. For the broader engineering conventions (UI, motion, writing style), see conventions.