Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 54 additions & 4 deletions tests/providers/xai/xai-responses-adjacency.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,72 @@ function xaiOauthResponses(overrides: Partial<OcxProviderConfig> = {}): OcxProvi
}

function buildBody(provider: OcxProviderConfig, rawBody: Record<string, unknown>): Record<string, unknown> {
const requestBody = typeof rawBody.model === "string" ? rawBody : { model: MODEL, ...rawBody };
const before = structuredClone(requestBody);
const built = createResponsesPassthroughAdapter(provider).buildRequest({
modelId: MODEL,
modelId: typeof requestBody.model === "string" ? requestBody.model : MODEL,
context: { messages: [] },
stream: true,
options: {},
previousResponseId: typeof rawBody.previous_response_id === "string"
? rawBody.previous_response_id
: undefined,
_rawBody: { model: MODEL, ...rawBody },
_rawBody: requestBody,
} as Parameters<ReturnType<typeof createResponsesPassthroughAdapter>["buildRequest"]>[0], {
headers: new Headers(),
});
if (built instanceof Promise) throw new Error("Expected a synchronous Responses request builder");
expect(requestBody).toEqual(before);
return JSON.parse(String(built.body)) as Record<string, unknown>;
}

describe("xAI Responses include compatibility", () => {
for (const baseUrl of ["https://api.x.ai/v1", "https://us.api.x.ai/v1", "https://cli-chat-proxy.grok.com/v1"]) {
test(`preserves Grok 4.7 encrypted tool continuation at ${baseUrl}`, () => {
const raw = {
model: "grok-4.7",
store: false,
reasoning: { effort: "xhigh" },
include: ["output.encrypted_content", "reasoning.encrypted_content", "web_search_call.action.sources", "output.encrypted_content"],
tools: [{ type: "function", name: "read_fixture", parameters: { type: "object", properties: {} } }],
input: [
{ type: "reasoning", encrypted_content: "synthetic-native-ciphertext", summary: [] },
{ type: "function_call", call_id: "call_fixture", name: "read_fixture", arguments: "{}" },
{ type: "function_call_output", call_id: "call_fixture", output: "nonce=synthetic-fixture" },
],
};
const before = structuredClone(raw);
const body = buildBody(xaiOauthResponses({ baseUrl }), raw);

expect(body.include).toEqual(["reasoning.encrypted_content", "web_search_call.action.sources"]);
expect(body.model).toBe("grok-4.7");
expect(body.reasoning).toEqual(raw.reasoning);
expect(body.store).toBe(false);
expect(body.tools).toEqual(raw.tools);
expect(body.input).toEqual(raw.input);
expect(raw).toEqual(before);
Comment thread
Reedtrullz marked this conversation as resolved.
Resolved
});
}

test("does not invent include values for absent, empty or non-array input", () => {
const provider = xaiOauthResponses();
expect(buildBody(provider, { input: [] })).not.toHaveProperty("include");
expect(buildBody(provider, { input: [], include: [] }).include).toEqual([]);
expect(buildBody(provider, { input: [], include: "reasoning.encrypted_content" }).include)
.toBe("reasoning.encrypted_content");
});

for (const baseUrl of ["https://chatgpt.com/backend-api/codex", "https://gateway.example/v1", "https://api.x.ai.evil.example/v1", "https://api.x.ai:444/v1"]) {
test(`preserves include entries and caller input outside xAI at ${baseUrl}`, () => {
const raw = { include: ["output.encrypted_content", "reasoning.encrypted_content"], input: [] };
const before = structuredClone(raw);
const body = buildBody(xaiOauthResponses({ baseUrl, authMode: "key" }), raw);

expect(body.include).toEqual(raw.include);
expect(raw).toEqual(before);
});
}

test("drops the include entry xAI rejects instead of ignoring", () => {
const body = buildBody(xaiOauthResponses(), {
include: ["output.encrypted_content", "reasoning.encrypted_content"],
Expand All @@ -57,7 +107,7 @@ describe("xAI Responses include compatibility", () => {
});

test("strips the rejected include entry for the US regional endpoint", () => {
const provider = xaiOauthResponses({ baseUrl: "https://us.api.x.ai/v1", authMode: "api-key" });
const provider = xaiOauthResponses({ baseUrl: "https://us.api.x.ai/v1", authMode: "key" });
const body = buildBody(provider, {
include: ["output.encrypted_content", "reasoning.encrypted_content"], input: [],
});
Expand All @@ -70,7 +120,7 @@ describe("xAI Responses include compatibility", () => {
const provider: OcxProviderConfig = {
adapter: "openai-responses",
baseUrl: "https://api.openai.com/v1",
authMode: "api-key",
authMode: "key",
};
const body = buildBody(provider, { include: ["output.encrypted_content"], input: [] });

Expand Down
Loading