@jango-blockchained/hoox-cli 0.5.1 → 0.5.6

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 (106) hide show
  1. package/bin/hoox.js +3 -4
  2. package/dist/index.js +32545 -0
  3. package/package.json +10 -15
  4. package/src/commands/check/check-command.test.ts +0 -476
  5. package/src/commands/check/check-command.ts +0 -1144
  6. package/src/commands/check/index.ts +0 -10
  7. package/src/commands/check/prerequisites-command.test.ts +0 -19
  8. package/src/commands/check/prerequisites-command.ts +0 -96
  9. package/src/commands/check/types.ts +0 -103
  10. package/src/commands/clone/clone-command.test.ts +0 -442
  11. package/src/commands/clone/clone-command.ts +0 -431
  12. package/src/commands/clone/index.ts +0 -1
  13. package/src/commands/config/config-command.test.ts +0 -583
  14. package/src/commands/config/config-command.ts +0 -897
  15. package/src/commands/config/env-command.test.ts +0 -43
  16. package/src/commands/config/env-command.ts +0 -295
  17. package/src/commands/config/index.ts +0 -3
  18. package/src/commands/config/kv-command.test.ts +0 -14
  19. package/src/commands/config/kv-command.ts +0 -290
  20. package/src/commands/dashboard/dashboard-command.test.ts +0 -47
  21. package/src/commands/dashboard/dashboard-command.ts +0 -128
  22. package/src/commands/dashboard/index.ts +0 -1
  23. package/src/commands/db/db-command.test.ts +0 -21
  24. package/src/commands/db/db-command.ts +0 -312
  25. package/src/commands/db/index.ts +0 -1
  26. package/src/commands/deploy/deploy-command.test.ts +0 -304
  27. package/src/commands/deploy/deploy-command.ts +0 -1135
  28. package/src/commands/deploy/index.ts +0 -2
  29. package/src/commands/deploy/telegram-service.ts +0 -76
  30. package/src/commands/deploy/types.ts +0 -34
  31. package/src/commands/dev/dev-command.test.ts +0 -383
  32. package/src/commands/dev/dev-command.ts +0 -398
  33. package/src/commands/dev/index.ts +0 -1
  34. package/src/commands/infra/index.ts +0 -5
  35. package/src/commands/infra/infra-command.test.ts +0 -719
  36. package/src/commands/infra/infra-command.ts +0 -974
  37. package/src/commands/infra/types.ts +0 -23
  38. package/src/commands/init/__tests__/cli-provisioner.test.ts +0 -17
  39. package/src/commands/init/cli-provisioner.ts +0 -71
  40. package/src/commands/init/index.ts +0 -1
  41. package/src/commands/init/init-command.test.ts +0 -876
  42. package/src/commands/init/init-command.ts +0 -593
  43. package/src/commands/init/types.ts +0 -23
  44. package/src/commands/logs/index.ts +0 -1
  45. package/src/commands/logs/logs-command.test.ts +0 -294
  46. package/src/commands/logs/logs-command.ts +0 -452
  47. package/src/commands/monitor/index.ts +0 -2
  48. package/src/commands/monitor/monitor-command.test.ts +0 -263
  49. package/src/commands/monitor/monitor-command.ts +0 -269
  50. package/src/commands/monitor/monitor-service.ts +0 -65
  51. package/src/commands/monitor/types.ts +0 -13
  52. package/src/commands/repair/index.ts +0 -2
  53. package/src/commands/repair/repair-command.test.ts +0 -224
  54. package/src/commands/repair/repair-command.ts +0 -220
  55. package/src/commands/repair/repair-service.ts +0 -138
  56. package/src/commands/repair/types.ts +0 -13
  57. package/src/commands/test/index.ts +0 -2
  58. package/src/commands/test/test-command.test.ts +0 -319
  59. package/src/commands/test/test-command.ts +0 -406
  60. package/src/commands/tui/index.ts +0 -1
  61. package/src/commands/tui/tui-command.ts +0 -87
  62. package/src/commands/update/index.ts +0 -1
  63. package/src/commands/update/update-command.ts +0 -168
  64. package/src/commands/waf/index.ts +0 -2
  65. package/src/commands/waf/types.ts +0 -48
  66. package/src/commands/waf/waf-command.test.ts +0 -506
  67. package/src/commands/waf/waf-command.ts +0 -548
  68. package/src/index.ts +0 -269
  69. package/src/services/cloudflare/cloudflare-service.test.ts +0 -658
  70. package/src/services/cloudflare/cloudflare-service.ts +0 -433
  71. package/src/services/cloudflare/index.ts +0 -2
  72. package/src/services/cloudflare/types.ts +0 -30
  73. package/src/services/config/config-service.test.ts +0 -395
  74. package/src/services/config/config-service.ts +0 -207
  75. package/src/services/config/index.ts +0 -9
  76. package/src/services/config/types.ts +0 -66
  77. package/src/services/db/db-service.test.ts +0 -51
  78. package/src/services/db/db-service.ts +0 -131
  79. package/src/services/db/index.ts +0 -1
  80. package/src/services/docker/docker-service.ts +0 -155
  81. package/src/services/docker/index.ts +0 -1
  82. package/src/services/env/env-service.test.ts +0 -236
  83. package/src/services/env/env-service.ts +0 -386
  84. package/src/services/env/index.ts +0 -1
  85. package/src/services/kv/index.ts +0 -1
  86. package/src/services/kv/kv-sync-service.test.ts +0 -38
  87. package/src/services/kv/kv-sync-service.ts +0 -234
  88. package/src/services/prerequisites/index.ts +0 -1
  89. package/src/services/prerequisites/prerequisites-service.test.ts +0 -89
  90. package/src/services/prerequisites/prerequisites-service.ts +0 -377
  91. package/src/services/prerequisites/types.ts +0 -48
  92. package/src/services/secrets/index.ts +0 -11
  93. package/src/services/secrets/secrets-service.test.ts +0 -495
  94. package/src/services/secrets/secrets-service.ts +0 -287
  95. package/src/services/secrets/types.ts +0 -50
  96. package/src/services/update/index.ts +0 -2
  97. package/src/services/update/update-service.test.ts +0 -76
  98. package/src/services/update/update-service.ts +0 -193
  99. package/src/ui/banner.ts +0 -141
  100. package/src/ui/index.ts +0 -8
  101. package/src/ui/menu.ts +0 -490
  102. package/src/utils/errors.test.ts +0 -69
  103. package/src/utils/errors.ts +0 -23
  104. package/src/utils/formatters.test.ts +0 -180
  105. package/src/utils/formatters.ts +0 -269
  106. package/src/utils/theme.ts +0 -94
@@ -1,304 +0,0 @@
1
- // @ts-nocheck
2
- /**
3
- * Unit tests for the deploy command.
4
- *
5
- * Stubs ConfigService and CloudflareService prototypes to verify the deploy
6
- * command logic in isolation. Uses Commander's exitOverride to suppress
7
- * process exits during test runs.
8
- *
9
- * Subcommand actions are async — we use parseAsync() and then inspect mocks
10
- * to confirm correct service calls.
11
- */
12
- import { afterEach, beforeEach, describe, expect, it, mock } from "bun:test";
13
- import { Command } from "commander";
14
- import { ConfigService } from "../../services/config/config-service.js";
15
- import { CloudflareService } from "../../services/cloudflare/cloudflare-service.js";
16
-
17
- // We import at the top level — the deploy command module also imports
18
- // @clack/prompts, which outputs to stdout during tests (fine).
19
-
20
- // ---------------------------------------------------------------------------
21
- // Stub variables — reassigned in beforeEach
22
- // ---------------------------------------------------------------------------
23
-
24
- let deployMock: ReturnType<typeof mock>;
25
- let loadMock: ReturnType<typeof mock>;
26
- let listEnabledWorkersMock: ReturnType<typeof mock>;
27
- let getWorkerMock: ReturnType<typeof mock>;
28
-
29
- // Preserve originals so we can restore them after tests
30
- const origLoad = ConfigService.prototype
31
- .load as typeof ConfigService.prototype.load;
32
- const origListEnabled = ConfigService.prototype
33
- .listEnabledWorkers as typeof ConfigService.prototype.listEnabledWorkers;
34
- const origGetWorker = ConfigService.prototype
35
- .getWorker as typeof ConfigService.prototype.getWorker;
36
- const origDeploy = CloudflareService.prototype
37
- .deploy as typeof CloudflareService.prototype.deploy;
38
-
39
- beforeEach(() => {
40
- mock.restore();
41
-
42
- // Reset process.exitCode between tests
43
- process.exitCode = undefined;
44
-
45
- // Reset prototypes to originals (in case a previous test didn't restore)
46
- (ConfigService.prototype as Record<string, unknown>).load = origLoad;
47
- (ConfigService.prototype as Record<string, unknown>).listEnabledWorkers =
48
- origListEnabled;
49
- (ConfigService.prototype as Record<string, unknown>).getWorker =
50
- origGetWorker;
51
- (CloudflareService.prototype as Record<string, unknown>).deploy = origDeploy;
52
-
53
- // Fresh mocks
54
- deployMock = mock(async (_path: string, _env?: string) => ({
55
- ok: true as const,
56
- data: { url: "https://test-worker.cryptolinx.workers.dev" },
57
- }));
58
-
59
- loadMock = mock(async () => ({}));
60
- listEnabledWorkersMock = mock(() => ["d1-worker", "hoox", "trade-worker"]);
61
- getWorkerMock = mock((_name: string) => ({
62
- enabled: true,
63
- path: "workers/test-worker",
64
- }));
65
-
66
- // Install mocks on prototypes
67
- (ConfigService.prototype as Record<string, unknown>).load = loadMock;
68
- (ConfigService.prototype as Record<string, unknown>).listEnabledWorkers =
69
- listEnabledWorkersMock;
70
- (ConfigService.prototype as Record<string, unknown>).getWorker =
71
- getWorkerMock;
72
- (CloudflareService.prototype as Record<string, unknown>).deploy = deployMock;
73
- });
74
-
75
- afterEach(() => {
76
- mock.restore();
77
-
78
- // Restore originals
79
- (ConfigService.prototype as Record<string, unknown>).load = origLoad;
80
- (ConfigService.prototype as Record<string, unknown>).listEnabledWorkers =
81
- origListEnabled;
82
- (ConfigService.prototype as Record<string, unknown>).getWorker =
83
- origGetWorker;
84
- (CloudflareService.prototype as Record<string, unknown>).deploy = origDeploy;
85
- });
86
-
87
- // ---------------------------------------------------------------------------
88
- // Dynamic import — load the deploy command after stubs are in place
89
- // ---------------------------------------------------------------------------
90
-
91
- async function importDeployCommand(): Promise<{
92
- registerDeployCommand: typeof import("./deploy-command.js").registerDeployCommand;
93
- }> {
94
- return import("./deploy-command.js");
95
- }
96
-
97
- /**
98
- * Create a fresh Commander program with the deploy command registered.
99
- */
100
- async function createProgram(): Promise<Command> {
101
- const { registerDeployCommand } = await importDeployCommand();
102
- const program = new Command().name("hoox-test").exitOverride(() => {
103
- // Suppress Commander's own exit during tests
104
- });
105
- registerDeployCommand(program);
106
- return program;
107
- }
108
-
109
- /** Make deployMock return a failure for all subsequent calls. */
110
- function makeDeployFail(error: string): void {
111
- deployMock = mock(async () => ({ ok: false as const, error }));
112
- (CloudflareService.prototype as Record<string, unknown>).deploy = deployMock;
113
- }
114
-
115
- // ---------------------------------------------------------------------------
116
- // Tests
117
- // ---------------------------------------------------------------------------
118
-
119
- describe("registerDeployCommand", () => {
120
- // -- Command registration -------------------------------------------------
121
-
122
- it("registers 'deploy' as a command on the program", async () => {
123
- const program = await createProgram();
124
- const deployCmd = program.commands.find((c) => c.name() === "deploy");
125
- expect(deployCmd).toBeDefined();
126
- });
127
-
128
- it("registers 'deploy all' subcommand", async () => {
129
- const program = await createProgram();
130
- const deployCmd = program.commands.find((c) => c.name() === "deploy")!;
131
- const allCmd = deployCmd.commands.find((c) => c.name() === "all");
132
- expect(allCmd).toBeDefined();
133
- expect(allCmd!.description()).toContain("Deploy all enabled workers");
134
- });
135
-
136
- it("registers 'deploy workers' subcommand", async () => {
137
- const program = await createProgram();
138
- const deployCmd = program.commands.find((c) => c.name() === "deploy")!;
139
- const workersCmd = deployCmd.commands.find((c) => c.name() === "workers");
140
- expect(workersCmd).toBeDefined();
141
- expect(workersCmd!.description()).toContain("Deploy all enabled workers");
142
- });
143
-
144
- it("registers 'deploy worker <name>' subcommand with argument", async () => {
145
- const program = await createProgram();
146
- const deployCmd = program.commands.find((c) => c.name() === "deploy")!;
147
- const workerCmd = deployCmd.commands.find((c) => c.name() === "worker");
148
- expect(workerCmd).toBeDefined();
149
- const args = workerCmd!.registeredArguments;
150
- expect(args.some((a) => a.name() === "name")).toBe(true);
151
- });
152
-
153
- it("registers 'deploy dashboard' subcommand", async () => {
154
- const program = await createProgram();
155
- const deployCmd = program.commands.find((c) => c.name() === "deploy")!;
156
- const dashboardCmd = deployCmd.commands.find(
157
- (c) => c.name() === "dashboard"
158
- );
159
- expect(dashboardCmd).toBeDefined();
160
- expect(dashboardCmd!.description()).toContain("dashboard");
161
- });
162
-
163
- // -- deploy workers -------------------------------------------------------
164
-
165
- describe("deploy workers", () => {
166
- it("calls listEnabledWorkers and deploys each", async () => {
167
- listEnabledWorkersMock = mock(() => [
168
- "d1-worker",
169
- "hoox",
170
- "trade-worker",
171
- ]);
172
- (ConfigService.prototype as Record<string, unknown>).listEnabledWorkers =
173
- listEnabledWorkersMock;
174
-
175
- const program = await createProgram();
176
- await program.parseAsync(["deploy", "workers"], { from: "user" });
177
-
178
- expect(listEnabledWorkersMock).toHaveBeenCalled();
179
- expect(deployMock).toHaveBeenCalledTimes(3);
180
- });
181
-
182
- it("handles no enabled workers gracefully", async () => {
183
- listEnabledWorkersMock = mock(() => []);
184
- (ConfigService.prototype as Record<string, unknown>).listEnabledWorkers =
185
- listEnabledWorkersMock;
186
-
187
- const program = await createProgram();
188
- await program.parseAsync(["deploy", "workers"], { from: "user" });
189
-
190
- expect(deployMock).toHaveBeenCalledTimes(0);
191
- });
192
-
193
- it("continues deploying remaining workers on partial failure", async () => {
194
- listEnabledWorkersMock = mock(() => ["a", "b", "c"]);
195
- (ConfigService.prototype as Record<string, unknown>).listEnabledWorkers =
196
- listEnabledWorkersMock;
197
-
198
- let calls = 0;
199
- deployMock = mock(async () => {
200
- calls++;
201
- if (calls === 2) {
202
- return { ok: false as const, error: "deploy error" };
203
- }
204
- return { ok: true as const, data: { url: "https://x.workers.dev" } };
205
- });
206
- (CloudflareService.prototype as Record<string, unknown>).deploy =
207
- deployMock;
208
-
209
- const program = await createProgram();
210
- await program.parseAsync(["deploy", "workers"], { from: "user" });
211
-
212
- expect(deployMock).toHaveBeenCalledTimes(3);
213
- expect(calls).toBe(3);
214
- });
215
-
216
- it("passes --env to deploy", async () => {
217
- listEnabledWorkersMock = mock(() => ["single-worker"]);
218
- (ConfigService.prototype as Record<string, unknown>).listEnabledWorkers =
219
- listEnabledWorkersMock;
220
-
221
- const program = await createProgram();
222
- await program.parseAsync(["deploy", "workers", "--env", "staging"], {
223
- from: "user",
224
- });
225
-
226
- expect(deployMock).toHaveBeenCalledTimes(1);
227
- const calls = (
228
- deployMock as unknown as { mock: { calls: Array<unknown[]> } }
229
- ).mock.calls;
230
- expect(calls[0][1]).toBe("staging");
231
- });
232
- });
233
-
234
- // -- deploy worker <name> -------------------------------------------------
235
-
236
- describe("deploy worker <name>", () => {
237
- it("deploys the specified worker successfully", async () => {
238
- const program = await createProgram();
239
- await program.parseAsync(["deploy", "worker", "hoox"], { from: "user" });
240
-
241
- expect(deployMock).toHaveBeenCalledTimes(1);
242
- const calls = (
243
- deployMock as unknown as { mock: { calls: Array<unknown[]> } }
244
- ).mock.calls;
245
- expect(calls[0][0]).toContain("test-worker");
246
- });
247
-
248
- it("passes --env to deploy", async () => {
249
- const program = await createProgram();
250
- await program.parseAsync(
251
- ["deploy", "worker", "hoox", "--env", "production"],
252
- { from: "user" }
253
- );
254
-
255
- const calls = (
256
- deployMock as unknown as { mock: { calls: Array<unknown[]> } }
257
- ).mock.calls;
258
- expect(calls[0][1]).toBe("production");
259
- });
260
-
261
- it("handles deploy failure (sets exitCode to 1)", async () => {
262
- makeDeployFail("authentication error");
263
- getWorkerMock = mock(() => ({
264
- enabled: true,
265
- path: "workers/hoox",
266
- }));
267
- (ConfigService.prototype as Record<string, unknown>).getWorker =
268
- getWorkerMock;
269
-
270
- const program = await createProgram();
271
- await program.parseAsync(["deploy", "worker", "hoox"], { from: "user" });
272
-
273
- expect(process.exitCode).toBe(1);
274
- });
275
-
276
- it("handles unknown worker name without calling deploy", async () => {
277
- getWorkerMock = mock(() => undefined);
278
- (ConfigService.prototype as Record<string, unknown>).getWorker =
279
- getWorkerMock;
280
-
281
- const program = await createProgram();
282
- await program.parseAsync(["deploy", "worker", "nonexistent"], {
283
- from: "user",
284
- });
285
-
286
- expect(deployMock).toHaveBeenCalledTimes(0);
287
- expect(process.exitCode).toBe(1);
288
- });
289
- });
290
-
291
- // -- config loading errors ------------------------------------------------
292
-
293
- it("handles config load failure gracefully", async () => {
294
- loadMock = mock(async () => {
295
- throw new Error("Config file not found");
296
- });
297
- (ConfigService.prototype as Record<string, unknown>).load = loadMock;
298
-
299
- const program = await createProgram();
300
- await program.parseAsync(["deploy", "workers"], { from: "user" });
301
-
302
- expect(process.exitCode).toBe(1);
303
- });
304
- });