In most software, a redesign that goes wrong costs somebody an irritating afternoon. They cannot find the button, they say so, you put the button back.
An authenticator does not get that forgiveness. The whole job is to produce the digits a server is expecting. If a redesign loses a vault, or decrypts every entry except one, or shows the right code beside the wrong account, nobody has an irritating afternoon. They are locked out of their bank at a moment they did not choose.
That is not hypothetical. In late 2024, an Authenticator update left some people staring at dashes and the message Could not generate code for this account, with backup codes as the way back in — if they had kept any.
So before the KeyNesta web app was redesigned, the first thing built was not a design. It was the thing that would tell us whether we had broken someone's vault.
The contract a redesign may not touch
A redesign is presentation only. These are data, and data gets a deliberate versioned migration or it gets left alone:
- the TOTP and HOTP engine, the crypto, the vault model, sync and the importers, all of which live in
core/src - the three keys the app boots from:
keynesta.vaults,keynesta.activeVaultandkeynesta.vault.<id> - the shape of the sealed envelope:
{ format: 'keynesta.vault', version: 1, keyslot, data } - the shape of a backup file, and the version number on the vault model itself
Writing that list down is easy. Proving a thousand lines of new CSS and restructured components did not disturb any of it is the hard part, and it is not something you can do by looking.
A real vault, not a fixture
The temptation is to hand-write a JSON file that looks like a sealed vault and test against that. The problem is obvious the moment you say it out loud: a fixture is a guess about your own format, and it stays a convincing guess right up until it is wrong.
So make-golden.mjs does not write a vault. It imports core and builds one — createDefaultVault, then the same reducer actions the app dispatches when a person adds a space or an entry, then createKeyslot and sealVault. What lands on disk is the exact payload a browser would be holding in local storage, produced by the same code that seals a real customer's vault.
Two useful consequences. It is a real vault, not a drawing of one. And the generator is restricted to core's public API, so a refactor that quietly changes the storage contract breaks the generator before the browser check even starts.
The contents were picked to be awkward rather than representative:
- a six-digit, thirty-second
SHA-1entry built on the ASCII secret from RFC-6238's appendix B - an eight-digit
SHA-256entry, because non-default digit counts are where authenticators quietly disagree - an
HOTPentry with its counter already advanced - a seven-digit entry on a sixty-second period
- two spaces, a group nested inside another group, and one entry sitting in the trash
The passphrase is in the file in cleartext. It is a test vault holding test secrets, there is nothing in it to protect, and a gate that only one person can run is not a gate.
The file also records the code the engine produced for every entry at a single frozen millisecond. That is the expected output, and it is the only thing in this whole arrangement that is allowed to be boring.
The gate
verify-golden.cjs opens the actual app in an actual browser. Two things are injected before the first line of app code runs: those three storage keys, and a Date subclass pinned to the golden file's frozen instant, so the codes are deterministic instead of being a race against the thirty-second window.
Then it behaves like somebody who has used the app for a year and just been handed an update.
- The stored vault is still discovered — the registry key and the active-vault key survived boot rather than being cleared by a well-meaning migration.
- It unlocks with the existing passphrase, typed into the real field and submitted with Enter.
- Every space is listed in the sidebar.
- Nothing from the trash has surfaced in the active list.
- Every active entry renders its exact expected code. The walk goes two levels deep, because entries live inside groups and a group only exists in the DOM while its space is selected.
- The nested group tree survived:
Infrastructure, withProductioninside it. - The vault re-seals without corruption. After all that clicking, the envelope in storage is still the right format and version with its keyslot and data intact.
Any console error fails the run as well. It finishes on one of two lines: PASS: an existing vault opens and every code is correct, or a count of failures and the words existing vaults would break.
Why it asserts the codes and ignores the pixels
The technique is old. Characterization testing, golden master, approval tests — different decades, same idea: record what the system does now, so a later change has something to be measured against.
The part that actually decides whether it works is what you choose to freeze. During a redesign the instinctive answer is the DOM, or screenshots. That test fails on the first intentional change and then on every one after it, so it gets skipped, then muted, then deleted, and the project carries on with no brake at all.
This gate therefore has no opinion about presentation. Row heights, hairlines, the type scale, where the menu went, the entire visual argument of the redesign — none of it is asserted anywhere. What it asserts is the one output a person would notice losing: the digits, present and correct, for every entry, wherever the new design decided to put them.
Indifferent to layout, absolute about data. That is the only combination that survives contact with a redesign.
Three of the first failures were the test's fault
The gate was run against the untouched app first, before any of the redesign existed, and it passed. That order is the whole point. A check written after the change cannot tell you whether the change caused the red.
Then it went red three times, and all three times the app was fine:
- entries live inside groups, so walking only the spaces never reached them
- Trash is not an active view, and treating it as one produced codes the check was not expecting
- the display-density preference is stored as a raw string rather than JSON, so the check read it wrongly
Every time, the correct move was to fix the check. Which is where the rule that does the real work comes in:
Never regenerate the golden vault to turn a red gate green.
A golden file you are willing to rewrite under deadline pressure is not a safety net, it is a formality with good manners. Its entire value is that it is older than the change being tested.
What it does not cover
Stating the limits is the house style, so:
- It checks presence, not pairing. Codes are collected from the page as a set and compared against the expected set. A redesign that showed every correct code beside the wrong account name would pass this gate. That gap is known, and closing it is the next thing the check needs.
- It is one vault, six active entries, one browser, one window size. A brake, not a fuzzer.
- The frozen clock is what makes it deterministic and also what makes it blind. A bug that only appears as a period rolls over is outside its reach.
- It covers the web app. When the iOS app was rebuilt onto the web app's design language, this gate's job was to prove the web app had not moved — not to vouch for the phone.
- Arithmetic is not its department. That belongs to core's own test suite, which checks the engine against RFC-6238's published vector: secret
12345678901234567890, atT=59s, eight digits, must come out as94287082. The gate assumes the engine is right and asks only whether the app still shows what the engine says.
Worth stealing
If you ship anything where a user's data outlives your interface, the cheap version of this is an afternoon's work:
- Generate the stored artefact with your production code, never by hand.
- Record the output a user would notice losing, at a pinned instant.
- Run the real app, in a real browser, against that artefact — before you start changing things.
- When it goes red, suspect the check first and the artefact last. Never edit the artefact to make it pass.
So far the gate has never gone red for a reason that turned out to be the app's fault. Its sibling check — the one asserting a vault row is exactly one line tall — has: a row with seven cells declared against five grid columns, so the star and the menu wrapped onto a second line, and an HOTP advance button standing six pixels proud of every other cell in the row.
A brake that never engages looks like a brake you could remove. We keep this one because of the single morning it does engage, which will be the morning somebody's vault would otherwise have stopped opening.
If you want the layer underneath all of this, the encryption architecture page has the scrypt parameters, how the master key is wrapped, and exactly what the sync server is holding.