chatccc 0.2.196 → 0.2.197

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.
Files changed (51) hide show
  1. package/agent-prompts/cursor_specific.md +13 -13
  2. package/bin/cccagent.mjs +17 -17
  3. package/config.sample.json +27 -27
  4. package/package.json +1 -1
  5. package/src/__tests__/agent-reload-config-rpc.test.ts +99 -0
  6. package/src/__tests__/builtin-chat-session.test.ts +277 -181
  7. package/src/__tests__/builtin-cli-json.test.ts +39 -39
  8. package/src/__tests__/builtin-config.test.ts +33 -33
  9. package/src/__tests__/builtin-context.test.ts +163 -163
  10. package/src/__tests__/builtin-file-tools.test.ts +224 -196
  11. package/src/__tests__/builtin-session-select.test.ts +116 -116
  12. package/src/__tests__/builtin-sigint.test.ts +56 -56
  13. package/src/__tests__/cards.test.ts +109 -109
  14. package/src/__tests__/ccc-adapter.test.ts +114 -113
  15. package/src/__tests__/chatgpt-subscription-rpc.test.ts +89 -89
  16. package/src/__tests__/chatgpt-subscription.test.ts +135 -135
  17. package/src/__tests__/chrome-devtools-guard.test.ts +165 -165
  18. package/src/__tests__/claude-raw-stream-log.test.ts +87 -0
  19. package/src/__tests__/codex-raw-stream-log.test.ts +120 -0
  20. package/src/__tests__/config-reload.test.ts +10 -10
  21. package/src/__tests__/config-sample.test.ts +18 -18
  22. package/src/__tests__/cursor-adapter.test.ts +113 -113
  23. package/src/__tests__/feishu-avatar.test.ts +40 -40
  24. package/src/__tests__/orchestrator.test.ts +181 -154
  25. package/src/__tests__/raw-stream-log.test.ts +106 -106
  26. package/src/__tests__/session.test.ts +40 -40
  27. package/src/__tests__/sim-platform.test.ts +12 -12
  28. package/src/__tests__/web-ui.test.ts +209 -209
  29. package/src/adapters/ccc-adapter.ts +121 -119
  30. package/src/adapters/claude-adapter.ts +603 -566
  31. package/src/adapters/codex-adapter.ts +57 -32
  32. package/src/adapters/cursor-adapter.ts +264 -264
  33. package/src/adapters/raw-stream-log.ts +124 -124
  34. package/src/agent-reload-config-rpc.ts +34 -0
  35. package/src/builtin/cli.ts +473 -461
  36. package/src/builtin/context.ts +323 -323
  37. package/src/builtin/file-tools.ts +1072 -915
  38. package/src/builtin/index.ts +404 -353
  39. package/src/builtin/session-select.ts +48 -48
  40. package/src/builtin/sigint.ts +50 -50
  41. package/src/cards.ts +195 -195
  42. package/src/chatgpt-subscription-rpc.ts +27 -27
  43. package/src/chatgpt-subscription.ts +299 -299
  44. package/src/chrome-devtools-guard.ts +318 -318
  45. package/src/config.ts +125 -125
  46. package/src/feishu-api.ts +49 -49
  47. package/src/index.ts +8 -13
  48. package/src/orchestrator.ts +166 -145
  49. package/src/runtime-reload.ts +34 -0
  50. package/src/session.ts +141 -141
  51. package/src/web-ui.ts +205 -205
@@ -1,181 +1,277 @@
1
- import { mkdtemp } from "node:fs/promises";
2
- import { tmpdir } from "node:os";
3
- import { join } from "node:path";
4
-
5
- import { afterEach, describe, expect, it, vi } from "vitest";
6
-
7
- import { config } from "../config.ts";
8
-
9
- const streamTextMock = vi.fn();
10
- const generateTextMock = vi.fn();
11
- const createRawStreamLogMock = vi.fn();
12
- const rawLogWriteLineMock = vi.fn();
13
- const rawLogCloseMock = vi.fn();
14
- const originalRawStreamLogs = structuredClone(config.rawStreamLogs);
15
-
16
- vi.mock("@ai-sdk/openai-compatible", () => ({
17
- createOpenAICompatible: vi.fn(() => (modelId: string) => ({ modelId })),
18
- }));
19
-
20
- vi.mock("ai", () => ({
21
- streamText: streamTextMock,
22
- generateText: generateTextMock,
23
- stepCountIs: vi.fn((count: number) => ({ count })),
24
- jsonSchema: vi.fn((schema: unknown) => schema),
25
- tool: vi.fn((definition: unknown) => definition),
26
- }));
27
-
28
- vi.mock("../adapters/raw-stream-log.ts", () => ({
29
- createRawStreamLog: createRawStreamLogMock,
30
- }));
31
-
32
- async function collect(iterable: AsyncIterable<unknown>): Promise<unknown[]> {
33
- const events: unknown[] = [];
34
- for await (const event of iterable) events.push(event);
35
- return events;
36
- }
37
-
38
- async function* textStream(...chunks: string[]): AsyncIterable<string> {
39
- for (const chunk of chunks) yield chunk;
40
- }
41
-
42
- async function* fullStream(...parts: unknown[]): AsyncIterable<unknown> {
43
- for (const part of parts) yield part;
44
- }
45
-
46
- afterEach(() => {
47
- streamTextMock.mockReset();
48
- generateTextMock.mockReset();
49
- createRawStreamLogMock.mockReset();
50
- rawLogWriteLineMock.mockReset();
51
- rawLogCloseMock.mockReset();
52
- config.rawStreamLogs = structuredClone(originalRawStreamLogs);
53
- });
54
-
55
- describe("ChatSession context management", () => {
56
- it("loads persisted context, compacts older messages, and persists the new assistant reply", async () => {
57
- const { ChatSession } = await import("../builtin/index.ts");
58
- const dir = await mkdtemp(join(tmpdir(), "chatccc-session-context-"));
59
-
60
- const seed = new ChatSession(
61
- { apiKey: "sk-test" },
62
- {
63
- persist: true,
64
- contextDir: dir,
65
- sessionId: "integration",
66
- compactAtTokens: 10_000,
67
- },
68
- );
69
- streamTextMock.mockReturnValueOnce({ textStream: textStream("old answer") });
70
- await collect(seed.chat("old question"));
71
-
72
- generateTextMock.mockResolvedValueOnce({ text: "## 当前任务状态\n- 旧问题已总结" });
73
- streamTextMock.mockReturnValueOnce({ textStream: textStream("new answer") });
74
-
75
- const restored = new ChatSession(
76
- { apiKey: "sk-test" },
77
- {
78
- persist: true,
79
- contextDir: dir,
80
- sessionId: "integration",
81
- compactAtTokens: 1,
82
- keepRecentMessages: 1,
83
- },
84
- );
85
- const events = await collect(restored.chat("new question"));
86
-
87
- expect(generateTextMock).toHaveBeenCalledOnce();
88
- expect(streamTextMock).toHaveBeenLastCalledWith(expect.objectContaining({
89
- messages: expect.arrayContaining([
90
- expect.objectContaining({ content: expect.stringContaining("旧问题已总结") }),
91
- expect.objectContaining({ role: "user", content: "new question" }),
92
- ]),
93
- }));
94
- expect(events).toContainEqual({ type: "compact", compactedMessages: 2 });
95
- expect(restored.history.map((m) => m.content).join("\n")).toContain("new answer");
96
- });
97
-
98
- it("streams tool calls and tool results from fullStream", async () => {
99
- const { ChatSession } = await import("../builtin/index.ts");
100
- const dir = await mkdtemp(join(tmpdir(), "chatccc-session-tools-"));
101
- const session = new ChatSession(
102
- { apiKey: "sk-test" },
103
- {
104
- persist: true,
105
- contextDir: dir,
106
- sessionId: "tools",
107
- },
108
- );
109
-
110
- streamTextMock.mockReturnValueOnce({
111
- fullStream: fullStream(
112
- { type: "tool-call", toolCallId: "call-1", toolName: "read_file", input: { path: "package.json" } },
113
- { type: "tool-result", toolCallId: "call-1", toolName: "read_file", output: { content: "{}" } },
114
- { type: "text-delta", text: "done" },
115
- ),
116
- });
117
-
118
- const events = await collect(session.chat("read package"));
119
-
120
- expect(events).toContainEqual({
121
- type: "tool_use",
122
- id: "call-1",
123
- name: "read_file",
124
- input: { path: "package.json" },
125
- });
126
- expect(events).toContainEqual({
127
- type: "tool_result",
128
- tool_use_id: "call-1",
129
- name: "read_file",
130
- content: { content: "{}" },
131
- is_error: false,
132
- });
133
- expect(events).toContainEqual({ type: "text", text: "done", accumulated: "done" });
134
- });
135
-
136
- it("writes raw CCC fullStream parts when raw stream logs are enabled", async () => {
137
- const { ChatSession } = await import("../builtin/index.ts");
138
- config.rawStreamLogs.ccc = {
139
- enabled: true,
140
- maxBytesPerTurn: 4096,
141
- retentionDays: 3,
142
- keepCompleted: true,
143
- };
144
- createRawStreamLogMock.mockResolvedValueOnce({
145
- filePath: "raw.jsonl.gz",
146
- writeLine: rawLogWriteLineMock,
147
- close: rawLogCloseMock,
148
- });
149
- const session = new ChatSession(
150
- { apiKey: "sk-test" },
151
- {
152
- sessionId: "raw-log-session",
153
- },
154
- );
155
- const textPart = { type: "text-delta", text: "hello" };
156
- const toolPart = {
157
- type: "tool-call",
158
- toolCallId: "call-1",
159
- toolName: "read_file",
160
- input: { path: "package.json" },
161
- };
162
-
163
- streamTextMock.mockReturnValueOnce({
164
- fullStream: fullStream(textPart, toolPart),
165
- });
166
-
167
- await collect(session.chat("hi"));
168
-
169
- expect(createRawStreamLogMock).toHaveBeenCalledWith(expect.objectContaining({
170
- enabled: true,
171
- tool: "ccc",
172
- sessionId: "raw-log-session",
173
- label: "prompt",
174
- maxBytesPerTurn: 4096,
175
- retentionDays: 3,
176
- }));
177
- expect(rawLogWriteLineMock).toHaveBeenNthCalledWith(1, JSON.stringify(textPart));
178
- expect(rawLogWriteLineMock).toHaveBeenNthCalledWith(2, JSON.stringify(toolPart));
179
- expect(rawLogCloseMock).toHaveBeenCalledWith({ keep: true });
180
- });
181
- });
1
+ import { mkdir, mkdtemp, writeFile } from "node:fs/promises";
2
+ import { tmpdir } from "node:os";
3
+ import { join } from "node:path";
4
+
5
+ import { afterEach, describe, expect, it, vi } from "vitest";
6
+
7
+ import { config } from "../config.ts";
8
+
9
+ const streamTextMock = vi.fn();
10
+ const generateTextMock = vi.fn();
11
+ const createRawStreamLogMock = vi.fn();
12
+ const rawLogWriteLineMock = vi.fn();
13
+ const rawLogCloseMock = vi.fn();
14
+ const originalRawStreamLogs = structuredClone(config.rawStreamLogs);
15
+
16
+ vi.mock("@ai-sdk/openai-compatible", () => ({
17
+ createOpenAICompatible: vi.fn(() => (modelId: string) => ({ modelId })),
18
+ }));
19
+
20
+ vi.mock("ai", () => ({
21
+ streamText: streamTextMock,
22
+ generateText: generateTextMock,
23
+ isLoopFinished: vi.fn(() => ({ loopFinished: true })),
24
+ stepCountIs: vi.fn((count: number) => ({ count })),
25
+ jsonSchema: vi.fn((schema: unknown) => schema),
26
+ tool: vi.fn((definition: unknown) => definition),
27
+ }));
28
+
29
+ vi.mock("../adapters/raw-stream-log.ts", () => ({
30
+ createRawStreamLog: createRawStreamLogMock,
31
+ }));
32
+
33
+ async function collect(iterable: AsyncIterable<unknown>): Promise<unknown[]> {
34
+ const events: unknown[] = [];
35
+ for await (const event of iterable) events.push(event);
36
+ return events;
37
+ }
38
+
39
+ async function* textStream(...chunks: string[]): AsyncIterable<string> {
40
+ for (const chunk of chunks) yield chunk;
41
+ }
42
+
43
+ async function* fullStream(...parts: unknown[]): AsyncIterable<unknown> {
44
+ for (const part of parts) yield part;
45
+ }
46
+
47
+ afterEach(() => {
48
+ streamTextMock.mockReset();
49
+ generateTextMock.mockReset();
50
+ createRawStreamLogMock.mockReset();
51
+ rawLogWriteLineMock.mockReset();
52
+ rawLogCloseMock.mockReset();
53
+ config.rawStreamLogs = structuredClone(originalRawStreamLogs);
54
+ });
55
+
56
+ describe("ChatSession context management", () => {
57
+ it("injects cwd project instruction files before runtime workspace details", async () => {
58
+ const { ChatSession } = await import("../builtin/index.ts");
59
+ const dir = await mkdtemp(join(tmpdir(), "chatccc-session-instructions-"));
60
+ await writeFile(join(dir, "AGENTS.md"), "agents root guidance", "utf-8");
61
+ await writeFile(join(dir, "AGENTS.local.md"), "agents local guidance", "utf-8");
62
+ await writeFile(join(dir, "CLAUDE.md"), "claude root guidance", "utf-8");
63
+ await writeFile(join(dir, "CLAUDE.local.md"), "claude local guidance", "utf-8");
64
+ streamTextMock.mockReturnValueOnce({ textStream: textStream() });
65
+
66
+ const session = new ChatSession(
67
+ { apiKey: "sk-test" },
68
+ {
69
+ cwd: dir,
70
+ sessionId: "project-instructions",
71
+ },
72
+ );
73
+ await collect(session.chat("hi"));
74
+
75
+ const system = streamTextMock.mock.calls.at(-1)?.[0].system as string;
76
+ expect(system).toContain("## Project Instructions");
77
+ expect(system).toContain("### AGENTS.md");
78
+ expect(system).toContain("agents root guidance");
79
+ expect(system).toContain("### AGENTS.local.md");
80
+ expect(system).toContain("agents local guidance");
81
+ expect(system).toContain("### CLAUDE.md");
82
+ expect(system).toContain("claude root guidance");
83
+ expect(system).toContain("### CLAUDE.local.md");
84
+ expect(system).toContain("claude local guidance");
85
+
86
+ expect(system.indexOf("agents root guidance")).toBeLessThan(system.indexOf("agents local guidance"));
87
+ expect(system.indexOf("agents local guidance")).toBeLessThan(system.indexOf("claude root guidance"));
88
+ expect(system.indexOf("claude root guidance")).toBeLessThan(system.indexOf("claude local guidance"));
89
+ expect(system.indexOf("claude local guidance")).toBeLessThan(system.indexOf(dir));
90
+ });
91
+
92
+ it("does not read project instruction files from parent directories", async () => {
93
+ const { ChatSession } = await import("../builtin/index.ts");
94
+ const parent = await mkdtemp(join(tmpdir(), "chatccc-session-parent-instructions-"));
95
+ const child = join(parent, "child");
96
+ await mkdir(child);
97
+ await writeFile(join(parent, "AGENTS.md"), "parent-only guidance", "utf-8");
98
+ streamTextMock.mockReturnValueOnce({ textStream: textStream() });
99
+
100
+ const session = new ChatSession(
101
+ { apiKey: "sk-test" },
102
+ {
103
+ cwd: child,
104
+ sessionId: "no-parent-instructions",
105
+ },
106
+ );
107
+ await collect(session.chat("hi"));
108
+
109
+ const system = streamTextMock.mock.calls.at(-1)?.[0].system as string;
110
+ expect(system).not.toContain("parent-only guidance");
111
+ });
112
+
113
+ it("uses loop-finished stopping by default", async () => {
114
+ const { ChatSession } = await import("../builtin/index.ts");
115
+ const dir = await mkdtemp(join(tmpdir(), "chatccc-session-unlimited-"));
116
+ streamTextMock.mockReturnValueOnce({ textStream: textStream("done") });
117
+
118
+ const session = new ChatSession(
119
+ { apiKey: "sk-test" },
120
+ {
121
+ cwd: dir,
122
+ sessionId: "unlimited-steps",
123
+ },
124
+ );
125
+ await collect(session.chat("run a multi-stage workflow"));
126
+
127
+ expect(streamTextMock).toHaveBeenLastCalledWith(expect.objectContaining({
128
+ stopWhen: { loopFinished: true },
129
+ }));
130
+ });
131
+
132
+ it("uses a configured tool step limit when provided", async () => {
133
+ const { ChatSession } = await import("../builtin/index.ts");
134
+ const dir = await mkdtemp(join(tmpdir(), "chatccc-session-step-budget-"));
135
+ streamTextMock.mockReturnValueOnce({ textStream: textStream("done") });
136
+
137
+ const session = new ChatSession(
138
+ { apiKey: "sk-test" },
139
+ {
140
+ cwd: dir,
141
+ sessionId: "step-budget",
142
+ maxSteps: 7,
143
+ },
144
+ );
145
+ await collect(session.chat("run a bounded workflow"));
146
+
147
+ expect(streamTextMock).toHaveBeenLastCalledWith(expect.objectContaining({
148
+ stopWhen: { count: 7 },
149
+ }));
150
+ });
151
+
152
+ it("loads persisted context, compacts older messages, and persists the new assistant reply", async () => {
153
+ const { ChatSession } = await import("../builtin/index.ts");
154
+ const dir = await mkdtemp(join(tmpdir(), "chatccc-session-context-"));
155
+
156
+ const seed = new ChatSession(
157
+ { apiKey: "sk-test" },
158
+ {
159
+ persist: true,
160
+ contextDir: dir,
161
+ sessionId: "integration",
162
+ compactAtTokens: 10_000,
163
+ },
164
+ );
165
+ streamTextMock.mockReturnValueOnce({ textStream: textStream("old answer") });
166
+ await collect(seed.chat("old question"));
167
+
168
+ generateTextMock.mockResolvedValueOnce({ text: "## 当前任务状态\n- 旧问题已总结" });
169
+ streamTextMock.mockReturnValueOnce({ textStream: textStream("new answer") });
170
+
171
+ const restored = new ChatSession(
172
+ { apiKey: "sk-test" },
173
+ {
174
+ persist: true,
175
+ contextDir: dir,
176
+ sessionId: "integration",
177
+ compactAtTokens: 1,
178
+ keepRecentMessages: 1,
179
+ },
180
+ );
181
+ const events = await collect(restored.chat("new question"));
182
+
183
+ expect(generateTextMock).toHaveBeenCalledOnce();
184
+ expect(streamTextMock).toHaveBeenLastCalledWith(expect.objectContaining({
185
+ messages: expect.arrayContaining([
186
+ expect.objectContaining({ content: expect.stringContaining("旧问题已总结") }),
187
+ expect.objectContaining({ role: "user", content: "new question" }),
188
+ ]),
189
+ }));
190
+ expect(events).toContainEqual({ type: "compact", compactedMessages: 2 });
191
+ expect(restored.history.map((m) => m.content).join("\n")).toContain("new answer");
192
+ });
193
+
194
+ it("streams tool calls and tool results from fullStream", async () => {
195
+ const { ChatSession } = await import("../builtin/index.ts");
196
+ const dir = await mkdtemp(join(tmpdir(), "chatccc-session-tools-"));
197
+ const session = new ChatSession(
198
+ { apiKey: "sk-test" },
199
+ {
200
+ persist: true,
201
+ contextDir: dir,
202
+ sessionId: "tools",
203
+ },
204
+ );
205
+
206
+ streamTextMock.mockReturnValueOnce({
207
+ fullStream: fullStream(
208
+ { type: "tool-call", toolCallId: "call-1", toolName: "read_file", input: { path: "package.json" } },
209
+ { type: "tool-result", toolCallId: "call-1", toolName: "read_file", output: { content: "{}" } },
210
+ { type: "text-delta", text: "done" },
211
+ ),
212
+ });
213
+
214
+ const events = await collect(session.chat("read package"));
215
+
216
+ expect(events).toContainEqual({
217
+ type: "tool_use",
218
+ id: "call-1",
219
+ name: "read_file",
220
+ input: { path: "package.json" },
221
+ });
222
+ expect(events).toContainEqual({
223
+ type: "tool_result",
224
+ tool_use_id: "call-1",
225
+ name: "read_file",
226
+ content: { content: "{}" },
227
+ is_error: false,
228
+ });
229
+ expect(events).toContainEqual({ type: "text", text: "done", accumulated: "done" });
230
+ });
231
+
232
+ it("writes raw CCC fullStream parts when raw stream logs are enabled", async () => {
233
+ const { ChatSession } = await import("../builtin/index.ts");
234
+ config.rawStreamLogs.ccc = {
235
+ enabled: true,
236
+ maxBytesPerTurn: 4096,
237
+ retentionDays: 3,
238
+ keepCompleted: true,
239
+ };
240
+ createRawStreamLogMock.mockResolvedValueOnce({
241
+ filePath: "raw.jsonl.gz",
242
+ writeLine: rawLogWriteLineMock,
243
+ close: rawLogCloseMock,
244
+ });
245
+ const session = new ChatSession(
246
+ { apiKey: "sk-test" },
247
+ {
248
+ sessionId: "raw-log-session",
249
+ },
250
+ );
251
+ const textPart = { type: "text-delta", text: "hello" };
252
+ const toolPart = {
253
+ type: "tool-call",
254
+ toolCallId: "call-1",
255
+ toolName: "read_file",
256
+ input: { path: "package.json" },
257
+ };
258
+
259
+ streamTextMock.mockReturnValueOnce({
260
+ fullStream: fullStream(textPart, toolPart),
261
+ });
262
+
263
+ await collect(session.chat("hi"));
264
+
265
+ expect(createRawStreamLogMock).toHaveBeenCalledWith(expect.objectContaining({
266
+ enabled: true,
267
+ tool: "ccc",
268
+ sessionId: "raw-log-session",
269
+ label: "prompt",
270
+ maxBytesPerTurn: 4096,
271
+ retentionDays: 3,
272
+ }));
273
+ expect(rawLogWriteLineMock).toHaveBeenNthCalledWith(1, JSON.stringify(textPart));
274
+ expect(rawLogWriteLineMock).toHaveBeenNthCalledWith(2, JSON.stringify(toolPart));
275
+ expect(rawLogCloseMock).toHaveBeenCalledWith({ keep: true });
276
+ });
277
+ });
@@ -1,39 +1,39 @@
1
- import { execFile } from "node:child_process";
2
- import { promisify } from "node:util";
3
-
4
- import { describe, expect, it } from "vitest";
5
-
6
- const execFileAsync = promisify(execFile);
7
-
8
- describe("builtin cli --stream-json", () => {
9
- it("writes only JSON lines to stdout when startup fails", async () => {
10
- let caught: unknown;
11
- try {
12
- await execFileAsync(process.execPath, [
13
- "bin/cccagent.mjs",
14
- "--stream-json",
15
- "--prompt",
16
- "hello",
17
- "--api-key",
18
- "",
19
- ], {
20
- cwd: process.cwd(),
21
- timeout: 10_000,
22
- windowsHide: true,
23
- });
24
- } catch (err) {
25
- caught = err;
26
- }
27
-
28
- expect(caught).toMatchObject({ code: 1 });
29
- const stdout = (caught as { stdout?: string }).stdout ?? "";
30
- const lines = stdout.trim().split(/\r?\n/).filter(Boolean);
31
- expect(lines.length).toBeGreaterThan(0);
32
- for (const line of lines) {
33
- expect(() => JSON.parse(line)).not.toThrow();
34
- }
35
- expect(JSON.parse(lines.at(-1)!)).toEqual(expect.objectContaining({
36
- type: "error",
37
- }));
38
- });
39
- });
1
+ import { execFile } from "node:child_process";
2
+ import { promisify } from "node:util";
3
+
4
+ import { describe, expect, it } from "vitest";
5
+
6
+ const execFileAsync = promisify(execFile);
7
+
8
+ describe("builtin cli --stream-json", () => {
9
+ it("writes only JSON lines to stdout when startup fails", async () => {
10
+ let caught: unknown;
11
+ try {
12
+ await execFileAsync(process.execPath, [
13
+ "bin/cccagent.mjs",
14
+ "--stream-json",
15
+ "--prompt",
16
+ "hello",
17
+ "--api-key",
18
+ "",
19
+ ], {
20
+ cwd: process.cwd(),
21
+ timeout: 10_000,
22
+ windowsHide: true,
23
+ });
24
+ } catch (err) {
25
+ caught = err;
26
+ }
27
+
28
+ expect(caught).toMatchObject({ code: 1 });
29
+ const stdout = (caught as { stdout?: string }).stdout ?? "";
30
+ const lines = stdout.trim().split(/\r?\n/).filter(Boolean);
31
+ expect(lines.length).toBeGreaterThan(0);
32
+ for (const line of lines) {
33
+ expect(() => JSON.parse(line)).not.toThrow();
34
+ }
35
+ expect(JSON.parse(lines.at(-1)!)).toEqual(expect.objectContaining({
36
+ type: "error",
37
+ }));
38
+ });
39
+ });
@@ -1,33 +1,33 @@
1
- import { afterEach, describe, expect, it } from "vitest";
2
-
3
- import { ChatSession } from "../builtin/index.ts";
4
- import { config } from "../config.ts";
5
-
6
- const originalDeepSeekApiKey = process.env.DEEPSEEK_API_KEY;
7
- const originalCccConfig = structuredClone(config.ccc);
8
-
9
- afterEach(() => {
10
- if (originalDeepSeekApiKey === undefined) {
11
- delete process.env.DEEPSEEK_API_KEY;
12
- } else {
13
- process.env.DEEPSEEK_API_KEY = originalDeepSeekApiKey;
14
- }
15
- config.ccc = structuredClone(originalCccConfig);
16
- });
17
-
18
- describe("builtin ChatSession config", () => {
19
- it("does not fall back to DEEPSEEK_API_KEY environment variable", () => {
20
- config.ccc = {
21
- DEEPSEEK_API_KEY: "",
22
- DEEPSEEK_BASE_URL: "https://api.deepseek.com/v1",
23
- model: "deepseek-v4-pro",
24
- };
25
- process.env.DEEPSEEK_API_KEY = "sk-env-should-not-be-used";
26
-
27
- expect(() => new ChatSession()).toThrow("ccc.DEEPSEEK_API_KEY 未设置");
28
- });
29
-
30
- it("allows constructor parameters to override config defaults", () => {
31
- expect(() => new ChatSession({ apiKey: "sk-test" })).not.toThrow();
32
- });
33
- });
1
+ import { afterEach, describe, expect, it } from "vitest";
2
+
3
+ import { ChatSession } from "../builtin/index.ts";
4
+ import { config } from "../config.ts";
5
+
6
+ const originalDeepSeekApiKey = process.env.DEEPSEEK_API_KEY;
7
+ const originalCccConfig = structuredClone(config.ccc);
8
+
9
+ afterEach(() => {
10
+ if (originalDeepSeekApiKey === undefined) {
11
+ delete process.env.DEEPSEEK_API_KEY;
12
+ } else {
13
+ process.env.DEEPSEEK_API_KEY = originalDeepSeekApiKey;
14
+ }
15
+ config.ccc = structuredClone(originalCccConfig);
16
+ });
17
+
18
+ describe("builtin ChatSession config", () => {
19
+ it("does not fall back to DEEPSEEK_API_KEY environment variable", () => {
20
+ config.ccc = {
21
+ DEEPSEEK_API_KEY: "",
22
+ DEEPSEEK_BASE_URL: "https://api.deepseek.com/v1",
23
+ model: "deepseek-v4-pro",
24
+ };
25
+ process.env.DEEPSEEK_API_KEY = "sk-env-should-not-be-used";
26
+
27
+ expect(() => new ChatSession()).toThrow("ccc.DEEPSEEK_API_KEY 未设置");
28
+ });
29
+
30
+ it("allows constructor parameters to override config defaults", () => {
31
+ expect(() => new ChatSession({ apiKey: "sk-test" })).not.toThrow();
32
+ });
33
+ });