Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display session ID in CLI mode #6898

Merged
merged 17 commits into from
Feb 24, 2025
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions openhands/core/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ async def main(loop: asyncio.AbstractEventLoop):
initial_user_action = MessageAction(content=task_str) if task_str else None

sid = str(uuid4())
display_message(f'Session ID: {sid}')

runtime = create_runtime(config, sid=sid, headless_mode=True)
await runtime.connect()
Expand Down
40 changes: 40 additions & 0 deletions tests/unit/test_cli_sid.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import asyncio
from unittest.mock import AsyncMock, patch

import pytest

from openhands.core.cli import main
from openhands.core.schema import AgentState


@pytest.fixture
def mock_runtime():
with patch('openhands.core.cli.create_runtime') as mock_create_runtime:
mock_runtime_instance = AsyncMock()
mock_create_runtime.return_value = mock_runtime_instance
yield mock_runtime_instance


@pytest.fixture
def mock_agent():
with patch('openhands.core.cli.create_agent') as mock_create_agent:
mock_agent_instance = AsyncMock()
mock_create_agent.return_value = mock_agent_instance
yield mock_agent_instance


@pytest.fixture
def mock_controller():
with patch('openhands.core.cli.create_controller') as mock_create_controller:
mock_controller_instance = AsyncMock()
mock_create_controller.return_value = (mock_controller_instance, None)
yield mock_controller_instance


@pytest.mark.asyncio
@patch('builtins.input', return_value='')
async def test_cli_session_id_output(mock_runtime, mock_agent, mock_controller, capsys):
# display sid in console when starting
await main(asyncio.get_event_loop())
captured = capsys.readouterr()
assert 'Session ID:' in captured.out
Loading