From 340731c3d7fd14a348802cb6c1d633ddecf2d085 Mon Sep 17 00:00:00 2001 From: CadeYu Date: Sat, 21 Mar 2026 14:03:11 +0800 Subject: [PATCH] fix(cli): use typer.Exit for model selection --- cli/utils.py | 5 +++-- tests/test_openrouter_model_selection.py | 14 ++++++++------ 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/cli/utils.py b/cli/utils.py index 8c4b1a85..508c6eb9 100644 --- a/cli/utils.py +++ b/cli/utils.py @@ -1,6 +1,7 @@ from typing import Callable, List, Optional, Tuple, Dict import questionary +import typer from rich.console import Console @@ -95,14 +96,14 @@ def resolve_model_choice( """Resolve built-in and custom model selections into a concrete model id.""" if choice is None: console.print(f"\n[red]No {model_role.lower()} llm engine selected. Exiting...[/red]") - exit(1) + raise typer.Exit(1) if provider.lower() == "openrouter" and choice == CUSTOM_OPENROUTER_MODEL: prompt_fn = prompt_fn or prompt_custom_openrouter_model custom_model = prompt_fn(model_role) if not custom_model or not custom_model.strip(): console.print("\n[red]No OpenRouter model ID provided. Exiting...[/red]") - exit(1) + raise typer.Exit(1) return custom_model.strip() return choice diff --git a/tests/test_openrouter_model_selection.py b/tests/test_openrouter_model_selection.py index dba5b131..80400ebf 100644 --- a/tests/test_openrouter_model_selection.py +++ b/tests/test_openrouter_model_selection.py @@ -1,5 +1,7 @@ import unittest +import typer + from cli.utils import CUSTOM_OPENROUTER_MODEL, resolve_model_choice @@ -20,29 +22,29 @@ class OpenRouterModelSelectionTests(unittest.TestCase): self.assertEqual(chosen, "minimax/minimax-m2.1") def test_exit_on_no_choice(self): - with self.assertRaises(SystemExit) as cm: + with self.assertRaises(typer.Exit) as cm: resolve_model_choice("openrouter", None, "Quick-Thinking") - self.assertEqual(cm.exception.code, 1) + self.assertEqual(cm.exception.exit_code, 1) def test_exit_on_empty_custom_model_input(self): - with self.assertRaises(SystemExit) as cm: + with self.assertRaises(typer.Exit) as cm: resolve_model_choice( "openrouter", CUSTOM_OPENROUTER_MODEL, "Deep-Thinking", prompt_fn=lambda _: " ", ) - self.assertEqual(cm.exception.code, 1) + self.assertEqual(cm.exception.exit_code, 1) def test_exit_on_none_custom_model_input(self): - with self.assertRaises(SystemExit) as cm: + with self.assertRaises(typer.Exit) as cm: resolve_model_choice( "openrouter", CUSTOM_OPENROUTER_MODEL, "Deep-Thinking", prompt_fn=lambda _: None, ) - self.assertEqual(cm.exception.code, 1) + self.assertEqual(cm.exception.exit_code, 1) if __name__ == "__main__":