Skip to content

Commit bf66282

Browse files
committed
use bodies
1 parent b999597 commit bf66282

File tree

3 files changed

+27
-40
lines changed

3 files changed

+27
-40
lines changed

worker/test/ai-gateway/pass-through.spec.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ describe("Pass-Through Tests", () => {
9292
expects: {
9393
headers: {
9494
// Without NO_MAPPING, Anthropic uses OpenAI compatibility mode with Authorization header
95-
"Authorization": /^Bearer /,
95+
Authorization: /^Bearer /,
9696
},
9797
},
9898
},
@@ -315,7 +315,8 @@ describe("Pass-Through Tests", () => {
315315

316316
it("should route to Bedrock endpoint with ap-southeast prefix", () =>
317317
runGatewayTest({
318-
model: "ap-southeast-2.anthropic.claude-3-7-sonnet-20250219-v1:0/bedrock",
318+
model:
319+
"ap-southeast-2.anthropic.claude-3-7-sonnet-20250219-v1:0/bedrock",
319320
request: {
320321
messages: [{ role: "user", content: "Test APAC Bedrock" }],
321322
maxTokens: 100,
@@ -326,7 +327,8 @@ describe("Pass-Through Tests", () => {
326327
// Note: AP prefix in model doesn't change the region, still uses us-east-1
327328
url: "https://bedrock-runtime.us-east-1.amazonaws.com/model/ap-southeast-2.anthropic.claude-3-7-sonnet-20250219-v1:0/invoke",
328329
response: "success",
329-
model: "ap-southeast-2.anthropic.claude-3-7-sonnet-20250219-v1:0",
330+
model:
331+
"ap-southeast-2.anthropic.claude-3-7-sonnet-20250219-v1:0",
330332
data: {
331333
id: "msg_bedrock_apac",
332334
type: "message",
@@ -350,7 +352,8 @@ describe("Pass-Through Tests", () => {
350352
describe("Mixed provider fallback scenarios", () => {
351353
it("should fallback from Groq to OpenAI to Anthropic", () =>
352354
runGatewayTest({
353-
model: "llama-3.3-70b-versatile/groq,gpt-4-turbo/openai,claude-3-7-sonnet-20250219/anthropic",
355+
model:
356+
"llama-3.3-70b-versatile/groq,gpt-4-turbo/openai,claude-3-7-sonnet-20250219/anthropic",
354357
request: {
355358
messages: [{ role: "user", content: "Test triple fallback" }],
356359
maxTokens: 100,
@@ -387,7 +390,7 @@ describe("Pass-Through Tests", () => {
387390
expects: {
388391
headers: {
389392
// Without NO_MAPPING, Anthropic uses OpenAI compatibility mode with Authorization header
390-
"Authorization": /^Bearer /,
393+
Authorization: /^Bearer /,
391394
},
392395
},
393396
},
@@ -422,7 +425,9 @@ describe("Pass-Through Tests", () => {
422425
id: "msg_no_mapping_fallback",
423426
type: "message",
424427
role: "assistant",
425-
content: [{ type: "text", text: "NO_MAPPING fallback response" }],
428+
content: [
429+
{ type: "text", text: "NO_MAPPING fallback response" },
430+
],
426431
model: "claude-3-7-sonnet-20250219",
427432
usage: { input_tokens: 10, output_tokens: 5 },
428433
},

worker/test/ai-gateway/registry-anthropic.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -682,4 +682,4 @@ describe("Anthropic Registry Tests", () => {
682682
}));
683683
});
684684
});
685-
});
685+
});

worker/test/ai-gateway/test-framework.ts

Lines changed: 15 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -164,28 +164,13 @@ export async function runGatewayTest(
164164
expect(requestWrapper.getMethod()).toBe(method);
165165
}
166166

167-
// Check body contains
168-
// Note: Commenting out body checks because getText() consumes the stream
169-
// and breaks fallback tests where multiple providers need to read the body
170-
// if (bodyContains && requestWrapper.getText) {
171-
// const body = await requestWrapper.getText();
172-
// for (const text of bodyContains) {
173-
// expect(body).toContain(text);
174-
// }
175-
// }
167+
if (bodyContains && requestWrapper.getText) {
168+
const body = await requestWrapper.getText();
169+
for (const text of bodyContains) {
170+
expect(body).toContain(text);
171+
}
172+
}
176173
}
177-
178-
// Verify full URL with path
179-
// if (expectation && requestWrapper.getUrl) {
180-
// const fullUrl = requestWrapper.getUrl();
181-
// const expectedPath = expectation.url.includes("/v1/")
182-
// ? expectation.url.substring(expectation.url.indexOf("/v1/"))
183-
// : "";
184-
// if (expectedPath) {
185-
// expect(fullUrl).toContain(expectedPath);
186-
// }
187-
// }
188-
189174
// Custom verification for complex cases
190175
if (expectation?.customVerify) {
191176
expectation.customVerify({ targetProps, requestWrapper, env, ctx });
@@ -245,24 +230,21 @@ export async function runGatewayTest(
245230
);
246231

247232
// Build request with custom headers if provided
248-
const requestOptions = createAIGatewayRequest(scenario.model, scenario.request);
249-
233+
const requestOptions = createAIGatewayRequest(
234+
scenario.model,
235+
scenario.request
236+
);
237+
250238
// Add custom headers like NO_MAPPING if specified
251239
if (scenario.request?.bodyMapping) {
252-
requestOptions.headers = {
253-
...requestOptions.headers,
254-
"Helicone-Gateway-Body-Mapping": scenario.request.bodyMapping,
255-
};
240+
(requestOptions.headers as any)["Helicone-Gateway-Body-Mapping"] = scenario.request.bodyMapping;
256241
}
257-
242+
258243
// Add any additional custom headers
259244
if (scenario.request?.headers) {
260-
requestOptions.headers = {
261-
...requestOptions.headers,
262-
...scenario.request.headers,
263-
};
245+
Object.assign(requestOptions.headers, scenario.request.headers);
264246
}
265-
247+
266248
const response = await SELF.fetch(
267249
"https://ai-gateway.helicone.ai/v1/chat/completions",
268250
requestOptions

0 commit comments

Comments
 (0)