Skip to content

Commit 9df3e8b

Browse files
committed
fix(cli): wire user_skills flag through call chain and fix tests
- Pass user_skills from simple_main to run_cli_entry - Pass load_user_skills through agent_chat to setup functions - Update test_main.py to account for user_skills parameter - Fix formatting issues (trailing whitespace)
1 parent e075b1e commit 9df3e8b

File tree

6 files changed

+17
-21
lines changed

6 files changed

+17
-21
lines changed

openhands_cli/agent_chat.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,7 @@ def run_cli_entry(resume_conversation_id: str | None = None, user_skills: bool =
8383
return
8484

8585
try:
86-
# Keep backward compatibility with upstream tests by not passing kwargs here
87-
initialized_agent = verify_agent_exists_or_setup_agent()
86+
initialized_agent = verify_agent_exists_or_setup_agent(load_user_skills=user_skills)
8887
except MissingAgentSpec:
8988
print_formatted_text(HTML('\n<yellow>Setup is required to use OpenHands CLI.</yellow>'))
9089
print_formatted_text(HTML('\n<yellow>Goodbye! 👋</yellow>'))

openhands_cli/argparsers/main_parser.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
def create_main_parser() -> argparse.ArgumentParser:
77
"""Create the main argument parser with CLI as default and serve as subcommand.
8-
8+
99
Returns:
1010
The configured argument parser
1111
"""
@@ -23,7 +23,7 @@ def create_main_parser() -> argparse.ArgumentParser:
2323
openhands serve --gpu # Launch GUI server with GPU support
2424
"""
2525
)
26-
26+
2727
# CLI arguments at top level (default mode)
2828
parser.add_argument(
2929
'--resume',
@@ -44,7 +44,7 @@ def create_main_parser() -> argparse.ArgumentParser:
4444
help='Disable loading user skills from ~/.openhands'
4545
)
4646
parser.set_defaults(user_skills=True)
47-
47+
4848
# Only serve as subcommand
4949
subparsers = parser.add_subparsers(
5050
dest='command',
@@ -66,6 +66,5 @@ def create_main_parser() -> argparse.ArgumentParser:
6666
action='store_true',
6767
help='Enable GPU support in the Docker container'
6868
)
69-
69+
7070
return parser
71-

openhands_cli/setup.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,15 @@ def verify_agent_exists_or_setup_agent(*, load_user_skills: bool = True) -> Agen
4646
"""
4747
settings_screen = SettingsScreen()
4848
try:
49-
# Keep backward compatibility with upstream tests by not passing kwargs here
50-
agent = load_agent_specs()
49+
agent = load_agent_specs(load_user_skills=load_user_skills)
5150
return agent
5251
except MissingAgentSpec:
5352
# For first-time users, show the full settings flow with choice between basic/advanced
5453
settings_screen.configure_settings(first_time=True)
5554

5655

5756
# Try once again after settings setup attempt
58-
# Keep backward compatibility with upstream tests by not passing kwargs here
59-
return load_agent_specs()
57+
return load_agent_specs(load_user_skills=load_user_skills)
6058

6159

6260
def setup_conversation(
@@ -104,4 +102,3 @@ def setup_conversation(
104102
HTML(f'<green>✓ Agent initialized with model: {agent.llm.model}</green>')
105103
)
106104
return conversation
107-

openhands_cli/simple_main.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def main() -> None:
4343

4444
# Start agent chat
4545
# Keep call signature backward-compatible for upstream tests
46-
run_cli_entry(resume_conversation_id=args.resume)
46+
run_cli_entry(resume_conversation_id=args.resume, user_skills=args.user_skills)
4747
except KeyboardInterrupt:
4848
print_formatted_text(HTML('\n<yellow>Goodbye! 👋</yellow>'))
4949
except EOFError:
@@ -58,4 +58,3 @@ def main() -> None:
5858

5959
if __name__ == '__main__':
6060
main()
61-

tests/test_cli_user_skills_flags.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@ def test_user_skills_disable_then_enable_then_disable_last_wins():
2424
parser = create_main_parser()
2525
args = parser.parse_args(['--user-skills', '--no-user-skills'])
2626
assert args.user_skills is False
27-
27+

tests/test_main.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ def test_main_starts_agent_chat_directly(
2525
# Should complete without raising an exception (graceful exit)
2626
simple_main.main()
2727

28-
# Should call run_cli_entry with no resume conversation ID
29-
mock_run_agent_chat.assert_called_once_with(resume_conversation_id=None)
28+
# Should call run_cli_entry with no resume conversation ID and default user_skills=True
29+
mock_run_agent_chat.assert_called_once_with(resume_conversation_id=None, user_skills=True)
3030

3131
@patch("openhands_cli.agent_chat.run_cli_entry")
3232
@patch("sys.argv", ["openhands"])
@@ -86,17 +86,19 @@ def test_main_with_resume_argument(self, mock_run_agent_chat: MagicMock) -> None
8686
# Should complete without raising an exception (graceful exit)
8787
simple_main.main()
8888

89-
# Should call run_cli_entry with the provided resume conversation ID
89+
# Should call run_cli_entry with the provided resume conversation ID and default user_skills=True
9090
mock_run_agent_chat.assert_called_once_with(
91-
resume_conversation_id="test-conversation-id"
91+
resume_conversation_id="test-conversation-id", user_skills=True
9292
)
9393

9494

9595
@pytest.mark.parametrize(
9696
"argv,expected_kwargs",
9797
[
98-
(["openhands"], {"resume_conversation_id": None}),
99-
(["openhands", "--resume", "test-id"], {"resume_conversation_id": "test-id"}),
98+
(["openhands"], {"resume_conversation_id": None, "user_skills": True}),
99+
(["openhands", "--resume", "test-id"], {"resume_conversation_id": "test-id", "user_skills": True}),
100+
(["openhands", "--no-user-skills"], {"resume_conversation_id": None, "user_skills": False}),
101+
(["openhands", "--resume", "test-id", "--no-user-skills"], {"resume_conversation_id": "test-id", "user_skills": False}),
100102
],
101103
)
102104
def test_main_cli_calls_run_cli_entry(monkeypatch, argv, expected_kwargs):

0 commit comments

Comments
 (0)