@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,319 +0,0 @@
1
- // @ts-nocheck
2
- import { describe, it, expect, beforeEach, afterEach, mock } from "bun:test";
3
- import { Command } from "commander";
4
- import { registerTestCommand, runStep, printSummary } from "./test-command.js";
5
- import type { TestStepResult, TestSummary } from "./test-command.js";
6
- import { CLIError, ExitCode } from "../../utils/errors.js";
7
-
8
- // ---------------------------------------------------------------------------
9
- // Helpers
10
- // ---------------------------------------------------------------------------
11
-
12
- const originalSpawn = Bun.spawn;
13
-
14
- /** Create a mock Bun.spawn that returns the given exit code and output. */
15
- function mockSpawn(exitCode: number, stdout = "", stderr = "") {
16
- return mock(() => ({
17
- exited: Promise.resolve(exitCode),
18
- stdout: new Blob([stdout]),
19
- stderr: new Blob([stderr]),
20
- }));
21
- }
22
-
23
- /** Capture stdout for assertion. */
24
- function captureStdout(): { output: () => string; restore: () => void } {
25
- const chunks: string[] = [];
26
- const originalWrite = process.stdout.write.bind(process.stdout);
27
- const writeMock = mock((chunk: string | Buffer) => {
28
- chunks.push(typeof chunk === "string" ? chunk : chunk.toString());
29
- return true;
30
- });
31
- process.stdout.write = writeMock as unknown as typeof process.stdout.write;
32
- return {
33
- output: () => chunks.join(""),
34
- restore: () => {
35
- process.stdout.write = originalWrite;
36
- },
37
- };
38
- }
39
-
40
- /** Create a fresh Commander program with global --json / --quiet options. */
41
- function makeProgram(): Command {
42
- const program = new Command();
43
- program.name("hoox");
44
- program.option("--json", "");
45
- program.option("--quiet", "");
46
- return program;
47
- }
48
-
49
- // ---------------------------------------------------------------------------
50
- // runStep
51
- // ---------------------------------------------------------------------------
52
-
53
- describe("runStep", () => {
54
- afterEach(() => {
55
- (Bun as any).spawn = originalSpawn;
56
- });
57
-
58
- it("returns success when exit code is 0", async () => {
59
- (Bun as any).spawn = mockSpawn(0, "all tests passed");
60
- const result = await runStep(["bun", "test"]);
61
- expect(result.success).toBe(true);
62
- expect(result.exitCode).toBe(0);
63
- expect(result.output).toBe("all tests passed");
64
- });
65
-
66
- it("returns failure when exit code is non-zero", async () => {
67
- (Bun as any).spawn = mockSpawn(1, "", "3 tests failed");
68
- const result = await runStep(["bun", "test"]);
69
- expect(result.success).toBe(false);
70
- expect(result.exitCode).toBe(1);
71
- expect(result.error).toBe("3 tests failed");
72
- });
73
-
74
- it("captures both stdout and stderr", async () => {
75
- (Bun as any).spawn = mockSpawn(0, "stdout text", "stderr text");
76
- const result = await runStep(["echo", "hello"]);
77
- expect(result.output).toBe("stdout text");
78
- expect(result.error).toBe("stderr text");
79
- });
80
-
81
- it("records duration", async () => {
82
- (Bun as any).spawn = mockSpawn(0);
83
- const result = await runStep(["bun", "test"]);
84
- expect(result.duration).toBeGreaterThanOrEqual(0);
85
- });
86
-
87
- it("returns the command string", async () => {
88
- (Bun as any).spawn = mockSpawn(0);
89
- const result = await runStep([
90
- "vitest",
91
- "run",
92
- "--config",
93
- "vite.config.ts",
94
- ]);
95
- expect(result.command).toBe("vitest run --config vite.config.ts");
96
- });
97
-
98
- it("handles spawn errors gracefully", async () => {
99
- (Bun as any).spawn = mock(() => {
100
- throw new Error("ENOENT: no such file");
101
- });
102
- const result = await runStep(["nonexistent"]);
103
- expect(result.success).toBe(false);
104
- expect(result.exitCode).toBeNull();
105
- expect(result.error).toContain("ENOENT");
106
- });
107
- });
108
-
109
- // ---------------------------------------------------------------------------
110
- // printSummary
111
- // ---------------------------------------------------------------------------
112
-
113
- describe("printSummary", () => {
114
- let capture: ReturnType<typeof captureStdout>;
115
-
116
- beforeEach(() => {
117
- capture = captureStdout();
118
- });
119
-
120
- afterEach(() => {
121
- capture.restore();
122
- });
123
-
124
- const passingSummary: TestSummary = {
125
- total: 4,
126
- passed: 4,
127
- failed: 0,
128
- results: [
129
- {
130
- step: "Lint",
131
- command: "bun run lint",
132
- success: true,
133
- exitCode: 0,
134
- duration: 1200,
135
- },
136
- {
137
- step: "TypeCheck",
138
- command: "bun run typecheck",
139
- success: true,
140
- exitCode: 0,
141
- duration: 3400,
142
- },
143
- {
144
- step: "Unit Tests",
145
- command: "bun test --coverage",
146
- success: true,
147
- exitCode: 0,
148
- duration: 8900,
149
- },
150
- {
151
- step: "Integration Tests",
152
- command: "vitest run...",
153
- success: true,
154
- exitCode: 0,
155
- duration: 15000,
156
- },
157
- ],
158
- };
159
-
160
- const failingSummary: TestSummary = {
161
- total: 2,
162
- passed: 1,
163
- failed: 1,
164
- results: [
165
- {
166
- step: "Lint",
167
- command: "bun run lint",
168
- success: true,
169
- exitCode: 0,
170
- duration: 500,
171
- },
172
- {
173
- step: "TypeCheck",
174
- command: "bun run typecheck",
175
- success: false,
176
- exitCode: 2,
177
- duration: 800,
178
- error: "TS2322: type error",
179
- },
180
- ],
181
- };
182
-
183
- it("prints a table for human output", () => {
184
- printSummary(passingSummary, {});
185
- const out = capture.output();
186
- expect(out).toContain("All 4 steps passed");
187
- expect(out).toContain("Lint");
188
- expect(out).toContain("passed");
189
- });
190
-
191
- it("shows failure count when some steps fail", () => {
192
- printSummary(failingSummary, {});
193
- const out = capture.output();
194
- expect(out).toContain("1/2 passed");
195
- expect(out).toContain("TypeCheck");
196
- expect(out).toContain("failed");
197
- });
198
-
199
- it("outputs JSON when json=true", () => {
200
- printSummary(passingSummary, { json: true });
201
- const out = capture.output();
202
- const parsed = JSON.parse(out);
203
- expect(parsed.total).toBe(4);
204
- expect(parsed.passed).toBe(4);
205
- expect(parsed.failed).toBe(0);
206
- expect(parsed.results).toHaveLength(4);
207
- });
208
-
209
- it("outputs nothing when quiet=true", () => {
210
- printSummary(passingSummary, { quiet: true });
211
- expect(capture.output()).toBe("");
212
- });
213
- });
214
-
215
- // ---------------------------------------------------------------------------
216
- // registerTestCommand — structure verification
217
- // ---------------------------------------------------------------------------
218
-
219
- describe("registerTestCommand", () => {
220
- it("registers test command with all subcommands", () => {
221
- const program = makeProgram();
222
- registerTestCommand(program);
223
-
224
- const testCmd = program.commands.find((c) => c.name() === "test");
225
- expect(testCmd).toBeDefined();
226
- expect(testCmd?.description()).toContain("Run tests");
227
-
228
- const subNames = testCmd?.commands.map((c) => c.name()) ?? [];
229
- expect(subNames).toContain("all");
230
- expect(subNames).toContain("unit");
231
- expect(subNames).toContain("integration");
232
- expect(subNames).toContain("worker");
233
- });
234
-
235
- it("all subcommand has --json option", () => {
236
- const program = makeProgram();
237
- registerTestCommand(program);
238
-
239
- const testCmd = program.commands.find((c) => c.name() === "test");
240
- const allCmd = testCmd?.commands.find((c) => c.name() === "all");
241
- expect(allCmd).toBeDefined();
242
-
243
- // Commander stores options; verify --json is registered
244
- const optionNames = allCmd?.options.map((o) => o.long) ?? [];
245
- expect(optionNames).toContain("--json");
246
- });
247
-
248
- it("unit subcommand has --coverage option", () => {
249
- const program = makeProgram();
250
- registerTestCommand(program);
251
-
252
- const testCmd = program.commands.find((c) => c.name() === "test");
253
- const unitCmd = testCmd?.commands.find((c) => c.name() === "unit");
254
- expect(unitCmd).toBeDefined();
255
-
256
- const optionNames = unitCmd?.options.map((o) => o.long) ?? [];
257
- expect(optionNames).toContain("--coverage");
258
- });
259
-
260
- it("integration subcommand has --coverage option", () => {
261
- const program = makeProgram();
262
- registerTestCommand(program);
263
-
264
- const testCmd = program.commands.find((c) => c.name() === "test");
265
- const intCmd = testCmd?.commands.find((c) => c.name() === "integration");
266
- expect(intCmd).toBeDefined();
267
-
268
- const optionNames = intCmd?.options.map((o) => o.long) ?? [];
269
- expect(optionNames).toContain("--coverage");
270
- });
271
-
272
- it("worker subcommand requires a name argument and has --coverage option", () => {
273
- const program = makeProgram();
274
- registerTestCommand(program);
275
-
276
- const testCmd = program.commands.find((c) => c.name() === "test");
277
- const workerCmd = testCmd?.commands.find((c) => c.name() === "worker");
278
- expect(workerCmd).toBeDefined();
279
-
280
- // Verify it expects a required argument
281
- const args = workerCmd?.registeredArguments ?? [];
282
- expect(args.length).toBeGreaterThan(0);
283
-
284
- const optionNames = workerCmd?.options.map((o) => o.long) ?? [];
285
- expect(optionNames).toContain("--coverage");
286
- });
287
-
288
- it("all subcommand runs pipeline steps and stops on first failure", async () => {
289
- const program = makeProgram();
290
- registerTestCommand(program);
291
-
292
- // First lint passes, typecheck fails → should stop after 2 steps
293
- let callCount = 0;
294
- const mockSpawnFn = mock((args: string[]) => {
295
- callCount++;
296
- const cmd = args.join(" ");
297
- // Lint passes (call 1), TypeCheck fails (call 2)
298
- const exitCode = cmd.includes("lint") ? 0 : 1;
299
- const stderr = cmd.includes("lint") ? "" : "TS2322: type error";
300
- return {
301
- exited: Promise.resolve(exitCode),
302
- stdout: new Blob([]),
303
- stderr: new Blob([stderr]),
304
- };
305
- });
306
- (Bun as any).spawn = mockSpawnFn;
307
-
308
- // Suppress spinner output by running without tty-like env
309
- await program.parseAsync(["test", "all"], {
310
- from: "user",
311
- });
312
-
313
- // Should only run 2 steps (lint + typecheck) before stopping
314
- expect(callCount).toBe(2);
315
- expect(process.exitCode).toBe(ExitCode.ERROR);
316
-
317
- (Bun as any).spawn = originalSpawn;
318
- });
319
- });