diff --git a/src/toad/widgets/comms_command_dialog.py b/src/toad/widgets/comms_command_dialog.py index 4e0e383cc..6ae20912d 100644 --- a/src/toad/widgets/comms_command_dialog.py +++ b/src/toad/widgets/comms_command_dialog.py @@ -74,8 +74,10 @@ def bind_control(self): self.paint() def paint(self): - self.label = next((choice.name for choice in self.field.metadata(PreparedChoices).parameter.options - if choice.value == self.field.value), 'Choose / connect a provider…') + parameter = self.field.metadata(PreparedChoices).parameter + current = parameter.choice_value(self.field.value) + self.label = next((choice.name for choice in parameter.options + if choice.value == current), 'Choose / connect a provider…') @on(Button.Pressed) def on_button_pressed(self, event: Button.Pressed): @@ -86,7 +88,7 @@ def on_button_pressed(self, event: Button.Pressed): async def choose(self): value = await self.app.push_screen_wait(CatalogChoiceDialog(self)) if value is not None and self.is_attached: - self.send(value) + self.send(self.field.metadata(PreparedChoices).parameter.editor_value(value)) class CatalogFieldSelection(ModelSelection): @@ -96,11 +98,12 @@ def __init__(self, editor: CatalogField): @property def choices(self): - return self.editor.field.metadata(PreparedChoices).parameter.options + return tuple(choice for choice in self.editor.field.metadata(PreparedChoices).parameter.options + if choice.value is not None) @property def current(self): - return self.editor.field.value + return self.editor.field.metadata(PreparedChoices).parameter.choice_value(self.editor.field.value) @property def selection_active(self): diff --git a/tests/textual/test_application_actions_in_the_running_app.py b/tests/textual/test_application_actions_in_the_running_app.py index cc9fa98bd..8e0b9c638 100644 --- a/tests/textual/test_application_actions_in_the_running_app.py +++ b/tests/textual/test_application_actions_in_the_running_app.py @@ -1,4 +1,5 @@ """Textual-facing: application actions (help, settings screen, command palette, sidebar buttons, tab close) run through Textual screens and keep the session, its draft and the saved settings.""" +from agent_comms.nominal.field_codec import FieldCodec from toad.forms.editors import ChoicesEditor from toad.launch_binding import AgentAttached @@ -15,7 +16,7 @@ from toad.preferences import SETTINGS from toad.screens.keymap import KeymapScreen from toad.screens.settings import SettingsScreen -from toad.widgets.comms_command_dialog import CatalogField +from toad.widgets.comms_command_dialog import CatalogField, CatalogFieldSelection from toad.widgets.comms_sidebar import CommsSidebar, NewSessionButton from toad.widgets.footer import ToadFooter from toad.widgets.session_tabs import SessionTabClose @@ -175,6 +176,10 @@ def call(self, request): assert isinstance(dialog.form.values["thinking_level"].editor, ChoicesEditor) released.set() await ui.until(lambda: not CommandPreparation.running_on(dialog), why="the real catalogs to arrive") + selection = CatalogFieldSelection(dialog.form.values['model'].editor) + parameter = dialog.choices['model'].parameter + assert selection.current == FieldCodec.encode(parameter.value) + assert selection.choices == tuple(choice for choice in parameter.options if choice.value is not None) button = dialog.query_one(ApplyCommandButton) await ui.until(lambda: not button.disabled, why="the command values to be accepted") editor = dialog.form.values["name"].editor