A rules popup that cannot lie about its numbers: how Lullwood builds "Be the rescuer"
Lullwood’s “Be the rescuer” popup lists what a run has to meet to take first place on the leaderboard. Three of its numbers are read, not typed: they come from the constants the leaderboard server enforces, so those numbers cannot drift from the check. The sentences around them are hand-typed, and this post is about where that line falls.
We build Lullwood, a free browser horror game, in three.js and Next.js. This post reads one small function from our source at commit 0698b3f, the head of our release branch when we wrote it, and says what it protects against and what it does not. Line numbers are for that commit.
The function
rescuerRules is in lib/game/rescuerRules.ts (L14-28). It returns eight strings, in the order a player meets the rules. The popup in components/GameMenu.tsx maps them straight into a list (L138). Here it is, with five of the eight strings replaced by comments. The three left in are the first rule, for orientation, and the two that read a constant.
export function rescuerRules(recordTimeMs: number | null): string[] {
const floorSeconds = (PLAUSIBILITY_FLOOR_MS / 1000).toFixed(1);
return [
'Play on Blackout difficulty (the default).',
// ...admin mode, win the run, the record to beat...
`The run has to take at least ${floorSeconds} seconds and under an hour. Faster runs are rejected as impossible.`,
// ...the timer, the nickname...
`Wait ${COOLDOWN_MS / 1000} seconds between submissions, and at most ${IP_LIMIT} per hour.`,
];
}The fourth rule also carries a value: the current top rescuer’s time, passed in as recordTimeMs and formatted, or a sentence saying no one holds the record yet. So three of the eight strings contain something computed, and the other five are plain text. The doc comment above the function states the intent: the list is built from the same constants the client gate and the server enforce, so the popup can’t drift from what is actually checked.
Where each number is enforced
The constants live in lib/game/leaderboard.ts, a file with no database and no Node-only imports, so the client, the Next route, the win-screen form and the leaderboard service on our own server all import it.
PLAUSIBILITY_FLOOR_MS(L30) is a formula, not a literal: the half-diagonal of the map divided by the fastest possible speed, halved as a margin. It rounds to about 15.7 seconds, which is the number the popup prints.validateTimeMs(L83-87) rejects anything under it, and the submit route calls that function (app/api/leaderboard/route.tsL45). The win-screen form also checks the same constant and renders nothing for a run under the floor (components/Leaderboard.tsxL127).COOLDOWN_MS(L17, 10,000) andIP_LIMIT(L18, 5) are checked in the leaderboard service, inservices/leaderboard-db/db.ts(L307-308), which refuses a submission withcooldownorip-limit. The Next route maps a 429 from that service to a rate-limited answer (route.tsL74-77).
One correction to the doc comment, from reading the callers: only the floor is checked on both sides. Outside the popup, the cooldown and the limit are imported by the service and by nothing in the client.
What a test pins, and what it does not
lib/game/rescuerRules.test.ts has three tests, and we ran them: three pass. The one that matters here is named “numbers come from the enforced constants” (L13). It does not assert “10 seconds”. It builds the expected text from the constants (`${COOLDOWN_MS / 1000} seconds between submissions`) and looks for it in the popup text. Tune the constant and the test follows it.
We checked that in a local working copy, reverted and never committed. Changing COOLDOWN_MS from 10,000 to 30,000 made the popup say “Wait 30 seconds between submissions” with no edit to the popup, and all three tests still passed. That is the behaviour the function exists for.
The browser test, e2e/rescuer-rules.spec.ts, opens the popup with a mocked record of 125,000 ms and checks it names Blackout, admin mode and a time to beat of 2:05. It does not assert any of the three constant-driven numbers. The unit test is the only thing that does.
What it does not cover
Three claims are the same kind of thing as the numbers, and they are typed by hand. The popup says a run must take under an hour, and the ceiling is a separate constant, PLAUSIBILITY_CEILING_MS (L31). It says per hour next to the limit of five, and the window is IP_WINDOW_MS (L19). It says a nickname is 3-20 letters, a-z only, and the rule the form and the server use is NICKNAME_PATTERN, /^[a-z]{3,20}$/ (L13).
We measured the middle one. Setting IP_WINDOW_MS to two hours in the same working copy left the popup saying “at most 5 per hour”, and the three tests passed. The popup would have lied, and nothing caught it. The nickname line is only partly covered: the first test looks for the string 3-20 letters in the popup, which proves the words are there and not that they match the pattern.
The prose rules have the same exposure, and we have already paid for it. Commit 9299ad5 (October 18, 2026) changed one line of the popup and one test needle. The line was “Win the run: find the lost child and carry them home.” and became “Win the run: reach the lost child and lift them. There is no trip home after that.” The commit message says why: the win had been lifting the child since the carry-home leg was removed, and the popup still told players to carry them home. The history of that mechanic is in the return trip. No constant could have prevented that edit, because there is no constant for a sentence. What holds it now is a test needle, lift them, that was changed in the same commit.
A comment drifted too. The header of rescuerRules.ts says the popup content is for components/Hud.tsx. The only component that imports the function is components/GameMenu.tsx. No test reads comments.
What to take from it
- Import the number, never copy it. A displayed value that is read from the enforcing constant cannot be wrong in the way a typed one can.
- Assert against the constant, not a literal. The test is a divergence detector: it fails if the popup and the constant stop agreeing. It would not fail if someone typed “10” and the constant happened to be 10, so the structure is the import and the test is the backstop.
- Count what is still hand-typed. Here, five of the eight strings contain no computed value, and three phrases (two inside the computed lines, one in a plain one) restate a rule that has its own constant or pattern. That is the remaining surface, and it is a short list.
If you want to see the popup, play Lullwood free in the browser and open the “Be the rescuer” button in the top-left menu row. The game-side view of the same rules is how to win Lullwood, where the win is lifting the child and the leaderboard counts only Blackout wins.