@jango-blockchained/hoox-cli 0.5.2 → 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 (114) 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 -1087
  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 -97
  9. package/src/commands/check/types.ts +0 -103
  10. package/src/commands/clone/clone-command.test.ts +0 -440
  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 -896
  15. package/src/commands/config/env-command.test.ts +0 -43
  16. package/src/commands/config/env-command.ts +0 -292
  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 -130
  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 -311
  25. package/src/commands/db/index.ts +0 -1
  26. package/src/commands/deploy/deploy-command.test.ts +0 -324
  27. package/src/commands/deploy/deploy-command.ts +0 -1054
  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 -405
  32. package/src/commands/dev/dev-command.ts +0 -398
  33. package/src/commands/dev/index.ts +0 -1
  34. package/src/commands/disclaimer/disclaimer-command.ts +0 -21
  35. package/src/commands/disclaimer/index.ts +0 -1
  36. package/src/commands/infra/index.ts +0 -5
  37. package/src/commands/infra/infra-command.test.ts +0 -719
  38. package/src/commands/infra/infra-command.ts +0 -974
  39. package/src/commands/infra/types.ts +0 -23
  40. package/src/commands/init/__tests__/cli-provisioner.test.ts +0 -17
  41. package/src/commands/init/cli-provisioner.ts +0 -71
  42. package/src/commands/init/index.ts +0 -1
  43. package/src/commands/init/init-command.test.ts +0 -854
  44. package/src/commands/init/init-command.ts +0 -597
  45. package/src/commands/init/types.ts +0 -23
  46. package/src/commands/logs/index.ts +0 -1
  47. package/src/commands/logs/logs-command.test.ts +0 -293
  48. package/src/commands/logs/logs-command.ts +0 -452
  49. package/src/commands/monitor/index.ts +0 -2
  50. package/src/commands/monitor/monitor-command.test.ts +0 -271
  51. package/src/commands/monitor/monitor-command.ts +0 -269
  52. package/src/commands/monitor/monitor-service.ts +0 -65
  53. package/src/commands/monitor/types.ts +0 -13
  54. package/src/commands/repair/index.ts +0 -2
  55. package/src/commands/repair/repair-command.test.ts +0 -243
  56. package/src/commands/repair/repair-command.ts +0 -220
  57. package/src/commands/repair/repair-service.ts +0 -164
  58. package/src/commands/repair/types.ts +0 -13
  59. package/src/commands/schema/index.ts +0 -1
  60. package/src/commands/schema/schema-command.ts +0 -137
  61. package/src/commands/test/index.ts +0 -2
  62. package/src/commands/test/test-command.test.ts +0 -318
  63. package/src/commands/test/test-command.ts +0 -406
  64. package/src/commands/tui/index.ts +0 -1
  65. package/src/commands/tui/tui-command.ts +0 -87
  66. package/src/commands/update/index.ts +0 -1
  67. package/src/commands/update/update-command.ts +0 -109
  68. package/src/commands/waf/index.ts +0 -2
  69. package/src/commands/waf/types.ts +0 -48
  70. package/src/commands/waf/waf-command.test.ts +0 -506
  71. package/src/commands/waf/waf-command.ts +0 -545
  72. package/src/index.ts +0 -261
  73. package/src/services/cloudflare/cloudflare-service.test.ts +0 -658
  74. package/src/services/cloudflare/cloudflare-service.ts +0 -433
  75. package/src/services/cloudflare/index.ts +0 -2
  76. package/src/services/cloudflare/types.ts +0 -30
  77. package/src/services/config/config-service.test.ts +0 -395
  78. package/src/services/config/config-service.ts +0 -202
  79. package/src/services/config/index.ts +0 -9
  80. package/src/services/config/types.ts +0 -66
  81. package/src/services/db/db-service.test.ts +0 -63
  82. package/src/services/db/db-service.ts +0 -131
  83. package/src/services/db/index.ts +0 -1
  84. package/src/services/docker/docker-service.ts +0 -155
  85. package/src/services/docker/index.ts +0 -1
  86. package/src/services/env/env-service.test.ts +0 -259
  87. package/src/services/env/env-service.ts +0 -372
  88. package/src/services/env/index.ts +0 -1
  89. package/src/services/kv/index.ts +0 -1
  90. package/src/services/kv/kv-sync-service.test.ts +0 -38
  91. package/src/services/kv/kv-sync-service.ts +0 -243
  92. package/src/services/prerequisites/index.ts +0 -1
  93. package/src/services/prerequisites/prerequisites-service.test.ts +0 -89
  94. package/src/services/prerequisites/prerequisites-service.ts +0 -377
  95. package/src/services/prerequisites/types.ts +0 -48
  96. package/src/services/schema/index.ts +0 -1
  97. package/src/services/schema/schema-service.ts +0 -99
  98. package/src/services/secrets/index.ts +0 -11
  99. package/src/services/secrets/secrets-service.test.ts +0 -502
  100. package/src/services/secrets/secrets-service.ts +0 -287
  101. package/src/services/secrets/types.ts +0 -50
  102. package/src/services/update/index.ts +0 -2
  103. package/src/services/update/update-service.test.ts +0 -76
  104. package/src/services/update/update-service.ts +0 -193
  105. package/src/ui/banner.ts +0 -141
  106. package/src/ui/index.ts +0 -8
  107. package/src/ui/menu.ts +0 -490
  108. package/src/utils/error-handler.ts +0 -62
  109. package/src/utils/errors.test.ts +0 -69
  110. package/src/utils/errors.ts +0 -24
  111. package/src/utils/formatters.test.ts +0 -180
  112. package/src/utils/formatters.ts +0 -269
  113. package/src/utils/git.ts +0 -134
  114. package/src/utils/theme.ts +0 -92
@@ -1,2 +0,0 @@
1
- export { registerDeployCommand } from "./deploy-command.js";
2
- export type { DeployOptions, DeployResult } from "./types.js";
@@ -1,76 +0,0 @@
1
- /**
2
- * Service for interacting with the Telegram Bot API.
3
- * Used by `hoox deploy telegram-webhook`.
4
- */
5
-
6
- export class TelegramService {
7
- /**
8
- * Set the webhook for a Telegram bot.
9
- * POST https://api.telegram.org/bot{TOKEN}/setWebhook
10
- */
11
- async setWebhook(
12
- botToken: string,
13
- webhookUrl: string,
14
- secretToken: string
15
- ): Promise<{ ok: boolean; description?: string; error?: string }> {
16
- try {
17
- const url = `https://api.telegram.org/bot${botToken}/setWebhook`;
18
- const response = await fetch(url, {
19
- method: "POST",
20
- headers: { "Content-Type": "application/json" },
21
- body: JSON.stringify({ url: webhookUrl, secret_token: secretToken }),
22
- });
23
- const data = (await response.json()) as {
24
- ok: boolean;
25
- description?: string;
26
- };
27
- return { ok: data.ok, description: data.description };
28
- } catch (err) {
29
- return {
30
- ok: false,
31
- error: err instanceof Error ? err.message : String(err),
32
- };
33
- }
34
- }
35
-
36
- /**
37
- * Get the current webhook status.
38
- * GET https://api.telegram.org/bot{TOKEN}/getWebhookInfo
39
- */
40
- async getWebhookInfo(botToken: string): Promise<{
41
- ok: boolean;
42
- url?: string;
43
- has_custom_certificate?: boolean;
44
- pending_update_count?: number;
45
- error?: string;
46
- }> {
47
- try {
48
- const response = await fetch(
49
- `https://api.telegram.org/bot${botToken}/getWebhookInfo`
50
- );
51
- const data = (await response.json()) as {
52
- ok: boolean;
53
- result?: {
54
- url: string;
55
- has_custom_certificate: boolean;
56
- pending_update_count: number;
57
- };
58
- description?: string;
59
- };
60
- if (data.ok && data.result) {
61
- return {
62
- ok: true,
63
- url: data.result.url,
64
- has_custom_certificate: data.result.has_custom_certificate,
65
- pending_update_count: data.result.pending_update_count,
66
- };
67
- }
68
- return { ok: false, error: data.description };
69
- } catch (err) {
70
- return {
71
- ok: false,
72
- error: err instanceof Error ? err.message : String(err),
73
- };
74
- }
75
- }
76
- }
@@ -1,34 +0,0 @@
1
- /**
2
- * Deploy command types — options and result interfaces for the deploy
3
- * command group (all, workers, worker, dashboard).
4
- */
5
-
6
- /**
7
- * Options for a single worker deployment.
8
- */
9
- export interface DeployOptions {
10
- /** Cloudflare environment (e.g. "production", "staging"). */
11
- env?: string;
12
- }
13
-
14
- /**
15
- * Result of deploying a single worker.
16
- */
17
- export interface DeployResult {
18
- /** Worker name as defined in wrangler.jsonc. */
19
- worker: string;
20
- /** Deployed URL extracted from wrangler output, if available. */
21
- url?: string;
22
- /** Whether the deployment succeeded. */
23
- success: boolean;
24
- /** Error message when success is false. */
25
- error?: string;
26
- /** Bundle size (e.g., "7102.32 KiB") */
27
- size?: string;
28
- /** Worker startup time (e.g., "37 ms") */
29
- startupTime?: string;
30
- /** Version ID */
31
- versionId?: string;
32
- /** Raw wrangler output (first non-empty line, for debugging) */
33
- rawOutput?: string;
34
- }
@@ -1,405 +0,0 @@
1
- /**
2
- * Unit tests for the dev command.
3
- *
4
- * Stubs ConfigService and CloudflareService prototypes to verify the dev
5
- * command logic in isolation. Uses Commander's exitOverride to suppress
6
- * process exits during test runs.
7
- *
8
- * Subcommand actions are async — we use parseAsync() and then inspect mocks
9
- * to confirm correct service calls.
10
- */
11
- import { afterEach, beforeEach, describe, expect, it, mock } from "bun:test";
12
- import { Command } from "commander";
13
- import { ConfigService } from "../../services/config/config-service.js";
14
- import { CloudflareService } from "../../services/cloudflare/cloudflare-service.js";
15
- import { PrerequisitesService } from "../../services/prerequisites/index.js";
16
- import { DockerService } from "../../services/docker/index.js";
17
-
18
- // ---------------------------------------------------------------------------
19
- // Stub variables — reassigned in beforeEach
20
- // ---------------------------------------------------------------------------
21
-
22
- let devMock: ReturnType<typeof mock>;
23
- let loadMock: ReturnType<typeof mock>;
24
- let listWorkersMock: ReturnType<typeof mock>;
25
- let listEnabledWorkersMock: ReturnType<typeof mock>;
26
- let getWorkerMock: ReturnType<typeof mock>;
27
- let validateMock: ReturnType<typeof mock>;
28
- let getDevRuntimeMock: ReturnType<typeof mock>;
29
- let checkWranglerMock: ReturnType<typeof mock>;
30
- let dockerCheckMock: ReturnType<typeof mock>;
31
- let composeExistsMock: ReturnType<typeof mock>;
32
-
33
- // Preserve originals so we can restore them after tests
34
- const origLoad = ConfigService.prototype
35
- .load as typeof ConfigService.prototype.load;
36
- const origListWorkers = ConfigService.prototype
37
- .listWorkers as typeof ConfigService.prototype.listWorkers;
38
- const origListEnabled = ConfigService.prototype
39
- .listEnabledWorkers as typeof ConfigService.prototype.listEnabledWorkers;
40
- const origGetWorker = ConfigService.prototype
41
- .getWorker as typeof ConfigService.prototype.getWorker;
42
- const origValidate = ConfigService.prototype
43
- .validate as typeof ConfigService.prototype.validate;
44
- const origGetDevRuntime = ConfigService.prototype
45
- .getDevRuntime as typeof ConfigService.prototype.getDevRuntime;
46
- const origDev = CloudflareService.prototype
47
- .dev as typeof CloudflareService.prototype.dev;
48
- const origCheckWrangler = PrerequisitesService.prototype
49
- .checkWranglerVersion as typeof PrerequisitesService.prototype.checkWranglerVersion;
50
- const origDockerCheck = DockerService.prototype
51
- .checkAvailability as typeof DockerService.prototype.checkAvailability;
52
- const origComposeExists = DockerService.prototype
53
- .composeFileExists as typeof DockerService.prototype.composeFileExists;
54
-
55
- // Preserve original Bun globals
56
- const origBunSpawn = Bun.spawn;
57
- const origBunFile = Bun.file;
58
-
59
- beforeEach(() => {
60
- mock.restore();
61
-
62
- // Reset process.exitCode between tests
63
- process.exitCode = undefined;
64
-
65
- // Restore prototypes to originals
66
- (ConfigService.prototype as unknown as Record<string, unknown>).load =
67
- origLoad;
68
- (ConfigService.prototype as unknown as Record<string, unknown>).listWorkers =
69
- origListWorkers;
70
- (
71
- ConfigService.prototype as unknown as Record<string, unknown>
72
- ).listEnabledWorkers = origListEnabled;
73
- (ConfigService.prototype as unknown as Record<string, unknown>).getWorker =
74
- origGetWorker;
75
- (ConfigService.prototype as unknown as Record<string, unknown>).validate =
76
- origValidate;
77
- (CloudflareService.prototype as unknown as Record<string, unknown>).dev =
78
- origDev;
79
-
80
- // Stub Bun.spawn to prevent actual process spawning during tests.
81
- // Uses individual property assignment (not globalThis.Bun = {...}) to
82
- // avoid "readonly property" errors in Bun 1.3.x.
83
- (Bun as unknown as unknown as Record<string, unknown>).spawn = mock(() => ({
84
- stdout: new Blob([]),
85
- stderr: new Blob([]),
86
- exited: Promise.resolve(0),
87
- stdin: { write: mock(() => {}), end: mock(() => {}) },
88
- kill: mock(() => {}),
89
- }));
90
- // Fresh mocks
91
- devMock = mock(async (_path: string, _port?: number) => ({
92
- ok: true as const,
93
- value: { port: _port ?? 8787 },
94
- }));
95
-
96
- loadMock = mock(async function (this: ConfigService) {
97
- // Use a regular function so `this` refers to the ConfigService instance
98
- (this as unknown as Record<string, unknown>).config = {};
99
- return {} as Record<string, unknown>;
100
- });
101
- listWorkersMock = mock(() => ["hoox", "trade-worker", "d1-worker"]);
102
- listEnabledWorkersMock = mock(() => ["hoox", "trade-worker", "d1-worker"]);
103
- getWorkerMock = mock((_name: string) => ({
104
- enabled: true,
105
- path: "workers/test-worker",
106
- }));
107
- validateMock = mock(() => ({ valid: true, errors: [] }));
108
- getDevRuntimeMock = mock(() => "native");
109
- checkWranglerMock = mock(async () => ({
110
- outdated: false,
111
- }));
112
- dockerCheckMock = mock(async () => ({ docker: false, compose: false }));
113
- composeExistsMock = mock(async () => false);
114
-
115
- // Install mocks on prototypes
116
- (ConfigService.prototype as unknown as Record<string, unknown>).load =
117
- loadMock;
118
- (ConfigService.prototype as unknown as Record<string, unknown>).listWorkers =
119
- listWorkersMock;
120
- (
121
- ConfigService.prototype as unknown as Record<string, unknown>
122
- ).listEnabledWorkers = listEnabledWorkersMock;
123
- (ConfigService.prototype as unknown as Record<string, unknown>).getWorker =
124
- getWorkerMock;
125
- (ConfigService.prototype as unknown as Record<string, unknown>).validate =
126
- validateMock;
127
- (
128
- ConfigService.prototype as unknown as Record<string, unknown>
129
- ).getDevRuntime = getDevRuntimeMock;
130
- (CloudflareService.prototype as unknown as Record<string, unknown>).dev =
131
- devMock;
132
- (
133
- PrerequisitesService.prototype as unknown as Record<string, unknown>
134
- ).checkWranglerVersion = checkWranglerMock;
135
- (
136
- DockerService.prototype as unknown as Record<string, unknown>
137
- ).checkAvailability = dockerCheckMock;
138
- (
139
- DockerService.prototype as unknown as Record<string, unknown>
140
- ).composeFileExists = composeExistsMock;
141
- });
142
-
143
- afterEach(() => {
144
- mock.restore();
145
-
146
- // Restore originals
147
- (ConfigService.prototype as unknown as Record<string, unknown>).load =
148
- origLoad;
149
- (ConfigService.prototype as unknown as Record<string, unknown>).listWorkers =
150
- origListWorkers;
151
- (
152
- ConfigService.prototype as unknown as Record<string, unknown>
153
- ).listEnabledWorkers = origListEnabled;
154
- (ConfigService.prototype as unknown as Record<string, unknown>).getWorker =
155
- origGetWorker;
156
- (ConfigService.prototype as unknown as Record<string, unknown>).validate =
157
- origValidate;
158
- (
159
- ConfigService.prototype as unknown as Record<string, unknown>
160
- ).getDevRuntime = origGetDevRuntime;
161
- (CloudflareService.prototype as unknown as Record<string, unknown>).dev =
162
- origDev;
163
- (
164
- PrerequisitesService.prototype as unknown as Record<string, unknown>
165
- ).checkWranglerVersion = origCheckWrangler;
166
- (
167
- DockerService.prototype as unknown as Record<string, unknown>
168
- ).checkAvailability = origDockerCheck;
169
- (
170
- DockerService.prototype as unknown as Record<string, unknown>
171
- ).composeFileExists = origComposeExists;
172
-
173
- // Restore Bun globals (individual property restore)
174
- (Bun as unknown as unknown as Record<string, unknown>).spawn = origBunSpawn;
175
- (Bun as unknown as unknown as Record<string, unknown>).file = origBunFile;
176
- });
177
-
178
- // ---------------------------------------------------------------------------
179
- // Dynamic import — load the dev command after stubs are in place
180
- // ---------------------------------------------------------------------------
181
-
182
- async function importDevCommand(): Promise<{
183
- registerDevCommand: typeof import("./dev-command.js").registerDevCommand;
184
- }> {
185
- return import("./dev-command.js");
186
- }
187
-
188
- /**
189
- * Create a fresh Commander program with the dev command registered.
190
- */
191
- async function createProgram(): Promise<Command> {
192
- const { registerDevCommand } = await importDevCommand();
193
- const program = new Command().name("hoox-test").exitOverride(() => {
194
- // Suppress Commander's own exit during tests
195
- });
196
- registerDevCommand(program);
197
- return program;
198
- }
199
-
200
- /** Make devMock return a failure for all subsequent calls. */
201
- function makeDevFail(error: string): void {
202
- devMock = mock(async () => ({ ok: false as const, error }));
203
- (CloudflareService.prototype as unknown as Record<string, unknown>).dev =
204
- devMock;
205
- }
206
-
207
- // ---------------------------------------------------------------------------
208
- // Tests
209
- // ---------------------------------------------------------------------------
210
-
211
- describe("registerDevCommand", () => {
212
- // -- Command registration --------------------------------------------------
213
-
214
- it("registers 'dev' as a command on the program", async () => {
215
- const program = await createProgram();
216
- const devCmd = program.commands.find((c) => c.name() === "dev");
217
- expect(devCmd).toBeDefined();
218
- });
219
-
220
- it("registers 'dev start' subcommand", async () => {
221
- const program = await createProgram();
222
- const devCmd = program.commands.find((c) => c.name() === "dev")!;
223
- const startCmd = devCmd.commands.find((c) => c.name() === "start");
224
- expect(startCmd).toBeDefined();
225
- expect(startCmd!.description()).toContain("wrangler dev");
226
- });
227
-
228
- it("registers 'dev worker <name>' subcommand with argument", async () => {
229
- const program = await createProgram();
230
- const devCmd = program.commands.find((c) => c.name() === "dev")!;
231
- const workerCmd = devCmd.commands.find((c) => c.name() === "worker");
232
- expect(workerCmd).toBeDefined();
233
- expect(workerCmd!.description()).toContain("wrangler dev");
234
- const args = workerCmd!.registeredArguments;
235
- expect(args.some((a) => a.name() === "name")).toBe(true);
236
- });
237
-
238
- it("registers 'dev dashboard' subcommand", async () => {
239
- const program = await createProgram();
240
- const devCmd = program.commands.find((c) => c.name() === "dev")!;
241
- const dashboardCmd = devCmd.commands.find((c) => c.name() === "dashboard");
242
- expect(dashboardCmd).toBeDefined();
243
- expect(dashboardCmd!.description()).toContain("dashboard");
244
- });
245
-
246
- // -- dev start -------------------------------------------------------------
247
-
248
- describe("dev start", () => {
249
- it("handles config validation failure gracefully", async () => {
250
- validateMock = mock(() => ({
251
- valid: false,
252
- errors: ["global.cloudflare_account_id is required"],
253
- }));
254
- (ConfigService.prototype as unknown as Record<string, unknown>).validate =
255
- validateMock;
256
-
257
- const program = await createProgram();
258
- await program.parseAsync(["dev", "start"], { from: "user" });
259
-
260
- expect(process.exitCode).toBe(2); // INVALID_USAGE
261
- });
262
-
263
- it("handles no enabled workers gracefully", async () => {
264
- listEnabledWorkersMock = mock(() => []);
265
- (
266
- ConfigService.prototype as unknown as Record<string, unknown>
267
- ).listEnabledWorkers = listEnabledWorkersMock;
268
-
269
- const program = await createProgram();
270
- await program.parseAsync(["dev", "start"], { from: "user" });
271
-
272
- expect(process.exitCode).toBe(2); // INVALID_USAGE
273
- });
274
-
275
- it("starts all enabled workers on assigned ports", async () => {
276
- listEnabledWorkersMock = mock(() => ["hoox", "trade-worker"]);
277
- (
278
- ConfigService.prototype as unknown as Record<string, unknown>
279
- ).listEnabledWorkers = listEnabledWorkersMock;
280
-
281
- const program = await createProgram();
282
- await program.parseAsync(["dev", "start"], { from: "user" });
283
-
284
- // Both workers should be started via CloudflareService.dev()
285
- expect(devMock).toHaveBeenCalledTimes(2);
286
- const calls = (
287
- devMock as unknown as { mock: { calls: Array<unknown[]> } }
288
- ).mock.calls;
289
- // hoox → port 8787, trade-worker → port 8788
290
- expect(calls[0][1]).toBe(8787);
291
- expect(calls[1][1]).toBe(8788);
292
- // exitCode remains unset since the action ran successfully
293
- });
294
- });
295
-
296
- // -- dev worker <name> -----------------------------------------------------
297
-
298
- describe("dev worker <name>", () => {
299
- it("starts the specified worker with default port", async () => {
300
- const program = await createProgram();
301
- await program.parseAsync(["dev", "worker", "hoox"], { from: "user" });
302
-
303
- expect(devMock).toHaveBeenCalledTimes(1);
304
- const calls = (
305
- devMock as unknown as { mock: { calls: Array<unknown[]> } }
306
- ).mock.calls;
307
- expect(calls[0][0]).toContain("test-worker");
308
- expect(calls[0][1]).toBe(8787);
309
- });
310
-
311
- it("passes --port to dev service", async () => {
312
- const program = await createProgram();
313
- await program.parseAsync(["dev", "worker", "hoox", "--port", "3000"], {
314
- from: "user",
315
- });
316
-
317
- const calls = (
318
- devMock as unknown as { mock: { calls: Array<unknown[]> } }
319
- ).mock.calls;
320
- expect(calls[0][1]).toBe(3000);
321
- });
322
-
323
- it("handles unknown worker name", async () => {
324
- getWorkerMock = mock(() => undefined);
325
- (
326
- ConfigService.prototype as unknown as Record<string, unknown>
327
- ).getWorker = getWorkerMock;
328
-
329
- const program = await createProgram();
330
- await program.parseAsync(["dev", "worker", "nonexistent"], {
331
- from: "user",
332
- });
333
-
334
- expect(devMock).toHaveBeenCalledTimes(0);
335
- expect(process.exitCode).toBe(2); // INVALID_USAGE
336
- });
337
-
338
- it("handles disabled worker", async () => {
339
- getWorkerMock = mock(() => ({
340
- enabled: false,
341
- path: "workers/disabled-worker",
342
- }));
343
- (
344
- ConfigService.prototype as unknown as Record<string, unknown>
345
- ).getWorker = getWorkerMock;
346
-
347
- const program = await createProgram();
348
- await program.parseAsync(["dev", "worker", "disabled-worker"], {
349
- from: "user",
350
- });
351
-
352
- expect(devMock).toHaveBeenCalledTimes(0);
353
- expect(process.exitCode).toBe(2); // INVALID_USAGE
354
- });
355
-
356
- it("handles dev failure (sets exitCode to 1)", async () => {
357
- makeDevFail("wrangler not found");
358
- getWorkerMock = mock(() => ({
359
- enabled: true,
360
- path: "workers/hoox",
361
- }));
362
- (
363
- ConfigService.prototype as unknown as Record<string, unknown>
364
- ).getWorker = getWorkerMock;
365
-
366
- const program = await createProgram();
367
- await program.parseAsync(["dev", "worker", "hoox"], { from: "user" });
368
-
369
- expect(process.exitCode).toBe(1); // ERROR
370
- });
371
- });
372
-
373
- // -- dev dashboard ---------------------------------------------------------
374
-
375
- describe("dev dashboard", () => {
376
- it("handles missing dashboard directory", async () => {
377
- // Override Bun.file for this test to say dashboard doesn't exist
378
- (Bun as unknown as unknown as Record<string, unknown>).file = mock(
379
- (_p: string) => ({
380
- exists: mock(async () => false),
381
- })
382
- );
383
-
384
- const program = await createProgram();
385
- await program.parseAsync(["dev", "dashboard"], { from: "user" });
386
-
387
- expect(process.exitCode).toBe(2); // INVALID_USAGE
388
- });
389
- });
390
-
391
- // -- config loading errors ------------------------------------------------
392
-
393
- it("handles config load failure gracefully", async () => {
394
- loadMock = mock(async () => {
395
- throw new Error("Config file not found");
396
- });
397
- (ConfigService.prototype as unknown as Record<string, unknown>).load =
398
- loadMock;
399
-
400
- const program = await createProgram();
401
- await program.parseAsync(["dev", "start"], { from: "user" });
402
-
403
- expect(process.exitCode).toBe(1);
404
- });
405
- });