From 25b3721184f19ae45b052414fe7662df224f96eb Mon Sep 17 00:00:00 2001 From: Ziang Zhang Date: Mon, 8 Jun 2026 14:30:28 +0800 Subject: [PATCH 1/3] 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 ec6c937649eabe02bf305fc2af1634455ace1a0a Mon Sep 17 00:00:00 2001 From: Ziang Zhang Date: Mon, 8 Jun 2026 09:46:07 +0800 Subject: [PATCH 2/3] 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 2bbe1f207d784bf6d03370486e79e14dd919af56 Mon Sep 17 00:00:00 2001 From: Ziang Zhang Date: Tue, 9 Jun 2026 18:50:27 +0800 Subject: [PATCH 3/3] 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