genlayer 0.0.34 → 0.1.0
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/CHANGELOG.md +9 -0
- package/dist/index.js +3339 -1294
- package/package.json +10 -8
- package/renovate.json +14 -0
- package/src/commands/general/index.ts +2 -0
- package/src/commands/general/init.ts +41 -8
- package/src/commands/general/start.ts +8 -3
- package/src/lib/clients/system.ts +24 -5
- package/src/lib/config/simulator.ts +5 -0
- package/src/lib/errors/versionRequired.ts +9 -0
- package/src/lib/interfaces/ISimulatorService.ts +3 -3
- package/src/lib/services/simulator.ts +68 -27
- package/tests/actions/init.test.ts +247 -330
- package/tests/actions/start.test.ts +172 -0
- package/tests/commands/init.test.ts +24 -20
- package/tests/commands/up.test.ts +94 -0
- package/tsconfig.json +1 -1
- package/vitest.config.ts +11 -0
- package/jest.config.js +0 -4
|
@@ -1,193 +1,154 @@
|
|
|
1
|
-
|
|
2
|
-
import {jest} from "@jest/globals";
|
|
1
|
+
import { vi, describe, beforeEach, afterEach, test, expect } from "vitest";
|
|
3
2
|
import inquirer from "inquirer";
|
|
4
|
-
|
|
5
3
|
import simulatorService from "../../src/lib/services/simulator";
|
|
6
|
-
import {initAction} from "../../src/commands/general/init";
|
|
4
|
+
import { initAction } from "../../src/commands/general/init";
|
|
5
|
+
import { tmpdir } from "os";
|
|
6
|
+
import {mkdtempSync} from "fs";
|
|
7
|
+
import {join} from "path";
|
|
7
8
|
|
|
8
|
-
|
|
9
|
-
const defaultActionOptions = {numValidators: 5, branch: "main"};
|
|
9
|
+
const tempDir = mkdtempSync(join(tmpdir(), "test-initAction-"));
|
|
10
|
+
const defaultActionOptions = { numValidators: 5, branch: "main", location: tempDir };
|
|
10
11
|
|
|
11
12
|
describe("init action", () => {
|
|
12
|
-
let error:
|
|
13
|
-
let log:
|
|
14
|
-
let inquirerPrompt:
|
|
15
|
-
|
|
16
|
-
let
|
|
17
|
-
let
|
|
18
|
-
let
|
|
19
|
-
let
|
|
20
|
-
let
|
|
21
|
-
let simServgetAiProvidersOptions:
|
|
22
|
-
let simServConfigSimulator:
|
|
23
|
-
let simServRunSimulator:
|
|
24
|
-
let simServWaitForSimulator:
|
|
25
|
-
let simServPullOllamaModel:
|
|
26
|
-
let simServDeleteAllValidators:
|
|
27
|
-
let simServCreateRandomValidators:
|
|
28
|
-
let simServOpenFrontend:
|
|
29
|
-
let
|
|
13
|
+
let error: ReturnType<any>;
|
|
14
|
+
let log: ReturnType<any>;
|
|
15
|
+
let inquirerPrompt: ReturnType<any>;
|
|
16
|
+
|
|
17
|
+
let simServCheckInstallRequirements: ReturnType<any>;
|
|
18
|
+
let simServCheckVersionRequirements: ReturnType<any>;
|
|
19
|
+
let simServResetDockerContainers: ReturnType<any>;
|
|
20
|
+
let simServResetDockerImages: ReturnType<any>;
|
|
21
|
+
let simServDownloadSimulator: ReturnType<any>;
|
|
22
|
+
let simServgetAiProvidersOptions: ReturnType<any>;
|
|
23
|
+
let simServConfigSimulator: ReturnType<any>;
|
|
24
|
+
let simServRunSimulator: ReturnType<any>;
|
|
25
|
+
let simServWaitForSimulator: ReturnType<any>;
|
|
26
|
+
let simServPullOllamaModel: ReturnType<any>;
|
|
27
|
+
let simServDeleteAllValidators: ReturnType<any>;
|
|
28
|
+
let simServCreateRandomValidators: ReturnType<any>;
|
|
29
|
+
let simServOpenFrontend: ReturnType<any>;
|
|
30
|
+
let simGetSimulatorUrl: ReturnType<any>;
|
|
30
31
|
|
|
31
32
|
beforeEach(() => {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
error =
|
|
35
|
-
log =
|
|
36
|
-
inquirerPrompt =
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
simServConfigSimulator =
|
|
44
|
-
simServgetAiProvidersOptions =
|
|
45
|
-
simServRunSimulator =
|
|
46
|
-
simServWaitForSimulator =
|
|
47
|
-
simServPullOllamaModel =
|
|
48
|
-
simServDeleteAllValidators =
|
|
49
|
-
simServCreateRandomValidators =
|
|
50
|
-
simServOpenFrontend =
|
|
51
|
-
|
|
33
|
+
vi.clearAllMocks();
|
|
34
|
+
|
|
35
|
+
error = vi.spyOn(console, "error").mockImplementation(() => {});
|
|
36
|
+
log = vi.spyOn(console, "log").mockImplementation(() => {});
|
|
37
|
+
inquirerPrompt = vi.spyOn(inquirer, "prompt");
|
|
38
|
+
|
|
39
|
+
simServCheckInstallRequirements = vi.spyOn(simulatorService, "checkInstallRequirements");
|
|
40
|
+
simServCheckVersionRequirements = vi.spyOn(simulatorService, "checkVersionRequirements");
|
|
41
|
+
simServResetDockerContainers = vi.spyOn(simulatorService, "resetDockerContainers");
|
|
42
|
+
simServResetDockerImages = vi.spyOn(simulatorService, "resetDockerImages");
|
|
43
|
+
simServDownloadSimulator = vi.spyOn(simulatorService, "downloadSimulator");
|
|
44
|
+
simServConfigSimulator = vi.spyOn(simulatorService, "configSimulator");
|
|
45
|
+
simServgetAiProvidersOptions = vi.spyOn(simulatorService, "getAiProvidersOptions");
|
|
46
|
+
simServRunSimulator = vi.spyOn(simulatorService, "runSimulator");
|
|
47
|
+
simServWaitForSimulator = vi.spyOn(simulatorService, "waitForSimulatorToBeReady");
|
|
48
|
+
simServPullOllamaModel = vi.spyOn(simulatorService, "pullOllamaModel");
|
|
49
|
+
simServDeleteAllValidators = vi.spyOn(simulatorService, "deleteAllValidators");
|
|
50
|
+
simServCreateRandomValidators = vi.spyOn(simulatorService, "createRandomValidators");
|
|
51
|
+
simServOpenFrontend = vi.spyOn(simulatorService, "openFrontend");
|
|
52
|
+
simGetSimulatorUrl = vi.spyOn(simulatorService, "getFrontendUrl")
|
|
52
53
|
});
|
|
53
54
|
|
|
54
55
|
afterEach(() => {
|
|
55
|
-
|
|
56
|
+
vi.restoreAllMocks();
|
|
56
57
|
});
|
|
57
58
|
|
|
58
59
|
test("if both requirements are missing, then the execution fails", async () => {
|
|
59
|
-
|
|
60
|
-
simServCheckRequirements.mockResolvedValue({git: false, docker: false});
|
|
60
|
+
simServCheckInstallRequirements.mockResolvedValue({ git: false, docker: false });
|
|
61
61
|
|
|
62
|
-
// When
|
|
63
62
|
await initAction(defaultActionOptions, simulatorService);
|
|
64
63
|
|
|
65
|
-
// Then
|
|
66
|
-
expect(error).toHaveBeenCalledTimes(1);
|
|
67
64
|
expect(error).toHaveBeenCalledWith(
|
|
68
|
-
"Git and Docker are not installed. Please install them and try again.\n"
|
|
65
|
+
"Git and Docker are not installed. Please install them and try again.\n"
|
|
69
66
|
);
|
|
70
67
|
});
|
|
71
68
|
|
|
72
69
|
test("if only docker is missing, then the execution fails", async () => {
|
|
73
|
-
|
|
74
|
-
simServCheckRequirements.mockResolvedValue({git: true, docker: false});
|
|
70
|
+
simServCheckInstallRequirements.mockResolvedValue({ git: true, docker: false });
|
|
75
71
|
|
|
76
|
-
// When
|
|
77
72
|
await initAction(defaultActionOptions, simulatorService);
|
|
78
73
|
|
|
79
|
-
// Then
|
|
80
|
-
expect(error).toHaveBeenCalledTimes(1);
|
|
81
74
|
expect(error).toHaveBeenCalledWith("Docker is not installed. Please install Docker and try again.\n");
|
|
82
75
|
});
|
|
83
76
|
|
|
84
77
|
test("if only git is missing, then the execution fails", async () => {
|
|
85
|
-
|
|
86
|
-
simServCheckRequirements.mockResolvedValue({git: false, docker: true});
|
|
78
|
+
simServCheckInstallRequirements.mockResolvedValue({ git: false, docker: true });
|
|
87
79
|
|
|
88
|
-
// When
|
|
89
80
|
await initAction(defaultActionOptions, simulatorService);
|
|
90
81
|
|
|
91
|
-
// Then
|
|
92
|
-
expect(error).toHaveBeenCalledTimes(1);
|
|
93
82
|
expect(error).toHaveBeenCalledWith("Git is not installed. Please install Git and try again.\n");
|
|
94
83
|
});
|
|
95
84
|
|
|
96
|
-
test("if check requirements fail, then the execution aborts", async () => {
|
|
97
|
-
|
|
98
|
-
simServCheckRequirements.mockRejectedValue(new Error("Error"));
|
|
85
|
+
test("if check install requirements fail, then the execution aborts", async () => {
|
|
86
|
+
simServCheckInstallRequirements.mockRejectedValue(new Error("Error"));
|
|
99
87
|
|
|
100
|
-
// When
|
|
101
88
|
await initAction(defaultActionOptions, simulatorService);
|
|
102
89
|
|
|
103
|
-
// Then
|
|
104
|
-
expect(error).toHaveBeenCalledTimes(1);
|
|
105
90
|
expect(error).toHaveBeenCalledWith(new Error("Error"));
|
|
106
91
|
});
|
|
107
92
|
|
|
108
|
-
test("if
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
await initAction(defaultActionOptions, simulatorService);
|
|
115
|
-
|
|
116
|
-
// Then
|
|
117
|
-
expect(log).toHaveBeenCalledTimes(1);
|
|
118
|
-
expect(log).toHaveBeenNthCalledWith(1, "Aborted!");
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
test("if resetDockerContainers fail, then the execution aborts", async () => {
|
|
122
|
-
// Given
|
|
123
|
-
inquirerPrompt.mockResolvedValue({confirmReset: true});
|
|
124
|
-
simServResetDockerContainers.mockRejectedValue(new Error("Error"));
|
|
93
|
+
test("if both versions are too low, then the execution fails", async () => {
|
|
94
|
+
const mockVersionNumber = "99.9.9";
|
|
95
|
+
simServCheckVersionRequirements.mockResolvedValue({
|
|
96
|
+
node: mockVersionNumber,
|
|
97
|
+
docker: mockVersionNumber,
|
|
98
|
+
});
|
|
125
99
|
|
|
126
|
-
// When
|
|
127
100
|
await initAction(defaultActionOptions, simulatorService);
|
|
128
101
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
102
|
+
expect(error).toHaveBeenCalledWith(
|
|
103
|
+
`Docker version ${mockVersionNumber} or higher is required. Please update Docker and try again.\nNode version ${mockVersionNumber} or higher is required. Please update Node and try again.\n`
|
|
104
|
+
);
|
|
132
105
|
});
|
|
133
106
|
|
|
134
|
-
test("if
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
107
|
+
test("if only docker version is too low, then the execution fails", async () => {
|
|
108
|
+
const mockVersionNumber = "99.9.9";
|
|
109
|
+
simServCheckVersionRequirements.mockResolvedValue({
|
|
110
|
+
docker: mockVersionNumber,
|
|
111
|
+
});
|
|
138
112
|
|
|
139
|
-
// When
|
|
140
113
|
await initAction(defaultActionOptions, simulatorService);
|
|
141
114
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
115
|
+
expect(error).toHaveBeenCalledWith(
|
|
116
|
+
`Docker version ${mockVersionNumber} or higher is required. Please update Docker and try again.\n`
|
|
117
|
+
);
|
|
145
118
|
});
|
|
146
119
|
|
|
147
|
-
test("if
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
120
|
+
test("if only node version is too low, then the execution fails", async () => {
|
|
121
|
+
const mockVersionNumber = "99.9.9";
|
|
122
|
+
simServCheckVersionRequirements.mockResolvedValue({
|
|
123
|
+
node: mockVersionNumber
|
|
124
|
+
});
|
|
151
125
|
|
|
152
|
-
// When
|
|
153
126
|
await initAction(defaultActionOptions, simulatorService);
|
|
154
127
|
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
128
|
+
expect(error).toHaveBeenCalledWith(
|
|
129
|
+
`Node version ${mockVersionNumber} or higher is required. Please update Node and try again.\n`
|
|
130
|
+
);
|
|
158
131
|
});
|
|
159
132
|
|
|
160
|
-
test("if not
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
simServDownloadSimulator.mockResolvedValue({wasInstalled: false});
|
|
164
|
-
simServConfigSimulator.mockRejectedValue(new Error("Error")); // This will stop the execution
|
|
133
|
+
test("if reset is not confirmed, abort", async () => {
|
|
134
|
+
inquirerPrompt.mockResolvedValue({ confirmReset: false });
|
|
135
|
+
simServCheckInstallRequirements.mockResolvedValue({ git: true, docker: true });
|
|
165
136
|
|
|
166
|
-
// When
|
|
167
137
|
await initAction(defaultActionOptions, simulatorService);
|
|
168
138
|
|
|
169
|
-
|
|
170
|
-
expect(simulatorService.downloadSimulator).toHaveBeenCalled();
|
|
171
|
-
expect(simulatorService.updateSimulator).not.toHaveBeenCalled();
|
|
139
|
+
expect(log).toHaveBeenCalledWith("Aborted!");
|
|
172
140
|
});
|
|
173
141
|
|
|
174
|
-
test("if
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
simServDownloadSimulator.mockResolvedValue({wasInstalled: true});
|
|
178
|
-
simServUpdateSimulator.mockResolvedValue(true);
|
|
179
|
-
simServConfigSimulator.mockRejectedValue(new Error("Error")); // This will stop the execution
|
|
142
|
+
test("if resetDockerContainers fail, then the execution aborts", async () => {
|
|
143
|
+
inquirerPrompt.mockResolvedValue({ confirmReset: true });
|
|
144
|
+
simServResetDockerContainers.mockRejectedValue(new Error("Error"));
|
|
180
145
|
|
|
181
|
-
// When
|
|
182
146
|
await initAction(defaultActionOptions, simulatorService);
|
|
183
147
|
|
|
184
|
-
|
|
185
|
-
expect(simulatorService.downloadSimulator).toHaveBeenCalled();
|
|
186
|
-
expect(simulatorService.updateSimulator).toHaveBeenCalled();
|
|
148
|
+
expect(error).toHaveBeenCalledWith(new Error("Error"));
|
|
187
149
|
});
|
|
188
150
|
|
|
189
|
-
test("should
|
|
190
|
-
// Given
|
|
151
|
+
test("should open the frontend if everything went well", async () => {
|
|
191
152
|
inquirerPrompt.mockResolvedValue({
|
|
192
153
|
confirmReset: true,
|
|
193
154
|
confirmDownload: true,
|
|
@@ -196,313 +157,269 @@ describe("init action", () => {
|
|
|
196
157
|
heuristai: "API_KEY2",
|
|
197
158
|
});
|
|
198
159
|
simServgetAiProvidersOptions.mockReturnValue([
|
|
199
|
-
{name: "OpenAI", value: "openai"},
|
|
200
|
-
{name: "Heurist", value: "heuristai"},
|
|
160
|
+
{ name: "OpenAI", value: "openai" },
|
|
161
|
+
{ name: "Heurist", value: "heuristai" },
|
|
201
162
|
]);
|
|
202
163
|
simServConfigSimulator.mockResolvedValue(true);
|
|
203
|
-
simServRunSimulator.
|
|
164
|
+
simServRunSimulator.mockResolvedValue(true);
|
|
165
|
+
simServWaitForSimulator.mockResolvedValue({ initialized: true });
|
|
166
|
+
simServPullOllamaModel.mockResolvedValue(true);
|
|
167
|
+
simServDeleteAllValidators.mockResolvedValue(true);
|
|
168
|
+
simServCreateRandomValidators.mockResolvedValue(true);
|
|
169
|
+
simServOpenFrontend.mockResolvedValue(true);
|
|
170
|
+
simGetSimulatorUrl.mockResolvedValue('http://localhost:8080/');
|
|
204
171
|
|
|
205
|
-
// When
|
|
206
172
|
await initAction(defaultActionOptions, simulatorService);
|
|
207
173
|
|
|
208
|
-
|
|
209
|
-
expect(
|
|
210
|
-
{
|
|
211
|
-
|
|
212
|
-
name: "selectedLlmProviders",
|
|
213
|
-
message: "Select which LLM providers do you want to use:",
|
|
214
|
-
choices: [
|
|
215
|
-
{name: "OpenAI", value: "openai"},
|
|
216
|
-
{name: "Heurist", value: "heuristai"},
|
|
217
|
-
],
|
|
218
|
-
validate: expect.any(Function),
|
|
219
|
-
},
|
|
220
|
-
]);
|
|
221
|
-
expect(simulatorService.configSimulator).toHaveBeenCalledWith({
|
|
222
|
-
OPENAIKEY: "API_KEY1",
|
|
223
|
-
HEURISTAIAPIKEY: "API_KEY2",
|
|
224
|
-
});
|
|
174
|
+
const frontendUrl = simulatorService.getFrontendUrl();
|
|
175
|
+
expect(log).toHaveBeenCalledWith(
|
|
176
|
+
`GenLayer simulator initialized successfully! Go to ${frontendUrl} in your browser to access it.`
|
|
177
|
+
);
|
|
225
178
|
});
|
|
226
179
|
|
|
227
180
|
test("if configSimulator fails, then the execution aborts", async () => {
|
|
228
|
-
|
|
229
|
-
inquirerPrompt.mockResolvedValue({confirmReset: true, confirmDownload: true, selectedLlmProviders: []});
|
|
181
|
+
inquirerPrompt.mockResolvedValue({ confirmReset: true, confirmDownload: true, selectedLlmProviders: [] });
|
|
230
182
|
simServConfigSimulator.mockRejectedValue(new Error("Error"));
|
|
231
183
|
|
|
232
|
-
// When
|
|
233
184
|
await initAction(defaultActionOptions, simulatorService);
|
|
234
185
|
|
|
235
|
-
// Then
|
|
236
|
-
expect(error).toHaveBeenCalledTimes(1);
|
|
237
186
|
expect(error).toHaveBeenCalledWith(new Error("Error"));
|
|
238
187
|
});
|
|
239
188
|
|
|
240
189
|
test("if runSimulator fails, then the execution aborts", async () => {
|
|
241
|
-
|
|
242
|
-
inquirerPrompt.mockResolvedValue({confirmReset: true, confirmDownload: true, selectedLlmProviders: []});
|
|
190
|
+
inquirerPrompt.mockResolvedValue({ confirmReset: true, confirmDownload: true, selectedLlmProviders: [] });
|
|
243
191
|
simServRunSimulator.mockRejectedValue(new Error("Error"));
|
|
244
192
|
|
|
245
|
-
// When
|
|
246
193
|
await initAction(defaultActionOptions, simulatorService);
|
|
247
194
|
|
|
248
|
-
// Then
|
|
249
|
-
expect(error).toHaveBeenCalledTimes(1);
|
|
250
195
|
expect(error).toHaveBeenCalledWith(new Error("Error"));
|
|
251
196
|
});
|
|
252
197
|
|
|
253
|
-
test("should
|
|
254
|
-
// Given
|
|
198
|
+
test("should pull Ollama model if 'ollama' is in providers", async () => {
|
|
255
199
|
inquirerPrompt.mockResolvedValue({
|
|
256
200
|
confirmReset: true,
|
|
257
201
|
confirmDownload: true,
|
|
258
|
-
selectedLlmProviders: ["openai", "heuristai"],
|
|
202
|
+
selectedLlmProviders: ["openai", "heuristai", "ollama"],
|
|
259
203
|
openai: "API_KEY1",
|
|
260
204
|
heuristai: "API_KEY2",
|
|
205
|
+
ollama: "API_KEY3",
|
|
261
206
|
});
|
|
262
207
|
simServgetAiProvidersOptions.mockReturnValue([
|
|
263
|
-
{name: "OpenAI", value: "openai"},
|
|
264
|
-
{name: "Heurist", value: "heuristai"},
|
|
208
|
+
{ name: "OpenAI", value: "openai" },
|
|
209
|
+
{ name: "Heurist", value: "heuristai" },
|
|
210
|
+
{ name: "Ollama", value: "ollama" },
|
|
265
211
|
]);
|
|
266
212
|
simServConfigSimulator.mockResolvedValue(true);
|
|
267
213
|
simServRunSimulator.mockResolvedValue(true);
|
|
268
|
-
simServWaitForSimulator.
|
|
214
|
+
simServWaitForSimulator.mockResolvedValue({ initialized: true });
|
|
215
|
+
simServPullOllamaModel.mockResolvedValue(true);
|
|
216
|
+
simServDeleteAllValidators.mockResolvedValue(true);
|
|
269
217
|
|
|
270
|
-
// When
|
|
271
218
|
await initAction(defaultActionOptions, simulatorService);
|
|
272
219
|
|
|
273
|
-
|
|
274
|
-
expect(simulatorService.runSimulator).toHaveBeenCalled();
|
|
220
|
+
expect(simServPullOllamaModel).toHaveBeenCalled();
|
|
275
221
|
});
|
|
276
222
|
|
|
277
|
-
test("
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
confirmDownload: true,
|
|
282
|
-
selectedLlmProviders: ["openai", "heuristai"],
|
|
283
|
-
openai: "API_KEY1",
|
|
284
|
-
heuristai: "API_KEY2",
|
|
285
|
-
});
|
|
286
|
-
simServgetAiProvidersOptions.mockReturnValue([
|
|
287
|
-
{name: "OpenAI", value: "openai"},
|
|
288
|
-
{name: "Heurist", value: "heuristai"},
|
|
289
|
-
]);
|
|
290
|
-
simServConfigSimulator.mockResolvedValue(true);
|
|
291
|
-
simServRunSimulator.mockResolvedValue(true);
|
|
292
|
-
simServWaitForSimulator.mockResolvedValue({
|
|
293
|
-
initialized: false,
|
|
294
|
-
errorCode: "ERROR",
|
|
295
|
-
errorMessage: "errorMessage",
|
|
296
|
-
});
|
|
223
|
+
test("logs error if checkVersionRequirements throws", async () => {
|
|
224
|
+
simServCheckInstallRequirements.mockResolvedValue({ git: true, docker: true });
|
|
225
|
+
const errorMsg = new Error("checkVersionRequirements error");
|
|
226
|
+
simServCheckVersionRequirements.mockRejectedValueOnce(errorMsg);
|
|
297
227
|
|
|
298
|
-
// When
|
|
299
228
|
await initAction(defaultActionOptions, simulatorService);
|
|
300
229
|
|
|
301
|
-
|
|
302
|
-
expect(log).toHaveBeenCalledWith("errorMessage");
|
|
303
|
-
expect(error).toHaveBeenCalledWith("Unable to initialize the GenLayer simulator. Please try again.");
|
|
230
|
+
expect(error).toHaveBeenCalledWith(errorMsg);
|
|
304
231
|
});
|
|
305
232
|
|
|
306
|
-
test("
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
});
|
|
315
|
-
simServgetAiProvidersOptions.mockReturnValue([
|
|
316
|
-
{name: "OpenAI", value: "openai"},
|
|
317
|
-
{name: "Heurist", value: "heuristai"},
|
|
318
|
-
]);
|
|
319
|
-
simServConfigSimulator.mockResolvedValue(true);
|
|
320
|
-
simServRunSimulator.mockResolvedValue(true);
|
|
321
|
-
simServWaitForSimulator.mockResolvedValue({
|
|
322
|
-
initialized: false,
|
|
323
|
-
errorCode: "TIMEOUT",
|
|
324
|
-
errorMessage: "errorMessage",
|
|
325
|
-
});
|
|
233
|
+
test("logs 'Aborted!' if confirmDownload is false", async () => {
|
|
234
|
+
inquirerPrompt
|
|
235
|
+
.mockResolvedValueOnce({ confirmReset: true })
|
|
236
|
+
.mockResolvedValueOnce({ confirmDownload: false });
|
|
237
|
+
|
|
238
|
+
simServCheckInstallRequirements.mockResolvedValue({ git: true, docker: true });
|
|
239
|
+
simServResetDockerContainers.mockResolvedValue(true);
|
|
240
|
+
simServResetDockerImages.mockResolvedValue(true);
|
|
326
241
|
|
|
327
|
-
// When
|
|
328
242
|
await initAction(defaultActionOptions, simulatorService);
|
|
329
243
|
|
|
330
|
-
|
|
331
|
-
expect(error).toHaveBeenCalledWith(
|
|
332
|
-
"The simulator is taking too long to initialize. Please try again after the simulator is ready.",
|
|
333
|
-
);
|
|
244
|
+
expect(log).toHaveBeenCalledWith("Aborted!");
|
|
334
245
|
});
|
|
335
246
|
|
|
336
|
-
test("
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
247
|
+
test("logs error if resetDockerContainers throws", async () => {
|
|
248
|
+
inquirerPrompt.mockResolvedValue({ confirmReset: true });
|
|
249
|
+
simServCheckInstallRequirements.mockResolvedValue({ git: true, docker: true });
|
|
250
|
+
const errorMsg = new Error("resetDockerContainers error");
|
|
251
|
+
simServResetDockerContainers.mockRejectedValueOnce(errorMsg);
|
|
252
|
+
|
|
253
|
+
await initAction(defaultActionOptions, simulatorService);
|
|
254
|
+
|
|
255
|
+
expect(error).toHaveBeenCalledWith(errorMsg);
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
test("prompts for LLM providers and validates that at least one is selected", async () => {
|
|
259
|
+
inquirerPrompt
|
|
260
|
+
.mockResolvedValueOnce({ confirmReset: true })
|
|
261
|
+
.mockResolvedValueOnce({ confirmDownload: true })
|
|
262
|
+
.mockImplementation((questions: any) => {
|
|
263
|
+
if (questions[0].type === "checkbox") {
|
|
264
|
+
const validateFunction = questions[0].validate;
|
|
265
|
+
expect(validateFunction([])).toBe("You must choose at least one option.");
|
|
266
|
+
expect(validateFunction(["openai"])).toBe(true);
|
|
267
|
+
return Promise.resolve({ selectedLlmProviders: ["openai"] });
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
if (questions[0].type === "input") {
|
|
271
|
+
const validateFunction = questions[0].validate;
|
|
272
|
+
expect(validateFunction("")).toBe("Please enter a valid API Key for OpenAI.");
|
|
273
|
+
expect(validateFunction("API_KEY1")).toBe(true);
|
|
274
|
+
return Promise.resolve({ openai: "API_KEY1" });
|
|
275
|
+
}
|
|
276
|
+
});
|
|
277
|
+
|
|
278
|
+
simServCheckInstallRequirements.mockResolvedValue({ git: true, docker: true });
|
|
279
|
+
simServResetDockerContainers.mockResolvedValue(true);
|
|
280
|
+
simServResetDockerImages.mockResolvedValue(true);
|
|
281
|
+
simServDownloadSimulator.mockResolvedValue({ wasInstalled: false });
|
|
349
282
|
simServConfigSimulator.mockResolvedValue(true);
|
|
350
283
|
simServRunSimulator.mockResolvedValue(true);
|
|
351
|
-
simServWaitForSimulator.
|
|
284
|
+
simServWaitForSimulator.mockResolvedValue({ initialized: true });
|
|
285
|
+
simServDeleteAllValidators.mockResolvedValue(true);
|
|
286
|
+
simServCreateRandomValidators.mockResolvedValue(true);
|
|
287
|
+
simServOpenFrontend.mockResolvedValue(true);
|
|
352
288
|
|
|
353
|
-
// When
|
|
354
289
|
await initAction(defaultActionOptions, simulatorService);
|
|
290
|
+
});
|
|
355
291
|
|
|
356
|
-
|
|
357
|
-
|
|
292
|
+
test("logs error if downloadSimulator throws", async () => {
|
|
293
|
+
inquirerPrompt.mockResolvedValue({ confirmReset: true, confirmDownload: true });
|
|
294
|
+
simServCheckInstallRequirements.mockResolvedValue({ git: true, docker: true });
|
|
295
|
+
simServResetDockerContainers.mockResolvedValue(true);
|
|
296
|
+
simServResetDockerImages.mockResolvedValue(true);
|
|
297
|
+
const errorMsg = new Error("downloadSimulator error");
|
|
298
|
+
simServDownloadSimulator.mockRejectedValueOnce(errorMsg);
|
|
299
|
+
|
|
300
|
+
await initAction(defaultActionOptions, simulatorService);
|
|
301
|
+
|
|
302
|
+
expect(error).toHaveBeenCalledWith(errorMsg);
|
|
358
303
|
});
|
|
359
304
|
|
|
360
|
-
test("
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
{name: "OpenAI", value: "openai"},
|
|
372
|
-
{name: "Heurist", value: "heuristai"},
|
|
373
|
-
{name: "Ollama", value: "ollama"},
|
|
374
|
-
]);
|
|
305
|
+
test("logs error message if simulator fails to initialize with ERROR code", async () => {
|
|
306
|
+
inquirerPrompt
|
|
307
|
+
.mockResolvedValueOnce({ confirmReset: true })
|
|
308
|
+
.mockResolvedValueOnce({ confirmDownload: true })
|
|
309
|
+
.mockResolvedValueOnce({ selectedLlmProviders: ["openai"] })
|
|
310
|
+
.mockResolvedValueOnce({ openai: "API_KEY1" });
|
|
311
|
+
|
|
312
|
+
simServCheckInstallRequirements.mockResolvedValue({ git: true, docker: true });
|
|
313
|
+
simServResetDockerContainers.mockResolvedValue(true);
|
|
314
|
+
simServResetDockerImages.mockResolvedValue(true);
|
|
315
|
+
simServDownloadSimulator.mockResolvedValue({ wasInstalled: false });
|
|
375
316
|
simServConfigSimulator.mockResolvedValue(true);
|
|
376
317
|
simServRunSimulator.mockResolvedValue(true);
|
|
318
|
+
|
|
377
319
|
simServWaitForSimulator.mockResolvedValue({
|
|
378
|
-
initialized:
|
|
320
|
+
initialized: false,
|
|
321
|
+
errorCode: "ERROR",
|
|
322
|
+
errorMessage: "Simulator failed to initialize due to configuration error.",
|
|
379
323
|
});
|
|
380
|
-
simServPullOllamaModel.mockResolvedValue(true);
|
|
381
|
-
simServDeleteAllValidators.mockRejectedValue(new Error("Error")); // This will stop the execution
|
|
382
324
|
|
|
383
|
-
// When
|
|
384
325
|
await initAction(defaultActionOptions, simulatorService);
|
|
385
326
|
|
|
386
|
-
|
|
387
|
-
expect(
|
|
327
|
+
expect(log).toHaveBeenCalledWith("Simulator failed to initialize due to configuration error.");
|
|
328
|
+
expect(error).toHaveBeenCalledWith("Unable to initialize the GenLayer simulator. Please try again.");
|
|
388
329
|
});
|
|
389
330
|
|
|
390
|
-
test("
|
|
391
|
-
// Given
|
|
331
|
+
test("logs error if runSimulator throws", async () => {
|
|
392
332
|
inquirerPrompt.mockResolvedValue({
|
|
393
333
|
confirmReset: true,
|
|
394
334
|
confirmDownload: true,
|
|
395
|
-
selectedLlmProviders: ["openai"
|
|
335
|
+
selectedLlmProviders: ["openai"],
|
|
396
336
|
openai: "API_KEY1",
|
|
397
|
-
heuristai: "API_KEY2",
|
|
398
337
|
});
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
338
|
+
simServCheckInstallRequirements.mockResolvedValue({ git: true, docker: true });
|
|
339
|
+
simServResetDockerContainers.mockResolvedValue(true);
|
|
340
|
+
simServResetDockerImages.mockResolvedValue(true);
|
|
341
|
+
simServDownloadSimulator.mockResolvedValue({ wasInstalled: false });
|
|
403
342
|
simServConfigSimulator.mockResolvedValue(true);
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
initialized: true,
|
|
407
|
-
});
|
|
408
|
-
simServPullOllamaModel.mockResolvedValue(true);
|
|
409
|
-
simServDeleteAllValidators.mockRejectedValue(new Error("Error")); // This will stop the execution
|
|
343
|
+
const errorMsg = new Error("runSimulator error");
|
|
344
|
+
simServRunSimulator.mockRejectedValueOnce(errorMsg);
|
|
410
345
|
|
|
411
|
-
// When
|
|
412
346
|
await initAction(defaultActionOptions, simulatorService);
|
|
413
347
|
|
|
414
|
-
|
|
415
|
-
expect(simServPullOllamaModel).not.toHaveBeenCalled();
|
|
348
|
+
expect(error).toHaveBeenCalledWith(errorMsg);
|
|
416
349
|
});
|
|
417
350
|
|
|
418
|
-
test("
|
|
419
|
-
// Given
|
|
351
|
+
test("logs specific message if waitForSimulatorToBeReady returns TIMEOUT errorCode", async () => {
|
|
420
352
|
inquirerPrompt.mockResolvedValue({
|
|
421
353
|
confirmReset: true,
|
|
422
354
|
confirmDownload: true,
|
|
423
|
-
selectedLlmProviders: ["openai"
|
|
355
|
+
selectedLlmProviders: ["openai"],
|
|
424
356
|
openai: "API_KEY1",
|
|
425
|
-
heuristai: "API_KEY2",
|
|
426
357
|
});
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
358
|
+
simServCheckInstallRequirements.mockResolvedValue({ git: true, docker: true });
|
|
359
|
+
simServResetDockerContainers.mockResolvedValue(true);
|
|
360
|
+
simServResetDockerImages.mockResolvedValue(true);
|
|
361
|
+
simServDownloadSimulator.mockResolvedValue({ wasInstalled: false });
|
|
431
362
|
simServConfigSimulator.mockResolvedValue(true);
|
|
432
363
|
simServRunSimulator.mockResolvedValue(true);
|
|
433
364
|
simServWaitForSimulator.mockResolvedValue({
|
|
434
|
-
initialized:
|
|
365
|
+
initialized: false,
|
|
366
|
+
errorCode: "TIMEOUT",
|
|
367
|
+
errorMessage: "errorMessage",
|
|
435
368
|
});
|
|
436
|
-
simServPullOllamaModel.mockResolvedValue(true);
|
|
437
|
-
simServDeleteAllValidators.mockRejectedValue(new Error("Error"));
|
|
438
369
|
|
|
439
|
-
// When
|
|
440
370
|
await initAction(defaultActionOptions, simulatorService);
|
|
441
371
|
|
|
442
|
-
|
|
443
|
-
|
|
372
|
+
expect(error).toHaveBeenCalledWith(
|
|
373
|
+
"The simulator is taking too long to initialize. Please try again after the simulator is ready."
|
|
374
|
+
);
|
|
444
375
|
});
|
|
445
376
|
|
|
446
|
-
test("
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
{name: "Heurist", value: "heuristai"},
|
|
458
|
-
]);
|
|
377
|
+
test("catches and logs error if waitForSimulatorToBeReady throws an exception", async () => {
|
|
378
|
+
inquirerPrompt
|
|
379
|
+
.mockResolvedValueOnce({ confirmReset: true })
|
|
380
|
+
.mockResolvedValueOnce({ confirmDownload: true })
|
|
381
|
+
.mockResolvedValueOnce({ selectedLlmProviders: ["openai"] })
|
|
382
|
+
.mockResolvedValueOnce({ openai: "API_KEY1" });
|
|
383
|
+
|
|
384
|
+
simServCheckInstallRequirements.mockResolvedValue({ git: true, docker: true });
|
|
385
|
+
simServResetDockerContainers.mockResolvedValue(true);
|
|
386
|
+
simServResetDockerImages.mockResolvedValue(true);
|
|
387
|
+
simServDownloadSimulator.mockResolvedValue({ wasInstalled: false });
|
|
459
388
|
simServConfigSimulator.mockResolvedValue(true);
|
|
460
389
|
simServRunSimulator.mockResolvedValue(true);
|
|
461
|
-
simServWaitForSimulator.mockResolvedValue({
|
|
462
|
-
initialized: true,
|
|
463
|
-
});
|
|
464
|
-
simServPullOllamaModel.mockResolvedValue(true);
|
|
465
|
-
simServDeleteAllValidators.mockResolvedValue(true);
|
|
466
|
-
simServCreateRandomValidators.mockRejectedValue(new Error("Error"));
|
|
467
390
|
|
|
468
|
-
|
|
391
|
+
const errorMsg = new Error("Unexpected simulator error");
|
|
392
|
+
simServWaitForSimulator.mockRejectedValueOnce(errorMsg);
|
|
393
|
+
|
|
469
394
|
await initAction(defaultActionOptions, simulatorService);
|
|
470
395
|
|
|
471
|
-
|
|
472
|
-
expect(error).toHaveBeenCalledWith("Unable to initialize the validators.");
|
|
396
|
+
expect(error).toHaveBeenCalledWith(errorMsg);
|
|
473
397
|
});
|
|
474
398
|
|
|
475
|
-
test("
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
{name: "Heurist", value: "heuristai"},
|
|
487
|
-
]);
|
|
399
|
+
test("catches and logs error if openFrontend throws an exception", async () => {
|
|
400
|
+
inquirerPrompt
|
|
401
|
+
.mockResolvedValueOnce({ confirmReset: true })
|
|
402
|
+
.mockResolvedValueOnce({ confirmDownload: true })
|
|
403
|
+
.mockResolvedValueOnce({ selectedLlmProviders: ["openai"] })
|
|
404
|
+
.mockResolvedValueOnce({ openai: "API_KEY1" });
|
|
405
|
+
|
|
406
|
+
simServCheckInstallRequirements.mockResolvedValue({ git: true, docker: true });
|
|
407
|
+
simServResetDockerContainers.mockResolvedValue(true);
|
|
408
|
+
simServResetDockerImages.mockResolvedValue(true);
|
|
409
|
+
simServDownloadSimulator.mockResolvedValue({ wasInstalled: false });
|
|
488
410
|
simServConfigSimulator.mockResolvedValue(true);
|
|
489
411
|
simServRunSimulator.mockResolvedValue(true);
|
|
490
|
-
simServWaitForSimulator.mockResolvedValue({
|
|
491
|
-
initialized: true,
|
|
492
|
-
});
|
|
493
|
-
simServPullOllamaModel.mockResolvedValue(true);
|
|
412
|
+
simServWaitForSimulator.mockResolvedValue({ initialized: true });
|
|
494
413
|
simServDeleteAllValidators.mockResolvedValue(true);
|
|
495
414
|
simServCreateRandomValidators.mockResolvedValue(true);
|
|
496
|
-
simServOpenFrontend.mockResolvedValue(true);
|
|
497
|
-
simServRedEnvConfigVariable.mockReturnValue("8080");
|
|
498
415
|
|
|
499
|
-
|
|
416
|
+
const errorMsg = new Error("Failed to open frontend");
|
|
417
|
+
simServOpenFrontend.mockImplementationOnce(() => {
|
|
418
|
+
throw errorMsg;
|
|
419
|
+
});
|
|
420
|
+
|
|
500
421
|
await initAction(defaultActionOptions, simulatorService);
|
|
501
422
|
|
|
502
|
-
|
|
503
|
-
const frontendUrl = simulatorService.getFrontendUrl();
|
|
504
|
-
expect(log).toHaveBeenCalledWith(
|
|
505
|
-
`GenLayer simulator initialized successfully! Go to ${frontendUrl} in your browser to access it.`,
|
|
506
|
-
);
|
|
423
|
+
expect(error).toHaveBeenCalledWith(errorMsg);
|
|
507
424
|
});
|
|
508
425
|
});
|