Never stop coding. Free MIT AI gateway: one endpoint, 375 providers (150+ free), 1,400+ models Kimi, Claude, GPT, Gemini, GLM, DeepSeek, MiniMax. Works with Claude Code, Codex, Cursor, OpenCode, Cline & Copilot. Quota-aware auto-fallback, RTK+Caveman compression saves 15-95% tokens, MCP/A2A, Desktop/PWA. Built by 900+ contributors
TypeScript a2aai-agentsai-gatewayanthropicclaudeclaude-codeclinecodexcopilotcursordeepseekfree-aigeminikimillm-gatewaymcpopenaiopenai-proxyqwentoken-saver
import test from "node:test";
import assert from "node:assert/strict";
import { GithubExecutor } from "../../open-sse/executors/github.ts";
// GitHub Copilot's /chat/completions endpoint rejects a conversation that ends with an
// assistant message: "This model does not support assistant message prefill. The
// conversation must end with a user message." Anthropic clients (e.g. newest Claude
// Desktop) send a trailing assistant turn as a prefill seed — the Anthropic API honors
// it, but Copilot 400s. GithubExecutor.dropTrailingAssistantPrefill() strips the
// trailing assistant message(s) before dispatch, scoped to the github executor only.
// Port of 9router#2143 (author: Manuel <[email protected]>).
test("dropTrailingAssistantPrefill drops a single trailing assistant message", () => {
const executor = new GithubExecutor();
const messages = [
{ role: "user", content: "Hi" },
{ role: "assistant", content: "Here is the answer:" },
];
const out = executor.dropTrailingAssistantPrefill(messages);
assert.equal(out.length, 1);
assert.equal(out[0].role, "user");
});
test("dropTrailingAssistantPrefill drops multiple consecutive trailing assistant messages", () => {
const executor = new GithubExecutor();
const messages = [
{ role: "user", content: "Hi" },
{ role: "assistant", content: "one" },
{ role: "assistant", content: "two" },
];
const out = executor.dropTrailingAssistantPrefill(messages);
assert.equal(out.length, 1);
assert.equal(out[0].role, "user");
});
test("dropTrailingAssistantPrefill is a no-op (same reference) when the conversation ends with a user message", () => {
const executor = new GithubExecutor();
const messages = [
{ role: "user", content: "Hi" },
{ role: "assistant", content: "Hello" },
{ role: "user", content: "More" },
];
const out = executor.dropTrailingAssistantPrefill(messages);
assert.equal(out, messages, "must return the same array reference when nothing changes");
assert.equal(out.length, 3);
});
test("dropTrailingAssistantPrefill is a no-op when the conversation ends with a tool message", () => {
const executor = new GithubExecutor();
const messages = [
{ role: "user", content: "Hi" },
{ role: "assistant", content: null, tool_calls: [{ id: "x" }] },
{ role: "tool", tool_call_id: "x", content: "result" },
];
const out = executor.dropTrailingAssistantPrefill(messages);
assert.equal(out, messages, "must return the same array reference when nothing changes");
assert.equal(out.length, 3);
assert.equal(out[2].role, "tool");
});
test("dropTrailingAssistantPrefill never empties an assistant-only conversation", () => {
const executor = new GithubExecutor();
const messages = [{ role: "assistant", content: "only" }];
const out = executor.dropTrailingAssistantPrefill(messages);
assert.equal(out.length, 1, "must keep at least one message");
assert.equal(out[0].role, "assistant");
});
test("dropTrailingAssistantPrefill is null/empty safe", () => {
const executor = new GithubExecutor();
assert.deepEqual(executor.dropTrailingAssistantPrefill([]), []);
assert.equal(executor.dropTrailingAssistantPrefill(undefined), undefined);
assert.equal(executor.dropTrailingAssistantPrefill(null), null);
});
test("GithubExecutor.transformRequest drops the trailing assistant prefill end-to-end", () => {
const executor = new GithubExecutor();
// Use a non-Claude id so getModelTargetFormat("gh", ...) resolves to null and
// this stays on the /chat/completions path this test targets. Since #14575 EVERY
// claude-* id on the gh alias (registered or not) carries targetFormat:"claude"
// (native /v1/messages, which supports prefill — port of decolua/9router#2608,
// see github-copilot-claude-native-messages.test.ts) and intentionally skips
// this drop, so a Claude id can no longer exercise it.
const body = {
model: "gpt-4.1",
messages: [
{ role: "user", content: "Hi" },
{ role: "assistant", content: "Here is the answer:" },
],
};
const out = executor.transformRequest("gpt-4.1", body, false, {});
assert.equal(out.messages.length, 1);
assert.equal(out.messages[0].role, "user");
});
test("GithubExecutor.transformRequest leaves a user-terminated conversation untouched end-to-end", () => {
const executor = new GithubExecutor();
const body = {
model: "claude-sonnet-4.6",
messages: [
{ role: "user", content: "Hi" },
{ role: "assistant", content: "Hello" },
{ role: "user", content: "More" },
],
};
const out = executor.transformRequest("claude-sonnet-4.6", body, false, {});
assert.equal(out.messages.length, 3);
assert.equal(out.messages[2].role, "user");
});