Testing
Tests are how we build quality in instead of inspecting it afterwards (see Principles). A change isn’t done until it’s tested and CI is green.
Test-first by default
Our default is test-driven development:
- Write a test that describes the behaviour you want, and watch it fail.
- Write the simplest code that makes it pass.
- Refactor, with the test keeping you safe.
It’s most valuable where mistakes are expensive and behaviour is easy to describe:
- Detection rules: a test with the traffic or event that must (and must not) raise an alert. A false positive can stop a production line.
- Compliance controls: a test with a passing and a failing resource for each control.
- Bug fixes: first a test that reproduces the bug, then the fix. The bug can’t come back unnoticed.
Where tests live
| Kind | Where | How |
|---|---|---|
| Unit tests (Go) | Next to the code, as *_test.go files in the same package | make test |
| Integration tests (Go) | The PostgreSQL layers in backend and intel | Run against a real PostgreSQL database with the migrations applied, not mocks |
| Detection rules | agent/internal/network/detection/rules | One test file per rule or family of rules |
| Compliance controls | backend/internal/platform/risk/controls | Tests per control |
| Frontend | No automated tests yet: lint and a production build only |
Prefer testing behaviour through public functions over testing private details, so refactoring doesn’t break tests that should still pass.
What CI checks
Every pull request runs the CI workflow. All checks must pass before merging:
| Job | Checks |
|---|---|
| Backend | make build, database migrations for backend and intel, then make test |
| Backend / Lint | golangci-lint |
| Frontend | yarn lint and yarn build |
| PR Title | The title follows Conventional Commits |
If CI fails on main, fixing it comes before any new work.
Before you open a pull request
- Run
make testlocally for the parts you changed. - Add or update tests for the behaviour you changed. A PR that changes behaviour without touching a test needs a reason in its description.
- Don’t skip or delete a failing test to get CI green. Fix it, or open an issue and explain why in the PR.
Gaps we know about
- Frontend: no automated tests. Until we add them, test UI changes by hand and describe what you checked in the PR.
- End-to-end: no automated tests of a full deployment (sensor to console). New plant deployments follow the New Plant Deployment checklist.