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 { describe, it, afterEach, mock } from "node:test";
import assert from "node:assert/strict";
import fs from "node:fs";
import { loadRtkFilters } from "../../../open-sse/services/compression/engines/rtk/filterLoader.ts";
// F5.3: collectFilterSources() enumerates the builtin filters dir with an unguarded
// fs.readdirSync. A read failure there (lost permission, TOCTOU between existsSync and
// readdirSync, NFS timeout, removed dir on a read-only container) must NOT propagate into
// the compression pipeline — compression is best-effort and may never fail the request.
describe("RTK filter loader resilience", () => {
afterEach(() => {
mock.restoreAll();
// Drop any cache poisoned during the mocked run.
loadRtkFilters({ refresh: true });
});
it("degrades gracefully (does not throw) when the builtin dir cannot be read", () => {
// The only readdirSync on the loadRtkFilters path is the builtin enumeration, so an
// unconditional throw exercises exactly that call site.
mock.method(fs, "readdirSync", () => {
throw Object.assign(new Error("EACCES (mock)"), { code: "EACCES" });
});
assert.doesNotThrow(() => loadRtkFilters({ refresh: true }));
});
});