mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-08-06 15:22:12 +03:00
GrokCliExecutor.execute() dispatches via raw https.request (nativePost) instead of the shared fetch path, so it never inherited (nor delegated to) BaseExecutor.execute()'s proactive-refresh gate the way codex.ts does via super.execute(). The only refresh that ever fired was the reactive one on a 401/403 from upstream — the rotating xAI refresh_token idled until real expiry, matching the "unusable within minutes, must delete/re-add" report. Wires in the same needsRefresh()/refreshCredentials() gate, using runWithOnPersist + isUnrecoverableRefreshError to keep the [refresh + persist] atomic under the same per-connection mutex Codex/Claude rely on for rotating refresh tokens (base.ts:592-644). Also fixes the smaller, separate bug #2 from the same report: grok-cli was absent from OAUTH_TEST_CONFIG in the connection-test route, so "Test Connection" always reported "Provider test not supported" regardless of token health. Added a checkExpiry entry (same pattern as qwen/cline/ kilocode — Grok Build's proxy doesn't expose a lightweight probe endpoint with the cli-specific headers this shared prober sends). Extracted OAUTH_TEST_CONFIG into its own module (oauthTestConfig.ts) so the new entry doesn't grow the frozen route.ts past its file-size cap. Bug #3 (no browser/device-code login for Grok Build) and bug #4 (quota display) from the same issue are feature gaps, not regressions — left as follow-ups per the triage plan-file. Refs #7610
27 lines
1.1 KiB
TypeScript
27 lines
1.1 KiB
TypeScript
import test from "node:test";
|
|
import assert from "node:assert/strict";
|
|
|
|
// #7610 bug #2: `grok-cli` was absent from OAUTH_TEST_CONFIG in
|
|
// src/app/api/providers/[id]/test/route.ts, so "Test Connection" for a Grok
|
|
// Build (OAuth) connection always fell through to the generic
|
|
// "Provider test not supported" branch, regardless of whether the token was
|
|
// actually healthy.
|
|
const { testOAuthConnection } = await import("../../src/app/api/providers/[id]/test/route.ts");
|
|
|
|
test("#7610: grok-cli OAuth connection test is no longer 'unsupported'", async () => {
|
|
const connection = {
|
|
provider: "grok-cli",
|
|
accessToken: "healthy-access-token",
|
|
refreshToken: "healthy-refresh-token",
|
|
// Far in the future — not expired, so this exercises the checkExpiry
|
|
// "still valid" branch rather than the refresh path.
|
|
tokenExpiresAt: new Date(Date.now() + 3600_000).toISOString(),
|
|
};
|
|
|
|
const result = await testOAuthConnection(connection);
|
|
|
|
assert.notEqual(result.diagnosis?.type, "unsupported");
|
|
assert.notEqual(result.error, "Provider test not supported");
|
|
assert.equal(result.valid, true);
|
|
});
|