Skip to content

test: cover res.status boundaries and validation - #7504

Open
renanmpimentel wants to merge 1 commit into
expressjs:masterfrom
renanmpimentel:test-status-validation
Open

renanmpimentel wants to merge 1 commit into
expressjs:masterfrom
renanmpimentel:test-status-validation

Conversation

@renanmpimentel

Copy link
Copy Markdown

The existing HTTP tests for status codes 99 and 1000 can still pass if Express's range guard is removed, because Node rejects the value later when the response ends. The tests therefore miss a regression in Express's own synchronous validation.

This test-only change:

  • Checks that res.status(99) and res.status(1000) immediately raise RangeError, while preserving the existing HTTP integration checks.
  • Covers the inclusive valid boundaries 100 and 999 directly, including the returned response and stored statusCode. Direct invocation avoids the special HTTP behavior of status 100.

Validation

  • npm run lint: passed.
  • npm run test-ci: 1,263 tests passed on Node 24.13.0/Linux.
  • Isolated regression proof: disabling the range guard leaves the old HTTP assertions passing; the strengthened suite fails on exactly the two missing RangeError assertions. Restoring the guard returns all 1,263 tests to green.
  • Separate inclusive-boundary regressions were detected by the new 100/999 cases and restored.
  • Focused StrykerJS 10.0.0 rerun: all 17 res.status candidates classified Killed, with no timeout/runtime-error outcomes.

To reproduce the rejection proof, temporarily replace code < 100 || code > 999 with false in res.status in an isolated copy, run npm test, then restore the condition.

Audit provenance and benefit

Prepared with AI assistance using Supertest, an LLM-agnostic skill for auditing test effectiveness. The benefit was finding false confidence from downstream HTTP validation and missing inclusive-boundary cases, then proving that the corrected tests detect those specific regressions. No skill, mutation-tool dependency, or application-code change is added to Express.

Fixes #7503

@ardenash

ardenash commented Oct 5, 2026 via email

Copy link
Copy Markdown

@ToniAdreal

Copy link
Copy Markdown

I independently verified the claims in this PR at head c5a13bf (Node 24.20.0, Linux):

  • Baseline: npx mocha test/res.status.js → 18 passing (16 existing + 2 new boundary cases).
  • Regression proof: I temporarily replaced the range guard in lib/response.js (if (code < 100 || code > 999) → if (false)). Exactly the two new RangeError assertions (99 and 1000, asserted directly at the status() call site) failed — all 16 other tests, including the HTTP-layer 500 assertions and the non-integer TypeError cases, stayed green.

So the new tests precisely close the discrimination gap described in the description: they pin down Express's own fail-fast range-guard contract at the call site instead of relying on Node's later rejection when the response ends. LGTM.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Regression tests can miss res.status range-validation failures

3 participants