
Understand it
Delivery continues after uploading bytes. A candidate can build successfully and fail a migration or readiness check in the target environment. Retain the previous active version while preparing the candidate, promote only after the required health evidence, and preserve a concrete recovery path.
The state transition in this lab receives the current version, candidate and readiness observations. Reject a blank candidate, an unchanged version or a candidate without successful required checks. On every rejection return the original active version; a partially configured candidate is not an active release. A real database migration may be irreversible, so reverting an executable is not automatically a schema rollback. Prefer compatible expand/contract changes and test recovery against actual persistent state. The capstone asks for an incident record showing the failing condition, observed data and successful recovery rather than a screenshot of a green pipeline.
The route project is Task Ledger: first keep a reproducible source history, then expose its data through a CLI and HTTP boundary, persist it in SQL, diagnose failures and prepare a release. This lesson owns one contract in that project. Run the worked example before changing the starter and explain which input makes the tempting shortcut fail.
Terminal practice: Run the capstone acceptance checks, introduce a failed readiness condition, retain the old version, and document the recovery.
The compiler lab is independent of the reading question. Edit solution.rs; the app supplies a separate caller with normal, empty and adversarial inputs. A successful unchanged demonstration does not prove your implementation. After the lab, apply the same contract to the route companion project. Its README separates the on-device adapter from the desktop Cargo/TCP profile.
Read the code
pub fn promote(
current: &str,
candidate: &str,
checks_ok: bool,
ready: bool,
) -> (String, bool) {
if !candidate.trim().is_empty()
&& candidate != current
&& checks_ok
&& ready
{
(candidate.to_owned(), true)
} else {
(current.to_owned(), false)
}
}
fn main() {
assert_eq!(
promote("v1", "v2", true, true),
("v2".to_owned(), true),
"case 1"
);
assert_eq!(
promote("v1", "", true, true),
("v1".to_owned(), false),
"case 2"
);
assert_eq!(
promote("v1", "v2", true, false),
("v1".to_owned(), false),
"case 3"
);
assert_eq!(
promote("v1", "v2", false, true),
("v1".to_owned(), false),
"case 4"
);
assert_eq!(
promote("v1", "v1", true, true),
("v1".to_owned(), false),
"case 5"
);
println!("worked example passed");
}
The worked implementation exercises keep a known-good version until the candidate is healthy. Its tests demonstrate the stated finite contract.
Practice starter
pub fn promote(current: &str, candidate: &str, checks_ok: bool, ready: bool) -> (String,bool) {
todo!("implement the contract")
}
Try it
Return candidate,true only for a nonblank changed candidate with checks_ok and ready both true. Every refused promotion returns current,false unchanged. Keep the public signature. Open the compiler lab and edit solution.rs; do not edit the private verification caller.
What success looks like: The separate caller accepts the changed solution and rejects unchanged TODO, a wrong implementation and a printed success message.
Check your understanding
A candidate fails readiness. Which version remains active?
Reveal the answer
- The failed candidate because it uploaded successfully
- No version; delete the previous artifact first
- The previous known-good version
Upload or build success is insufficient to replace an active service.
Go deeper
Common misconception: The failed candidate because it uploaded successfully
A failed readiness check preserves the previous active version.
- Identify the boundary: Keep a known-good version until the candidate is healthy. Write down its accepted inputs and observable output.
- Exercise the failure: Upload or build success is insufficient to replace an active service.
- Check the independent caller: Return candidate,true only for a nonblank changed candidate with checks_ok and ready both true. Every refused promotion returns current,false unchanged.
Transfer challenge: Apply this contract to Task Ledger, introduce the failure described in the lesson, and show the failing check before fixing it.
Connections
- Bind an Artifact to Its Source: Verify release identity and digest metadata