Never stop coding. Free MIT AI gateway: one endpoint, 375 providers (150+ free), 1,400+ models Kimi, Claude, GPT, Gemini, GLM, DeepSeek, MiniMax. Works with Claude Code, Codex, Cursor, OpenCode, Cline & Copilot. Quota-aware auto-fallback, RTK+Caveman compression saves 15-95% tokens, MCP/A2A, Desktop/PWA. Built by 900+ contributors
TypeScript a2aai-agentsai-gatewayanthropicclaudeclaude-codeclinecodexcopilotcursordeepseekfree-aigeminikimillm-gatewaymcpopenaiopenai-proxyqwentoken-saver
import { test, after } from "node:test";
import assert from "node:assert/strict";
import { startFaultyUpstream } from "../helpers/faultyUpstream.ts";
test("ok mode returns 200 with body", async () => {
const up = await startFaultyUpstream({ kind: "ok", body: "hello" });
after(() => up.stop());
const res = await fetch(up.url);
assert.equal(res.status, 200);
assert.equal(await res.text(), "hello");
await up.stop();
});
test("status mode returns the given HTTP error code", async () => {
const up = await startFaultyUpstream({ kind: "status", code: 503, body: "down" });
const res = await fetch(up.url);
assert.equal(res.status, 503);
assert.equal(await res.text(), "down");
await up.stop();
});
test("latency mode delays the response", async () => {
const up = await startFaultyUpstream({ kind: "latency", ms: 120, body: "slow" });
const t0 = Date.now();
await (await fetch(up.url)).text();
assert.ok(Date.now() - t0 >= 100, "should be delayed ~120ms");
await up.stop();
});
test("reset mode destroys the socket (fetch rejects)", async () => {
const up = await startFaultyUpstream({ kind: "reset" });
await assert.rejects(() => fetch(up.url).then((r) => r.text()));
await up.stop();
});
test("timeout mode never responds (AbortSignal aborts)", async () => {
const up = await startFaultyUpstream({ kind: "timeout" });
await assert.rejects(() => fetch(up.url, { signal: AbortSignal.timeout(120) }));
await up.stop();
});
test("setMode switches behavior on a running server", async () => {
const up = await startFaultyUpstream({ kind: "ok", body: "a" });
up.setMode({ kind: "status", code: 429, body: "rl" });
const res = await fetch(up.url);
assert.equal(res.status, 429);
await up.stop();
});