OmniRoute/tests/unit/gemini-cli-client-version-fetch.test.ts
Bob.Hou ef3b71c687
feat(identity): refresh pinned CLI versions from their release feeds (#15642)
Onda 2 (HouMinXi) validada num único board em `.claude/worktrees/batch-w2` sobre `origin/release/v3.8.52` (`e05f1bd78bac`), 26 PRs, superfícies protegidas 0.

Evidência: `typecheck:core` limpo. changelog-integrity, complexity (2973/3218) e cognitive-complexity (1356/1437) dentro do baseline. Testes focados: 235 passaram. Os 5 vermelhos não são deste diff: o `.test.tsx` do cloudflared passa no Vitest (1/1); o intervalo do Codex usage passou 3/3 isolado (flake sob carga); o banner no-auth cai no mesmo `useContext` nulo de `tests/unit/request-log-detail-stream.test.ts`, que já existe no tip, por causa do React duplicado em `node_modules/node_modules` desta worktree.

O file-size do board ainda vê o teto antigo de `gateways.ts` (já corrigido em #15679) e o crescimento próprio desta onda em RoutingTab, auth, responseSanitizer, search, proxyFetch e stream. Esse rebaseline entra no follow-up, fora do squash.

⚠️ base-red inherited: #15306 (timeouts de suíte no tip, não neste diff).

Obrigado, @HouMinXi.
2026-10-06 17:40:27 -03:00

54 lines
1.8 KiB
TypeScript

/**
* Registry lookup for the advertised Gemini CLI client version.
*
* The captured pin is the floor; a newer dotted triple from the npm
* `@google/gemini-cli` `latest` document replaces it for 6 hours. A rejected
* fetch, a non-triple, or an older publish stays on the pin.
*/
import assert from "node:assert/strict";
import test from "node:test";
const canonical = await import("../../src/shared/constants/geminiCliClient.ts");
const NPM_LATEST = "https://registry.npmjs.org/@google/gemini-cli/latest";
function jsonResponse(body: unknown, status = 200): Response {
return new Response(JSON.stringify(body), {
status,
headers: { "Content-Type": "application/json" },
});
}
test.afterEach(() => {
canonical.resetGeminiCliClientVersionCache();
});
test("a fetched version newer than the pin is returned", async () => {
const urls: string[] = [];
const fetchMock = async (url: string | URL | Request) => {
urls.push(String(url));
return jsonResponse({ version: "0.62.0" });
};
assert.equal(
await canonical.refreshGeminiCliClientVersion(fetchMock as typeof fetch),
"0.62.0"
);
assert.equal(canonical.getGeminiCliClientVersion(), "0.62.0");
assert.equal(canonical.getGeminiCliUserAgent(), "GeminiCLI/0.62.0 (linux; x64)");
assert.equal(urls.length, 1);
assert.equal(urls[0], NPM_LATEST);
});
test("a fetch that rejects falls back to the pin", async () => {
const fetchMock = async () => {
throw new Error("registry unreachable");
};
assert.equal(
await canonical.refreshGeminiCliClientVersion(fetchMock as typeof fetch),
"0.1.0"
);
assert.equal(canonical.getGeminiCliClientVersion(), canonical.GEMINI_CLI_CLIENT_VERSION);
assert.equal(canonical.getGeminiCliUserAgent(), "GeminiCLI/0.1.0 (linux; x64)");
});