chatccc 0.2.186 → 0.2.188
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.
- package/config.sample.json +39 -32
- package/package.json +1 -1
- package/src/__tests__/builtin-config.test.ts +33 -0
- package/src/__tests__/chrome-devtools-guard.test.ts +40 -0
- package/src/__tests__/config-reload.test.ts +30 -16
- package/src/__tests__/config-sample.test.ts +41 -19
- package/src/__tests__/feishu-avatar.test.ts +180 -115
- package/src/__tests__/orchestrator.test.ts +165 -17
- package/src/__tests__/session.test.ts +17 -7
- package/src/__tests__/web-ui.test.ts +22 -0
- package/src/adapters/codex-adapter.ts +26 -21
- package/src/builtin/cli.ts +8 -16
- package/src/builtin/index.ts +12 -11
- package/src/cards.ts +48 -7
- package/src/chrome-devtools-guard.ts +78 -2
- package/src/config.ts +158 -108
- package/src/feishu-api.ts +219 -190
- package/src/index.ts +2 -2
- package/src/orchestrator.ts +211 -19
- package/src/platform-adapter.ts +9 -1
- package/src/session.ts +92 -64
- package/src/web-ui.ts +32 -7
|
@@ -39,23 +39,23 @@ async function loadFeishuApiWithHome(homeDir: string, userDataDir: string) {
|
|
|
39
39
|
async function writeCodexAuth(homeDir: string): Promise<void> {
|
|
40
40
|
const codexDir = join(homeDir, ".codex");
|
|
41
41
|
await mkdir(codexDir, { recursive: true });
|
|
42
|
-
await writeFile(
|
|
43
|
-
join(codexDir, "auth.json"),
|
|
44
|
-
JSON.stringify({ tokens: { access_token: "codex-access-token", account_id: "codex-account-id" } }),
|
|
45
|
-
"utf-8",
|
|
46
|
-
);
|
|
47
|
-
}
|
|
42
|
+
await writeFile(
|
|
43
|
+
join(codexDir, "auth.json"),
|
|
44
|
+
JSON.stringify({ tokens: { access_token: "codex-access-token", account_id: "codex-account-id" } }),
|
|
45
|
+
"utf-8",
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
48
|
|
|
49
49
|
function mockAvatarFetch(uploadedNames: string[], usageResponse: Response): void {
|
|
50
50
|
vi.stubGlobal("fetch", vi.fn(async (url: string | URL | Request, init?: RequestInit) => {
|
|
51
51
|
const urlText = String(url);
|
|
52
|
-
if (urlText === "https://chatgpt.com/backend-api/wham/usage") {
|
|
53
|
-
return usageResponse.clone();
|
|
54
|
-
}
|
|
55
|
-
if (urlText === "https://chatgpt.com/backend-api/wham/rate-limit-reset-credits") {
|
|
56
|
-
return new Response(JSON.stringify({ credits: [] }), { status: 200 });
|
|
57
|
-
}
|
|
58
|
-
if (urlText === "https://open.feishu.test/im/v1/images") {
|
|
52
|
+
if (urlText === "https://chatgpt.com/backend-api/wham/usage") {
|
|
53
|
+
return usageResponse.clone();
|
|
54
|
+
}
|
|
55
|
+
if (urlText === "https://chatgpt.com/backend-api/wham/rate-limit-reset-credits") {
|
|
56
|
+
return new Response(JSON.stringify({ credits: [] }), { status: 200 });
|
|
57
|
+
}
|
|
58
|
+
if (urlText === "https://open.feishu.test/im/v1/images") {
|
|
59
59
|
const form = init?.body as FormData;
|
|
60
60
|
const image = form.get("image") as File;
|
|
61
61
|
uploadedNames.push(image.name);
|
|
@@ -68,6 +68,24 @@ function mockAvatarFetch(uploadedNames: string[], usageResponse: Response): void
|
|
|
68
68
|
}));
|
|
69
69
|
}
|
|
70
70
|
|
|
71
|
+
function mockAvatarUploadOnlyFetch(uploadedNames: string[]): ReturnType<typeof vi.fn> {
|
|
72
|
+
const fetchMock = vi.fn(async (url: string | URL | Request, init?: RequestInit) => {
|
|
73
|
+
const urlText = String(url);
|
|
74
|
+
if (urlText === "https://open.feishu.test/im/v1/images") {
|
|
75
|
+
const form = init?.body as FormData;
|
|
76
|
+
const image = form.get("image") as File;
|
|
77
|
+
uploadedNames.push(image.name);
|
|
78
|
+
return new Response(JSON.stringify({ code: 0, data: { image_key: "img_test" } }), { status: 200 });
|
|
79
|
+
}
|
|
80
|
+
if (urlText === "https://open.feishu.test/im/v1/chats/chat_1") {
|
|
81
|
+
return new Response(JSON.stringify({ code: 0 }), { status: 200 });
|
|
82
|
+
}
|
|
83
|
+
throw new Error(`unexpected fetch: ${urlText}`);
|
|
84
|
+
});
|
|
85
|
+
vi.stubGlobal("fetch", fetchMock);
|
|
86
|
+
return fetchMock;
|
|
87
|
+
}
|
|
88
|
+
|
|
71
89
|
describe("Codex avatar usage battery", () => {
|
|
72
90
|
afterEach(() => {
|
|
73
91
|
vi.unstubAllGlobals();
|
|
@@ -103,109 +121,134 @@ describe("Codex avatar usage battery", () => {
|
|
|
103
121
|
}
|
|
104
122
|
});
|
|
105
123
|
|
|
106
|
-
it("
|
|
107
|
-
const homeDir = await mkdtemp(join(tmpdir(), "chatccc-avatar-home-"));
|
|
108
|
-
const userDataDir = await mkdtemp(join(tmpdir(), "chatccc-avatar-data-"));
|
|
109
|
-
|
|
110
|
-
const fetchMock =
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
},
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
);
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
|
|
124
|
+
it("uses provided Codex usage without fetching usage again", async () => {
|
|
125
|
+
const homeDir = await mkdtemp(join(tmpdir(), "chatccc-avatar-home-"));
|
|
126
|
+
const userDataDir = await mkdtemp(join(tmpdir(), "chatccc-avatar-data-"));
|
|
127
|
+
const uploadedNames: string[] = [];
|
|
128
|
+
const fetchMock = mockAvatarUploadOnlyFetch(uploadedNames);
|
|
129
|
+
|
|
130
|
+
try {
|
|
131
|
+
const { setChatAvatar } = await loadFeishuApiWithHome(homeDir, userDataDir);
|
|
132
|
+
await setChatAvatar("tenant-token", "chat_1", "codex", "busy", {
|
|
133
|
+
codexUsage: {
|
|
134
|
+
fiveHour: { usedPercent: 37, remainingPercent: 63, resetAtEpochSeconds: null, resetAfterSeconds: null },
|
|
135
|
+
weekly: { usedPercent: 12, remainingPercent: 88, resetAtEpochSeconds: null, resetAfterSeconds: null },
|
|
136
|
+
rateLimitResetCreditsAvailable: null,
|
|
137
|
+
rateLimitResetCredits: null,
|
|
138
|
+
},
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
expect(uploadedNames).toEqual(["avatar_codex_busy_week_88_5h_63.jpg"]);
|
|
142
|
+
expect(fetchMock).not.toHaveBeenCalledWith("https://chatgpt.com/backend-api/wham/usage", expect.anything());
|
|
143
|
+
} finally {
|
|
144
|
+
await rm(homeDir, { recursive: true, force: true });
|
|
145
|
+
await rm(userDataDir, { recursive: true, force: true });
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
it("returns both usage windows and available reset credit expiries", async () => {
|
|
150
|
+
const homeDir = await mkdtemp(join(tmpdir(), "chatccc-avatar-home-"));
|
|
151
|
+
const userDataDir = await mkdtemp(join(tmpdir(), "chatccc-avatar-data-"));
|
|
152
|
+
await writeCodexAuth(homeDir);
|
|
153
|
+
const fetchMock = vi.fn(async (url: string | URL | Request) => {
|
|
154
|
+
const urlText = String(url);
|
|
155
|
+
if (urlText === "https://chatgpt.com/backend-api/wham/usage") {
|
|
156
|
+
return new Response(JSON.stringify({
|
|
157
|
+
rate_limit: {
|
|
158
|
+
primary_window: { used_percent: 37, reset_after_seconds: 10349, reset_at: 1781528212 },
|
|
159
|
+
secondary_window: { used_percent: 12, reset_after_seconds: 325063, reset_at: 1781842926 },
|
|
160
|
+
},
|
|
161
|
+
rate_limit_reset_credits: { available_count: 1 },
|
|
162
|
+
}), { status: 200 });
|
|
163
|
+
}
|
|
164
|
+
if (urlText === "https://chatgpt.com/backend-api/wham/rate-limit-reset-credits") {
|
|
165
|
+
return new Response(JSON.stringify({
|
|
166
|
+
available_count: 2,
|
|
167
|
+
credits: [
|
|
168
|
+
{
|
|
169
|
+
status: "available",
|
|
170
|
+
granted_at: "2026-06-12T04:01:47.770016Z",
|
|
171
|
+
expires_at: "2026-07-12T04:01:47.770016Z",
|
|
172
|
+
},
|
|
173
|
+
{
|
|
174
|
+
status: "redeemed",
|
|
175
|
+
granted_at: "2026-06-13T04:01:47.770016Z",
|
|
176
|
+
expires_at: "2026-07-13T04:01:47.770016Z",
|
|
177
|
+
},
|
|
178
|
+
{
|
|
179
|
+
status: "available",
|
|
180
|
+
granted_at: "2026-06-18T00:44:23.904386Z",
|
|
181
|
+
expires_at: "2026-07-18T00:44:23.904386Z",
|
|
182
|
+
},
|
|
183
|
+
],
|
|
184
|
+
}), { status: 200 });
|
|
185
|
+
}
|
|
186
|
+
throw new Error(`unexpected fetch: ${urlText}`);
|
|
187
|
+
});
|
|
188
|
+
vi.stubGlobal("fetch", fetchMock);
|
|
189
|
+
|
|
190
|
+
try {
|
|
191
|
+
const { getCodexUsageSummary } = await loadFeishuApiWithHome(homeDir, userDataDir);
|
|
192
|
+
await expect(getCodexUsageSummary()).resolves.toEqual({
|
|
193
|
+
fiveHour: { usedPercent: 37, remainingPercent: 63, resetAfterSeconds: 10349, resetAtEpochSeconds: 1781528212 },
|
|
194
|
+
weekly: { usedPercent: 12, remainingPercent: 88, resetAfterSeconds: 325063, resetAtEpochSeconds: 1781842926 },
|
|
195
|
+
rateLimitResetCreditsAvailable: 2,
|
|
196
|
+
rateLimitResetCredits: [
|
|
197
|
+
{ grantedAt: "2026-06-12T04:01:47.770016Z", expiresAt: "2026-07-12T04:01:47.770016Z" },
|
|
198
|
+
{ grantedAt: "2026-06-18T00:44:23.904386Z", expiresAt: "2026-07-18T00:44:23.904386Z" },
|
|
199
|
+
],
|
|
200
|
+
});
|
|
201
|
+
expect(fetchMock).toHaveBeenCalledWith(
|
|
202
|
+
"https://chatgpt.com/backend-api/wham/rate-limit-reset-credits",
|
|
203
|
+
expect.objectContaining({
|
|
204
|
+
headers: expect.objectContaining({
|
|
205
|
+
Authorization: "Bearer codex-access-token",
|
|
206
|
+
"ChatGPT-Account-ID": "codex-account-id",
|
|
207
|
+
"OpenAI-Beta": "codex-1",
|
|
208
|
+
originator: "Codex Desktop",
|
|
209
|
+
}),
|
|
210
|
+
}),
|
|
211
|
+
);
|
|
212
|
+
} finally {
|
|
213
|
+
await rm(homeDir, { recursive: true, force: true });
|
|
214
|
+
await rm(userDataDir, { recursive: true, force: true });
|
|
215
|
+
}
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
it("consumes a Codex rate-limit reset credit through the WHAM endpoint", async () => {
|
|
219
|
+
const homeDir = await mkdtemp(join(tmpdir(), "chatccc-avatar-home-"));
|
|
220
|
+
const userDataDir = await mkdtemp(join(tmpdir(), "chatccc-avatar-data-"));
|
|
221
|
+
await writeCodexAuth(homeDir);
|
|
222
|
+
const fetchMock = vi.fn(async () => new Response(JSON.stringify({
|
|
223
|
+
code: "reset",
|
|
224
|
+
windows_reset: 2,
|
|
225
|
+
}), { status: 200 }));
|
|
226
|
+
vi.stubGlobal("fetch", fetchMock);
|
|
227
|
+
|
|
228
|
+
try {
|
|
229
|
+
const { consumeCodexRateLimitResetCredit } = await loadFeishuApiWithHome(homeDir, userDataDir);
|
|
230
|
+
await expect(consumeCodexRateLimitResetCredit("request-1")).resolves.toEqual({
|
|
231
|
+
code: "reset",
|
|
232
|
+
windowsReset: 2,
|
|
233
|
+
});
|
|
234
|
+
expect(fetchMock).toHaveBeenCalledWith(
|
|
235
|
+
"https://chatgpt.com/backend-api/wham/rate-limit-reset-credits/consume",
|
|
236
|
+
expect.objectContaining({
|
|
237
|
+
method: "POST",
|
|
238
|
+
headers: expect.objectContaining({
|
|
239
|
+
Authorization: "Bearer codex-access-token",
|
|
240
|
+
"Content-Type": "application/json",
|
|
241
|
+
}),
|
|
242
|
+
body: JSON.stringify({ redeem_request_id: "request-1" }),
|
|
243
|
+
}),
|
|
244
|
+
);
|
|
245
|
+
} finally {
|
|
246
|
+
await rm(homeDir, { recursive: true, force: true });
|
|
247
|
+
await rm(userDataDir, { recursive: true, force: true });
|
|
172
248
|
}
|
|
173
|
-
});
|
|
174
|
-
|
|
175
|
-
it("
|
|
176
|
-
const homeDir = await mkdtemp(join(tmpdir(), "chatccc-avatar-home-"));
|
|
177
|
-
const userDataDir = await mkdtemp(join(tmpdir(), "chatccc-avatar-data-"));
|
|
178
|
-
await writeCodexAuth(homeDir);
|
|
179
|
-
const fetchMock = vi.fn(async () => new Response(JSON.stringify({
|
|
180
|
-
code: "reset",
|
|
181
|
-
windows_reset: 2,
|
|
182
|
-
}), { status: 200 }));
|
|
183
|
-
vi.stubGlobal("fetch", fetchMock);
|
|
184
|
-
|
|
185
|
-
try {
|
|
186
|
-
const { consumeCodexRateLimitResetCredit } = await loadFeishuApiWithHome(homeDir, userDataDir);
|
|
187
|
-
await expect(consumeCodexRateLimitResetCredit("request-1")).resolves.toEqual({
|
|
188
|
-
code: "reset",
|
|
189
|
-
windowsReset: 2,
|
|
190
|
-
});
|
|
191
|
-
expect(fetchMock).toHaveBeenCalledWith(
|
|
192
|
-
"https://chatgpt.com/backend-api/wham/rate-limit-reset-credits/consume",
|
|
193
|
-
expect.objectContaining({
|
|
194
|
-
method: "POST",
|
|
195
|
-
headers: expect.objectContaining({
|
|
196
|
-
Authorization: "Bearer codex-access-token",
|
|
197
|
-
"Content-Type": "application/json",
|
|
198
|
-
}),
|
|
199
|
-
body: JSON.stringify({ redeem_request_id: "request-1" }),
|
|
200
|
-
}),
|
|
201
|
-
);
|
|
202
|
-
} finally {
|
|
203
|
-
await rm(homeDir, { recursive: true, force: true });
|
|
204
|
-
await rm(userDataDir, { recursive: true, force: true });
|
|
205
|
-
}
|
|
206
|
-
});
|
|
207
|
-
|
|
208
|
-
it("falls back to the pre-combined Codex avatar when usage lookup fails", async () => {
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
it("falls back to the pre-combined Codex avatar when usage lookup fails", async () => {
|
|
209
252
|
const homeDir = await mkdtemp(join(tmpdir(), "chatccc-avatar-home-"));
|
|
210
253
|
const userDataDir = await mkdtemp(join(tmpdir(), "chatccc-avatar-data-"));
|
|
211
254
|
const uploadedNames: string[] = [];
|
|
@@ -257,6 +300,28 @@ describe("Cursor avatar usage battery", () => {
|
|
|
257
300
|
}
|
|
258
301
|
});
|
|
259
302
|
|
|
303
|
+
it("uses provided Cursor usage without fetching usage again", async () => {
|
|
304
|
+
const homeDir = await mkdtemp(join(tmpdir(), "chatccc-avatar-home-"));
|
|
305
|
+
const userDataDir = await mkdtemp(join(tmpdir(), "chatccc-avatar-data-"));
|
|
306
|
+
const uploadedNames: string[] = [];
|
|
307
|
+
mockAvatarUploadOnlyFetch(uploadedNames);
|
|
308
|
+
|
|
309
|
+
try {
|
|
310
|
+
const { setChatAvatar } = await loadFeishuApiWithHome(homeDir, userDataDir);
|
|
311
|
+
await setChatAvatar("tenant-token", "chat_1", "cursor", "idle", {
|
|
312
|
+
cursorUsage: {
|
|
313
|
+
planUsage: { apiPercentUsed: 30 },
|
|
314
|
+
},
|
|
315
|
+
});
|
|
316
|
+
|
|
317
|
+
expect(uploadedNames).toEqual(["avatar_cursor_idle_battery_70.jpg"]);
|
|
318
|
+
expect(getCursorUsageSummaryMock).not.toHaveBeenCalled();
|
|
319
|
+
} finally {
|
|
320
|
+
await rm(homeDir, { recursive: true, force: true });
|
|
321
|
+
await rm(userDataDir, { recursive: true, force: true });
|
|
322
|
+
}
|
|
323
|
+
});
|
|
324
|
+
|
|
260
325
|
it("uses On-Demand budget for Cursor avatar battery when configured", async () => {
|
|
261
326
|
const homeDir = await mkdtemp(join(tmpdir(), "chatccc-avatar-home-"));
|
|
262
327
|
const userDataDir = await mkdtemp(join(tmpdir(), "chatccc-avatar-data-"));
|
|
@@ -77,10 +77,11 @@ import {
|
|
|
77
77
|
_setAdapterForToolForTest,
|
|
78
78
|
_setSessionRegistryFileForTest,
|
|
79
79
|
_setSessionToolsFileForTest,
|
|
80
|
-
loadSessionRegistryForBinding,
|
|
81
|
-
recordSessionRegistry,
|
|
82
|
-
resetState,
|
|
83
|
-
|
|
80
|
+
loadSessionRegistryForBinding,
|
|
81
|
+
recordSessionRegistry,
|
|
82
|
+
resetState,
|
|
83
|
+
sessionInfoMap,
|
|
84
|
+
} from "../session.ts";
|
|
84
85
|
import { activePrompts, resetBindingState } from "../session-chat-binding.ts";
|
|
85
86
|
import { ABD_APPEND_PROMPT } from "../shared-prefix.ts";
|
|
86
87
|
|
|
@@ -362,11 +363,11 @@ describe("handleCommand WeChat processing ack", () => {
|
|
|
362
363
|
expect(userText).not.toContain("/abd");
|
|
363
364
|
});
|
|
364
365
|
|
|
365
|
-
it("cleans stale Feishu p2p binding but keeps valid commands from auto-creating a group", async () => {
|
|
366
|
-
const platform = mockPlatform("feishu");
|
|
367
|
-
await recordSessionRegistry({
|
|
368
|
-
chatId: "feishu-p2p",
|
|
369
|
-
sessionId: "stale-sid",
|
|
366
|
+
it("cleans stale Feishu p2p binding but keeps valid commands from auto-creating a group", async () => {
|
|
367
|
+
const platform = mockPlatform("feishu");
|
|
368
|
+
await recordSessionRegistry({
|
|
369
|
+
chatId: "feishu-p2p",
|
|
370
|
+
sessionId: "stale-sid",
|
|
370
371
|
tool: "claude",
|
|
371
372
|
chatName: "旧私聊绑定",
|
|
372
373
|
running: false,
|
|
@@ -376,13 +377,109 @@ describe("handleCommand WeChat processing ack", () => {
|
|
|
376
377
|
|
|
377
378
|
expect(platform.createGroup).not.toHaveBeenCalled();
|
|
378
379
|
expect(platform.sendRawCard).toHaveBeenCalled();
|
|
379
|
-
const registry = await loadSessionRegistryForBinding();
|
|
380
|
-
expect(registry["feishu-p2p"]).toBeUndefined();
|
|
381
|
-
});
|
|
382
|
-
|
|
383
|
-
it("
|
|
384
|
-
const platform = mockPlatform("feishu");
|
|
385
|
-
|
|
380
|
+
const registry = await loadSessionRegistryForBinding();
|
|
381
|
+
expect(registry["feishu-p2p"]).toBeUndefined();
|
|
382
|
+
});
|
|
383
|
+
|
|
384
|
+
it("shows Claude effort switch card in an active Feishu session", async () => {
|
|
385
|
+
const platform = mockPlatform("feishu");
|
|
386
|
+
vi.mocked(platform.getChatInfo).mockResolvedValue({ name: "claude-session", description: "Claude Session: sid-claude-effort" });
|
|
387
|
+
vi.mocked(platform.extractSessionInfo).mockReturnValue({ sessionId: "sid-claude-effort", tool: "claude" });
|
|
388
|
+
await recordSessionRegistry({
|
|
389
|
+
chatId: "feishu-chat",
|
|
390
|
+
sessionId: "sid-claude-effort",
|
|
391
|
+
tool: "claude",
|
|
392
|
+
chatName: "claude-session",
|
|
393
|
+
running: false,
|
|
394
|
+
});
|
|
395
|
+
sessionInfoMap.set("feishu-chat", {
|
|
396
|
+
sessionId: "sid-claude-effort",
|
|
397
|
+
tool: "claude",
|
|
398
|
+
turnCount: 0,
|
|
399
|
+
lastContextTokens: 0,
|
|
400
|
+
startTime: Date.now(),
|
|
401
|
+
});
|
|
402
|
+
|
|
403
|
+
await handleCommand(platform, "/effort", "feishu-chat", "ou-user", Date.now(), "group");
|
|
404
|
+
|
|
405
|
+
expect(platform.sendRawCard).toHaveBeenCalled();
|
|
406
|
+
const card = JSON.parse(vi.mocked(platform.sendRawCard).mock.calls[0][1]);
|
|
407
|
+
const raw = JSON.stringify(card);
|
|
408
|
+
expect(raw).toContain("/effort low");
|
|
409
|
+
expect(raw).toContain("/effort xhigh");
|
|
410
|
+
expect(raw).toContain("/effort max");
|
|
411
|
+
});
|
|
412
|
+
|
|
413
|
+
it("switches Codex effort for the current session and reflects it in /state", async () => {
|
|
414
|
+
const platform = mockPlatform("feishu");
|
|
415
|
+
vi.mocked(platform.getChatInfo).mockResolvedValue({ name: "codex-session", description: "Codex Session: sid-codex-effort" });
|
|
416
|
+
vi.mocked(platform.extractSessionInfo).mockReturnValue({ sessionId: "sid-codex-effort", tool: "codex" });
|
|
417
|
+
_setAdapterForToolForTest("codex", mockAdapter("sid-codex-effort"));
|
|
418
|
+
await recordSessionRegistry({
|
|
419
|
+
chatId: "codex-chat",
|
|
420
|
+
sessionId: "sid-codex-effort",
|
|
421
|
+
tool: "codex",
|
|
422
|
+
chatName: "codex-session",
|
|
423
|
+
running: false,
|
|
424
|
+
});
|
|
425
|
+
sessionInfoMap.set("codex-chat", {
|
|
426
|
+
sessionId: "sid-codex-effort",
|
|
427
|
+
tool: "codex",
|
|
428
|
+
turnCount: 0,
|
|
429
|
+
lastContextTokens: 0,
|
|
430
|
+
startTime: Date.now(),
|
|
431
|
+
});
|
|
432
|
+
|
|
433
|
+
await handleCommand(platform, "/effort xhigh", "codex-chat", "ou-user", Date.now(), "group");
|
|
434
|
+
expect(platform.sendCard).toHaveBeenCalledWith(
|
|
435
|
+
"codex-chat",
|
|
436
|
+
"Effort 切换",
|
|
437
|
+
expect.stringContaining("xhigh"),
|
|
438
|
+
"green",
|
|
439
|
+
);
|
|
440
|
+
|
|
441
|
+
vi.mocked(platform.sendCard).mockClear();
|
|
442
|
+
vi.mocked(platform.sendRawCard).mockClear();
|
|
443
|
+
await handleCommand(platform, "/state", "codex-chat", "ou-user", Date.now() + 1, "group");
|
|
444
|
+
|
|
445
|
+
expect(platform.sendRawCard).toHaveBeenCalled();
|
|
446
|
+
const card = JSON.parse(vi.mocked(platform.sendRawCard).mock.calls[0][1]);
|
|
447
|
+
expect(JSON.stringify(card)).toContain("xhigh");
|
|
448
|
+
});
|
|
449
|
+
|
|
450
|
+
it("rejects /effort in Cursor sessions", async () => {
|
|
451
|
+
const platform = mockPlatform("feishu");
|
|
452
|
+
vi.mocked(platform.getChatInfo).mockResolvedValue({ name: "cursor-session", description: "Cursor Session: sid-cursor-effort" });
|
|
453
|
+
vi.mocked(platform.extractSessionInfo).mockReturnValue({ sessionId: "sid-cursor-effort", tool: "cursor" });
|
|
454
|
+
_setAdapterForToolForTest("cursor", mockAdapter("sid-cursor-effort"));
|
|
455
|
+
await recordSessionRegistry({
|
|
456
|
+
chatId: "cursor-chat",
|
|
457
|
+
sessionId: "sid-cursor-effort",
|
|
458
|
+
tool: "cursor",
|
|
459
|
+
chatName: "cursor-session",
|
|
460
|
+
running: false,
|
|
461
|
+
});
|
|
462
|
+
sessionInfoMap.set("cursor-chat", {
|
|
463
|
+
sessionId: "sid-cursor-effort",
|
|
464
|
+
tool: "cursor",
|
|
465
|
+
turnCount: 0,
|
|
466
|
+
lastContextTokens: 0,
|
|
467
|
+
startTime: Date.now(),
|
|
468
|
+
});
|
|
469
|
+
|
|
470
|
+
await handleCommand(platform, "/effort high", "cursor-chat", "ou-user", Date.now(), "group");
|
|
471
|
+
|
|
472
|
+
expect(platform.sendCard).toHaveBeenCalledWith(
|
|
473
|
+
"cursor-chat",
|
|
474
|
+
"Effort 切换",
|
|
475
|
+
expect.stringContaining("不支持 effort"),
|
|
476
|
+
"red",
|
|
477
|
+
);
|
|
478
|
+
});
|
|
479
|
+
|
|
480
|
+
it("handles /usage without creating a new Feishu group", async () => {
|
|
481
|
+
const platform = mockPlatform("feishu");
|
|
482
|
+
const usage = {
|
|
386
483
|
fiveHour: { usedPercent: 37, remainingPercent: 63, resetAtEpochSeconds: 1781528212, resetAfterSeconds: 10349 },
|
|
387
484
|
weekly: { usedPercent: 12, remainingPercent: 88, resetAtEpochSeconds: 1781842926, resetAfterSeconds: 325063 },
|
|
388
485
|
rateLimitResetCreditsAvailable: 2,
|
|
@@ -390,7 +487,8 @@ describe("handleCommand WeChat processing ack", () => {
|
|
|
390
487
|
{ grantedAt: "2026-06-12T04:01:47.770016Z", expiresAt: "2026-07-12T04:01:47.770016Z" },
|
|
391
488
|
{ grantedAt: "2026-06-18T00:44:23.904386Z", expiresAt: "2026-07-18T00:44:23.904386Z" },
|
|
392
489
|
],
|
|
393
|
-
}
|
|
490
|
+
};
|
|
491
|
+
mockGetCodexUsageSummary.mockResolvedValue(usage);
|
|
394
492
|
|
|
395
493
|
await handleCommand(platform, "/usage", "feishu-p2p", "ou-user", Date.now(), "p2p");
|
|
396
494
|
|
|
@@ -411,6 +509,7 @@ describe("handleCommand WeChat processing ack", () => {
|
|
|
411
509
|
expect(card.elements[0].text.content).toContain("[██░░░░░░░░░░░░░░░░░░]");
|
|
412
510
|
expect(card.elements[2].actions[0].text.content).toBe("发起重置");
|
|
413
511
|
expect(card.elements[2].actions[0].value).toEqual({ action: "codex_reset_request", availableCount: 2 });
|
|
512
|
+
expect(platform.setChatAvatar).toHaveBeenCalledWith("feishu-p2p", "codex", "idle", { codexUsage: usage });
|
|
414
513
|
});
|
|
415
514
|
|
|
416
515
|
it("adds ChatGPT subscription expiry to Codex /usage when CDP lookup succeeds", async () => {
|
|
@@ -445,6 +544,24 @@ describe("handleCommand WeChat processing ack", () => {
|
|
|
445
544
|
expect(card.elements[0].text.content).toContain("- 自动续费: 否");
|
|
446
545
|
});
|
|
447
546
|
|
|
547
|
+
it("shows an actionable ChatGPT subscription failure reason when Chrome CDP is enabled", async () => {
|
|
548
|
+
const platform = mockPlatform("feishu");
|
|
549
|
+
mockGetChatGptSubscriptionStatus.mockResolvedValue({
|
|
550
|
+
ok: false,
|
|
551
|
+
code: "chatgpt_session_missing",
|
|
552
|
+
reason: "ChatGPT browser session has no access token.",
|
|
553
|
+
chromeCdp: { enabled: true, port: 15166, status: "healthy" },
|
|
554
|
+
chatgpt: { sessionOk: true },
|
|
555
|
+
});
|
|
556
|
+
|
|
557
|
+
await handleCommand(platform, "/usage", "feishu-p2p", "ou-user", Date.now(), "p2p");
|
|
558
|
+
|
|
559
|
+
const card = JSON.parse(vi.mocked(platform.sendRawCard).mock.calls[0][1]);
|
|
560
|
+
expect(card.elements[0].text.content).toContain("**ChatGPT 订阅查询失败:**");
|
|
561
|
+
expect(card.elements[0].text.content).toContain("请在 15166 端口对应的 Chrome 浏览器中登录 ChatGPT");
|
|
562
|
+
expect(card.elements[0].text.content).toContain("ChatGPT browser session has no access token.");
|
|
563
|
+
});
|
|
564
|
+
|
|
448
565
|
it("handles /usage as Cursor usage in Cursor chats", async () => {
|
|
449
566
|
const platform = mockPlatform("feishu");
|
|
450
567
|
await recordSessionRegistry({
|
|
@@ -472,6 +589,37 @@ describe("handleCommand WeChat processing ack", () => {
|
|
|
472
589
|
expect.stringContaining("Pool remaining: $171417.76"),
|
|
473
590
|
"blue",
|
|
474
591
|
);
|
|
592
|
+
expect(platform.setChatAvatar).toHaveBeenCalledWith(
|
|
593
|
+
"cursor-chat",
|
|
594
|
+
"cursor",
|
|
595
|
+
"idle",
|
|
596
|
+
{ cursorUsage: expect.objectContaining({ displayMessage: "You've hit your usage limit" }) },
|
|
597
|
+
);
|
|
598
|
+
});
|
|
599
|
+
|
|
600
|
+
it("keeps the busy avatar status when /usage runs for an active Cursor session", async () => {
|
|
601
|
+
const platform = mockPlatform("feishu");
|
|
602
|
+
await recordSessionRegistry({
|
|
603
|
+
chatId: "cursor-chat",
|
|
604
|
+
sessionId: "sid-cursor",
|
|
605
|
+
tool: "cursor",
|
|
606
|
+
chatName: "cursor-session",
|
|
607
|
+
running: true,
|
|
608
|
+
});
|
|
609
|
+
activePrompts.set("sid-cursor", {
|
|
610
|
+
controller: new AbortController(),
|
|
611
|
+
stopped: false,
|
|
612
|
+
startTime: Date.now(),
|
|
613
|
+
});
|
|
614
|
+
|
|
615
|
+
await handleCommand(platform, "/usage", "cursor-chat", "ou-user", Date.now(), "group");
|
|
616
|
+
|
|
617
|
+
expect(platform.setChatAvatar).toHaveBeenCalledWith(
|
|
618
|
+
"cursor-chat",
|
|
619
|
+
"cursor",
|
|
620
|
+
"busy",
|
|
621
|
+
{ cursorUsage: expect.objectContaining({ displayMessage: "You've hit your usage limit" }) },
|
|
622
|
+
);
|
|
475
623
|
});
|
|
476
624
|
|
|
477
625
|
it("advertises /usage in new Codex and Cursor session ready messages", async () => {
|
|
@@ -91,11 +91,12 @@ import {
|
|
|
91
91
|
stopSession,
|
|
92
92
|
startUnifiedDisplayLoop,
|
|
93
93
|
stopUnifiedDisplayLoop,
|
|
94
|
-
_setProcessAliveForTest,
|
|
95
|
-
_resetProcessAliveForTest,
|
|
96
|
-
_setProcessMonitorIntervalForTest,
|
|
97
|
-
_resetProcessMonitorIntervalForTest,
|
|
98
|
-
|
|
94
|
+
_setProcessAliveForTest,
|
|
95
|
+
_resetProcessAliveForTest,
|
|
96
|
+
_setProcessMonitorIntervalForTest,
|
|
97
|
+
_resetProcessMonitorIntervalForTest,
|
|
98
|
+
setSessionEffortOverride,
|
|
99
|
+
} from "../session.ts";
|
|
99
100
|
import {
|
|
100
101
|
activePrompts,
|
|
101
102
|
bindChatToSession,
|
|
@@ -895,8 +896,17 @@ describe("getSessionStatus", () => {
|
|
|
895
896
|
expect(status!.effort).not.toBeNull();
|
|
896
897
|
// model 必为字符串(留空时显示 '(留空)',否则为环境变量值);不应是占位符
|
|
897
898
|
expect(typeof status!.model).toBe("string");
|
|
898
|
-
expect(status!.model.length).toBeGreaterThan(0);
|
|
899
|
-
});
|
|
899
|
+
expect(status!.model.length).toBeGreaterThan(0);
|
|
900
|
+
});
|
|
901
|
+
|
|
902
|
+
it("Codex session status uses the per-session effort override", async () => {
|
|
903
|
+
mockSessionInfo("chat-codex", { sessionId: "sid-codex-effort", tool: "codex" });
|
|
904
|
+
setSessionEffortOverride("sid-codex-effort", "xhigh");
|
|
905
|
+
|
|
906
|
+
const status = await getSessionStatus("chat-codex");
|
|
907
|
+
|
|
908
|
+
expect(status!.effort).toBe("xhigh");
|
|
909
|
+
});
|
|
900
910
|
|
|
901
911
|
it("Cursor 会话:effort 恒为 null(卡片渲染时隐藏该行,避免显示无意义的 effort)", async () => {
|
|
902
912
|
mockSessionInfo("chat-cursor", { sessionId: "sid-cur", tool: "cursor" });
|
|
@@ -34,6 +34,22 @@ describe("unflattenConfig", () => {
|
|
|
34
34
|
});
|
|
35
35
|
});
|
|
36
36
|
|
|
37
|
+
it("maps Cursor and Codex alternative models into agent config", () => {
|
|
38
|
+
expect(
|
|
39
|
+
unflattenConfig({
|
|
40
|
+
CHATCCC_CURSOR_ALTERNATIVE_MODEL: "gpt-5.5-high",
|
|
41
|
+
CHATCCC_CODEX_ALTERNATIVE_MODEL: "gpt-5.3-codex",
|
|
42
|
+
}),
|
|
43
|
+
).toEqual({
|
|
44
|
+
cursor: {
|
|
45
|
+
alternativeModel: "gpt-5.5-high",
|
|
46
|
+
},
|
|
47
|
+
codex: {
|
|
48
|
+
alternativeModel: "gpt-5.3-codex",
|
|
49
|
+
},
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
|
|
37
53
|
it("maps Chrome CDP guard fields into chromeDevtools config", () => {
|
|
38
54
|
expect(
|
|
39
55
|
unflattenConfig({
|
|
@@ -57,6 +73,12 @@ describe("dashboard edit modal", () => {
|
|
|
57
73
|
expect(PAGE_HTML).toContain("document.getElementById('edit-modal').classList.remove('hidden');");
|
|
58
74
|
expect(PAGE_HTML).toContain("document.getElementById('edit-overlay').classList.remove('hidden');");
|
|
59
75
|
});
|
|
76
|
+
|
|
77
|
+
it("uses plain alternative model labels for Cursor and Codex", () => {
|
|
78
|
+
expect(PAGE_HTML).toContain("field-CHATCCC_CURSOR_ALTERNATIVE_MODEL");
|
|
79
|
+
expect(PAGE_HTML).toContain("field-CHATCCC_CODEX_ALTERNATIVE_MODEL");
|
|
80
|
+
expect(PAGE_HTML).toContain("备选模型");
|
|
81
|
+
});
|
|
60
82
|
});
|
|
61
83
|
|
|
62
84
|
// ---------------------------------------------------------------------------
|