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 fs from "node:fs";
import os from "node:os";
import path from "node:path";
const TEST_DATA_DIR = fs.mkdtempSync(path.join(os.tmpdir(), "omniroute-grok-device-route-"));
process.env.DATA_DIR = TEST_DATA_DIR;
const core = await import("../../src/lib/db/core.ts");
const settingsDb = await import("../../src/lib/db/settings.ts");
const route = await import("../../src/app/api/oauth/[provider]/[action]/route.ts");
const originalFetch = globalThis.fetch;
test.before(async () => {
await settingsDb.updateSettings({ requireLogin: false });
});
test.afterEach(() => {
globalThis.fetch = originalFetch;
});
test.after(() => {
core.resetDbInstance();
fs.rmSync(TEST_DATA_DIR, { recursive: true, force: true, maxRetries: 5, retryDelay: 100 });
});
test("grok-cli poll does not require a PKCE code verifier", async () => {
let upstreamBody = "";
globalThis.fetch = (async (_input, init) => {
upstreamBody = String(init?.body);
return new Response(
JSON.stringify({
error: "authorization_pending",
error_description: "User has not yet authorized",
}),
{ status: 400, headers: { "Content-Type": "application/json" } }
);
}) as typeof fetch;
const request = new Request("http://localhost:20128/api/oauth/grok-cli/poll", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ deviceCode: "opaque-device-code" }),
});
const response = await route.POST(request, {
params: Promise.resolve({ provider: "grok-cli", action: "poll" }),
});
const body = await response.json();
const params = new URLSearchParams(upstreamBody);
assert.equal(response.status, 200);
assert.equal(body.success, false);
assert.equal(body.pending, true);
assert.equal(body.error, "authorization_pending");
assert.equal(params.get("device_code"), "opaque-device-code");
});