mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 05:27:39 +00:00
refactor(channels): dedupe transport and gateway test scaffolds
This commit is contained in:
@@ -104,6 +104,21 @@ describe("OpenAI-compatible HTTP API (e2e)", () => {
|
||||
agentCommand.mockReset();
|
||||
agentCommand.mockResolvedValueOnce({ payloads } as never);
|
||||
};
|
||||
const expectAgentSessionKeyMatch = async (request: {
|
||||
body: unknown;
|
||||
headers?: Record<string, string>;
|
||||
matcher: RegExp;
|
||||
}) => {
|
||||
mockAgentOnce([{ text: "hello" }]);
|
||||
const res = await postChatCompletions(port, request.body, request.headers);
|
||||
expect(res.status).toBe(200);
|
||||
expect(agentCommand).toHaveBeenCalledTimes(1);
|
||||
const [opts] = agentCommand.mock.calls[0] ?? [];
|
||||
expect((opts as { sessionKey?: string } | undefined)?.sessionKey ?? "").toMatch(
|
||||
request.matcher,
|
||||
);
|
||||
await res.text();
|
||||
};
|
||||
|
||||
try {
|
||||
{
|
||||
@@ -126,56 +141,32 @@ describe("OpenAI-compatible HTTP API (e2e)", () => {
|
||||
}
|
||||
|
||||
{
|
||||
mockAgentOnce([{ text: "hello" }]);
|
||||
const res = await postChatCompletions(
|
||||
port,
|
||||
{ model: "openclaw", messages: [{ role: "user", content: "hi" }] },
|
||||
{ "x-openclaw-agent-id": "beta" },
|
||||
);
|
||||
expect(res.status).toBe(200);
|
||||
|
||||
expect(agentCommand).toHaveBeenCalledTimes(1);
|
||||
const [opts] = agentCommand.mock.calls[0] ?? [];
|
||||
expect((opts as { sessionKey?: string } | undefined)?.sessionKey ?? "").toMatch(
|
||||
/^agent:beta:/,
|
||||
);
|
||||
await res.text();
|
||||
}
|
||||
|
||||
{
|
||||
mockAgentOnce([{ text: "hello" }]);
|
||||
const res = await postChatCompletions(port, {
|
||||
model: "openclaw:beta",
|
||||
messages: [{ role: "user", content: "hi" }],
|
||||
await expectAgentSessionKeyMatch({
|
||||
body: { model: "openclaw", messages: [{ role: "user", content: "hi" }] },
|
||||
headers: { "x-openclaw-agent-id": "beta" },
|
||||
matcher: /^agent:beta:/,
|
||||
});
|
||||
expect(res.status).toBe(200);
|
||||
|
||||
expect(agentCommand).toHaveBeenCalledTimes(1);
|
||||
const [opts] = agentCommand.mock.calls[0] ?? [];
|
||||
expect((opts as { sessionKey?: string } | undefined)?.sessionKey ?? "").toMatch(
|
||||
/^agent:beta:/,
|
||||
);
|
||||
await res.text();
|
||||
}
|
||||
|
||||
{
|
||||
mockAgentOnce([{ text: "hello" }]);
|
||||
const res = await postChatCompletions(
|
||||
port,
|
||||
{
|
||||
await expectAgentSessionKeyMatch({
|
||||
body: {
|
||||
model: "openclaw:beta",
|
||||
messages: [{ role: "user", content: "hi" }],
|
||||
},
|
||||
{ "x-openclaw-agent-id": "alpha" },
|
||||
);
|
||||
expect(res.status).toBe(200);
|
||||
matcher: /^agent:beta:/,
|
||||
});
|
||||
}
|
||||
|
||||
expect(agentCommand).toHaveBeenCalledTimes(1);
|
||||
const [opts] = agentCommand.mock.calls[0] ?? [];
|
||||
expect((opts as { sessionKey?: string } | undefined)?.sessionKey ?? "").toMatch(
|
||||
/^agent:alpha:/,
|
||||
);
|
||||
await res.text();
|
||||
{
|
||||
await expectAgentSessionKeyMatch({
|
||||
body: {
|
||||
model: "openclaw:beta",
|
||||
messages: [{ role: "user", content: "hi" }],
|
||||
},
|
||||
headers: { "x-openclaw-agent-id": "alpha" },
|
||||
matcher: /^agent:alpha:/,
|
||||
});
|
||||
}
|
||||
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user