File size: 1,888 Bytes
cd8bd0a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import { test } from "node:test";
import assert from "node:assert/strict";
import {
  buildClineGlobalState,
  buildClineSecrets,
  resolveClineTarget,
} from "../../../bin/cli/commands/setup-cline.mjs";

test("buildClineGlobalState sets the openai provider for Plan + Act, root base URL, model", () => {
  const gs = buildClineGlobalState({}, { baseUrl: "http://vps:20128", model: "glm/glm-5.2" });
  assert.equal(gs.actModeApiProvider, "openai");
  assert.equal(gs.planModeApiProvider, "openai");
  assert.equal(gs.openAiBaseUrl, "http://vps:20128");
  assert.equal(gs.openAiModelId, "glm/glm-5.2");
  assert.equal(gs.planModeOpenAiModelId, "glm/glm-5.2");
});

test("buildClineGlobalState merges (preserves unrelated existing keys)", () => {
  const gs = buildClineGlobalState(
    { telemetrySetting: "off", taskHistory: [1, 2, 3] },
    { baseUrl: "http://x:20128", model: "m" }
  );
  assert.equal(gs.telemetrySetting, "off");
  assert.deepEqual(gs.taskHistory, [1, 2, 3]);
  assert.equal(gs.openAiBaseUrl, "http://x:20128");
});

test("buildClineSecrets stores the key (separate secrets file), preserving others", () => {
  const sec = buildClineSecrets({ anthropicApiKey: "keepme" }, { apiKey: "sk-omni" });
  assert.equal(sec.openAiApiKey, "sk-omni");
  assert.equal(sec.anthropicApiKey, "keepme");
});

test("buildClineSecrets falls back to a placeholder when no key", () => {
  assert.equal(buildClineSecrets({}, { apiKey: "" }).openAiApiKey, "sk_omniroute");
});

test("resolveClineTarget strips /v1 from --remote (Cline wants the ROOT url)", () => {
  const { baseUrl } = resolveClineTarget({ remote: "http://vps:20128/v1/" });
  assert.equal(baseUrl, "http://vps:20128");
});

test("resolveClineTarget: explicit --api-key wins", () => {
  const { apiKey } = resolveClineTarget({ remote: "http://x:20128", apiKey: "sk-explicit" });
  assert.equal(apiKey, "sk-explicit");
});