November 12, 2026 · In Mercadito
A party where everything goes wrong
Eventos passed all its tests. Then we wrote another one that doesn't walk the happy path: two phones at once, the signal dropping, the guest who changes her mind. It found nine bugs in an afternoon.
Eventos is Mercadito's new module: an invitation on a page, the guest list with its RSVPs, a QR pass for whoever says yes and a scanner for whoever watches the door. It had over a hundred automated tests, all green. The trouble with those tests is that they're written by whoever wrote the code, and they walk what that person had already imagined.
So we wrote a different one, with a single rule: it's a party from end to end where almost everything goes wrong, the server may never answer with an internal error, nothing is counted twice and at the end the numbers add up. The host adds guests from four phones at once. A date says February 31st. The doorman's phone loses signal and resends the same entry five times. An aunt says yes, then no, then maybe.
The first run found nine things. The list is capped at 50 invitations, and with four phones adding at once it ended up with 54: each request counted how many there were, saw there was room and added, unaware of the other three. Same with photos: five uploads at once left 15 where 12 fit. An impossible date and a null character in a name brought the whole request down. And if the doorman undid a walk-in entry logged by mistake, that person stayed on the list as confirmed but never arrived.
// Contar y agregar van juntos, de uno en uno por evento.
// El cerrojo dura lo que dura la transacción.
export async function enLista(q, evento) {
await q("select pg_advisory_xact_lock(hashtext($1))", ["shotai:lista:" + evento]);
const [f] = await q(
"select count(*)::int as n from shotai.invitados where evento = $1 and origen <> 'puerta'",
[evento],
);
return f.n;
}None of the nine was hard to fix. What was hard was seeing them: they all live in the gap between two requests, or in the input nobody would type on purpose. The test stayed in the repository and runs with the rest. There are three suites now, and the chaos one is the one that has changed the code the most.