test(guards): load no module graph inside a guard's test body

step-up-elevation-guard timed out under load in three separate gates
and passed every time on its own. One of its tests imported
@/lib/auth/step-up inside the test body to read the fresh-factor set,
and that module reaches the database client and the generated Prisma
client: the import alone ran against the test timeout, and how long it
took depended on the machine, not on the code under test.

The fresh-factor definitions (StepUpMethod, FRESH_FACTOR_METHODS,
isFreshFactorMethod) move to step-up-factors.ts, which imports nothing;
the guard imports it statically and the test is synchronous. Two more
guards did the same: next-image-optimizer-guard loaded next.config and
its plugins per test, and proxy-relative-redirect-guard loaded the
redirect helper with next/server. Both import statically now.

guard-dynamic-import-guard.test.ts parses every file of the guard
project with the TypeScript parser and fails on any import() call, so
a guard that needs a value imports it with the file or reads the
source; a test that must load late belongs to the isolated project.
This commit is contained in:
Marc-André Bombeck committed 2026-10-23 22:51:51 +02:00
1 parent 2357807706
commit 3e8846929c
8 files changed
+179 -60

No files matched your search

+4 -2
View File
@@ -47,10 +47,12 @@ import {
} from "@/lib/auth/existing-factor-proof";
import {
mintStepUpElevation,
isFreshFactorMethod,
STEP_UP_ELEVATION_TTL_SECONDS,
type StepUpMethod,
} from "@/lib/auth/step-up";
import {
isFreshFactorMethod,
type StepUpMethod,
} from "@/lib/auth/step-up-factors";
import { stepUpMintSchema } from "@/lib/validations/step-up";
export const dynamic = "force-dynamic";