Skip to content

feat(testing): add deterministic HTTP fixtures - #17

Merged
constantin-jais merged 2 commits into
migrate/recover-codefrom
work/testing-http-fixtures
Nov 17, 2026
Merged

constantin-jais merged 2 commits into
migrate/recover-codefrom
work/testing-http-fixtures

Conversation

@constantin-jais

@constantin-jais constantin-jais commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

What

Adds packages/testing/src/http-fixtures: deterministic HTTP fixtures for tests.

  • uniqueIp(): next address in 10.0.0.0/8 from a process counter, so rate-limit counters stay isolated between tests without randomness.
  • formEncode(): flat object to application/x-www-form-urlencoded.
  • sameOriginPost() / crossOriginPost(): standard Request builders, to exercise a cross-site refusal.

Why a draft

This is a pilot: one small change opened to get the CI verdict on the pinned toolchain, which could not be reproduced locally.

  • Local run on the package: 14 tests pass (4 on the base), lint and typecheck pass. The local Bun is not the pinned one, so check:toolchain and the full bun run check did not run.
  • CI on this head: composition / validate passes on the pinned Bun (version 1.4.0 vs 1.4.0), and the testing package reports 14 pass, 0 fail, Ran 14 tests across 2 files.
  • The module is not exported from packages/testing/src/index.ts and nothing is added to the global check chain: both are owner decisions.
  • No work package of the PRD names this change yet. This repository runs no work-package link check, so nothing is red for it; the link is still owed before this leaves draft.

Tests

What turns them red: making extra headers replace the defaults, or freezing the counter (6 of 10 tests of the first commit fail). A refactor that keeps the same observable headers and address uniqueness stays green.

Open points for the owner

  • Names: uniqueIp, sameOriginPost, crossOriginPost, formEncode.
  • Whether to export the module from the package entry.
  • The counter wraps after 2^24 calls; no reset is exposed.

Add uniqueIp(), formEncode(), sameOriginPost() and crossOriginPost() under
packages/testing/src/http-fixtures. Addresses come from a process counter in
10.0.0.0/8 (no randomness, so rate-limit counters stay isolated between
tests); builders return standard Request objects with header dictionaries
typed as plain string records.

Tests: what turns them red. Replacing the header merge so extras replace the
defaults, and freezing the counter, fail 6 of 10 tests (same-origin marker
erased, duplicate addresses). A refactor that keeps the same observable
headers and uniqueness does not turn them red: expectations come from the
brief (10.a.b.c form, "q=hello+world", Sec-Fetch-Site kept), not from the
code output.

Not wired into src/index.ts or the global check chain: owner decision.

Signed-off-by: Constantin Jais <74049135+constantin-jais@users.noreply.github.com>
Review findings on packages/testing/src/http-fixtures, each reproduced
red before the fix:

1. [medium] The crossOriginPost "extra header cannot restore a
   same-origin marker" test never asserted sec-fetch-site: the mutant
   that sets same-origin whenever an extra header is passed survived
   (old test file: 10 pass, 0 fail). The test now asserts
   sec-fetch-site=cross-site and the third-party Origin. Same mutant
   against the new file: 1 fail.

2. [medium] sameOriginPost claimed to send a form POST "as a browser
   sends it" but had no Origin header, which browsers send on every
   POST. It now defaults origin to new URL(url).origin. Covered by
   "carries the target's own Origin" (two URLs, incl. a port).
   Neutralised (default renamed to a no-op header): 1 fail.

3. [low] An extra header could override sec-fetch-site or origin.
   Both builders now refuse it, case-insensitively, with a named
   ProtectedHeaderOverrideError (strictest option). Covered by 8
   tests (2 builders x 4 casings/headers). Neutralised (guard forced
   false): 8 fail; case-sensitive guard: 4 fail.

Package suite: 23 pass, 0 fail; biome ci and tsc --noEmit clean.

Deviation from the brief, declared: comportement_voulu asks for
authenticated and JSON request builders, but interfaces lists only
uniqueIp, sameOriginPost, crossOriginPost and formEncode; neither
builder exists. Authentication and a JSON content-type stay reachable
through extraHeaders. The module is not exported by the package
(already declared, left to the owner). The new refusal of origin /
sec-fetch-site overrides is a stricter behaviour than the brief states.

Signed-off-by: Constantin Jais <74049135+constantin-jais@users.noreply.github.com>
@constantin-jais
constantin-jais marked this pull request as ready for review November 17, 2026 20:54
@constantin-jais
constantin-jais merged commit f5a52ef into migrate/recover-code Nov 17, 2026
1 check passed
@constantin-jais
constantin-jais deleted the work/testing-http-fixtures branch November 17, 2026 21:27
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.

1 participant