mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-15 11:11:09 +00:00
test: move disabled compat routes to http harness
This commit is contained in:
@@ -40,15 +40,6 @@ afterAll(async () => {
|
||||
await enabledServer?.close({ reason: "openai http enabled suite done" });
|
||||
});
|
||||
|
||||
async function startServerWithDefaultConfig(port: number) {
|
||||
return await startGatewayServer(port, {
|
||||
host: "127.0.0.1",
|
||||
auth: { mode: "none" },
|
||||
controlUiEnabled: false,
|
||||
openAiChatCompletionsEnabled: false,
|
||||
});
|
||||
}
|
||||
|
||||
async function startServer(port: number, opts?: { openAiChatCompletionsEnabled?: boolean }) {
|
||||
return await startGatewayServer(port, {
|
||||
host: "127.0.0.1",
|
||||
@@ -89,23 +80,6 @@ async function postChatCompletions(port: number, body: unknown, headers?: Record
|
||||
return res;
|
||||
}
|
||||
|
||||
async function expectChatCompletionsDisabled(
|
||||
start: (port: number) => Promise<{ close: (opts?: { reason?: string }) => Promise<void> }>,
|
||||
) {
|
||||
const port = await getFreePort();
|
||||
const server = await start(port);
|
||||
try {
|
||||
const res = await postChatCompletions(port, {
|
||||
model: "openclaw",
|
||||
messages: [{ role: "user", content: "hi" }],
|
||||
});
|
||||
expect(res.status).toBe(404);
|
||||
await res.text();
|
||||
} finally {
|
||||
await server.close({ reason: "test done" });
|
||||
}
|
||||
}
|
||||
|
||||
function parseSseDataLines(text: string): string[] {
|
||||
return text
|
||||
.split("\n")
|
||||
@@ -115,15 +89,6 @@ function parseSseDataLines(text: string): string[] {
|
||||
}
|
||||
|
||||
describe("OpenAI-compatible HTTP API (e2e)", () => {
|
||||
it("rejects when disabled (default + config)", { timeout: 90_000 }, async () => {
|
||||
await expectChatCompletionsDisabled(startServerWithDefaultConfig);
|
||||
await expectChatCompletionsDisabled((port) =>
|
||||
startServer(port, {
|
||||
openAiChatCompletionsEnabled: false,
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it("handles request validation and routing", async () => {
|
||||
const port = enabledPort;
|
||||
const mockAgentOnce = (payloads: Array<{ text: string }>) => {
|
||||
|
||||
@@ -203,36 +203,6 @@ async function expectInvalidRequest(
|
||||
}
|
||||
|
||||
describe("OpenResponses HTTP API (e2e)", () => {
|
||||
it("rejects when disabled (default + config)", { timeout: 90_000 }, async () => {
|
||||
const port = await getFreePort();
|
||||
const server = await startServer(port);
|
||||
try {
|
||||
const res = await postResponses(port, {
|
||||
model: "openclaw",
|
||||
input: "hi",
|
||||
});
|
||||
expect(res.status).toBe(404);
|
||||
await ensureResponseConsumed(res);
|
||||
} finally {
|
||||
await server.close({ reason: "test done" });
|
||||
}
|
||||
|
||||
const disabledPort = await getFreePort();
|
||||
const disabledServer = await startServer(disabledPort, {
|
||||
openResponsesEnabled: false,
|
||||
});
|
||||
try {
|
||||
const res = await postResponses(disabledPort, {
|
||||
model: "openclaw",
|
||||
input: "hi",
|
||||
});
|
||||
expect(res.status).toBe(404);
|
||||
await ensureResponseConsumed(res);
|
||||
} finally {
|
||||
await disabledServer.close({ reason: "test done" });
|
||||
}
|
||||
});
|
||||
|
||||
it("handles OpenResponses request parsing and validation", async () => {
|
||||
const port = enabledPort;
|
||||
const mockAgentOnce = (payloads: Array<{ text: string }>, meta?: unknown) => {
|
||||
|
||||
@@ -9,6 +9,29 @@ import {
|
||||
} from "./server-http.test-harness.js";
|
||||
import type { ReadinessChecker } from "./server/readiness.js";
|
||||
|
||||
describe("gateway OpenAI-compatible disabled HTTP routes", () => {
|
||||
it("returns 404 when compat endpoints are disabled", async () => {
|
||||
await withGatewayServer({
|
||||
prefix: "openai-compat-disabled",
|
||||
resolvedAuth: AUTH_NONE,
|
||||
run: async (server) => {
|
||||
for (const path of ["/v1/chat/completions", "/v1/responses"]) {
|
||||
const req = createRequest({
|
||||
path,
|
||||
method: "POST",
|
||||
headers: { "content-type": "application/json" },
|
||||
});
|
||||
const { res, getBody } = createResponse();
|
||||
await dispatchRequest(server, req, res);
|
||||
|
||||
expect(res.statusCode, path).toBe(404);
|
||||
expect(getBody(), path).toBe("Not Found");
|
||||
}
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("gateway probe endpoints", () => {
|
||||
it("returns detailed readiness payload for local /ready requests", async () => {
|
||||
const getReadiness: ReadinessChecker = () => ({
|
||||
|
||||
Reference in New Issue
Block a user