Enforce OpenContext HTTP byte limit while streaming (#136)
Some checks are pending
CI / build (push) Waiting to run
test / test (push) Waiting to run

This commit is contained in:
RissRIce 2026-08-09 22:57:05 -06:00 • committed by GitHub
parent 7eba9efd10
commit edf9a1b063
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 96 additions and 32 deletions

View file

@ -0,0 +1,33 @@
import { afterEach, describe, expect, it, vi } from "vitest";
import { httpAdapter } from "./http.js";
afterEach(() => {
vi.unstubAllGlobals();
});
describe("http adapter response limits", () => {
it("enforces the byte limit for multibyte responses without a content-length header", async () => {
const content = "é".repeat(3 * 1024 * 1024);
vi.stubGlobal("fetch", vi.fn().mockResolvedValue(new Response(content)));
await expect(
httpAdapter.load("https://example.com/context.md", {
dir: process.cwd(),
offline: false,
config: {}
})
).rejects.toThrow(/response exceeds the 5242880 byte limit/);
});
it("decodes responses within the byte limit", async () => {
vi.stubGlobal("fetch", vi.fn().mockResolvedValue(new Response("café")));
await expect(
httpAdapter.load("https://example.com/context.md", {
dir: process.cwd(),
offline: false,
config: {}
})
).resolves.toMatchObject({ content: "café", trust: "untrusted" });
});
});