Compare commits

Author SHA1 Message Date
chrnx cf7d30d8c2 Merge pull request 'test(metrics): read the content-type as string | string[]' (#15) from test/core-rc1-header-arrays into develop
CI / dco (push) Has been skipped
CI / runtimes (bun) (push) Successful in 10s
CI / build (push) Successful in 12s
CI / runtimes (deno) (push) Successful in 10s
CI / runtimes (edge) (push) Successful in 9s
Promote → GitHub / push-github (push) Successful in 7s
2026-10-30 15:55:10 +00:00
chrnx 29b2fa0483 test(metrics): read the content-type as string | string[]
CI / dco (pull_request) Successful in 4s
CI / build (pull_request) Successful in 13s
CI / runtimes (bun) (pull_request) Successful in 10s
CI / runtimes (edge) (pull_request) Successful in 7s
CI / runtimes (deno) (pull_request) Successful in 10s
Core RC.1 widens response header values to string | string[] (core
#113, a documented Breaking change for readers). The metrics test read
the transformer's content-type as a string and fails to typecheck
against the RC.1 candidate. Narrowing with String() also typechecks on
26.9.0-beta.2. Plugin source is unaffected.

Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
2026-10-30 10:24:34 -05:00
chrnx 5ed24d415b Merge pull request 'ci: move workflow actions off the deprecated Node 20 runtime' (#14) from chore/ci-node24-actions into develop
CI / dco (push) Has been skipped
CI / runtimes (bun) (push) Successful in 10s
CI / build (push) Successful in 12s
CI / runtimes (edge) (push) Successful in 8s
CI / runtimes (deno) (push) Successful in 10s
Promote → GitHub / push-github (push) Successful in 5s
2026-10-18 04:42:13 +00:00
chrnx 9379b58dd8 ci: move workflow actions off the deprecated Node 20 runtime
CI / dco (pull_request) Successful in 4s
CI / runtimes (bun) (pull_request) Successful in 10s
CI / build (pull_request) Successful in 12s
CI / runtimes (edge) (pull_request) Successful in 8s
CI / runtimes (deno) (pull_request) Successful in 10s
actions/checkout and actions/setup-node v4 -> v5, softprops/action-gh-release
v2 -> v3; all three run on Node 24. setup-deno@v2, setup-bun@v2 and
crates-io-auth-action@v1 already resolve to Node 24 releases. Jobs keep
node-version 22.

Refs Green-Tea/core#103

Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
2026-10-17 22:55:51 -05:00
5 changed files with 10 additions and 132 deletions

No files matched your search

+5 -5
View File
@@ -24,7 +24,7 @@ jobs:
if: github.event_name == 'pull_request' if: github.event_name == 'pull_request'
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v5
with: with:
fetch-depth: 0 fetch-depth: 0
- name: Every commit needs a Signed-off-by - name: Every commit needs a Signed-off-by
@@ -48,8 +48,8 @@ jobs:
build: build:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v5
- uses: actions/setup-node@v4 - uses: actions/setup-node@v5
with: with:
node-version: '22' node-version: '22'
- run: npm ci - run: npm ci
@@ -71,8 +71,8 @@ jobs:
matrix: matrix:
runtime: [deno, bun, edge] runtime: [deno, bun, edge]
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v5
- uses: actions/setup-node@v4 - uses: actions/setup-node@v5
with: with:
node-version: '22' node-version: '22'
- run: npm ci - run: npm ci
+1 -1
View File
@@ -28,7 +28,7 @@ jobs:
if: ${{ github.server_url != 'https://github.com' }} if: ${{ github.server_url != 'https://github.com' }}
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v5
with: with:
fetch-depth: 0 # full history for a clean push fetch-depth: 0 # full history for a clean push
- name: Push to GitHub - name: Push to GitHub
+2 -2
View File
@@ -30,8 +30,8 @@ jobs:
id-token: write # OIDC — this is what publishes, and what earns provenance id-token: write # OIDC — this is what publishes, and what earns provenance
contents: write # create the GitHub release for this tag contents: write # create the GitHub release for this tag
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v5
- uses: actions/setup-node@v4 - uses: actions/setup-node@v5
with: with:
node-version: '22' node-version: '22'
- uses: denoland/setup-deno@v2 - uses: denoland/setup-deno@v2
+2 -1
View File
@@ -88,7 +88,8 @@ test('the transformer serves the text format with the content type Prometheus ex
const rendered = prometheus('green_tea_requests_total{route="/x",method="GET",status="200"} 1\n'); const rendered = prometheus('green_tea_requests_total{route="/x",method="GET",status="200"} 1\n');
assert.equal(rendered.status, 200); assert.equal(rendered.status, 200);
assert.match(rendered.headers!['content-type'], /text\/plain/); // Core RC.1 widens response header values to `string | string[]` (core #113), so a reader narrows.
assert.match(String(rendered.headers!['content-type']), /text\/plain/);
assert.match(rendered.body, /green_tea_requests_total/); assert.match(rendered.body, /green_tea_requests_total/);
}); });
-123
View File
@@ -1,123 +0,0 @@
// The default `keyOf` buckets callers by `ctx.ip`, so it is only as good as the address the serving
// path hands it. Node's `listen()` has always filled `ctx.ip` from the socket. `serveDeno` and
// `serveBun` left it as `''` until core #116 (merged in core #117), which put every caller in the
// one `'unknown'` bucket: the first client to reach `max` locked out everybody else.
//
// So this runs over a real socket on each runtime, with the plugin's default `keyOf`, rather than
// through `app.fetch` with a hand-written one — `app.fetch` has no peer, and a custom `keyOf` would
// test the test. Two clients reach one dual-stack listener, one over IPv4 and one over IPv6, which is
// the cheapest way to get two distinct peer addresses on one host.
//
// Against a core without #116 the Deno and Bun runs fail here, on purpose. Node is the control: its
// path never had the bug and must stay green.
import { strict as assert } from 'node:assert';
import { createServer } from 'node:net';
import type { AddressInfo } from 'node:net';
import { test } from 'node:test';
import { createApp, ctx, Get, Module, needs, Route } from '@green-tea/core';
import type { App } from '@green-tea/core';
import { rateLimit } from '../src/index.ts';
import type { RateLimiter } from '../src/index.ts';
@Route('/')
class Probe {
@Get('/probe')
async probe(@needs('rateLimit') limit: RateLimiter, @ctx() context: { ip?: string }) {
await limit('signin');
return { ip: context.ip };
}
}
@Module({ mountpoint: '/', controllers: [Probe] })
class ProbeModule {}
/** A running server, whichever helper started it. */
interface Served {
port: number;
close(): Promise<void>;
}
interface RuntimeGlobals {
Deno?: unknown;
Bun?: unknown;
}
/**
* Serves `app` on `hostname` through the helper this runtime actually uses in production.
*
* The adapters are imported lazily because each one only works on its own runtime. Node takes no
* hostname: `listen(port)` binds the unspecified address, which is dual-stack wherever IPv6 exists.
*/
async function serve(app: App, hostname: string): Promise<Served> {
const globals = globalThis as RuntimeGlobals;
if (globals.Deno) {
const { serveDeno } = await import('@green-tea/core/deno');
const server = await serveDeno(app, { hostname, port: 0, onListen: () => {} });
const { port } = (server as unknown as { addr: { port: number } }).addr;
return { port, close: () => server.close({ timeoutMs: 1_000 }) };
}
if (globals.Bun) {
const { serveBun } = await import('@green-tea/core/bun');
const server = await serveBun(app, { hostname, port: 0 });
return { port: server.port, close: () => server.close({ timeoutMs: 1_000 }) };
}
const server = await app.listen(0);
return { port: (server.address() as AddressInfo).port, close: () => app.close({ timeoutMs: 1_000 }) };
}
/** Whether this host can bind the IPv6 loopback at all; some CI containers cannot. */
function ipv6Available(): Promise<boolean> {
return new Promise((resolve) => {
const probe = createServer();
probe.once('error', () => resolve(false));
probe.listen(0, '::1', () => probe.close(() => resolve(true)));
});
}
test('two peers on different addresses get separate budgets on the real serving path', async (t) => {
// Without IPv6, the fallback is two IPv4 loopback addresses. Every 127/8 address answers on Linux,
// which is what CI runs; macOS configures only 127.0.0.1, so there the fallback cannot connect.
const ipv6 = await ipv6Available();
const [hostname, a, b] = ipv6 ? ['::', '127.0.0.1', '[::1]'] : ['0.0.0.0', '127.0.0.1', '127.0.0.2'];
if (!ipv6) t.diagnostic('no IPv6 loopback: falling back to 127.0.0.1 and 127.0.0.2 (Linux only)');
const app = createApp({
modules: [ProbeModule],
plugins: [rateLimit({ rules: { signin: { windowMs: 60_000, max: 1, message: 'too many' } } })],
});
const server = await serve(app, hostname);
const hit = (host: string) => fetch(`http://${host}:${server.port}/probe`);
try {
const first = await hit(a);
assert.equal(first.status, 200);
const { ip: ipA } = (await first.json()) as { ip?: string };
assert.equal((await hit(a)).status, 429, 'client A was not limited at max: 1');
const other = await hit(b);
const body = (await other.text()) || '(empty body)';
// Checked before B's status so a regression names its cause: an empty `ctx.ip` is what folds both
// clients into one bucket, and the 429 that follows is only its symptom.
assert.ok(ipA, `ctx.ip was empty for client A on this serving path: ${JSON.stringify(ipA)}`);
assert.equal(other.status, 200, `client B shared client A's bucket (ctx.ip ${JSON.stringify(ipA)}): ${body}`);
const { ip: ipB } = JSON.parse(body) as { ip?: string };
assert.ok(ipB, 'ctx.ip was empty for client B');
assert.notEqual(ipA, ipB, 'both clients reported the same ctx.ip');
} finally {
await server.close();
}
});