fix(build): move a route test out of src/pages so the container build resolves #180
Inga granskare
Etiketter
Inga etiketter
area/backups
area/ci
area/control-panel
area/identity
area/infra
area/observability
area/payments
area/security
area/storage
area/web
blocked
needs-info
needs-triage
ready-for-implementation
type
bug
type
chore
type
docs
type
epic
type
feature
type
task
wontfix
Ingen milstolpe
Inget projekt
Inga tilldelade
1 deltagare
Notiser
Förfallodatum
Inget förfallodatum satt.
Beroenden
Inga beroenden satta
Referens
bitborg/bitborg-web!180
Läser in…
Hänvisa till i nytt ärende
Ingen beskrivning angiven.
Ta bort grenen "fix/no-tests-in-pages"
Borttagning av en gren är permanent. Även om den borttagna grenen kan fortsätta existera en kort tid innan den faktiskt tas bort, kan det INTE ångras i de flesta fall. Vill du fortsätta?
src/pages/api/resend-setup-link.test.tsbroke the container build onmain. Astro routes everyfile under
src/pages/— a.tsfile there becomes an API endpoint — so the test file was compiledas a real route, and its
import { vi } from "vitest"became a runtime import of a devDependency.The Containerfile's build stage installs production dependencies only (
pnpm install --frozen-lockfile --prod), sovitestis not there and the build fails:The test moves to
src/test/, out of route space. It is the same test — only the relative pathschange, two levels to one. That rewrite is load-bearing rather than cosmetic: Vitest keys
vi.mockby the resolved module path, so
../../lib/captchahad to become../lib/captchato keeppointing at the same
src/lib/captchathe route itself imports. Get it wrong and the suite stillpasses while mocking nothing.
src/test/is a deliberate deviation from this repo's colocation convention (src/lib/x.test.tsnext to
src/lib/x.ts). A test for a route cannot be colocated, because the directory it would sitin is the router.
Verified, not assumed
Both sides reproduced with a real
podman build, not inferred from the error text:main(d053d09)Rolldown failed to resolve import "vitest"Successfully tagged localhost/bitborg-web:latestOn this branch:
pnpm test293 passing across 23 files (the moved test is still collected —vitest.config.tsincludessrc/**/*.test.ts, which coverssrc/test/),pnpm lintclean,pnpm check0 errors and 0 warnings.Why CI did not catch this, and the guard that now does
Not an oversight in the test suite — a structural blind spot.
ci.ymlinstalls withpnpm install --frozen-lockfile, dev dependencies included, then runspnpm build. Under that installvitestresolves, so the build succeeds and the route is bundled without complaint. Only the
--prodinstallin the Containerfile can surface the missing dependency, and that build runs on push to
main, afterreview. Without a guard the same mistake lands again the next time a test is written next to a route,
and is again invisible until it is already on
main.So
eslint.config.mjsgains a "No tests in route space" block: any*.test.*or*.spec.*undersrc/pages/is an error, with the reason and the remedy in the message.A lint rule rather than a production-install build step in pull-request CI, because it fails earlier
and cheaper — at the
lefthookpre-commit hook on the machine where the file was written, before themistake reaches a branch, rather than after a full image build in CI.
Also demonstrated rather than asserted — a throwaway test file, added and then removed:
src/pages/api/__guard-probe.test.tspnpm eslintcleansrc/pages/__probe-root.test.tsThe second probe checks the glob's zero-segment case, so a test dropped directly into
src/pages/is caught and not only one nested under
api/. With both probes removed the tree is clean:pnpm eslintandpnpm format:checkpass.