Capstone: the quality strategy
Write the strategy for 300 engineers and about 150 services: tiers, floors, owners and a twelve-month plan, backed by what one service can show and honest about what it cannot
You are Basile. Mehdi will read what you write, fund or cut it, and sign it. Engineering leads will read it to learn what is now expected of their teams. The deliverable is QUALITY-STRATEGY.md, at most eight pages. The lab, labs/testing, is still the checkout service: one service, measured honestly. You use it as evidence of what the methods can see, and you write what it cannot show about the other 149.
You have done most of the parts. The test strategy for a payments product was one product’s argument. This is the organisation’s, and it is a different kind of document.
What changes at organisation level
A product strategy ranks the risks of one thing and picks a level for each. That works because one team can hold the whole product in its head. Nobody can hold 150 services. So an organisation strategy does not decide what each team tests. It decides four things teams cannot decide alone:
Tiers. Which services get the most care, and by what rule. Money, identity and anything that cannot be undone sit in the top tier. Ojaline’s top tier is the 24 tier-1 services. Checkout, the seller wallet’s settlement job and the nightly capture sweep are in it. The rule is written down so a team can place its own service, and so an argument about tiers is an argument about the rule.
Floors. For each tier, the least a service must show before it ships: gate time, a flake limit, a mutation score on the code that handles money, a synthetic check, at least two named owners. A floor is a measurable promise, not advice. Anything above it is the team’s choice.
Who runs what. A central platform runs the shared parts: CI, sharding, the flake dashboard, the synthetic-check runner, canary tooling. Teams own the tests and the product strategy. Say which side owns each item and what a team gets for free. Without that, the programme is 150 teams building 150 half-finished versions of the same thing.
Pace. How quickly the floors rise. This is where most organisation strategies fail, so it gets its own section below.
The rest is the same craft you already have: risks, levels, gates, evidence, gaps. The difference is that you write it as defaults and rules that a thousand decisions can follow, and you accept that most will go unchecked unless the rules are measured by machines.
Tiers, with an honest cost
Tiering is a trade. A top-tier service pays in time: mutation runs, a canary, a synthetic check, an on-call owner. A bottom-tier service pays little and is allowed to break. The saving only exists if the bottom is real. A strategy that puts 120 services in tier 1 has chosen nothing.
Write the rule as questions with yes or no answers: does it move or hold money, does it touch identity or permissions, would an hour of downtime stop orders, can its output be recalled once it leaves. Two yeses and it is tier 1. You will be wrong at the margin, so add an appeal and a review date. A rule you can state in four lines gets used. Google’s testing chapter gets the same effect with test sizes: a small, medium or large label that a tool can read, so a policy can talk about all three without arguing about each test.
Floors you can check
A floor is only a floor if a script can read it. The lab gives you one measurable stand-in for each:
| Floor | What it protects | Where the lab shows it |
|---|---|---|
| Gate time at most 10 minutes | A developer waits for it many times a day | scripts/check.sh, 3 seconds here |
| Gate red for no code reason at most 1% of runs | The team believes a red build | the 20-run loop |
| Mutation score on money code at least 60% | The tests would notice a change | 41% on checkout/pricing.py |
| A synthetic check exists | Someone finds out when it breaks | scripts/synthetic_check.py |
| At least two named owners | One resignation does not orphan the service | not in the lab: the register says |
The numbers are yours to defend. 1% comes from Google’s report that tests begin to lose value as flakiness approaches it, which is a figure about Google’s suite, and your own flake data should replace it as soon as you have some. 60% for mutation is a choice. State why, and say which files it covers: money and pricing code, not generated code or glue.
Look at what the lab does to a floor. It passes the gate-time floor by a factor of two hundred, and that tells you nothing about a real service where the gate takes 25 minutes. It fails the mutation floor at 41%. And it cannot show the flake floor at all: 20 clean runs are consistent with a true rate near 12%. You need roughly 300 clean runs to support a limit of 1%. A floor check that prints PASS on 20 runs is lying, so the script you write prints UNPROVEN.
The ratchet
Run the checks on the day the policy is announced and suppose half the tier-1 services fail mutation. If the policy says 60% by Friday, teams will do one of three things: ignore it, write assertion-free tests to move the number, or lobby for exemptions. All three damage the signal you are trying to build.
A ratchet avoids that with two rules. No service may be worse than its own baseline, measured and dated, so a regression is red from the first week. And each tier’s floor rises on a published schedule, for example 40% at the end of quarter two, 50% at quarter three, 60% at quarter four. A service below the floor files a short plan with an owner and a date. The floor is then a thing people are moving toward, with an exception process that leaves a record.
The plan has to say what happens when the schedule slips. If the floor is missed by most tier-1 services, either the floor was wrong or the support was not enough. Decide beforehand which you will check first. You will usually find the support was not enough: a team that cannot run mutation in under ten minutes will not run it.
Levels, and who owns each
The organisation’s job on levels is to supply the machinery and set the default shape, not to count tests. CI at scale gave you sharding and test selection, and the central platform owns both. The simulation below is the one from that chapter: it shows why a policy that runs only what a change can reach needs one full run behind it.
// CI: only the tests next to the files that changed
const tests = changedFiles.flatMap((f) => testsByFile[f] || []);
// util.js changed -> util.test runs. billing.test never does.// CI: every test that depends on a change, directly or not
const affected = reverseClosure(changedFiles, importGraph); // visited set: cycles terminate
const tests = [...affected].flatMap((f) => testsByFile[f] || []);
// a file the graph does not know (package.json, CI config) -> run everything
// and a full run on merge, so a hole in the graph is caught on main, not in production The default shape for a service is small and medium tests on every change, a contract test for every provider or consumer you depend on, and a handful of end-to-end journeys that run on a schedule, not in the merge gate. The shape of a suite explained why. Tier 1 adds three things: invariants on money code (Testing money), fault-injection for each dependency (Testing across services), and a canary with abort rules written first (Testing in production). Ownership goes in a table: the service team owns its tests and its flake list, the platform team owns the pipeline and the dashboards, and a named person owns each tier-1 service’s synthetic check and who gets paged.
Metrics, flake budget and what to stop testing
You already have five metrics with their limits. At organisation level two more rules apply. Compare a service with its own past, never with another team, and never publish a league table: the first number someone is ranked by is the first one they will game. And give every metric a consumer who has to act on it. A dashboard nobody must answer to is decoration.
The flake budget becomes a company rule: one number, one way of measuring it, a consequence. For instance, a tier-1 service above 1% for two weeks stops merging feature work until the worst offenders are fixed or quarantined. Add the cost of a quarantine: a test on the list more than two weeks gets deleted unless an owner says why not. Flaky tests has the mechanism.
The strategy must also say what not to test. In an organisation this is a rule for review, not a list: a new test must name the risk it covers and fail if that risk appears. Page snapshots, mock call counts and tests of the framework fail that rule. Say it in one sentence so a reviewer can use it. The chapter What not to test covers the reasoning and the measuring.
Where to look for judgement
Four chapters earlier in this module are there to be used here: a history of testing ideas, what the research says about tests, reviews and defects, formal methods where they pay, and what not to test. The history tells you which of your proposals are old ideas with a new name. The research tells you how much weight your own metrics can bear. Formal methods tell you whether one of Ojaline’s tier-1 protocols, the settlement job’s retries for instance, deserves a model before more tests. The last one gives you the deletion rule above. If you have not read them, the lab below still works. Mark the places in your strategy where they would have changed an answer.
The same applies to AI. The failed share of deploys rose as AI seats arrived, and nobody knows whether that is cause or coincidence. Your strategy should not guess. It should say that generated tests are held to the same rule as any test, that review time is the scarce resource, and that the failed-deploy share is a metric to watch each quarter. Testing AI features covers the product side. AI agents in the test loop covers the agent side.
One source to carry with you: the Google SRE book’s chapter on testing for reliability. It makes the argument you rely on in tier 1: a passing test cannot prove a system reliable, only a failing one proves it is not, so monitoring in production complements testing and does not replace it.
What one service cannot show
This is the part of the document an experienced reviewer reads first. The lab can tell you what the methods measure and how large the numbers are on one service you can see. It cannot tell you:
- What the other 149 services look like. You will have one row in the register and 149 gaps.
- How teams respond when a number becomes a target. That needs a pilot with two or three teams before the policy goes company-wide.
- What the platform costs to run for 300 engineers, and who is on call for it.
- Whether the checkout team’s habits are typical. Checkout has a good test culture and a lab built around it.
- Whether a floor helps. It could be right and still cost more than the defects it prevents. The escape rate over a year says so, and the lab cannot.
Each of these has a source of truth: the service register, a pilot, the platform’s own cost, an incident review, a year of data. Name each, and give it an owner and a date.
Work in a throwaway copy. From the folder that holds labs:
rsync -a --exclude .venv --exclude .playwright-browsers --exclude data --exclude mutants labs/testing/ scratch-capstone/
cd scratch-capstone
ln -s "$PWD/../labs/testing/.venv" .venv
export CHECKOUT_DB="$PWD/scratch.sqlite"
mkdir evidence opsEvery command runs from scratch-capstone. No step starts a server, so ports 8094 and 8095 stay free.
If you did the payments-product strategy project: steps 1 to 4 below repeat its measurements, with the same file names. Copy its evidence/00-environment.txt, 01-check.txt, 03-mutation.txt, 04-flaky.txt and 05-seeded.txt into evidence/ here, keep its 02-shape.txt as the coverage figure, and go to step 5. Do not repeat the measuring: this chapter’s work starts where that one ended, with a register of many services and a floor for each.
1. Record the environment and the baseline. The date and versions go first.
echo "lab run on $(date -u +%F), $(.venv/bin/python --version 2>&1), pytest $(.venv/bin/pytest --version 2>&1 | awk '{print $2}')" | tee evidence/00-environment.txt
/usr/bin/time -p ./scripts/check.sh > evidence/01-check.txt 2>&1
grep -E "passed|ALL CHECKS|^real" evidence/01-check.txtlab run on 2026-11-23, Python 3.9.6, pytest 8.4.2
23 passed, 1 skipped, 1 deselected, 1 warning in 0.70s
ALL CHECKS PASSED
real 3.03Your date and times will differ. The whole gate, suite plus the smoke test that starts both services, takes about three seconds. A floor of ten minutes passes by a wide margin, which tells you the floor is not tested by this service at all.
2. Measure how thorough the tests are. Coverage for the package and the mutation score for checkout/pricing.py.
.venv/bin/pytest -q -p no:randomly --cov=checkout --cov-branch 2>&1 | grep -E "^(checkout/(pricing|orders|payments_client|api|legacy)|TOTAL)" | tee evidence/02-coverage.txt
.venv/bin/python scripts/mutate.py run 2>&1 | tr '\r' '\n' | grep -E '[0-9]+/[0-9]+ ' | tail -1 | sed -E 's/^[^0-9]*//' | tee evidence/03-mutation.txtcheckout/api.py 83 22 4 0 72%
checkout/legacy.py 20 20 8 0 0%
checkout/orders.py 40 4 10 2 88%
checkout/payments_client.py 26 14 4 0 40%
checkout/pricing.py 61 3 14 3 92%
TOTAL 442 79 66 10 80%
68/68 🎉 28 🫥 0 ⏰ 0 🤔 0 🙁 40 🔇 068 mutants, 28 killed, 40 survived: 41%, against 92% coverage (branch coverage on) on the same file. If you finished the ten-bugs project and your tests/ is stronger, quote yours and say so.
3. Measure flakiness. Twenty runs of the gate in random order, then twenty of the quarantined test. About 25 seconds.
f=0; for i in $(seq 1 20); do .venv/bin/pytest -q >/dev/null 2>&1 || f=$((f+1)); done; echo "gating suite red in $f of 20 runs (random order each time)" | tee evidence/04-flaky.txt
f=0; for i in $(seq 1 20); do .venv/bin/pytest -m flaky -p no:randomly -q >/dev/null 2>&1 || f=$((f+1)); done; echo "quarantined test failed $f of 20 runs" | tee -a evidence/04-flaky.txtgating suite red in 0 of 20 runs (random order each time)
quarantined test failed 14 of 20 runsThe gate was never red. The quarantined test failed 14 of 20 in this one run. Across all the runs taken while writing the course it failed about 35% to 60% of the time, varying from run to run, so quote a range and the number of runs. Twenty runs of the gate cannot tell 1% from 10%. Step 5 makes the script say so.
4. Ask whether the suite would notice a bug. The lab applies ten known bugs one at a time and reverts each.
.venv/bin/python scripts/seed_bugs.py try | grep "caught by" | tee evidence/05-seeded.txt
.venv/bin/python scripts/seed_bugs.py status | grep -c clean2 of 10 caught by tests/
10The starter suite catches 2 of 10, in about 15 seconds. The second line must print 10: every patch is reverted. If it does not, run .venv/bin/python scripts/seed_bugs.py revert all and check again. A strategy that relies on a gate catching bugs has to say how many it would catch. The lab gives you one measured answer for one suite.
5. Build the floor check and run it. The floor for tier 1 goes in ops/policy.json, one service’s measurements in ops/register.json, and a script compares them. The register row quotes your own evidence files. Nothing is entered for owners, because the lab cannot tell you who owns a service, and that gap is the point.
cat > ops/policy.json <<'JSON'
{
"tier1": {
"gate_seconds": {"max": 600},
"gate_red_pct": {"max": 1.0},
"mutation_pct": {"min": 60},
"owners": {"min": 2},
"synthetic_check": {"must_be": true}
}
}
JSON
cat > ops/register.json <<'JSON'
[
{
"service": "checkout",
"tier": "tier1",
"measured_on": "2026-11-23",
"gate_seconds": {"value": 3.03, "source": "evidence/01-check.txt"},
"gate_red_runs": {"red": 0, "runs": 20, "source": "evidence/04-flaky.txt"},
"mutation_pct": {"value": 41, "source": "evidence/03-mutation.txt"},
"synthetic_check": {"value": true, "source": "scripts/synthetic_check.py"}
}
]
JSONPut your own real time from evidence/01-check.txt in gate_seconds. Now create scripts/floor_check.py.
"""Compare each service in a register with its tier's floor.
usage: floor_check.py POLICY REGISTER [--total 150]
Prints one line per service and measure: PASS, FAIL, UNPROVEN or UNMEASURED.
UNPROVEN means the data cannot show the measure is inside the floor: for a rate,
the upper end of a one-sided 95% interval is above the limit. Exit 1 on any FAIL.
"""
import argparse
import json
import math
import os
import sys
Z = 1.645 # one-sided 95%
def upper_bound_pct(red: int, runs: int) -> float:
"""Wilson upper bound for a rate of red runs, in percent."""
p = red / runs
centre = p + Z * Z / (2 * runs)
spread = Z * math.sqrt(p * (1 - p) / runs + Z * Z / (4 * runs * runs))
return 100 * (centre + spread) / (1 + Z * Z / runs)
def judge(measure: str, rule: dict, entry) -> str:
if entry is None:
return "UNMEASURED"
if not os.path.exists(entry["source"]):
return f"UNMEASURED (source {entry['source']} not found)"
if measure == "gate_red_pct":
red, runs = entry["red"], entry["runs"]
high = upper_bound_pct(red, runs)
seen = f"{red} red in {runs} runs, 95% upper bound {high:.1f}%"
if 100 * red / runs > rule["max"]:
return f"FAIL {seen}"
return f"PASS {seen}" if high <= rule["max"] else f"UNPROVEN {seen}"
value = entry["value"]
if "max" in rule:
ok = value <= rule["max"]
return f"{'PASS' if ok else 'FAIL'} {value} (limit {rule['max']})"
if "min" in rule:
ok = value >= rule["min"]
return f"{'PASS' if ok else 'FAIL'} {value} (floor {rule['min']})"
ok = value == rule["must_be"]
return f"{'PASS' if ok else 'FAIL'} {value}"
def main() -> int:
ap = argparse.ArgumentParser()
ap.add_argument("policy")
ap.add_argument("register")
ap.add_argument("--total", type=int, default=0, help="services that exist, measured or not")
args = ap.parse_args()
policy = json.load(open(args.policy))
register = json.load(open(args.register))
counts = {"PASS": 0, "FAIL": 0, "UNPROVEN": 0, "UNMEASURED": 0}
for svc in register:
print(f"{svc['service']} ({svc['tier']}, measured {svc.get('measured_on', 'never')})")
for measure, rule in policy[svc["tier"]].items():
key = "gate_red_runs" if measure == "gate_red_pct" else measure
verdict = judge(measure, rule, svc.get(key))
counts[verdict.split()[0]] += 1
print(f" {measure:16} {verdict}")
print("totals: " + ", ".join(f"{k} {v}" for k, v in counts.items()))
if args.total:
print(f"register covers {len(register)} of {args.total} services: "
f"{args.total - len(register)} have no row at all")
return 1 if counts["FAIL"] else 0
if __name__ == "__main__":
sys.exit(main()).venv/bin/python scripts/floor_check.py ops/policy.json ops/register.json --total 150 | tee evidence/06-floor.txtcheckout (tier1, measured 2026-11-23)
gate_seconds PASS 3.03 (limit 600)
gate_red_pct UNPROVEN 0 red in 20 runs, 95% upper bound 11.9%
mutation_pct FAIL 41 (floor 60)
owners UNMEASURED
synthetic_check PASS True
totals: PASS 2, FAIL 1, UNPROVEN 1, UNMEASURED 1
register covers 1 of 150 services: 149 have no row at allOne service, five measures: two passes, one fail, one that the data cannot prove, one nobody measured. The last line is the strategy’s biggest gap, and the script prints it. The command exits 1 because of the failure. Your gate_seconds will match your own timing, and the rest should match.
6. Write the strategy. Create QUALITY-STRATEGY.md from the skeleton and fill every bracket. Cut anything that does not serve a decision. At most eight pages, about 3,000 words with the tables.
# Quality strategy: Ojaline engineering
Owner: Basile, principal engineer. Approver: Mehdi, director of engineering.
Reviewed: [date]. Next review: [date, at most 6 months].
## 1. Why now, and what success looks like in twelve months
[The failed-deploy share, the escapes you can name, and three outcomes with numbers.]
## 2. Tiers
[The four-line rule. How many services in each tier today, from the register, and how many are unplaced.]
## 3. Floors and the ratchet
| Measure | Tier 1 floor | Today (checkout, 1 of 24) | Schedule by quarter |
|---|---|---|---|
[Rows from policy.json; reasons for each number; the exception process.]
## 4. Levels, and who owns each
[Default shape, tier 1 additions, a table of owner by item: service team, platform, named person.]
## 5. CI shape
[Merge gate, nightly, release; what platform provides; where selection and sharding sit.]
## 6. Testing in production
[Canary, flag, synthetic check per tier; abort rules as numbers; who is paged.]
## 7. Metrics, flake budget and review rules
[Five metrics with their never-use-for; the flake budget with consequence; the rule for a new test.]
## 8. What the evidence cannot show
[The lab's one service against 150. One row per gap: the source of truth, the owner, the date.]
## 9. Twelve-month plan
| Quarter | Work | Owner | Success measure | Stop rule |
|---|---|---|---|---|
## Appendix: evidence index
[Each figure, its file in evidence/, the command, the date.]evidence/. The plan has four quarters, each item with an owner, a measure and a stop rule. Section 8 names at least five things one service cannot show.7. Review it against this rubric. Swap with a peer, or read yours cold after a day. Mark each line pass, partly or fail, with the sentence that earns it.
| # | Check | Pass when |
|---|---|---|
| 1 | Tiers are a rule | A team could place its own service from the four lines, without asking. |
| 2 | Every floor is checkable | A script could read each floor. None says only “adequate”. |
| 3 | The ratchet exists | No service must pass on day one; each floor has dates and an exception process that leaves a record. |
| 4 | Ownership is split | Each item says whether a service team, the platform or a named person owns it. |
| 5 | Figures trace | Every number has a file, a command and a date. A spot check of three finds all three. |
| 6 | One service is not the company | No lab number is presented as Ojaline’s. Section 8 says what a register and a pilot must supply. |
| 7 | Metrics have limits | Each says what it informs and what it must never be used for. |
| 8 | The plan can stop | Each plan item has a measure and a stop rule. |
| 9 | Judgement is marked | Where a module 5 chapter would have changed an answer, the strategy says so. |
| 10 | It fits | Eight pages or fewer, and a tech lead could say what changes for their team. |
Break it. The floor check trusts what the register says. In ops/register.json of your scratch copy, change "runs": 20 to "runs": 400 and run scripts/floor_check.py again. On the lab here the flake line changed from UNPROVEN 0 red in 20 runs, 95% upper bound 11.9% to PASS 0 red in 400 runs, 95% upper bound 0.7%, and nothing else stopped it: the script only checks that the source file exists, not that the file says 400. Ask who can type that number in your organisation, and what your strategy says should produce it instead (the pipeline, writing to a place the team cannot edit). Then change the source path to evidence/nope.txt and see UNMEASURED (source evidence/nope.txt not found). Put the numbers back when you are done.
8. Put the lab back. Everything ran in scratch-capstone, so the real lab is untouched. Copy QUALITY-STRATEGY.md, evidence/ and ops/ somewhere you will keep them, then cd .. and rm -rf scratch-capstone. rm -rf removes the .venv link without touching the real environment. Check git status in the real lab: it should show nothing new.
All companies and people in these examples are fictional. Any resemblance to a real business or person is unintended.