03 — Testing and verification
Chapter 03 separates two things that are easy to confuse. Tests are an automated safety net, run over and over — they make sure tomorrow’s change doesn’t break today’s. Verification is proof that this specific change does what it should — observed, not assumed. A passing test doesn’t yet mean the feature works in the browser; a manual check without tests doesn’t protect against a regression next week. That’s why both are mandatory.
A test in every commit — and how to write it
Every Commit — A saved, labelled point in the project’s history — a confirmation of a specific batch of changes. Small, described commits make a history you can return to any working state from. more in the glossary → that changes behavior carries a test. ↗
The default mode is TDD — Test-Driven Development: first you write a test (what you expect), then the code that satisfies it. The test stays in the project and guards that a change broke nothing — proof instead of “it probably works”. more in the glossary → — the test first, not after the fact:
- Red — you write a test describing the expected behaviour; it fails, because the behaviour doesn’t exist yet.
- Green — the smallest code change that makes the test pass.
- Refactor — tidy up while the suite is green (02).
A bug is fixed the same way: first a test that reproduces it, then the fix. The test stays in the project as a regression Guard — A test that enforces a project rule (e.g. “every module is in the AI_README”) and stops the commit when it’s broken. A rule without a guard is only a wish — a long session will break it in good faith. more in the glossary →, so the same bug doesn’t quietly return a month later. “I’ll add tests later” is a sin for the same reason as “I’ll document it at the end”: later never comes.
How to spread the tests — the pyramid from the reference project:
| Level | Tool | What it covers | When |
|---|---|---|---|
| Unit | pytest / Jest | pure logic: normalisation, matching, validators | on every commit |
| Integration | Supertest (HTTP) | routes, auth guards, JSON APIs | on every commit |
| E2E / browser | Playwright — A tool that drives a real browser in tests: it clicks, types and checks what’s on screen. It checks the app the way a user will see it — including on a phone profile. more in the glossary → | real paths in the browser, on a separate port | before a Deploy — Releasing a new version of the app “live”, where real people use it. It’s the moment a change reaches real people — which is why it happens only on an explicit “deploy”. more in the glossary →, on UI changes |
| Smoke | a script | “does the server come up and do N routes answer correctly” | after a restart, before and after a deploy |
Many fast unit tests at the base, few slow browser tests at the top.
Proof instead of a request
Show proof, don’t ask the user to check: ↗
After a change visible in the app, it’s the assistant that shows it works — not you who gets asked to click around and check. Proof looks like this:
- an HTTP code or redirect target —
curl -s -o /dev/null -w "%{http_code} %{redirect_url}" https://…; - an HTML fragment confirming the change — e.g. that Open Graph (OG) — Tags that decide how a link looks when pasted into Facebook, LinkedIn or a messenger (image, title, description). A good link card means more clicks — a bad one can show what you don’t want (e.g. a price). more in the glossary → now points to the right file;
- numbers from the database — how many accounts, how many prices, an
integrity_check: okresult; - a screenshot for visual changes.
“Done and verified” is said only once it really is verified — no hedging “probably”, but no bluffing either.
A smoke test that knows what it’s checking
Smoke test — A quick “does it even work” test right after a deploy — checks the most important paths (e.g. login). Catches disasters in 30 seconds before a user sees them. A cheap way to sleep well after a deploy. more in the glossary → check the right page, not just
200↗
A 200 only means the server sent something back — an error page, a blank page or the login page included. So a smoke test looks for a marker: an element that only appears on the right page. In the reference project the pricing page for an anonymous visitor was supposed to show a price-gate — the smoke test checked for it, not just the status code.
Login is tested from both sides: an anonymous visitor must be bounced to the login page, and a logged-in user must see the content. Testing only one side lets through a bug where everyone sees everything, or nobody sees anything.
Checking after the deploy — and fixing in the window
After a deploy, smoke the live server ↗
Tests in the Repository (repo) — A store of the whole project’s code together with its full history of changes — who changed what and when. The repo is the project’s memory: code, documentation and change history in one place. more in the glossary → don’t see the server’s configuration, its environment variables or Environment (dev / prod) — Separate places where the app runs: “dev” for safe tests, “prod” for real users. Dev is a playground, prod is where real users are — the rules for each are completely different. more in the glossary → data. So after a deploy, the smoke test runs on the live server — via localhost — The address a computer (or server) uses to connect to itself. On a server it lets you check the new version “from inside” before users see it. more in the glossary →, behind the Maintenance window — A short, planned period when users see a “work in progress” page while the database or configuration changes behind it. It guarantees the app never runs, even briefly, on half-changed data. more in the glossary →-page flag, before users are let back in.
If a trivial and safe bug shows up in that window, you fix it on the spot instead of releasing a known failure. That’s exactly how the reference project caught and fixed a pre-existing ERR_HTTP_HEADERS_SENT error on the map page — it only appeared in production, during the post-deploy smoke test.
An honest report — including what didn’t work
Report honestly: ↗
Tests failed — the report says so, with the output. A step was skipped — the report says it was skipped. A special case: a test that fails not because of a regression but because of data drift. An example from the reference project: a Fixture — Prepared data or state a test runs against (e.g. a small database with a few records). A test is only repeatable if it always starts from the same point. more in the glossary → with a recorded “85%” result stopped matching because production data had changed, while the code was correct. Such a failure has to be called by its name (“stale fixture, not a regression”), shouldn’t block the deploy, and comes with a proposed follow-up (refreshing the fixtures). Hiding it, or treating it as a regression — those are two different ways of writing a bad report.
Numbers from the source
Numbers come from the source ↗
Documentation ages and memory fails. A number in a report (“we have 1,240 accounts”) comes from a query to the database or a test result, not from an earlier note. SELECT COUNT(*) doesn’t lie; a sentence in an AI_README — A map file in every code directory: what’s here, what it’s for and what to watch out for — written for search. The assistant finds the right file with one search instead of reading the whole directory. more in the glossary → from a month ago might.
A guard proven on the real failure
A guard is proven by the incident, not by the fixture. ↗
A check written after an outage is written by the same head that let the bug through — and the fixture you test it with inherits the same blind spot. In the reference project a data-freshness guard passed nine green unit tests and then missed exactly the outage it was written for: the comparison was > where it should have been >=, and the frozen sources sat precisely on the threshold.
A guard that lets its own reference case through is worse than none — it turns an open question into false calm. So the order is: aim it at production or a copy of it, confirm it fires on the outage’s data, and only then freeze the threshold in a fixture — with a separate test exactly on the threshold.
Tests that survive a refactor and keep being run
Test the contract, not the implementation; keep the suite fast and deterministic ↗
A test tied to the implementation (internal function names, call order) breaks on every refactor even though the behaviour didn’t change — and teaches people to ignore red tests. A contract test checks what the module promises: input → output.
A slow or “flaky” suite (green one run, red the next) simply stops being run. Hence isolated I/O, fixed random seeds, and tests that share a port or database run one after another (in Jest: --runInBand while a dev server runs in the background). Red tests block Merge — Combining the changes from one branch into another. A merge brings in every commit from the source branch — other people’s too — so first you check what exactly comes in. more in the glossary → and deploying — otherwise they’re just decoration.
The default set of checks for websites
Web projects carry by default: ↗
This set has proven itself in practice — typically a few dozen test methods and a few hundred cases — and is worth carrying into every web project by default: SEO — Making sure search engines understand a site and show it high in the results. A site nobody can find effectively doesn’t exist. more in the glossary → meta on every page, Canonical — A tag that tells search engines which address is “the real one” for a piece of content. It prevents duplicates (e.g. the same product under several addresses) that split your Google ranking. more in the glossary → and hreflang — A tag that tells the search engine what language a page is in and where its versions in other languages are. Without it a multilingual site confuses Google — the language versions “fight” over the same phrase. more in the glossary →, structured data (JSON-LD — Structured data: a description of the page invisible to humans that the search engine reads (e.g. FAQ, author, breadcrumbs). Opens “rich snippets” in Google — richer results, higher CTR. more in the glossary →), colour contrast and keyboard navigation, language parity (a missing key or page in one language = a test that fails), no dead internal links, and every page actually building. This website has some of them: a PL/EN parity test for the chapters and a dead-link check after every build — they catch a missing language version or a link to nowhere before anyone outside sees it.