Repository navigation
feat(testing): add deterministic HTTP fixtures - #17
Merged
constantin-jais merged 2 commits intoNov 17, 2026
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds
packages/testing/src/http-fixtures: deterministic HTTP fixtures for tests.uniqueIp(): next address in10.0.0.0/8from a process counter, so rate-limit counters stay isolated between tests without randomness.formEncode(): flat object toapplication/x-www-form-urlencoded.sameOriginPost()/crossOriginPost(): standardRequestbuilders, 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.
check:toolchainand the fullbun run checkdid not run.composition / validatepasses on the pinned Bun (version 1.4.0 vs 1.4.0), and thetestingpackage reports14 pass, 0 fail, Ran 14 tests across 2 files.packages/testing/src/index.tsand nothing is added to the global check chain: both are owner decisions.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
uniqueIp,sameOriginPost,crossOriginPost,formEncode.