"Vibe-Trading: Your Personal Trading Agent"
Python ai-agentalgorithmic-tradingbacktestingfintechllmmcpmulti-agentpythonquantitative-financetrading
fix(cli): reject non-positive --limit for list and memory search
Rudy Celeklia539ee223ed2
diff --git a/agent/cli/_legacy.py b/agent/cli/_legacy.pyindex 71742bae2..9af4c9018 100644--- a/agent/cli/_legacy.py+++ b/agent/cli/_legacy.py@@ -5487,6 +5487,17 @@ def _dispatch_connector(args: argparse.Namespace) -> int:# CLI entrypoint# ---------------------------------------------------------------------------+def _positive_int(value: str) -> int:+ """argparse type for counts that must be at least one."""+ try:+ number = int(value)+ except ValueError:+ raise argparse.ArgumentTypeError(f"invalid int value: {value!r}") from None+ if number < 1:+ raise argparse.ArgumentTypeError(f"must be a positive integer, got {number}")+ return number++def _build_parser() -> argparse.ArgumentParser:"""Build the CLI parser with subcommands and compatibility flags."""parser = argparse.ArgumentParser(description="Vibe-Trading CLI")@@ -5578,7 +5589,7 @@ def _build_parser() -> argparse.ArgumentParser:channels_pairing.add_argument("pairing_args", nargs="*", help="Pairing command arguments")list_parser = subparsers.add_parser("list", help="List runs")- list_parser.add_argument("--limit", dest="list_limit", type=int, default=20, help="Maximum number of runs")+ list_parser.add_argument("--limit", dest="list_limit", type=_positive_int, default=20, help="Maximum number of runs")show_parser = subparsers.add_parser("show", help="Show run details")show_parser.add_argument("run_id", help="Run identifier")@@ -5643,7 +5654,7 @@ def _build_parser() -> argparse.ArgumentParser:memory_search_parser = memory_subparsers.add_parser("search", help="Recall memories for a query")memory_search_parser.add_argument("query", help="Search text")memory_search_parser.add_argument(- "--limit", dest="memory_limit", type=int, default=5, help="Maximum matches (default: 5)"+ "--limit", dest="memory_limit", type=_positive_int, default=5, help="Maximum matches (default: 5)")memory_forget_parser = memory_subparsers.add_parser("forget", help="Remove a memory entry")diff --git a/agent/tests/test_cli_limit_validation.py b/agent/tests/test_cli_limit_validation.pynew file mode 100644index 000000000..92f6a0cc0--- /dev/null+++ b/agent/tests/test_cli_limit_validation.py@@ -0,0 +1,31 @@+"""`list --limit` and `memory search --limit` must be positive counts."""++from __future__ import annotations++import pytest++from cli import _legacy+++ "argv",+ [+ ["list", "--limit", "-1"],+ ["list", "--limit", "0"],+ ["memory", "search", "runbook", "--limit", "-1"],+ ["memory", "search", "runbook", "--limit", "0"],+ ],+)+def test_non_positive_limit_is_a_usage_error(+ argv: list[str], capsys: pytest.CaptureFixture[str]+) -> None:+ with pytest.raises(SystemExit) as exc:+ _legacy._build_parser().parse_args(argv)+ assert exc.value.code == 2+ assert "positive integer" in capsys.readouterr().err+++def test_positive_limit_is_accepted() -> None:+ parser = _legacy._build_parser()+ assert parser.parse_args(["list", "--limit", "3"]).list_limit == 3+ assert parser.parse_args(["memory", "search", "q", "--limit", "2"]).memory_limit == 2