refactor(channels): dedupe transport and gateway test scaffolds

This commit is contained in:
Peter Steinberger
2026-02-16 14:52:15 +00:00
parent f717a13039
commit 93ca0ed54f
95 changed files with 4068 additions and 5221 deletions

View File

@@ -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:/,
});
}
{