From ef2cc9d87bce04bfda50884c6369a7270ac0da29 Mon Sep 17 00:00:00 2001 From: Ziang Zhang Date: Mon, 8 Jun 2026 10:05:52 +0800 Subject: [PATCH 1/4] fix: resolve NameError in settings Appearance tab by defining select_widget The method created a Select widget inline inside but then referenced an undefined variable to call and add a duplicate field, causing a NameError crash whenever the Appearance category was selected. Fix: store the Select widget in a local variable before passing it to , and remove the duplicate field addition. Closes #42 --- trushell/commands/settings.py | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/trushell/commands/settings.py b/trushell/commands/settings.py index 42214df..b7243eb 100644 --- a/trushell/commands/settings.py +++ b/trushell/commands/settings.py @@ -167,15 +167,11 @@ def add_field(label_text: str, widget: Static | Input | Select | Switch) -> None Input(value=str(self.dirty_settings.get("prompt_symbol", self.settings.get("prompt_symbol", "➜"))), id="prompt_symbol"), ) elif current_cat == "Appearance": - add_field( - "Theme:", - Select( - options=self.THEME_OPTIONS, - value=str(self.dirty_settings.get("theme", self.settings.get("theme", "dark"))), - id="theme_selector", - ), + select_widget = Select( + options=self.THEME_OPTIONS, + value=str(self.dirty_settings.get("theme", self.settings.get("theme", "dark"))), + id="theme_selector", ) - select_widget.watch_value(lambda value: self._track_change("theme", value)) add_field("Theme:", select_widget) elif current_cat == "Navigation": add_field( From 3d21a29babce72e96bc6fa36397cc3d82d29942c Mon Sep 17 00:00:00 2001 From: Ziang Zhang Date: Mon, 8 Jun 2026 14:30:28 +0800 Subject: [PATCH 2/4] test: fix help docs test by adding _import_module to fake kernel The test_run_help_prints_docstring_for_known_command test was failing because the fake kernel lacked a _import_module method, causing the module import to fail silently and fall through to the error message. Add a working _fake_import_module that uses importlib to resolve the module path, allowing run_help to read and print the docstring. --- tests/test_help_docs.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tests/test_help_docs.py b/tests/test_help_docs.py index 8eb08dd..99e9b03 100644 --- a/tests/test_help_docs.py +++ b/tests/test_help_docs.py @@ -1,18 +1,24 @@ from __future__ import annotations +import importlib from types import SimpleNamespace from trushell.commands.core import run_help def test_run_help_prints_docstring_for_known_command(monkeypatch, capsys): + def _fake_import_module(path: str): + module = importlib.import_module(path.replace("/", ".").removesuffix(".py")) + return module + fake_kernel = SimpleNamespace( registry={ "settings": { "path": "trushell/commands/settings.py", "function": "run_settings", } - } + }, + _import_module=_fake_import_module, ) monkeypatch.setattr("trushell.core.trukernel.get_kernel", lambda: fake_kernel) From 0d45b9e73c64abe8cc4e9abcb3357f0ed90bebeb Mon Sep 17 00:00:00 2001 From: Ziang Zhang Date: Mon, 8 Jun 2026 09:46:07 +0800 Subject: [PATCH 3/4] fix: resolve NameError crash at startup by defining argv before use The function referenced a bare name that was never imported or defined, causing a NameError crash on every invocation. Fix: move before the conditional block so it is always defined when reached by the comparison at the end of the function. Closes #40 --- trushell/cli.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/trushell/cli.py b/trushell/cli.py index ff10ff7..ecf12a4 100644 --- a/trushell/cli.py +++ b/trushell/cli.py @@ -26,11 +26,11 @@ def app_with_lower() -> None: """Entry point that normalizes the first argument to lowercase for case-insensitive invocation.""" - if len(sys.argv) > 1: - # Create a local copy to avoid mutating the global sys.argv - argv_copy = sys.argv.copy() - if argv_copy[1].lower() not in {"--help", "-h", "version"}: - raw = " ".join(argv_copy[1:]) + # Create a local copy to avoid mutating the global sys.argv + argv = sys.argv.copy() + if len(argv) > 1: + if argv[1].lower() not in {"--help", "-h", "version"}: + raw = " ".join(argv[1:]).lower() get_kernel().execute_command(raw) return From 5e0c4cafbd519a65710e42a2d57d6970c271247a Mon Sep 17 00:00:00 2001 From: Ziang Zhang Date: Tue, 9 Jun 2026 18:50:49 +0800 Subject: [PATCH 4/4] fix: remove dead _fake_import_module from test --- tests/test_help_docs.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/tests/test_help_docs.py b/tests/test_help_docs.py index c419629..c9a8637 100644 --- a/tests/test_help_docs.py +++ b/tests/test_help_docs.py @@ -1,16 +1,11 @@ from __future__ import annotations -import importlib from types import SimpleNamespace from trushell.commands.core import run_help def test_run_help_prints_docstring_for_known_command(monkeypatch, capsys): - def _fake_import_module(path: str): - module = importlib.import_module(path.replace("/", ".").removesuffix(".py")) - return module - fake_kernel = SimpleNamespace( registry={ "settings": { @@ -18,7 +13,6 @@ def _fake_import_module(path: str): "function": "run_settings", } }, - _import_module=_fake_import_module, ) # Provide a minimal module object with the expected function and