Delivery: A Repeatable Release · 25 min · free lesson

Validate Before Starting the Service

Reject invalid deployment configuration.

Core idea

A deployment configuration must fail before the service accepts traffic.

Diagram for Validate Before Starting the Service: a Rust code example flows to the lesson rule and the key observation.
The worked implementation exercises reject invalid deployment configuration. Its tests demonstrate the stated finite contract.

Understand it

A service can compile correctly and still fail because its deployment configuration is wrong. Parse the bind port, database address and operational limits before opening a listener. Report the failed field without echoing a password-bearing connection URL.

This lab accepts decimal ports from 1024 to 65535 and a nonempty database setting containing no whitespace. It rejects signed port syntax, surrounding whitespace and malformed numbers so accepted configuration is predictable. The database check here is intentionally syntactic; it does not prove connectivity, credentials or migration compatibility. The desktop service should perform those separate startup checks and expose readiness only after required initialization. A liveness endpoint and a readiness endpoint answer different operational questions.

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: Start cargo serve --port 8080 --database tasks.db. Refuse an invalid port, then check /health after successful startup.

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 config(port: &str, database: &str) -> Result<u16, &'static str> {
    if port.is_empty() || !port.bytes().all(|b| b.is_ascii_digit()) {
        return Err("port");
    }
    let n = port.parse::<u16>().map_err(|_| "port")?;
    if n < 1024 {
        return Err("port");
    }
    if database.is_empty() || database.chars().any(char::is_whitespace)
    {
        return Err("database");
    }
    Ok(n)
}

fn main() {
    assert_eq!(config("8080", "tasks.db"), Ok(8080), "case 1");
    assert_eq!(config("0", "tasks.db"), Err("port"), "case 2");
    assert_eq!(config("65536", "tasks.db"), Err("port"), "case 3");
    assert_eq!(config("+8080", "tasks.db"), Err("port"), "case 4");
    assert_eq!(config("8080", ""), Err("database"), "case 5");
    assert_eq!(config("8080", "bad path"), Err("database"), "case 6");
    assert_eq!(config("65535", "db"), Ok(65535), "case 7");
    println!("worked example passed");
}

The worked implementation exercises reject invalid deployment configuration. Its tests demonstrate the stated finite contract.

Practice starter

pub fn config(port: &str, database: &str) -> Result<u16,&'static str> {
    todo!("implement the contract")
}

Open local example in Playground ↗

Try it

Accept an ASCII-digit decimal port in 1024..=65535 and a nonempty database string without whitespace. Return port for port errors and database for database errors; validate the port first. 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

What does accepting a database configuration string prove?

Reveal the answer
  1. That every future request will succeed
  2. Only the declared syntactic policy
  3. That credentials and migrations work

Configuration parsing, connectivity and readiness are separate checks.

Go deeper

Common misconception: That credentials and migrations work

A deployment configuration must fail before the service accepts traffic.

  1. Identify the boundary: Reject invalid deployment configuration. Write down its accepted inputs and observable output.
  2. Exercise the failure: Configuration parsing, connectivity and readiness are separate checks.
  3. Check the independent caller: Accept an ASCII-digit decimal port in 1024..=65535 and a nonempty database string without whitespace. Return port for port errors and database for database errors; validate the port first.

Transfer challenge: Apply this contract to Task Ledger, introduce the failure described in the lesson, and show the failing check before fixing it.

Connections

  • Make Checks Block Delivery: Require all declared release checks
  • Bind an Artifact to Its Source: Verify release identity and digest metadata