Skip to content

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

1.5 KB
Raw Blame
import test from "node:test";
import assert from "node:assert/strict";

const update = await import("../../bin/cli/commands/update.mjs");

// #4376: `omniroute update` reported "Latest version: 3.8.30" while npm's `latest`
// dist-tag was already 3.8.31, so it told users on an old build they were "running
// the latest version". Root cause: getLatestVersion() ran `npm view omniroute version`
// without `--prefer-online`, so npm served a stale value from its HTTP cache.
// The fix forces npm to revalidate the cache against the registry.
test("getLatestVersion passes --prefer-online to bypass the stale npm cache (#4376)", async () => {
  let capturedArgs = null;
  const fakeExec = async (cmd: string, args: string[]) => {
    capturedArgs = { cmd, args };
    return { stdout: "3.8.31\n" };
  };
  const latest = await update.getLatestVersion(fakeExec);
  assert.equal(latest, "3.8.31");
  assert.ok(capturedArgs, "exec must be invoked");
  assert.equal(capturedArgs.cmd, "npm");
  assert.ok(
    capturedArgs.args.includes("--prefer-online"),
    `expected --prefer-online in npm args, got: ${JSON.stringify(capturedArgs.args)}`
  );
  // still the right query
  assert.ok(capturedArgs.args.includes("view"));
  assert.ok(capturedArgs.args.includes("omniroute"));
  assert.ok(capturedArgs.args.includes("version"));
});

test("getLatestVersion returns null when npm is unavailable (#4376)", async () => {
  const latest = await update.getLatestVersion(async () => {
    throw new Error("npm not found");
  });
  assert.equal(latest, null);
});