Skip to content

Checkpoint: A Release Gate

The Course
•
24 min study

Close the four earlier lessons and work from this brief. The workspace has an executable case table but an unfinished run function. Complete the rule before looking at the solution. Twenty-four minutes is a suggested first pass; split the work across sessions if you need more time.

The brief

Before the deploy pipeline promotes a new build of the Review Queue, it asks a release gate: may this build go to production? This isn't the readiness probe from earlier today. Readiness is asked of every running instance, every few seconds, and must answer from what that instance can see right now. The release gate is asked once per deploy, by the pipeline, and can depend on slower evidence gathered for that deploy:

  • schemaMatches: the database's schema version is the one this build expects (the migration from today's lesson has run).
  • probePassed: a smoke test against the new build, on a staging copy, passed.
  • restoreVerified: the latest backup was restored somewhere and checked. A backup that has never been restored is a hope, not a backup.

Return { release: true, blockedBy: [] } only when all three are exactly true. Otherwise return release: false and list every failed check in blockedBy, in the order "schema", "probe", "restore", so the pipeline can tell the person deploying what to fix. A missing field is a failed check.

Keep the function deterministic and leave its input unchanged. In the real project this rule would run in the pipeline script or a protected route handler that the pipeline calls; the table is a contract harness, not a substitute for testing that transport.

Acceptance cases

  • Input {"schemaMatches": true, "probePassed": true, "restoreVerified": false} → {"release": false, "blockedBy": ["restore"]}.
  • Input {"schemaMatches": true, "probePassed": true, "restoreVerified": true} → {"release": true, "blockedBy": []}.
  • Input {"schemaMatches": false, "probePassed": true} → {"release": false, "blockedBy": ["schema", "restore"]}.

Add one case of your own to examples: the least convenient input you can think of, such as an empty list, a missing field or a repeated value. Work out its expected result before you run it. The table's Input kept column must say yes on every row: the rule may not change what it was given.

Checkpoint workspace Next.js · 5 files
import "./globals.css"; export default function RootLayout({ children }) { return ( <html lang="en"> <body> <header> <strong>Review Queue · Practice lab</strong> </header> {children} </body> </html> ); } import Cases from "./Cases.jsx"; export default function Page() { return ( <main> <h1>A Release Gate</h1> <p> Read the input and predict the result before running. Change lib/contract.js for the exercise. </p> <Cases /> </main> ); } import { run, examples } from "@/lib/contract.js"; const text = (value) => JSON.stringify(value) ?? "undefined"; export default async function Cases() { const results = await Promise.all( examples.map(async ([input, expected]) => { // Record the input before running, to show whether run changed it. const before = text(input); const actual = await run(input); return { input: before, expected, actual, kept: text(input) === before, pass: text(actual) === text(expected), }; }), ); return ( <section> <h2>Executable cases</h2> <p> Checks: {results.filter((row) => row.pass).length}/{results.length}{" "} passed </p> <table> <thead> <tr> <th>Input</th> <th>Expected</th> <th>Actual</th> <th>Input kept</th> </tr> </thead> <tbody> {results.map((row, i) => ( <tr key={i}> <td> <code>{row.input}</code> </td> <td> <code>{text(row.expected)}</code> </td> <td className={row.pass ? "pass" : "fail"}> <code>{text(row.actual)}</code> </td> <td className={row.kept ? "pass" : "fail"}> {row.kept ? "yes" : "no: run changed it"} </td> </tr> ))} </tbody> </table> </section> ); } body { font: 16px/1.5 system-ui; margin: 0; color: #182b3c; background: #f4f8fc; } header, main { max-width: 900px; margin: auto; padding: 20px; } header { border-bottom: 1px solid #cbd5e1; } a { color: #075985; } button, input, textarea, select { font: inherit; padding: 8px; margin: 4px; } button { cursor: pointer; } table { border-collapse: collapse; width: 100%; } th, td { padding: 10px; border: 1px solid #cbd5e1; text-align: left; vertical-align: top; } pre, code { white-space: pre-wrap; overflow-wrap: anywhere; } .pass { color: #166534; } .fail, [role="alert"] { color: #a01818; } section { margin: 16px 0; padding: 12px; background: white; border-radius: 8px; } nav { display: flex; gap: 16px; } export function run(input) { // Implement the release gate from the brief. return null; } export const examples = [ [ { schemaMatches: true, probePassed: true, restoreVerified: false }, { release: false, blockedBy: ["restore"] }, ], [ { schemaMatches: true, probePassed: true, restoreVerified: true }, { release: true, blockedBy: [] }, ], [ { schemaMatches: false, probePassed: true }, { release: false, blockedBy: ["schema", "restore"] }, ], ];
Runs with real Next.js on your computer: unzip, then npm install and npm run dev.
Add and remove files here; write their code in the editor.
Hint 1: the idea

release is derived from blockedBy, not computed separately: if the list of failed checks is empty, the build may go. Computing both from one list means they can't disagree.

Hint 2: a first step

Write the three checks as data: pairs of a name and an input field, in the required order. Then keep the names whose field isn't exactly true.

Show one solution
One checkpoint solution Next.js · 5 files
import "./globals.css"; export default function RootLayout({ children }) { return ( <html lang="en"> <body> <header> <strong>Review Queue · Practice lab</strong> </header> {children} </body> </html> ); } import Cases from "./Cases.jsx"; export default function Page() { return ( <main> <h1>A Release Gate</h1> <p> Read the input and predict the result before running. Change lib/contract.js for the exercise. </p> <Cases /> </main> ); } import { run, examples } from "@/lib/contract.js"; const text = (value) => JSON.stringify(value) ?? "undefined"; export default async function Cases() { const results = await Promise.all( examples.map(async ([input, expected]) => { // Record the input before running, to show whether run changed it. const before = text(input); const actual = await run(input); return { input: before, expected, actual, kept: text(input) === before, pass: text(actual) === text(expected), }; }), ); return ( <section> <h2>Executable cases</h2> <p> Checks: {results.filter((row) => row.pass).length}/{results.length}{" "} passed </p> <table> <thead> <tr> <th>Input</th> <th>Expected</th> <th>Actual</th> <th>Input kept</th> </tr> </thead> <tbody> {results.map((row, i) => ( <tr key={i}> <td> <code>{row.input}</code> </td> <td> <code>{text(row.expected)}</code> </td> <td className={row.pass ? "pass" : "fail"}> <code>{text(row.actual)}</code> </td> <td className={row.kept ? "pass" : "fail"}> {row.kept ? "yes" : "no: run changed it"} </td> </tr> ))} </tbody> </table> </section> ); } body { font: 16px/1.5 system-ui; margin: 0; color: #182b3c; background: #f4f8fc; } header, main { max-width: 900px; margin: auto; padding: 20px; } header { border-bottom: 1px solid #cbd5e1; } a { color: #075985; } button, input, textarea, select { font: inherit; padding: 8px; margin: 4px; } button { cursor: pointer; } table { border-collapse: collapse; width: 100%; } th, td { padding: 10px; border: 1px solid #cbd5e1; text-align: left; vertical-align: top; } pre, code { white-space: pre-wrap; overflow-wrap: anywhere; } .pass { color: #166534; } .fail, [role="alert"] { color: #a01818; } section { margin: 16px 0; padding: 12px; background: white; border-radius: 8px; } nav { display: flex; gap: 16px; } const CHECKS = [ ["schema", "schemaMatches"], ["probe", "probePassed"], ["restore", "restoreVerified"], ]; export function run(input) { const blockedBy = CHECKS.filter(([, field]) => input[field] !== true).map( ([name]) => name, ); return { release: blockedBy.length === 0, blockedBy }; } export const examples = [ [ { schemaMatches: true, probePassed: true, restoreVerified: false }, { release: false, blockedBy: ["restore"] }, ], [ { schemaMatches: true, probePassed: true, restoreVerified: true }, { release: true, blockedBy: [] }, ], [ { schemaMatches: false, probePassed: true }, { release: false, blockedBy: ["schema", "restore"] }, ], ];
Runs with real Next.js on your computer: unzip, then npm install and npm run dev.
Add and remove files here; write their code in the editor.

The checks are a list of [name, field] pairs, so their order is the order of blockedBy, and adding a fourth check is one line. input[field] !== true treats false, a missing field and a truthy string like "yes" all as failed: the gate opens only on evidence. filter and map build new arrays, so the Input kept column says yes.

Before the next day

  1. Which layer owns this decision, and which layer translates it for the reader?
  2. What happens on the least convenient input, not only the happy path?
  3. What would you test in a real browser or server that this pure function cannot establish?

Was this article helpful?

Your response is saved on this device.