mirror of
https://github.com/profullstack/logicsrc.git
synced 2026-12-01 09:24:46 +00:00
Enforce OpenContext HTTP byte limit while streaming (#136)
Some checks are pending
CI / build (push) Waiting to run
test / test (push) Waiting to run
Some checks are pending
CI / build (push) Waiting to run
test / test (push) Waiting to run
This commit is contained in:
parent
7eba9efd10
commit
edf9a1b063
2 changed files with 96 additions and 32 deletions
33
packages/opencontext/src/adapters/http.test.ts
Normal file
33
packages/opencontext/src/adapters/http.test.ts
Normal 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" });
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue