From f10df8b6fe4139abdd8e00301370c9a219c01c27 Mon Sep 17 00:00:00 2001 From: bhuvan-somisetty Date: Tue, 15 Sep 2026 13:01:53 +0530 Subject: [PATCH] fix: reject non-positive --interval in concore watch --interval was passed straight through to time.sleep() with no validation, so a negative value crashed with an unhandled ValueError instead of a normal CLI error, and 0 turned the watch loop into a busy-loop. Fixes #582 --- concore_cli/cli.py | 3 +++ tests/test_cli.py | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/concore_cli/cli.py b/concore_cli/cli.py index 4b376c9..c3ef2f3 100644 --- a/concore_cli/cli.py +++ b/concore_cli/cli.py @@ -167,6 +167,9 @@ def stop(): @click.option("--once", is_flag=True, help="Print a single snapshot and exit") def watch(study_dir, interval, once): """Watch a running simulation study for live monitoring""" + if interval <= 0: + console.print("[red]Error:[/red] --interval must be greater than 0") + sys.exit(1) try: watch_study(study_dir, interval, once, console) except Exception as e: diff --git a/tests/test_cli.py b/tests/test_cli.py index d746040..8f4506a 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -786,6 +786,24 @@ def test_inspect_missing_source_file(self): self.assertEqual(result.exit_code, 0) self.assertIn("Missing files", result.output) + def test_watch_rejects_negative_interval(self): + with self.runner.isolated_filesystem(temp_dir=self.temp_dir): + os.mkdir("study") + result = self.runner.invoke( + cli, ["watch", "study", "--interval", "-1"] + ) + self.assertEqual(result.exit_code, 1) + self.assertIn("--interval must be greater than 0", result.output) + + def test_watch_rejects_zero_interval(self): + with self.runner.isolated_filesystem(temp_dir=self.temp_dir): + os.mkdir("study") + result = self.runner.invoke( + cli, ["watch", "study", "--interval", "0"] + ) + self.assertEqual(result.exit_code, 1) + self.assertIn("--interval must be greater than 0", result.output) + if __name__ == "__main__": unittest.main()