diff --git a/src/gateway/openai-http.message-channel.test.ts b/src/gateway/openai-http.message-channel.test.ts deleted file mode 100644 index db6a21d15ec..00000000000 --- a/src/gateway/openai-http.message-channel.test.ts +++ /dev/null @@ -1,59 +0,0 @@ -import { describe, expect, it } from "vitest"; -import { agentCommand, installGatewayTestHooks, withGatewayServer } from "./test-helpers.js"; - -installGatewayTestHooks({ scope: "test" }); - -const OPENAI_SERVER_OPTIONS = { - host: "127.0.0.1", - auth: { mode: "none" as const }, - controlUiEnabled: false, - openAiChatCompletionsEnabled: true, -}; - -async function runOpenAiMessageChannelRequest(params?: { messageChannelHeader?: string }) { - agentCommand.mockReset(); - agentCommand.mockResolvedValueOnce({ payloads: [{ text: "ok" }] } as never); - - let firstCall: { messageChannel?: string } | undefined; - await withGatewayServer( - async ({ port }) => { - const headers: Record = { - "content-type": "application/json", - "x-openclaw-scopes": "operator.write", - }; - if (params?.messageChannelHeader) { - headers["x-openclaw-message-channel"] = params.messageChannelHeader; - } - const res = await fetch(`http://127.0.0.1:${port}/v1/chat/completions`, { - method: "POST", - headers, - body: JSON.stringify({ - model: "openclaw", - messages: [{ role: "user", content: "hi" }], - }), - }); - - expect(res.status).toBe(200); - firstCall = (agentCommand.mock.calls[0] as unknown[] | undefined)?.[0] as - | { messageChannel?: string } - | undefined; - await res.text(); - }, - { serverOptions: OPENAI_SERVER_OPTIONS }, - ); - return firstCall; -} - -describe("OpenAI HTTP message channel", () => { - it("passes x-openclaw-message-channel through to agentCommand", async () => { - const firstCall = await runOpenAiMessageChannelRequest({ - messageChannelHeader: "custom-client-channel", - }); - expect(firstCall?.messageChannel).toBe("custom-client-channel"); - }); - - it("defaults messageChannel to webchat when header is absent", async () => { - const firstCall = await runOpenAiMessageChannelRequest(); - expect(firstCall?.messageChannel).toBe("webchat"); - }); -}); diff --git a/src/gateway/openai-http.test.ts b/src/gateway/openai-http.test.ts index d46386bbf76..d602f98aa74 100644 --- a/src/gateway/openai-http.test.ts +++ b/src/gateway/openai-http.test.ts @@ -152,6 +152,7 @@ describe("OpenAI-compatible HTTP API (e2e)", () => { (agentCommand.mock.calls[0] as unknown[] | undefined)?.[0] as | { sessionKey?: string; + messageChannel?: string; message?: string; extraSystemPrompt?: string; images?: Array<{ type: string; data: string; mimeType: string }>; @@ -204,6 +205,7 @@ describe("OpenAI-compatible HTTP API (e2e)", () => { }); expect(res.status).toBe(200); expect(agentCommand).toHaveBeenCalledTimes(1); + expect(getFirstAgentCall()?.messageChannel).toBe("webchat"); await res.text(); } @@ -270,6 +272,21 @@ describe("OpenAI-compatible HTTP API (e2e)", () => { await res.text(); } + { + mockAgentOnce([{ text: "hello" }]); + const res = await postChatCompletions( + port, + { + model: "openclaw", + messages: [{ role: "user", content: "hi" }], + }, + { "x-openclaw-message-channel": "custom-client-channel" }, + ); + expect(res.status).toBe(200); + expect(getFirstAgentCall()?.messageChannel).toBe("custom-client-channel"); + await res.text(); + } + { mockAgentOnce([{ text: "hello" }]); const res = await postChatCompletions(