Skip to content

Running the tests

Suite Command Needs
Python (core and API) uv run pytest -q Podman or Docker for the API tests; the system's expat library for rasterio (most systems have it; slim container images need libexpat1)
Live web services uv run pytest -q -m network Internet access; set KNOWTATION_SOURCE_CORESTACK_KEY to call CoRE Stack for real
Lint and format uv run ruff check . && uv run ruff format --check .
Web unit tests cd web && npx vitest run
Web type check and build cd web && npx tsc -p . && npx vite build
End to end podman compose up -d --build, then cd web && npx playwright test. The tests sign in as the admin from .env (or KNOWTATION_E2E_ADMIN_USERNAME and KNOWTATION_E2E_ADMIN_PASSWORD), once, in e2e/admin.setup.ts. They cover accounts (creating users, the starting password, invitations through the inbox, a public dataset without review controls, disabling and deleting users), the review flow, security headers, the api. and docs. hosts, with /docs/ and /api/docs staying on the app host while KNOWTATION_USE_SUBDOMAINS is off, the docs site (policy, no outside requests, search), accessibility (axe, WCAG 2 A/AA) on every page in light and dark, no sideways scrolling at 390, 768 and 1024 px, the sidebar across resizes, and a phone-width header that doesn't overlap The running stack; npx playwright install chromium once
Licences reuse lint REUSE tool

Database for the API tests

The API tests start a throwaway Postgres 18 with testcontainers. With rootless Podman they use unix:///run/user/<uid>/podman/podman.sock (turn it on with systemctl --user enable --now podman.socket) and set TESTCONTAINERS_RYUK_DISABLED=true themselves. To use an existing database instead, as CI does, set KNOWTATION_TEST_DATABASE_URL, for example postgresql+psycopg://knowtation:knowtation@localhost:5432/knowtation_test. The tests truncate its tables.

Generated files

Regenerate them, rather than editing by hand, after changing their source. CI fails if they are out of date.

File Source Command
packages/core/src/knowtation_core/model/generated.py schema/knowtation.yaml uv run python -m knowtation_core.model.regenerate
web/openapi.json, web/src/api/schema.d.ts The API routes and models cd web && npm run gen:api
docs/reference/database.md, .env.example, and the marked blocks (<!-- generated:… -->) in README, CONTRIBUTING and docs/ knowtation_api: the tables, the environment variables, the permissions uv run python -m knowtation_api.docgen (add --check to only list what is out of date)
testdata/* testdata/generate.py uv run python testdata/generate.py

No paid API calls in tests

LLM tests use Pydantic AI's TestModel and FunctionModel. The API accepts the model name test only when KNOWTATION_ALLOW_TEST_MODEL=true, which only the tests set.

Types, docstrings and the docs site

  • uv run pyright type-checks both packages (standard mode); it must report no errors.
  • uv run ruff check . includes the docstring rules (Google style): every public module, class and function needs a docstring.
  • scripts/build-docs.sh builds the documentation site into site/ with MkDocs (strict: broken links fail). It generates the data-model pages from the LinkML schema and the web client's pages with TypeDoc.
  • python scripts/check-module-size.py warns about modules over 400 lines.