mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-08-13 18:52:18 +03:00
* feat(devin-desktop): replace public Windsurf provider * fix(migrations): renumber Devin Desktop migration to 151 (avoid 147 collision) 147_windsurf_to_devin_desktop.sql collided with the released 147_api_keys_model_access_mode.sql — getMigrationFiles throws "Migration version collision detected" on every DB start. Base occupies slots up to 150, so renumber the new migration to 151 and point the windsurf→devin RENAMED_MIGRATION_COMPATIBILITY entries (and tests) at it. 147 is freed in KNOWN_GAPS since 147_api_keys now owns the slot. Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com> --------- Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com>
117 lines
5.1 KiB
TypeScript
117 lines
5.1 KiB
TypeScript
import { describe, it } from "node:test";
|
|
import assert from "node:assert/strict";
|
|
|
|
const mod = await import("../../open-sse/services/tokenRefresh.ts");
|
|
|
|
describe("tokenRefresh helpers", () => {
|
|
describe("getRefreshLeadMs", () => {
|
|
it("returns explicit lead time for known providers", () => {
|
|
assert.equal(mod.getRefreshLeadMs("codex"), 5 * 60 * 1000);
|
|
assert.equal(mod.getRefreshLeadMs("openai"), 5 * 60 * 1000);
|
|
assert.equal(mod.getRefreshLeadMs("claude"), 5 * 60 * 1000);
|
|
assert.equal(mod.getRefreshLeadMs("antigravity"), 15 * 60 * 1000);
|
|
});
|
|
|
|
it("falls back to TOKEN_EXPIRY_BUFFER_MS for unknown providers", () => {
|
|
assert.equal(mod.getRefreshLeadMs("unknown-provider"), mod.TOKEN_EXPIRY_BUFFER_MS);
|
|
assert.equal(mod.getRefreshLeadMs(""), mod.TOKEN_EXPIRY_BUFFER_MS);
|
|
// `iflow` was removed from the product; its 24h entry outlived it in the TTL map.
|
|
// Asserted here rather than deleted from the "known providers" case above, so a
|
|
// silent reintroduction of the entry turns this red instead of passing unnoticed.
|
|
assert.equal(mod.getRefreshLeadMs("iflow"), mod.TOKEN_EXPIRY_BUFFER_MS);
|
|
});
|
|
|
|
it("honors a positive per-connection refreshLeadMs override", () => {
|
|
// Override beats both the provider default and the fallback buffer.
|
|
assert.equal(mod.getRefreshLeadMs("codex", { refreshLeadMs: 90_000 }), 90_000);
|
|
assert.equal(mod.getRefreshLeadMs("unknown-provider", { refreshLeadMs: 12_345 }), 12_345);
|
|
});
|
|
|
|
it("ignores invalid or non-positive override values", () => {
|
|
// Falls through to provider default / buffer when the override is unusable.
|
|
assert.equal(mod.getRefreshLeadMs("codex", null), 5 * 60 * 1000);
|
|
assert.equal(mod.getRefreshLeadMs("codex", {}), 5 * 60 * 1000);
|
|
assert.equal(mod.getRefreshLeadMs("codex", { refreshLeadMs: 0 }), 5 * 60 * 1000);
|
|
assert.equal(mod.getRefreshLeadMs("codex", { refreshLeadMs: -1 }), 5 * 60 * 1000);
|
|
assert.equal(
|
|
mod.getRefreshLeadMs("codex", { refreshLeadMs: "60000" as unknown as number }),
|
|
5 * 60 * 1000
|
|
);
|
|
assert.equal(mod.getRefreshLeadMs("codex", { refreshLeadMs: NaN }), 5 * 60 * 1000);
|
|
assert.equal(
|
|
mod.getRefreshLeadMs("unknown-provider", { refreshLeadMs: -5 }),
|
|
mod.TOKEN_EXPIRY_BUFFER_MS
|
|
);
|
|
});
|
|
});
|
|
|
|
describe("supportsTokenRefresh", () => {
|
|
it("returns true for explicitly supported providers", () => {
|
|
assert.equal(mod.supportsTokenRefresh("gemini"), true);
|
|
assert.equal(mod.supportsTokenRefresh("claude"), true);
|
|
assert.equal(mod.supportsTokenRefresh("codex"), true);
|
|
assert.equal(mod.supportsTokenRefresh("github"), true);
|
|
assert.equal(mod.supportsTokenRefresh("kiro"), true);
|
|
assert.equal(mod.supportsTokenRefresh("cline"), true);
|
|
assert.equal(mod.supportsTokenRefresh("devin-desktop"), false);
|
|
assert.equal(mod.supportsTokenRefresh("devin-cli"), false);
|
|
assert.equal(mod.supportsTokenRefresh("windsurf"), false);
|
|
});
|
|
|
|
it("returns false for unknown providers without refreshUrl/tokenUrl", () => {
|
|
assert.equal(mod.supportsTokenRefresh("nonexistent-provider"), false);
|
|
});
|
|
});
|
|
|
|
describe("isUnrecoverableRefreshError", () => {
|
|
it("returns true for unrecoverable error types", () => {
|
|
assert.equal(mod.isUnrecoverableRefreshError({ error: "unrecoverable_refresh_error" }), true);
|
|
assert.equal(mod.isUnrecoverableRefreshError({ error: "refresh_token_reused" }), true);
|
|
assert.equal(mod.isUnrecoverableRefreshError({ error: "invalid_request" }), true);
|
|
assert.equal(mod.isUnrecoverableRefreshError({ error: "invalid_grant" }), true);
|
|
});
|
|
|
|
it("returns false for recoverable errors", () => {
|
|
assert.equal(mod.isUnrecoverableRefreshError({ error: "rate_limited" }), false);
|
|
assert.equal(mod.isUnrecoverableRefreshError({ error: "server_error" }), false);
|
|
});
|
|
|
|
it("returns false for null/undefined/non-object", () => {
|
|
assert.equal(mod.isUnrecoverableRefreshError(null) || false, false);
|
|
assert.equal(mod.isUnrecoverableRefreshError(undefined) || false, false);
|
|
assert.equal(mod.isUnrecoverableRefreshError("string") || false, false);
|
|
});
|
|
});
|
|
|
|
describe("isProviderBlocked", () => {
|
|
it("returns false for unknown provider", () => {
|
|
assert.equal(mod.isProviderBlocked("nonexistent"), false);
|
|
});
|
|
});
|
|
|
|
describe("diagnostic functions", () => {
|
|
it("getConnectionRefreshMutexStatus returns object", () => {
|
|
const status = mod.getConnectionRefreshMutexStatus();
|
|
assert.equal(typeof status, "object");
|
|
assert.notEqual(status, null);
|
|
});
|
|
|
|
it("getCircuitBreakerStatus returns object", () => {
|
|
const status = mod.getCircuitBreakerStatus();
|
|
assert.equal(typeof status, "object");
|
|
assert.notEqual(status, null);
|
|
});
|
|
});
|
|
|
|
describe("constants", () => {
|
|
it("TOKEN_EXPIRY_BUFFER_MS is 5 minutes", () => {
|
|
assert.equal(mod.TOKEN_EXPIRY_BUFFER_MS, 300000);
|
|
});
|
|
|
|
it("REFRESH_LEAD_MS is a record with expected keys", () => {
|
|
assert.equal(typeof mod.REFRESH_LEAD_MS, "object");
|
|
assert.equal(mod.REFRESH_LEAD_MS.codex, 5 * 60 * 1000);
|
|
});
|
|
});
|
|
});
|