chatccc 0.2.103 → 0.2.107

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -48,8 +48,8 @@ const baseAppConfig: AppConfig = {
48
48
  model: "initial-model",
49
49
  subagentModel: "initial-subagent-model",
50
50
  effort: "initial-effort",
51
- apiKey: "sk-initial",
52
- baseUrl: "https://initial.gw/anthropic",
51
+ apiKey: "",
52
+ baseUrl: "",
53
53
  },
54
54
  cursor: { enabled: true, defaultAgent: false, path: "/initial/cursor", model: "initial-cursor-model" },
55
55
  codex: { enabled: true, defaultAgent: false, path: "/initial/codex", model: "initial-codex-model", effort: "initial-codex-effort" },
@@ -89,16 +89,16 @@ describe("applyLoadedConfig — 刷新 export let 常量", () => {
89
89
  model: "claude-sonnet-4-6",
90
90
  subagentModel: "claude-haiku-4-5-20251001",
91
91
  effort: "high",
92
- apiKey: "sk-newkey",
93
- baseUrl: "https://gw2.example/anthropic",
92
+ apiKey: "sk-test",
93
+ baseUrl: "https://api.example.com",
94
94
  },
95
95
  });
96
96
 
97
97
  expect(CLAUDE_MODEL).toBe("claude-sonnet-4-6");
98
98
  expect(CLAUDE_SUBAGENT_MODEL).toBe("claude-haiku-4-5-20251001");
99
99
  expect(CLAUDE_EFFORT).toBe("high");
100
- expect(CLAUDE_API_KEY).toBe("sk-newkey");
101
- expect(CLAUDE_BASE_URL).toBe("https://gw2.example/anthropic");
100
+ expect(CLAUDE_API_KEY).toBe("sk-test");
101
+ expect(CLAUDE_BASE_URL).toBe("https://api.example.com");
102
102
  });
103
103
 
104
104
  it("更新 GIT_TIMEOUT_SECONDS 与 GIT_TIMEOUT_MS(毫秒派生值同步刷新)", () => {
@@ -1,195 +1,83 @@
1
- import { describe, it, expect } from "vitest";
2
- import {
3
- applyClaudeApiMode,
4
- chooseStartPath,
5
- detectClaudeApiMode,
6
- unflattenConfig,
7
- } from "../web-ui.ts";
8
-
9
- // ---------------------------------------------------------------------------
10
- // detectClaudeApiMode — 加载已有 config 时如何判定 UI 初始模式
11
- // 契约:apiKey 或 baseUrl 任一非空(trim 后) → "thirdparty",否则 "official"。
12
- // ---------------------------------------------------------------------------
13
-
14
- describe("detectClaudeApiMode", () => {
15
- it("两者都缺失 → official", () => {
16
- expect(detectClaudeApiMode(undefined)).toBe("official");
17
- expect(detectClaudeApiMode({})).toBe("official");
18
- });
19
-
20
- it("两者都为空字符串 → official", () => {
21
- expect(detectClaudeApiMode({ apiKey: "", baseUrl: "" })).toBe("official");
22
- });
23
-
24
- it("两者都全空白 → official", () => {
25
- expect(detectClaudeApiMode({ apiKey: " ", baseUrl: "\t\n" })).toBe(
26
- "official",
27
- );
28
- });
29
-
30
- it("apiKey 非空 → thirdparty(即使 baseUrl 为空)", () => {
31
- expect(detectClaudeApiMode({ apiKey: "sk-x", baseUrl: "" })).toBe(
32
- "thirdparty",
33
- );
34
- });
35
-
36
- it("baseUrl 非空 → thirdparty(即使 apiKey 为空)", () => {
37
- expect(
38
- detectClaudeApiMode({ apiKey: "", baseUrl: "https://gw/anthropic" }),
39
- ).toBe("thirdparty");
40
- });
41
-
42
- it("两者都非空 → thirdparty", () => {
43
- expect(
44
- detectClaudeApiMode({
45
- apiKey: "sk-x",
46
- baseUrl: "https://gw/anthropic",
47
- }),
48
- ).toBe("thirdparty");
49
- });
50
- });
51
-
52
- // ---------------------------------------------------------------------------
53
- // applyClaudeApiMode — 服务端写入前归一化扁平 vars
54
- // 关键契约:
55
- // - mode=official 时即使 vars 不含这两个键,也要写入 ""(覆盖原 config.json)
56
- // - mode=thirdparty 时原样保留(包括前端传 "")
57
- // - mode 未传 默认按 official 兌底(不保留可能误填的密钥)
58
- // ---------------------------------------------------------------------------
59
-
60
- describe("applyClaudeApiMode", () => {
61
- it("mode=official 时清空 CLAUDE_API_KEY / CLAUDE_BASE_URL(即使 vars 没传)", () => {
62
- const out = applyClaudeApiMode({ CHATCCC_APP_ID: "x" }, "official");
63
- expect(out).toEqual({
64
- CHATCCC_APP_ID: "x",
65
- CLAUDE_API_KEY: "",
66
- CLAUDE_BASE_URL: "",
67
- });
68
- });
69
-
70
- it("mode=official 时覆盖前端误传的非空 apiKey / baseUrl", () => {
71
- const out = applyClaudeApiMode(
72
- {
73
- CLAUDE_API_KEY: "sk-leftover",
74
- CLAUDE_BASE_URL: "https://leftover/anthropic",
75
- CHATCCC_APP_ID: "x",
76
- },
77
- "official",
78
- );
79
- expect(out.CLAUDE_API_KEY).toBe("");
80
- expect(out.CLAUDE_BASE_URL).toBe("");
81
- expect(out.CHATCCC_APP_ID).toBe("x");
82
- });
83
-
84
- it("mode=thirdparty 时原样保留前端值", () => {
85
- const out = applyClaudeApiMode(
86
- {
87
- CLAUDE_API_KEY: "sk-test",
88
- CLAUDE_BASE_URL: "https://gw/anthropic",
89
- },
90
- "thirdparty",
91
- );
92
- expect(out).toEqual({
93
- CLAUDE_API_KEY: "sk-test",
94
- CLAUDE_BASE_URL: "https://gw/anthropic",
95
- });
96
- });
97
-
98
- it("mode=thirdparty 时保留前端主动提交的 ''(允许局部清空)", () => {
99
- const out = applyClaudeApiMode(
100
- { CLAUDE_API_KEY: "", CLAUDE_BASE_URL: "https://gw/anthropic" },
101
- "thirdparty",
102
- );
103
- expect(out.CLAUDE_API_KEY).toBe("");
104
- expect(out.CLAUDE_BASE_URL).toBe("https://gw/anthropic");
105
- });
106
-
107
- it("mode 未传(undefined) → 按 official 兌底清空", () => {
108
- const out = applyClaudeApiMode(
109
- { CLAUDE_API_KEY: "sk-x" },
110
- undefined,
111
- );
112
- expect(out.CLAUDE_API_KEY).toBe("");
113
- expect(out.CLAUDE_BASE_URL).toBe("");
114
- });
115
-
116
- it("mode 是未知字符串 → 按 official 兌底清空", () => {
117
- const out = applyClaudeApiMode(
118
- { CLAUDE_API_KEY: "sk-x" },
119
- "garbage-mode",
120
- );
121
- expect(out.CLAUDE_API_KEY).toBe("");
122
- expect(out.CLAUDE_BASE_URL).toBe("");
123
- });
124
-
125
- it("不修改入参对象(返回新对象)", () => {
126
- const input = { CLAUDE_API_KEY: "sk-x" };
127
- const out = applyClaudeApiMode(input, "official");
128
- expect(input).toEqual({ CLAUDE_API_KEY: "sk-x" }); // 原对象未变
129
- expect(out).not.toBe(input);
130
- });
131
- });
132
-
133
- describe("unflattenConfig", () => {
134
- it("maps Claude subagent model into claude.subagentModel", () => {
135
- expect(
136
- unflattenConfig({
137
- CHATCCC_ANTHROPIC_MODEL: "claude-sonnet-4-6",
138
- CHATCCC_ANTHROPIC_SUBAGENT_MODEL: "claude-haiku-4-5-20251001",
139
- }),
140
- ).toEqual({
141
- claude: {
142
- model: "claude-sonnet-4-6",
143
- subagentModel: "claude-haiku-4-5-20251001",
144
- },
145
- });
146
- });
147
- });
148
-
149
- // ---------------------------------------------------------------------------
150
- // chooseStartPath — /api/start 的路径选择
151
- // 关键护栏:
152
- // - setup 模式(hasInplaceActivateHook=true)下 isServiceRunning 永远为 true
153
- // (setup 进程自己占着 PID 文件),必须无条件走 inplace;否则用户点
154
- // "保存并启动"将永远拿到 "Service is already running"。
155
- // - dashboard 模式 + service 已运行(通常就是当前进程自己)→ "reload":
156
- // 用户点"保存并启动"想让新 config 生效,但服务正在跑——不真重启,仅
157
- // 调用 reloadConfigFromDisk() 刷新进程内 export let 常量。绝不能再
158
- // 返回"already running"挡用户路。
159
- // - dashboard 模式 + service 未运行 → spawn 一个新的(旧 service 退出后场景)。
160
- // ---------------------------------------------------------------------------
161
-
162
- describe("chooseStartPath", () => {
163
- it("setup 模式(注入 inplace hook)→ inplace(不管 PID 文件状态)", () => {
164
- expect(
165
- chooseStartPath({
166
- hasInplaceActivateHook: true,
167
- isServiceRunning: true,
168
- }),
169
- ).toBe("inplace");
170
- expect(
171
- chooseStartPath({
172
- hasInplaceActivateHook: true,
173
- isServiceRunning: false,
174
- }),
175
- ).toBe("inplace");
176
- });
177
-
178
- it("dashboard 模式 + service 已运行 → reload(仅刷新 config,不真重启)", () => {
179
- expect(
180
- chooseStartPath({
181
- hasInplaceActivateHook: false,
182
- isServiceRunning: true,
183
- }),
184
- ).toBe("reload");
185
- });
186
-
187
- it("dashboard 模式 + service 未运行 → spawn", () => {
188
- expect(
189
- chooseStartPath({
190
- hasInplaceActivateHook: false,
191
- isServiceRunning: false,
192
- }),
193
- ).toBe("spawn");
194
- });
195
- });
1
+ import { describe, it, expect } from "vitest";
2
+ import {
3
+ chooseStartPath,
4
+ unflattenConfig,
5
+ } from "../web-ui.ts";
6
+
7
+ describe("unflattenConfig", () => {
8
+ it("maps Claude subagent model into claude.subagentModel", () => {
9
+ expect(
10
+ unflattenConfig({
11
+ CHATCCC_ANTHROPIC_MODEL: "claude-sonnet-4-6",
12
+ CHATCCC_ANTHROPIC_SUBAGENT_MODEL: "claude-haiku-4-5-20251001",
13
+ }),
14
+ ).toEqual({
15
+ claude: {
16
+ model: "claude-sonnet-4-6",
17
+ subagentModel: "claude-haiku-4-5-20251001",
18
+ },
19
+ });
20
+ });
21
+
22
+ it("maps Claude apiKey and baseUrl into claude config", () => {
23
+ expect(
24
+ unflattenConfig({
25
+ CHATCCC_ANTHROPIC_API_KEY: "sk-test-key",
26
+ CHATCCC_ANTHROPIC_BASE_URL: "https://api.example.com",
27
+ }),
28
+ ).toEqual({
29
+ claude: {
30
+ apiKey: "sk-test-key",
31
+ baseUrl: "https://api.example.com",
32
+ },
33
+ });
34
+ });
35
+ });
36
+
37
+ // ---------------------------------------------------------------------------
38
+ // chooseStartPath /api/start 的路径选择
39
+ // 关键护栏:
40
+ // - setup 模式(hasInplaceActivateHook=true)下 isServiceRunning 永远为 true
41
+ // (setup 进程自己占着 PID 文件),必须无条件走 inplace;否则用户点
42
+ // "保存并启动"将永远拿到 "Service is already running"。
43
+ // - dashboard 模式 + service 已运行(通常就是当前进程自己)→ "reload":
44
+ // 用户点"保存并启动"想让新 config 生效,但服务正在跑——不真重启,仅
45
+ // 调用 reloadConfigFromDisk() 刷新进程内 export let 常量。绝不能再
46
+ // 返回"already running"挡用户路。
47
+ // - dashboard 模式 + service 未运行 → spawn 一个新的(旧 service 退出后场景)。
48
+ // ---------------------------------------------------------------------------
49
+
50
+ describe("chooseStartPath", () => {
51
+ it("setup 模式(注入 inplace hook)→ inplace(不管 PID 文件状态)", () => {
52
+ expect(
53
+ chooseStartPath({
54
+ hasInplaceActivateHook: true,
55
+ isServiceRunning: true,
56
+ }),
57
+ ).toBe("inplace");
58
+ expect(
59
+ chooseStartPath({
60
+ hasInplaceActivateHook: true,
61
+ isServiceRunning: false,
62
+ }),
63
+ ).toBe("inplace");
64
+ });
65
+
66
+ it("dashboard 模式 + service 已运行 → reload(仅刷新 config,不真重启)", () => {
67
+ expect(
68
+ chooseStartPath({
69
+ hasInplaceActivateHook: false,
70
+ isServiceRunning: true,
71
+ }),
72
+ ).toBe("reload");
73
+ });
74
+
75
+ it("dashboard 模式 + service 未运行 → spawn", () => {
76
+ expect(
77
+ chooseStartPath({
78
+ hasInplaceActivateHook: false,
79
+ isServiceRunning: false,
80
+ }),
81
+ ).toBe("spawn");
82
+ });
83
+ });