Skip to content

Commit d67cbd4

Browse files
committed
test fix
1 parent 2afa321 commit d67cbd4

3 files changed

Lines changed: 3 additions & 16 deletions

File tree

apps/backend/src/app/api/latest/ai/query/[mode]/route.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export const POST = createSmartRouteHandler({
3434

3535

3636
if (apiKey === "FORWARD_TO_PRODUCTION") {
37-
const prodResponse = await forwardToProduction(fullReq.headers, mode, body);
37+
const prodResponse = await forwardToProduction(mode, body);
3838
return {
3939
statusCode: prodResponse.status,
4040
bodyType: "response" as const,

apps/backend/src/lib/ai/forward.ts

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,11 @@
11
import { type RequestBody } from "@/lib/ai/schema";
22

33
export async function forwardToProduction(
4-
requestHeaders: Record<string, string[] | undefined>,
54
mode: "stream" | "generate",
65
body: RequestBody,
76
): Promise<Response> {
87
const productionUrl = `https://api.stack-auth.com/api/latest/ai/query/${mode}`;
9-
const allowedHeaders = new Set([
10-
"x-stack-access-type",
11-
"x-stack-access-token",
12-
"x-stack-publishable-client-key",
13-
]);
14-
158
const forwardHeaders = new Headers();
16-
for (const [key, values] of Object.entries(requestHeaders)) {
17-
if (values == null) continue;
18-
const lowerKey = key.toLowerCase();
19-
if (!allowedHeaders.has(lowerKey)) continue;
20-
forwardHeaders.set(lowerKey, values[0] ?? "");
21-
}
229

2310
forwardHeaders.set("content-type", "application/json");
2411

apps/e2e/tests/backend/endpoints/api/v1/ai-query.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
import { getEnvVariable } from "@stackframe/stack-shared/dist/utils/env";
12
import { describe } from "vitest";
23
import { it } from "../../../../helpers";
34
import { niceBackendFetch, Project } from "../../../backend-helpers";
4-
import { getEnvVariable } from "@stackframe/stack-shared/dist/utils/env";
55

66
const hasRealAiKey = (() => {
77
const key = getEnvVariable("STACK_OPENROUTER_API_KEY", "");
@@ -210,7 +210,7 @@ describe("AI Query Endpoint - Validation", () => {
210210
},
211211
});
212212

213-
expect(response.status).not.toBe(400);
213+
expect(response.body).not.toMatchObject({ code: "SCHEMA_ERROR" });
214214

215215
}, 10000); // 60 seconds for AI API call
216216
});

0 commit comments

Comments
 (0)