Automate releases without automating unsafe promotion
Ordinary software tests whether code behaves as expected. ML systems also depend on changing data, feature meaning, statistical behaviour, artifact compatibility, and delayed outcomes. A deployment can therefore have perfectly valid code and still produce a worse model.
CI, CD, and CT automate different parts of the lifecycle. Continuous integration validates changes; continuous delivery or deployment moves an approved release; continuous training produces a new candidate when an approved trigger justifies it. None of them means releasing every change automatically.
What You Will Be Able to Explain
- Design code, data, feature, model, and integration tests
- Separate CI, CD, and CT responsibilities
- Trace an evaluated release pipeline
- Stop deployment when a model regression test fails
- Explain why drift alone must not trigger blind retraining
What CI, CD, CT and release gates each mean
These terms name different responsibilities. Read the meaning before following them through the diagrams and worked example.
Core vocabulary
Testing creates gates across the entire ML contract
Code tests cover transformations, utility functions, and the inference interface. Data tests cover schema, ranges, missingness, category membership, timestamps, and duplicates. They answer different questions: correct function logic versus acceptable input.
Feature tests verify expected calculations, freshness, and parity between historical and serving paths. Model tests enforce minimum metrics, slice requirements, regression limits, and deterministic examples where appropriate. Integration tests load the real preprocessing and artifact together and exercise the endpoint contract.
ML tests protect more than application code
Which different contracts can fail before a model reaches users?
Each test layer protects a different contract
Follow the release path from a change to production
A complete release path is code or approved data change → tests → train candidate → evaluate → register → approve → shadow or canary → production → monitor. Each transition records evidence and retains the current production artifact until the new one proves safe.
CI, CD, and CT are related but distinct loops
What is integrated, released, and retrained?
CI, CD, and CT have different outputs
A training trigger is not permission to deploy
CT may start on a schedule, enough new labelled data, measured performance decay, or an approved drift investigation. Drift alone says the input distribution changed; retraining on corrupt, biased, or unlabelled data can make the system worse.
Worked Example: A valid dataset still produces a rejected candidate
Given: The incoming data passes schema, range, missingness, and duplicate checks. The current production model has recall 0.78 on the fixed release set. The candidate has recall 0.71; the required minimum is 0.75 and regression beyond 0.02 is prohibited.
- Data gate passes: the records are structurally acceptable. This says nothing yet about candidate quality.
- Training completes and produces a loadable artifact with recorded lineage.
- Minimum metric gate: 0.71 < 0.75, so the candidate fails.
- Regression check: 0.78 − 0.71 = 0.07 decline, which is greater than the allowed 0.02. It fails again.
- The pipeline records the failed evidence, does not promote the candidate, and leaves the current production version serving.
Result and interpretation: Deployment stops even though data validation and training succeeded. Layered tests prevent one kind of success from being mistaken for complete release readiness.
The following figures turn the example into an operational decision. Follow every branch and note which state is recorded before work continues.
A model regression test can stop an otherwise valid build
What happens when data is valid but candidate performance declines?
Encode the metric and regression checks that block a release
The label above each block states what it is. Runnable Python can be executed as shown with the standard library; pseudocode and configuration communicate architecture and require adaptation to a real platform.
Write separate data and model assertions
These checks show why a passing data contract cannot override a failed model gate.
def validate_rows(rows):
assert rows, "dataset is empty"
assert all(0 <= r["age"] <= 120 for r in rows)
assert len({r["event_id"] for r in rows}) == len(rows)
def validate_candidate(metrics, production_metrics):
assert metrics["recall"] >= 0.75
assert production_metrics["recall"] - metrics["recall"] <= 0.02
validate_rows([{"event_id":"e1", "age":41}]) # passes
validate_candidate({"recall":0.71}, {"recall":0.78}) # failsDescribe an evidence-driven CT trigger
The drift alert begins diagnosis. Candidate training starts only after evidence and approval satisfy the policy.
on drift_alert:
verify pipeline and source health
wait for sufficient outcome labels
compare production performance and required slices
if persistent material degradation is confirmed and retraining is approved:
train candidate
run all release tests
register and canary only if every gate passesChoose triggers, approvals and rollback conditions
- Choose tests from plausible failures and product risk, not only from easy-to-measure functions.
- Keep fixed release sets and golden cases versioned; refresh them through review rather than silently.
- Separate candidate creation from approval and traffic release.
- Automate reversible low-risk steps first; keep explicit approval where consequences or evidence uncertainty are high.
Failure Analysis and Recovery
Observed failure → likely cause → controlled response
Connect to Earlier Lessons
- Train/test split
Protect release evidence from training contamination.
- Model evaluation
Select metrics that match error costs.
- LLM evaluation
See additional testing concerns for probabilistic language systems.
Summary / Key Takeaways
- ML testing covers code, data, features, model behaviour, and integration because each can fail independently.
- A passing data contract proves structural acceptability, not that a trained candidate meets quality requirements.
- CI validates integrated changes, CD controls an approved release, and CT creates a newly trained candidate.
- Candidate creation, evaluation, approval, canary release, and production promotion are separate governed transitions.
- Drift is an investigation signal; automatic retraining on unverified data can amplify defects or bias.
- A candidate with recall 0.71 is correctly blocked when the minimum is 0.75, even though its data and artifact are valid.
- Every release pipeline needs explicit stop conditions, preserved evidence, a known-good production version, and tested rollback.