Repository navigation
Expand file tree
/
Copy pathprogram.smoke.e2e.test.ts
More file actions
242 lines (223 loc) · 6.9 KB
/
Copy pathprogram.smoke.e2e.test.ts
File metadata and controls
242 lines (223 loc) · 6.9 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
import { beforeEach, describe, expect, it, vi } from "vitest";
import {
configureCommand,
ensureConfigReady,
installBaseProgramMocks,
installSmokeProgramMocks,
messageCommand,
onboardCommand,
runChannelLogin,
runChannelLogout,
runTui,
runtime,
setupCommand,
statusCommand,
} from "./program.test-mocks.js";
installBaseProgramMocks();
installSmokeProgramMocks();
const { buildProgram } = await import("./program.js");
describe("cli program (smoke)", () => {
beforeEach(() => {
vi.clearAllMocks();
runTui.mockResolvedValue(undefined);
ensureConfigReady.mockResolvedValue(undefined);
});
it("runs message with required options", async () => {
const program = buildProgram();
await expect(
program.parseAsync(["message", "send", "--target", "+1", "--message", "hi"], {
from: "user",
}),
).rejects.toThrow("exit");
expect(messageCommand).toHaveBeenCalled();
});
it("runs message react with signal author fields", async () => {
const program = buildProgram();
await expect(
program.parseAsync(
[
"message",
"react",
"--channel",
"signal",
"--target",
"signal:group:abc123",
"--message-id",
"1737630212345",
"--emoji",
"✅",
"--target-author-uuid",
"123e4567-e89b-12d3-a456-426614174000",
],
{ from: "user" },
),
).rejects.toThrow("exit");
expect(messageCommand).toHaveBeenCalled();
});
it("runs status command", async () => {
const program = buildProgram();
await program.parseAsync(["status"], { from: "user" });
expect(statusCommand).toHaveBeenCalled();
});
it("registers memory command", () => {
const program = buildProgram();
const names = program.commands.map((command) => command.name());
expect(names).toContain("memory");
});
it("runs tui without overriding timeout", async () => {
const program = buildProgram();
await program.parseAsync(["tui"], { from: "user" });
expect(runTui).toHaveBeenCalledWith(expect.objectContaining({ timeoutMs: undefined }));
});
it("runs tui with explicit timeout override", async () => {
const program = buildProgram();
await program.parseAsync(["tui", "--timeout-ms", "45000"], {
from: "user",
});
expect(runTui).toHaveBeenCalledWith(expect.objectContaining({ timeoutMs: 45000 }));
});
it("warns and ignores invalid tui timeout override", async () => {
const program = buildProgram();
await program.parseAsync(["tui", "--timeout-ms", "nope"], { from: "user" });
expect(runtime.error).toHaveBeenCalledWith('warning: invalid --timeout-ms "nope"; ignoring');
expect(runTui).toHaveBeenCalledWith(expect.objectContaining({ timeoutMs: undefined }));
});
it("runs config alias as configure", async () => {
const program = buildProgram();
await program.parseAsync(["config"], { from: "user" });
expect(configureCommand).toHaveBeenCalled();
});
it("runs setup without wizard flags", async () => {
const program = buildProgram();
await program.parseAsync(["setup"], { from: "user" });
expect(setupCommand).toHaveBeenCalled();
expect(onboardCommand).not.toHaveBeenCalled();
});
it("runs setup wizard when wizard flags are present", async () => {
const program = buildProgram();
await program.parseAsync(["setup", "--remote-url", "ws://example"], {
from: "user",
});
expect(onboardCommand).toHaveBeenCalled();
expect(setupCommand).not.toHaveBeenCalled();
});
it("passes auth api keys to onboard", async () => {
const cases = [
{
authChoice: "opencode-zen",
flag: "--opencode-zen-api-key",
key: "sk-opencode-zen-test",
field: "opencodeZenApiKey",
},
{
authChoice: "openrouter-api-key",
flag: "--openrouter-api-key",
key: "sk-openrouter-test",
field: "openrouterApiKey",
},
{
authChoice: "moonshot-api-key",
flag: "--moonshot-api-key",
key: "sk-moonshot-test",
field: "moonshotApiKey",
},
{
authChoice: "together-api-key",
flag: "--together-api-key",
key: "sk-together-test",
field: "togetherApiKey",
},
{
authChoice: "moonshot-api-key-cn",
flag: "--moonshot-api-key",
key: "sk-moonshot-cn-test",
field: "moonshotApiKey",
},
{
authChoice: "kimi-code-api-key",
flag: "--kimi-code-api-key",
key: "sk-kimi-code-test",
field: "kimiCodeApiKey",
},
{
authChoice: "synthetic-api-key",
flag: "--synthetic-api-key",
key: "sk-synthetic-test",
field: "syntheticApiKey",
},
{
authChoice: "zai-api-key",
flag: "--zai-api-key",
key: "sk-zai-test",
field: "zaiApiKey",
},
] as const;
for (const entry of cases) {
const program = buildProgram();
await program.parseAsync(
["onboard", "--non-interactive", "--auth-choice", entry.authChoice, entry.flag, entry.key],
{ from: "user" },
);
expect(onboardCommand).toHaveBeenCalledWith(
expect.objectContaining({
nonInteractive: true,
authChoice: entry.authChoice,
[entry.field]: entry.key,
}),
runtime,
);
onboardCommand.mockClear();
}
});
it("passes custom provider flags to onboard", async () => {
const program = buildProgram();
await program.parseAsync(
[
"onboard",
"--non-interactive",
"--auth-choice",
"custom-api-key",
"--custom-base-url",
"https://llm.example.com/v1",
"--custom-api-key",
"sk-custom-test",
"--custom-model-id",
"foo-large",
"--custom-provider-id",
"my-custom",
"--custom-compatibility",
"anthropic",
],
{ from: "user" },
);
expect(onboardCommand).toHaveBeenCalledWith(
expect.objectContaining({
nonInteractive: true,
authChoice: "custom-api-key",
customBaseUrl: "https://llm.example.com/v1",
customApiKey: "sk-custom-test",
customModelId: "foo-large",
customProviderId: "my-custom",
customCompatibility: "anthropic",
}),
runtime,
);
});
it("runs channels login", async () => {
const program = buildProgram();
await program.parseAsync(["channels", "login", "--account", "work"], {
from: "user",
});
expect(runChannelLogin).toHaveBeenCalledWith(
{ channel: undefined, account: "work", verbose: false },
runtime,
);
});
it("runs channels logout", async () => {
const program = buildProgram();
await program.parseAsync(["channels", "logout", "--account", "work"], {
from: "user",
});
expect(runChannelLogout).toHaveBeenCalledWith({ channel: undefined, account: "work" }, runtime);
});
});