Files
OmniRoute/tests/unit/cli/setup-kilo.test.ts
Diego Rodrigues de Sa e Souza 70bd6fbcc9 feat(cli): setup-kilo — configure Kilo Code for OmniRoute (CLI auth + VS Code settings) (#4284)
CLI #5 of the series. `omniroute setup-kilo` configures Kilo Code
(kilocode.kilo-code, a Cline/Roo descendant) to use OmniRoute.

Two surfaces (both written, matching the dashboard cli-tools/kilo-settings):
- ~/.local/share/kilo/auth.json — CLI mode: auth["openai-compatible"] =
  { apiKey, baseUrl (WITH /v1 — Kilo appends /chat/completions), model }.
- VS Code settings.json — extension: kilocode.customProvider (name/baseURL/apiKey)
  + kilocode.defaultModel. Only touched when the file already exists.

Remote-aware (--remote/--api-key → active context → localhost). Model via --model
or an interactive pick from /v1/models (Kilo's extension has no auto-discovery).
Prints the exact UI settings to paste. Merges both files (preserves existing).

Researched against current Kilo docs: confirmed openAiBaseUrl needs /v1 (unlike
Cline's root url), the openai-compatible keys, and the export/import + CLI surfaces.
Kilo's wire (/v1/chat/completions) already validated → "OK".

Tests: buildKiloAuth (provider + /v1 + merge + key fallback), buildKiloVscodeSettings
(kilocode.* keys + preserve), resolveKiloTarget (/v1 ensure, key win). 6 unit tests;
check:cli-i18n green.
2026-06-19 12:57:22 -03:00

46 lines
2.0 KiB
TypeScript

import { test } from "node:test";
import assert from "node:assert/strict";
import {
buildKiloAuth,
buildKiloVscodeSettings,
resolveKiloTarget,
} from "../../../bin/cli/commands/setup-kilo.mjs";
test("buildKiloAuth sets the openai-compatible provider (baseUrl WITH /v1, model)", () => {
const auth = buildKiloAuth({}, { apiKey: "sk-x", baseUrl: "http://vps:20128/v1", model: "glm/glm-5.2" });
assert.equal(auth["openai-compatible"].apiKey, "sk-x");
assert.equal(auth["openai-compatible"].baseUrl, "http://vps:20128/v1");
assert.equal(auth["openai-compatible"].model, "glm/glm-5.2");
});
test("buildKiloAuth merges (preserves other providers/keys)", () => {
const auth = buildKiloAuth({ anthropic: { apiKey: "keep" } }, { apiKey: "k", baseUrl: "http://x/v1", model: "m" });
assert.equal(auth.anthropic.apiKey, "keep");
assert.equal(auth["openai-compatible"].model, "m");
});
test("buildKiloAuth falls back to a placeholder key", () => {
const auth = buildKiloAuth({}, { apiKey: "", baseUrl: "http://x/v1", model: "m" });
assert.equal(auth["openai-compatible"].apiKey, "sk_omniroute");
});
test("buildKiloVscodeSettings sets kilocode.customProvider + defaultModel, preserving others", () => {
const s = buildKiloVscodeSettings(
{ "editor.fontSize": 14 },
{ apiKey: "k", baseUrl: "http://vps:20128/v1", model: "glm/glm-5.2" }
);
assert.equal(s["editor.fontSize"], 14);
assert.equal(s["kilocode.customProvider"].name, "OmniRoute");
assert.equal(s["kilocode.customProvider"].baseURL, "http://vps:20128/v1");
assert.equal(s["kilocode.defaultModel"], "glm/glm-5.2");
});
test("resolveKiloTarget ensures /v1 on the base URL (Kilo wants it)", () => {
assert.equal(resolveKiloTarget({ remote: "http://vps:20128" }).baseUrl, "http://vps:20128/v1");
assert.equal(resolveKiloTarget({ remote: "http://vps:20128/v1/" }).baseUrl, "http://vps:20128/v1");
});
test("resolveKiloTarget: explicit --api-key wins", () => {
assert.equal(resolveKiloTarget({ remote: "http://x:20128", apiKey: "sk-explicit" }).apiKey, "sk-explicit");
});