From 10a41cfafab3ef64429eea933de4149ba4d09ed7 Mon Sep 17 00:00:00 2001 From: ChiragArora31 Date: Wed, 1 Apr 2026 11:05:30 +0530 Subject: [PATCH] fix(cli/status): validate --interval only when --watch is used The --interval flag is only relevant when --watch is enabled. Previously, passing `--interval 0` without `--watch` threw an error, whereas `--interval 5` was silently ignored. Now, invalid intervals are ignored when `--watch` is omitted, ensuring consistent behavior. Also adds a test case to prevent regression. --- packages/cli/__tests__/commands/status.test.ts | 15 +++++++++++++++ packages/cli/src/commands/status.ts | 12 +++++++----- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/packages/cli/__tests__/commands/status.test.ts b/packages/cli/__tests__/commands/status.test.ts index a9db08dda..5a47c6259 100644 --- a/packages/cli/__tests__/commands/status.test.ts +++ b/packages/cli/__tests__/commands/status.test.ts @@ -605,6 +605,21 @@ describe("status command", () => { expect(errors).toContain("--interval must be a positive integer"); }); + it("ignores --interval entirely when --watch is not set", async () => { + mockTmux.mockResolvedValue(null); + mockSessionManager.list.mockResolvedValue([]); + + // Invalid value (0) should NOT cause an error without --watch + await expect( + program.parseAsync(["node", "test", "status", "--interval", "0"]), + ).resolves.not.toThrow(); + + // Valid value should also be silently ignored without --watch + await expect( + program.parseAsync(["node", "test", "status", "--interval", "10"]), + ).resolves.not.toThrow(); + }); + it("schedules watch refreshes with the requested interval", async () => { mockTmux.mockResolvedValue(null); setIntervalSpy = vi.spyOn(globalThis, "setInterval").mockImplementation(() => 1 as never); diff --git a/packages/cli/src/commands/status.ts b/packages/cli/src/commands/status.ts index a6dc5e74d..625e06370 100644 --- a/packages/cli/src/commands/status.ts +++ b/packages/cli/src/commands/status.ts @@ -243,11 +243,13 @@ export function registerStatus(program: Command): void { } let watchIntervalSeconds = DEFAULT_WATCH_INTERVAL_SECONDS; - try { - watchIntervalSeconds = parseWatchIntervalSeconds(opts.interval); - } catch (err) { - console.error(chalk.red(err instanceof Error ? err.message : String(err))); - process.exit(1); + if (opts.watch) { + try { + watchIntervalSeconds = parseWatchIntervalSeconds(opts.interval); + } catch (err) { + console.error(chalk.red(err instanceof Error ? err.message : String(err))); + process.exit(1); + } } const renderStatus = async (refreshing = false): Promise => {