Files
OmniRoute/tests/unit/cli/setup-cursor.test.ts
Diego Rodrigues de Sa e Souza 9616b65b53 feat(cli): setup-cursor — print Cursor setup steps for OmniRoute (#4291)
CLI #7 of the series. Cursor stores its OpenAI key + "Override OpenAI Base URL"
in an opaque SQLite DB (state.vscdb) with no stable schema — not safe to
file-write. So `omniroute setup-cursor` prints the exact in-app steps and lists
real model names from /v1/models.

- Resolves apiBase WITH /v1 (Cursor appends /chat/completions) + key from
  --remote/--api-key → active context → localhost.
- Prints Settings → Models → Override OpenAI Base URL + key + model-name steps,
  with a clear caveat that the custom base URL powers Cursor's CHAT panel only
  (Composer / inline-edit / autocomplete stay on Cursor's backend).

Researched against current Cursor behavior. Tests: resolveCursorTarget (/v1, key),
buildCursorInstructions (base URL + /v1 note + model samples + caveat). 4 unit
tests; check:cli-i18n green.
2026-06-19 13:21:55 -03:00

26 lines
1.2 KiB
TypeScript

import { test } from "node:test";
import assert from "node:assert/strict";
import { resolveCursorTarget, buildCursorInstructions } from "../../../bin/cli/commands/setup-cursor.mjs";
test("resolveCursorTarget ensures /v1 (Cursor appends /chat/completions)", () => {
assert.equal(resolveCursorTarget({ remote: "http://vps:20128" }).apiBase, "http://vps:20128/v1");
assert.equal(resolveCursorTarget({ remote: "http://vps:20128/v1/" }).apiBase, "http://vps:20128/v1");
});
test("resolveCursorTarget: explicit --api-key wins", () => {
assert.equal(resolveCursorTarget({ remote: "http://x:20128", apiKey: "sk-x" }).apiKey, "sk-x");
});
test("buildCursorInstructions includes the base URL, /v1 note, and model samples", () => {
const txt = buildCursorInstructions({ apiBase: "http://vps:20128/v1", models: ["glm/glm-5.2", "kmc/kimi-k2.7"] });
assert.ok(txt.includes("http://vps:20128/v1"));
assert.ok(txt.includes("Override OpenAI Base URL"));
assert.ok(txt.includes("glm/glm-5.2"));
assert.ok(/chat panel only/i.test(txt));
});
test("buildCursorInstructions falls back to sample models when none given", () => {
const txt = buildCursorInstructions({ apiBase: "http://x/v1", models: [] });
assert.ok(txt.includes("glm/glm-5.2"));
});