The projectSkills and evidence3 min read
Quality
Each guarantee is proven where it applies: on a real Postgres database, with tests that read the code, with a hash chain the daily check recomputes, and with a gate that checks every commit before production.
A test that mocks the database doesn’t prove what the database guarantees. So each rule is proven where it applies. A Postgres constraint is tested on Postgres. An architecture rule is checked in the source code. And a calculation rule is tested with a sweep, because three examples aren’t enough.
- test suites run against a real Postgres database
- 111
- apps/*/test/db/*.db.test.ts
- hand-written CHECK constraints, re-read on the database after every applied migration
- 169
- apps/erp/scripts/constants/db-invariants.ts#EXPECTED_CHECKS
- regression tests, most of which read the source code and reject any departure from a rule
- 92
- apps/*/test/*.regression.test.ts
Database guarantees are proven on a real database
The total of an order, the state of its payment, the direction of a stock movement: everything that touches money and the law is guaranteed by CHECK constraints, written by hand in the migrations. Except that a constraint nobody has ever tried may well refuse nothing at all.
So each constraint has its test on Postgres. It attempts the forbidden write and checks that the database refuses it. Often, it also checks that the database accepts exactly what the code computes. Another test reads the migrations and rejects a constraint that doesn’t have that refusal case. And after each migration is applied, pnpm db:invariants reads the list of expected constraints back from the database. If one is missing, or if there’s one the list doesn’t know, the migration’s release to production fails.
apps/erp/test/db/checks.db.test.ts · lines 198–218it("Order_total_check REFUSE un total qui n'est pas articles + livraison", async () => {
await expect(
db.order.create({
data: {
amountVatCents: 0,
amountItemsCents: 1_000,
amountShippingCents: 200,
amountTotalCents: 1_199,
termsVersion: "test",
termsAcceptedAt: new Date(),
email: `total-${Date.now()}@comportement.test`,
shippingName: "Cas",
shippingLine1: "1 rue du Test",
shippingZip: "44000",
shippingCity: "Nantes",
shippingCountryCode: "FR",
shippingMethodKind: ShippingMethodKind.PARCEL,
},
}),
).rejects.toThrow(/Order_total_check/);
});Further reading: Tests, Prisma migrations, ADR 0009.
If someone edits a payment, it shows, even with full privileges
The law requires point-of-sale software to make any change visible. The database already refused to let anyone update or delete a payment. Except that a trigger can be disabled without leaving a trace.
So when a payment is created, the database gives it a number with no gaps and a SHA-256 hash of its content, chained to the hash of the previous one. A trigger does this calculation, and the application doesn’t touch it. A query recomputes both chains every morning, and after every migration run in production. If someone touches a row, the chain breaks from that row on.
packages/db/prisma/migrations/20261025000100_encaissements_chaines/migration.sql · lines 32–37-- L'empreinte d'un maillon : celle du précédent, puis le contenu du maillon. Les dates sont
-- écrites en UTC, au millième, pour ne pas dépendre du fuseau de la session.
CREATE FUNCTION "cash_chain_hash"(previous text, payload text) RETURNS text
LANGUAGE sql IMMUTABLE AS $$
SELECT encode(sha256(convert_to(coalesce(previous, '') || '|' || payload, 'UTF8')), 'hex')
$$;Further reading: Payments that cannot be edited, ADR 0008.
Tests read the code and reject any deviation from a rule
Some rules can’t be checked by running a function: “every action that changes what the storefront displays invalidates its cache”, “every deferred block has its safety net”, “every server action opens with its guard”. In code review, you end up missing one.
So these rules are tests. They read the source code and fail on every deviation, with a message that says what to do. They also check that they aren’t running on nothing, and that their patterns really catch what they’re supposed to catch. They all run on every push to main.
apps/erp/test/cache-invalidation.regression.test.ts · lines 357–366it.each(INVALIDENT)("%s périme une entrée de cache", (name) => {
expect(
INVALIDATION_CALL.test(withoutComments(read(name))),
`${name} écrit une donnée que lit un scope \`"use cache"\` sans appeler de ` +
"helper d'invalidation : les entrées en cache serviraient l'ancienne valeur, " +
"sans un rouge nulle part. Si le geste a cessé de changer une surface cachée, " +
"DÉPLACER le fichier dans `SANS_INVALIDATION` avec sa raison — jamais retirer " +
"la ligne.",
).toBe(true);
});There are other examples: guarded actions, the storefront’s rights, deferred blocks. In the case study Tests that read the code in place of the reviewer, I explain where they come from and what they don’t see.
What goes to main is checked before production
A push to main deploys production. And the project has no hosted continuous integration, because its minutes were billed. Without a gate, a red commit would ship to production.
So the pre-push hook is what checks the pushed commit. It does it in a detached worktree, so uncommitted local files can’t make it pass. It checks secrets, the packages, the twins, the types of both applications, ESLint, the tests for the files touched and every test that reads the code. When the change touches something only the database can prove, the Postgres suite runs on a local database. When the storefront changes, the hook builds it and compares the weight of its JavaScript against a ceiling. And the production variables all have to be there.
This gate has its limits. It’s local, so git push --no-verify skips it. Some guards give way if you provide an attestation. It’s recorded, but nothing prevents it. And the end-to-end tests are only run by hand. Quality and delivery lists these limits.
Further reading: Git checks, ADR 0010.