@@ -1311,3 +1311,68 @@ describe("provider-executed hosted calls", () => {
13111311 )).toBeUndefined();
13121312 });
13131313});
1314+
1315+ describe("xAI hosted-call authorization through handleResponses", () => {
1316+ const hostedCall = {
1317+ type: "custom_tool_call",
1318+ id: "ctc_search",
1319+ call_id: "xs_call-1",
1320+ name: "x_keyword_search",
1321+ input: "{}",
1322+ status: "completed",
1323+ };
1324+
1325+ async function post(baseUrl: string): Promise<Response> {
1326+ const config = {
1327+ port: 0,
1328+ defaultProvider: "fixture",
1329+ providers: {
1330+ fixture: {
1331+ adapter: "openai-responses",
1332+ baseUrl,
1333+ authMode: "key",
1334+ apiKey: "fixture-key",
1335+ },
1336+ },
1337+ } as OcxConfig;
1338+ const savedFetch = globalThis.fetch;
1339+ globalThis.fetch = (async () => Response.json({
1340+ id: "resp_search",
1341+ status: "completed",
1342+ output: [hostedCall],
1343+ })) as typeof fetch;
1344+ try {
1345+ return await handleResponses(new Request("http://localhost/v1/responses", {
1346+ method: "POST",
1347+ headers: { "content-type": "application/json" },
1348+ body: JSON.stringify({
1349+ model: "fixture/grok-4.6",
1350+ stream: false,
1351+ input: [{ role: "user", content: [{ type: "input_text", text: "search" }] }],
1352+ tools: [
1353+ { type: "function", name: "shell", parameters: { type: "object" } },
1354+ { type: "x_search" },
1355+ ],
1356+ }),
1357+ }), config, { model: "", provider: "" });
1358+ } finally {
1359+ globalThis.fetch = savedFetch;
1360+ }
1361+ }
1362+
1363+ test("accepts the measured xs_call shape for an exact xAI destination", async () => {
1364+ const response = await post("https://api.x.ai/v1");
1365+
1366+ expect(response.status).toBe(200);
1367+ const body = await response.json() as { output: Array<Record<string, unknown>> };
1368+ expect(body.output[0]).toMatchObject(hostedCall);
1369+ });
1370+
1371+ test("rejects the identical item for a lookalike destination", async () => {
1372+ const response = await post("https://api.x.ai.evil.test/v1");
1373+
1374+ expect(response.status).toBe(502);
1375+ const body = await response.json() as { error: { message: string } };
1376+ expect(body.error.message).toContain('undeclared client tool "x_keyword_search"');
1377+ });
1378+ });
0 commit comments