Found while adding route-handler tests to the judging security PRs (review finding F1). It is a
one-line fix, but it silently blocks the second route test anyone adds anywhere in the repo, so it
is worth fixing on main rather than inside a feature branch.
What happens
src/modules/judging/api/leaderboard/__tests__/route.test.ts — the repo's only route-handler test,
and therefore the pattern everyone copies — has no top-level import or export. It necessarily
uses the jest.mock(...) then require('../route') form, because the mocks must be registered
before the module under test is loaded:
const mockCreateRequestContainer = jest.fn()
jest.mock(…)
const { GET } = require('../route') as typeof import('../route')
With no top-level import or export, TypeScript treats the file as a global script rather than a
module. const mockCreateRequestContainer therefore becomes a global declaration, and the moment a
second route test declares the same name, yarn typecheck fails:
Cannot redeclare block-scoped variable 'mockCreateRequestContainer'
Why it is worth filing
The error points at the variable, not at the missing export, so it reads as a name collision that
"should" be file-local — the diagnosis is genuinely non-obvious. And because this file is the
precedent for route tests, every new one copies the shape. The judging PRs (#150, #153, #157, #159)
each added export {} with a comment; the precedent itself still lacks it, so the trap is still
armed for the next person.
Expected
Add export {} at the top of judging/api/leaderboard/__tests__/route.test.ts, with a short comment
explaining why it is required. Worth a line in AGENTS.md too, next to whatever describes test
conventions, since the jest.mock + require ordering makes this unavoidable for any route test.
Unrelated but found alongside
yarn typecheck is incremental and caches tsconfig.tsbuildinfo; it reported stale errors after test
files were moved. rm -f tsconfig.tsbuildinfo before trusting a typecheck failure. Possibly worth
gitignoring or cleaning in the script.
Found while adding route-handler tests to the judging security PRs (review finding F1). It is a
one-line fix, but it silently blocks the second route test anyone adds anywhere in the repo, so it
is worth fixing on
mainrather than inside a feature branch.What happens
src/modules/judging/api/leaderboard/__tests__/route.test.ts— the repo's only route-handler test,and therefore the pattern everyone copies — has no top-level
importorexport. It necessarilyuses the
jest.mock(...)thenrequire('../route')form, because the mocks must be registeredbefore the module under test is loaded:
With no top-level import or export, TypeScript treats the file as a global script rather than a
module.
const mockCreateRequestContainertherefore becomes a global declaration, and the moment asecond route test declares the same name,
yarn typecheckfails:Why it is worth filing
The error points at the variable, not at the missing
export, so it reads as a name collision that"should" be file-local — the diagnosis is genuinely non-obvious. And because this file is the
precedent for route tests, every new one copies the shape. The judging PRs (#150, #153, #157, #159)
each added
export {}with a comment; the precedent itself still lacks it, so the trap is stillarmed for the next person.
Expected
Add
export {}at the top ofjudging/api/leaderboard/__tests__/route.test.ts, with a short commentexplaining why it is required. Worth a line in AGENTS.md too, next to whatever describes test
conventions, since the
jest.mock+requireordering makes this unavoidable for any route test.Unrelated but found alongside
yarn typecheckis incremental and cachestsconfig.tsbuildinfo; it reported stale errors after testfiles were moved.
rm -f tsconfig.tsbuildinfobefore trusting a typecheck failure. Possibly worthgitignoring or cleaning in the script.