WIP: test(rate-limit): separate budgets per peer address on every runtime #13

Draft
chrnx wants to merge 1 commits from test/rate-limit-peer-ip into develop
pull from: test/rate-limit-peer-ip
Owner

Draft: blocked on the core release. On Deno and Bun this test fails against the pinned @green-tea/core@26.9.0-beta.2, on purpose. Merge it together with the core pin bump to the first release that carries core #116 (merged in core #117), and not before. Until then, red runtimes (deno) and runtimes (bun) checks are expected. They are the regression being caught, not a broken test.

What this changes

The default keyOf buckets callers by ctx.ip. Until core #116, serveDeno and serveBun left ctx.ip as '', so every caller on those runtimes landed in the one 'unknown' bucket, and the first client to reach max locked out everyone else. Node's listen() always filled it from the socket.

packages/rate-limit/test/peer-ip.test.ts drives the plugin's default keyOf over a real socket, on whichever runtime runs it:

  • one dual-stack listener on ::, via serveDeno, serveBun, or app.listen() on Node
  • max: 1; client A connects over 127.0.0.1 and client B over ::1
  • A's second request must be 429, B's first must be 200, and the two ctx.ip values must be non-empty and different

Node is the control: it passes on any core. A host with no IPv6 loopback falls back to 127.0.0.1 and 127.0.0.2, which only Linux routes, and the test logs a diagnostic when it does.

Test only. There is no plugin-contract change, no src/ change and no engines change. Nothing in this PR bumps the core pin. That belongs to the release cut.

Why a draft rather than a skip

CI installs core with npm ci from the lockfile: @green-tea/core@26.9.0-beta.2 from npmjs.org, and Deno resolves that same tree through nodeModulesDir: "manual". No mechanism points CI at an unreleased core, and the repo has no convention for tests that wait on one. Skipping on old core, or marking the test todo, would let it pass silently on exactly the core it exists to reject. So the test stays strict, and this PR waits for the pin.

Which runtimes you ran

Against the pinned 26.9.0-beta.2 (what CI will see):

  • npm test (Node): 61 pass, 0 fail
  • npm run test:deno: 31 pass, 1 fail (ctx.ip was empty for client A on this serving path: "")
  • npm run test:bun: 31 pass, 1 fail (same assertion)
  • npm run test:edge: rate-limit does not declare workerd

Against a candidate core built from core develop at 4d1639f and swapped into node_modules/@green-tea/core locally:

  • npm test: 61 pass, 0 fail
  • npm run test:deno: 32 pass, 0 fail
  • npm run test:bun: 32 pass, 0 fail

Checklist

  • The base branch above is contrib
  • Commits are signed off (git commit -s)
  • lint, format:check, typecheck, complexity:check and deno publish --dry-run pass locally
  • New behaviour has a test
  • Core is still imported as import type only in src/. The test imports it as a value, as the other tests do
  • engines unchanged
  • Not a breaking change

npm audit --audit-level=moderate: 0 vulnerabilities. No open Dependabot alerts.

> **Draft: blocked on the core release.** On Deno and Bun this test fails against the pinned `@green-tea/core@26.9.0-beta.2`, on purpose. Merge it together with the core pin bump to the first release that carries core #116 (merged in core #117), and not before. Until then, red `runtimes (deno)` and `runtimes (bun)` checks are expected. They are the regression being caught, not a broken test. ## What this changes The default `keyOf` buckets callers by `ctx.ip`. Until core #116, `serveDeno` and `serveBun` left `ctx.ip` as `''`, so every caller on those runtimes landed in the one `'unknown'` bucket, and the first client to reach `max` locked out everyone else. Node's `listen()` always filled it from the socket. `packages/rate-limit/test/peer-ip.test.ts` drives the plugin's **default** `keyOf` over a real socket, on whichever runtime runs it: - one dual-stack listener on `::`, via `serveDeno`, `serveBun`, or `app.listen()` on Node - `max: 1`; client A connects over `127.0.0.1` and client B over `::1` - A's second request must be 429, B's first must be 200, and the two `ctx.ip` values must be non-empty and different Node is the control: it passes on any core. A host with no IPv6 loopback falls back to `127.0.0.1` and `127.0.0.2`, which only Linux routes, and the test logs a diagnostic when it does. Test only. There is no plugin-contract change, no `src/` change and no `engines` change. Nothing in this PR bumps the core pin. That belongs to the release cut. ### Why a draft rather than a skip CI installs core with `npm ci` from the lockfile: `@green-tea/core@26.9.0-beta.2` from npmjs.org, and Deno resolves that same tree through `nodeModulesDir: "manual"`. No mechanism points CI at an unreleased core, and the repo has no convention for tests that wait on one. Skipping on old core, or marking the test todo, would let it pass silently on exactly the core it exists to reject. So the test stays strict, and this PR waits for the pin. ## Which runtimes you ran Against the pinned `26.9.0-beta.2` (what CI will see): - [x] `npm test` (Node): 61 pass, 0 fail - [x] `npm run test:deno`: 31 pass, **1 fail** (`ctx.ip was empty for client A on this serving path: ""`) - [x] `npm run test:bun`: 31 pass, **1 fail** (same assertion) - [ ] `npm run test:edge`: rate-limit does not declare workerd Against a candidate core built from core `develop` at `4d1639f` and swapped into `node_modules/@green-tea/core` locally: - [x] `npm test`: 61 pass, 0 fail - [x] `npm run test:deno`: 32 pass, 0 fail - [x] `npm run test:bun`: 32 pass, 0 fail ## Checklist - [x] The base branch above is `contrib` - [x] Commits are signed off (`git commit -s`) - [x] `lint`, `format:check`, `typecheck`, `complexity:check` and `deno publish --dry-run` pass locally - [x] New behaviour has a test - [x] Core is still imported as `import type` only in `src/`. The test imports it as a value, as the other tests do - [x] `engines` unchanged - [x] Not a breaking change `npm audit --audit-level=moderate`: 0 vulnerabilities. No open Dependabot alerts.
chrnx added 1 commit 2026-10-14 02:55:08 +00:00
test(rate-limit): give peers on different addresses separate budgets on every runtime
CI / dco (pull_request) Successful in 3s
CI / build (pull_request) Successful in 13s
CI / runtimes (bun) (pull_request) Failing after 10s
CI / runtimes (edge) (pull_request) Successful in 7s
CI / runtimes (deno) (pull_request) Failing after 8s
5e9ca2678b
The default keyOf buckets callers by ctx.ip. serveDeno and serveBun left ctx.ip empty until
core #116 (merged in core #117), so every caller on those runtimes shared the 'unknown' bucket
and the first one to reach max locked out everybody else.

This drives the plugin's default keyOf over a real socket: one dual-stack listener, client A over
127.0.0.1 and client B over ::1, max: 1. A's second request must be 429 and B's first 200, with two
distinct ctx.ip values. Node's listen() path runs the same test as the control and passes on any
core; on Deno and Bun it passes only on a core that carries #116, and fails on 26.9.0-beta.2.
Hosts without an IPv6 loopback fall back to 127.0.0.1 and 127.0.0.2, which only Linux routes.

Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
chrnx marked the pull request as work in progress 2026-10-14 02:55:22 +00:00
Some required checks failed
CI / dco (pull_request) Successful in 3s
Required
Details
CI / build (pull_request) Successful in 13s
Required
Details
CI / runtimes (bun) (pull_request) Failing after 10s
Required
Details
CI / runtimes (edge) (pull_request) Successful in 7s
Required
Details
CI / runtimes (deno) (pull_request) Failing after 8s
Required
Details
Checking for merge conflicts…
This pull request is marked as a work in progress.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin test/rate-limit-peer-ip:test/rate-limit-peer-ip
git checkout test/rate-limit-peer-ip
Sign in to join this conversation.