Build1 publisherNot yet confirmed elsewhere3 min readPublished
Careful review passed, tsc passed, and the default dispatcher threw on every call
An auth package author wrote 238 tests against code he had already reviewed line by line. The bugs that mattered only appeared when tests ran the real dependency chain.
The Engineer · Build desk
What happened
- Before writing tests for Beaver-Auth, the author had put every module through multiple rounds of deliberate review, covering enumeration protection, hashed tokens, refresh rotation and TOTP replay defense.
- The post's headline states: I Wrote 238 Tests Against My Own Auth Package and Found 4 Real Bugs.
- The body of the post states that the author wrote 238 tests against the actual code and found 8 real bugs, some of which would have silently broken production on day one.
- Passing tests only tell you the code does what the tests expect; if the tests were written from the same mental model as the code, they will confirm a bug as correct behavior because code and test share the same wrong assumption.
- The fix was not writing more tests but testing against the real, integrated system rather than a hand-built mock of the author's own logic or modules isolated from what calls them; several bugs surfaced only because a test exercised the real dependency chain.
Compiled by The EngineerSomething wrong?How this is made
Why it matters
The author of the TypeScript package Beaver-Auth says he had put every module through multiple rounds of deliberate review before he wrote any tests, covering enumeration protection, hashed tokens, refresh rotation and TOTP replay defense [1]. Then 238 tests against the actual code turned up real bugs, and the two he documents in detail surfaced only because a test exercised the real dependency chain instead of a hand-built mock of his own logic [18][3].
The mechanism he describes is the useful part, because it is a claim you can check against your own repository. Passing tests prove only that the code does what the tests expect; if the tests were written from the same mental model as the code, both agree on the same wrong assumption and the suite happily certifies a bug as correct behaviour [2]. More assertions do not move that. Different inputs do.
The dispatcher bug is the clean case. Beaver-Auth defines a TaskDispatcher interface whose dispatch method takes taskName, payload, handler, and an optional onFailure [4]. The default implementation had drifted to a three-parameter version with payload missing entirely [5]. Callers still passed four arguments in the interface's order, so the payload object landed in the handler slot, the real handler function landed in onFailure's slot, and the real onFailure was silently dropped [6]. Calling handler() then throws TypeError: handler is not a function on every dispatch, in every deployment using the default dispatcher, which is the zero-config default [7]. That means every verification email and every password reset email [8].
According to the author, tsc --noEmit reported zero errors and no warnings, because TypeScript checks method parameters bivariantly by default and a parameter typed unknown structurally accepts anything [9]. A compiling signature was not evidence that the shapes agreed at the call site. The correction was one line, plus a regression test that runs the path through the real dispatcher rather than a test double [10].
The second bug is a reachability failure. LoginEngine exposed logoutJwtSession(familyId), which revokes a refresh-token family, and it was well tested in isolation [11]. But no public API path ever returned a familyId to a caller: login returned a status, the user, an accessToken and a refreshToken [12]. The feature was fully implemented and completely unreachable [13]. A unit test cannot find this, because writing one means handing the function a familyId you already have, which is precisely what a real consumer cannot do [14]. An integration test that role-played a consumer, logging in and then trying to log out with only what the login response provided, hit the gap on the first run [15]. The fix threads familyId through the LoginResult type [16].
One caution about the source itself: its headline says 238 tests found 4 real bugs, while the body of the same post says 8 [17][18]. Those cannot both be right [19], so treat the count as unverified. The two defects described in detail do not depend on it.
Worth watching in your own code: whether any test in the suite is constructed from a value the public API never hands out, and whether the zero-config default path, the one most users will run, is covered by a test that touches the real implementation rather than a double [7][10].
Clarity's read
What the record supports and how the coverage leans. The claims behind it follow.
Reality
- Evidence42
- Adoption
- Insufficient
- Hype gap+22
- Incentives68
- Confidence38
Claim ledger
Ranked by verification strength, evidence, and original report placement.
- [1]
Before writing tests for Beaver-Auth, the author had put every module through multiple rounds of deliberate review, covering enumeration protection, hashed tokens, refresh rotation and TOTP replay defense.
- [2]
Passing tests only tell you the code does what the tests expect; if the tests were written from the same mental model as the code, they will confirm a bug as correct behavior because code and test share the same wrong assumption.
- [3]
The fix was not writing more tests but testing against the real, integrated system rather than a hand-built mock of the author's own logic or modules isolated from what calls them; several bugs surfaced only because a test exercised the real dependency chain.
- [4]
The TaskDispatcher interface declares dispatch(taskName: string, payload: unknown, handler: () => Promise<void>, onFailure?: (error: unknown) => Promise<void> | void): Promise<void>.
- [5]
The default TaskDispatcher implementation had drifted to a signature missing the payload parameter entirely: dispatch(taskName, handler, onFailure?).
- [6]
Every caller still invoked dispatch with all four arguments matching the interface shape, so positionally the payload object landed in the handler slot, the real handler landed in onFailure's slot, and the real onFailure was silently dropped.
- [7]
Running that code makes handler() throw TypeError: handler is not a function on every dispatch, in every deployment using the default dispatcher, which is the zero-config default nearly everyone would be using.
- [8]
The dispatcher failure would have affected every verification email and every password reset email, silently.
- [9]
tsc --noEmit reported zero errors and no warnings for the mismatched dispatcher, because TypeScript checks method parameters bivariantly by default, permitting a function with fewer parameters to satisfy an interface expecting more, especially when a mismatched parameter type is unknown, which structurally accepts anything.
- [10]
The dispatcher fix was a one-line signature correction, plus a regression test that exercises the path through the real dispatcher rather than a test double.
- [11]
LoginEngine had a logoutJwtSession(familyId: string) method to revoke a refresh-token family and stop a JWT session minting new access tokens, and it was well tested in isolation.
- [12]
Nothing in the public API ever returned a familyId to the caller; login returned { status: 'success-jwt', user, accessToken, refreshToken } with no familyId.
- [13]
The logout feature was fully implemented and completely unreachable, because a consumer had no way to obtain the familyId the logout function required.
- [14]
Unit tests of logoutJwtSession in isolation could never catch the gap, because the test is constructed by directly passing in a familyId the tester already knows, which the broken consumer flow never could.
- [15]
The unreachable-logout gap surfaced only once the author wrote an integration test role-playing an actual consumer: log in, then try to log out using only what the login response provided.
- [16]
The fix was to thread familyId through the LoginResult type and the places it is used.
- [17]
The post's headline states: I Wrote 238 Tests Against My Own Auth Package and Found 4 Real Bugs.
- [18]
The body of the post states that the author wrote 238 tests against the actual code and found 8 real bugs, some of which would have silently broken production on day one.
- [19]
The source contradicts itself on the bug count: the headline says 4 real bugs and the body says 8, so at most one figure can be correct.
Sources
1 independent publisher whose own reporting we read for this story.
- dev.toI Wrote 238 Tests Against My Own Auth Package and Found 4 Real Bugs
1 article · August 18, 2026
Topics and entities
Follow any of these and your For You feed starts watching them — no settings page required.
Topics
- Limits of Careful Code ReviewFollow
- Integration TestingFollow
- Authentication Library EngineeringFollow
- TypeScript Type-Safety LimitsFollow
Entities
- Beaver-AuthFollow
- TypeScriptFollow
- dev.toFollow