Continuous integration is the practice of combining changes frequently and verifying the combined result. A CI pipeline should fail on a broken build, test failure, or violated policy, then report which check failed. It is not a production health monitor and cannot validate behavior that only appears after traffic reaches the service.
Continuous integration: test the merge candidate
Operational decision
A dispatch API pipeline first checks formatting and types, then unit tests, then an integration test against a temporary database. Parallelize independent checks, but do not promote an image before every required result is known. Pin tool versions and dependency resolution so rerunning the same commit has interpretable results. The shell block shows the order within one job; a real runner needs isolated services, timeouts, cache keys, and explicit permissions. A flaky test should be repaired or quarantined with an owner and expiry rather than retried until it passes. Save a test report and the exact source commit for later diagnosis. A merge gate is effective only if the protected branch actually requires the job.
set -euo pipefail
python -m ruff check src tests
python -m mypy src
python -m pytest -q tests/unit
python -m pytest -q tests/integrationCost and verification
A full integration suite on every edit may increase queue time and discourage small changes. Keep a fast mandatory layer and schedule longer checks where they still block release when relevant. Caches lower compute cost but can hide stale dependencies; key them by lockfile and toolchain. Do not interpret a green unit suite as proof that migrations, deployment configuration, or external contracts are correct. Test reports should identify skipped tests as well as passed ones.
Common Mistakes
- Do not let a flaky test pass by unlimited retry.
- Do not package before required gates complete.
- Do not forget to require the CI job in branch protection.
Connected lessons
- DevOps Tutorial
- Git change control: small merges and protected branches
- Immutable artifacts and release provenance
- Database change safety: expand, migrate, contract
Advanced follow-up
Advanced follow-up
Advanced follow-up
- Merge queue checks: test the combined commit that will land
- Selective CI: default to full verification when impact is uncertain
- Flaky tests: quarantine one failure mode with an owner and expiry
Related Prompt Engineering lesson: Prompt changes in CI: test the merge candidate.
