AntFleet

Disagreement · a2392d54-anthropic-3

Middleware test re-derives response in beforeEach but `res` is typed as the implementation return — silently breaks if middleware ever returns void/undefined

mismatch
repo e24ef98c·PR #7·reviewed 2 weeks ago

Primary finding

Middleware test re-derives response in beforeEach but `res` is typed as the implementation return — silently breaks if middleware ever returns void/undefined

lowtest-gapmedium
  • apps/web/middleware.test.ts:24-33
makeReq() casts a bare `{ nextUrl: new URL(...) }` to NextRequest. If middleware ever begins reading `req.headers`, `req.cookies`, `req.method`, etc., the cast will silently produce `undefined` accesses and the resulting NextResponse may be malformed, but the header assertions will still pass or throw a hard-to-debug TypeError. The comment block 'We import the module's SECURITY_HEADERS map via re-export rather than instantiating the full middleware function with mock NextRequest' is misleading — the test does in fact instantiate middleware with a stub NextRequest, not import a SECURITY_HEADERS map.

Recommendation

Either (a) export SECURITY_HEADERS as a const from the middleware module and assert against that map directly (matching the comment), or (b) update the comment to accurately describe the current stub-request approach. Also use NextRequest's actual constructor (`new NextRequest(new URL('https://...'))`) instead of the unsafe cast to catch breakages at the type level.

Counterpart finding

Misleading test comment contradicts actual test approach

lowdocs-gaphigh
  • apps/web/middleware.test.ts:8-10
  • apps/web/middleware.test.ts:13
  • apps/web/middleware.test.ts:26-28
The comment claims the tests import a SECURITY_HEADERS map via re-export instead of instantiating the middleware. In reality, the tests call the middleware function with a mocked request and read headers from the response. This mismatch can confuse contributors maintaining the tests or middleware.

Recommendation

Update the comment to accurately describe the current test strategy (i.e., invoking the middleware with a mocked NextRequest and asserting on the returned NextResponse headers). Alternatively, change the tests to import and check a re-exported SECURITY_HEADERS map as described, but be consistent between code and comments.

Why this didn't post

This finding didn't meet AntFleet's unanimous agreement threshold. Both frontier models review every PR independently; only findings they both flag with the same severity and category are posted to the PR. This one fell through.

read the methodology →