145 lines
9.1 KiB
Markdown
145 lines
9.1 KiB
Markdown
# Testing
|
|
|
|
[Русский](../ru/TESTING.md)
|
|
|
|
Choose checks for the change. Unit tests cover rules, integration tests exercise real dependencies, and browser E2E tests exercise user actions. Run commands from the repository root.
|
|
|
|
## Commands
|
|
|
|
| Area | Command | Requirements |
|
|
| --- | --- | --- |
|
|
| Backend, fast tests | `make -C backend test-fast` | Go |
|
|
| Backend, race | `make -C backend test` | Go and a C toolchain |
|
|
| Backend, integration | `make -C backend test-int` | Go, Python 3, Docker |
|
|
| Frontend | `make -C frontend check` | Node.js, pnpm, installed dependencies |
|
|
| ML API | `make -C ml verify` | Python, uv, installed dependencies |
|
|
| Contracts | `make -C api check` | Installed API tools |
|
|
| OpenAPI 3.2 generators | `make -C api check-toolchain` | Go, frontend, and ML toolchains |
|
|
| Technical smoke | `make -C deploy smoke` | Docker Compose |
|
|
| Browser E2E | `make -C deploy test-e2e` | Docker Compose, frontend dependencies |
|
|
| E2E with mail | `make -C deploy test-e2e-registration` | The same dependencies |
|
|
| Documentation | `make docs-check` | Python 3 |
|
|
|
|
`make test` runs service tests. `make check` adds formatting, lint, types, builds, and configuration checks. `make verify` also generates code and checks drift, the OpenAPI toolchain, backend race tests, integration tests, and smoke.
|
|
|
|
Playwright, security scanners, real ML models, and the runner sandbox have separate checks. Passing `verify` does not replace them.
|
|
|
|
## Backend: unit and race
|
|
|
|
Tests next to source files cover domain/usecase behavior and adapters without external infrastructure. Use configured mockery mocks or small behavior-specific fakes for ports.
|
|
|
|
```sh
|
|
make -C backend mocks
|
|
make -C backend test-fast
|
|
make -C backend test-race
|
|
```
|
|
|
|
For a changed workflow, cover success, domain rejection, and dependency failure. Concurrent operations need version, retry, and cancellation checks. Assert results and persisted effects rather than incidental internal call order.
|
|
|
|
## Integration tests
|
|
|
|
Tests in `backend/integration_test/` use the `integration` build tag and Testcontainers with real PostgreSQL, Redis, SeaweedFS, and explicitly selected Kafka.
|
|
|
|
```sh
|
|
make -C backend test-int-compile
|
|
make -C backend test-int-list
|
|
make -C backend test-int
|
|
```
|
|
|
|
`test-int-compile` compiles without containers; `test-int-list` lists selected top-level tests. Neither command proves that scenarios passed. `test-int` requires working Docker and fails if it is unavailable.
|
|
|
|
### Shared bootstrap
|
|
|
|
In `bootstrap_test.go`, `bootstrap(t)` starts PostgreSQL, Redis, and SeaweedFS, applies migrations, and returns configuration and clients. Select only what a test needs, for example `bootstrap(t, postgresService)` or `bootstrap(t, postgresService, kafkaService)`.
|
|
|
|
Each call owns its containers and dynamic ports. `t.Cleanup` releases resources, including after startup failures. Call bootstrap in a parent test and share its environment with subtests; keep neighboring tests' data isolated.
|
|
|
|
Shared helpers create pools, separate databases, and Kafka topics. Use them instead of duplicating container setup. Add the HTTP server and domain fixtures for the specific scenario.
|
|
|
|
For SQL, check real transactions, constraints, and migrations. For outbox and events, check repeated delivery and recovery after failure. For data access, cover allowed requests, another account/organization, and revoked permission.
|
|
|
|
`TestCompanyQuota`, `TestHoldings` and the holding migration test check real PostgreSQL quotas: window boundaries, retries, the shared E0 pool, concurrency, policy changes and guarded rollback. Separate HTTP tests cover invitation sending, company isolation and immediate contact closure after revocation.
|
|
|
|
### Shards
|
|
|
|
`backend/scripts/run-integration-suite.py` discovers tests and distributes a sorted list. A top-level test and all its subtests stay in one shard. Indexes start at 1; set both variables together.
|
|
|
|
```sh
|
|
TEST_SHARD_INDEX=1 TEST_SHARD_TOTAL=2 make -C backend test-int-list
|
|
TEST_SHARD_INDEX=1 TEST_SHARD_TOTAL=2 make -C backend test-int
|
|
TEST_SHARD_INDEX=2 TEST_SHARD_TOTAL=2 make -C backend test-int
|
|
make -C backend test-scripts
|
|
```
|
|
|
|
With no variables, the whole suite runs. CI uses two shards. `test-scripts` checks distribution coverage, test selection, and failure propagation. Distribution is deterministic but does not balance individual test durations.
|
|
|
|
## Frontend
|
|
|
|
Vitest runs in Node and checks logic, data transformations, and components in its available environment. Browser specs in `frontend/e2e/` are excluded from this run.
|
|
|
|
```sh
|
|
make -C frontend test
|
|
make -C frontend typecheck
|
|
make -C frontend check
|
|
```
|
|
|
|
`check` includes formatting, ESLint, Stylelint, types, Vitest, FSD boundaries, and a production build. MSW and replaced API responses verify frontend behavior, not server authorization or persistence.
|
|
|
|
## Browser E2E suite
|
|
|
|
```sh
|
|
make -C frontend install
|
|
make -C deploy test-e2e
|
|
make -C deploy test-e2e-registration
|
|
```
|
|
|
|
Both commands create a throwaway Compose project with its own secrets and volumes. The browser reaches the application through Nginx. The script removes test containers and volumes on exit; results remain in `frontend/test-results/e2e/`.
|
|
|
|
Ordinary `test-e2e` disables mail. It runs technical and available UI scenarios while skipping tests that require mail and special fixtures. `test-e2e-registration` enables a local Resend-compatible receiver and synthetic data for registration and business flows. It does not send mail through real Resend.
|
|
|
|
The suite contains two kinds of checks:
|
|
|
|
- Real backend flows: registration, profile, questionnaire, organizations, hiring needs, search, invitations, and the minimal path in `acceptance-path.spec.ts`. The mail stand enables their fixtures.
|
|
- API replacement through `page.route`: screen states, errors, conflicts, and parts of assessment and accessibility scenarios. These tests verify browser behavior in the supplied state.
|
|
|
|
Playwright runs Chromium with one worker and no retries. The real-bank search runs first so other specs cannot change its results. The configuration accepts only a loopback stand address.
|
|
|
|
Inspect the HTML report, trace, and screenshot on failure. Report passed, failed, and skipped counts: a green run with a required scenario skipped does not complete its acceptance. Never point E2E at a shared or production stand.
|
|
|
|
### Demonstration flow acceptance
|
|
|
|
Before presenting, run `make docs-check`, `make -C deploy check`, smoke and the mail-enabled E2E suite. `acceptance-path.spec.ts` must pass the full test with a `synthetic_demo` category, publication, search with an explanation, invitation, C4 and contact disclosure; repeated acceptance must not create duplicates, and revocation must close contact access. A skipped spec is not acceptance.
|
|
|
|
Match the evidence to the deployed commit or images. A local mail fixture does not demonstrate real Resend delivery, local Nginx does not prove external HTTPS, and a synthetic bank does not establish grade accuracy. For a release, repeat smoke and E2E on the fixed images as described in [DEPLOYMENT.md](DEPLOYMENT.md).
|
|
|
|
## ML and models
|
|
|
|
`make -C ml verify` checks formatting, Ruff, mypy, pytest, packaging, the contract, and Pydantic model drift. Ordinary tests are separate from slow checks using real weights.
|
|
|
|
```sh
|
|
make -C ml model-fetch
|
|
make -C ml test-model
|
|
```
|
|
|
|
`model-fetch` downloads pinned Giga and Qwen3 embedding files and checks SHA-256; it requires access to the weight source and disk space. `test-model` compares real models with research vectors; set `ML_TEST_DEVICE=cuda` for a GPU. This checks inference reproducibility, not matching quality for real candidates.
|
|
|
|
## Runner and labs
|
|
|
|
`make -C runner check` and `make -C labd check` check the Go modules. Their unit tests need neither a running sandbox nor LXD.
|
|
|
|
Real runner, isolation, and lab checks run separately in environments intended for testing. [runner/](../../runner/README.en.md) and [labd/](../../labd/README.en.md) describe their requirements and commands. Results from a local development container do not establish isolation of the deployed runner.
|
|
|
|
## Contracts, infrastructure, and security
|
|
|
|
After an API change, run `make generate`, check its consumers, and run `make check-generated`. For intentional output updates, review and commit the expected diff together with its source.
|
|
|
|
`make -C deploy check` validates configuration and supporting scripts. `smoke` checks infrastructure readiness and HTTP routes; `perimeter-test` checks Nginx rules using throwaway containers. Neither replaces a business flow. `make -C observability check` validates monitoring configuration.
|
|
|
|
`make security` checks dependencies, source, and secrets; `make security-images` builds and scans images. [security/](../../security/README.en.md) explains tool installation and reports.
|
|
|
|
## Reporting checks
|
|
|
|
Record the command, checked commit or diff, outcome, and relevant limitations. Preserve a reproducible failure case without secrets. Assessment validity, matching quality, and performance need separate datasets, methods, and measurements.
|
|
|
|
An old result does not verify a new commit. Health checks do not prove business flows, synthetic categories do not establish grade validity, and a replaced dependency does not prove the real service works.
|