2026-04-10 16:55:51 +09:00
|
|
|
"""Tests for gateway /yolo session scoping."""
|
|
|
|
|
|
|
|
|
|
import os
|
|
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
|
|
|
|
|
|
import gateway.run as gateway_run
|
|
|
|
|
from gateway.config import Platform
|
|
|
|
|
from gateway.platforms.base import MessageEvent
|
|
|
|
|
from gateway.session import SessionSource
|
refactor: remove dead code — 1,784 lines across 77 files (#9180)
Deep scan with vulture, pyflakes, and manual cross-referencing identified:
- 41 dead functions/methods (zero callers in production)
- 7 production-dead functions (only test callers, tests deleted)
- 5 dead constants/variables
- ~35 unused imports across agent/, hermes_cli/, tools/, gateway/
Categories of dead code removed:
- Refactoring leftovers: _set_default_model, _setup_copilot_reasoning_selection,
rebuild_lookups, clear_session_context, get_logs_dir, clear_session
- Unused API surface: search_models_dev, get_pricing, skills_categories,
get_read_files_summary, clear_read_tracker, menu_labels, get_spinner_list
- Dead compatibility wrappers: schedule_cronjob, list_cronjobs, remove_cronjob
- Stale debug helpers: get_debug_session_info copies in 4 tool files
(centralized version in debug_helpers.py already exists)
- Dead gateway methods: send_emote, send_notice (matrix), send_reaction
(bluebubbles), _normalize_inbound_text (feishu), fetch_room_history
(matrix), _start_typing_indicator (signal), parse_feishu_post_content
- Dead constants: NOUS_API_BASE_URL, SKILLS_TOOL_DESCRIPTION,
FILE_TOOLS, VALID_ASPECT_RATIOS, MEMORY_DIR
- Unused UI code: _interactive_provider_selection,
_interactive_model_selection (superseded by prompt_toolkit picker)
Test suite verified: 609 tests covering affected files all pass.
Tests for removed functions deleted. Tests using removed utilities
(clear_read_tracker, MEMORY_DIR) updated to use internal APIs directly.
2026-04-13 16:32:04 -07:00
|
|
|
from tools.approval import disable_session_yolo, is_session_yolo_enabled
|
2026-04-10 16:55:51 +09:00
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(autouse=True)
|
|
|
|
|
def _clean_yolo_state(monkeypatch):
|
|
|
|
|
monkeypatch.delenv("HERMES_YOLO_MODE", raising=False)
|
refactor: remove dead code — 1,784 lines across 77 files (#9180)
Deep scan with vulture, pyflakes, and manual cross-referencing identified:
- 41 dead functions/methods (zero callers in production)
- 7 production-dead functions (only test callers, tests deleted)
- 5 dead constants/variables
- ~35 unused imports across agent/, hermes_cli/, tools/, gateway/
Categories of dead code removed:
- Refactoring leftovers: _set_default_model, _setup_copilot_reasoning_selection,
rebuild_lookups, clear_session_context, get_logs_dir, clear_session
- Unused API surface: search_models_dev, get_pricing, skills_categories,
get_read_files_summary, clear_read_tracker, menu_labels, get_spinner_list
- Dead compatibility wrappers: schedule_cronjob, list_cronjobs, remove_cronjob
- Stale debug helpers: get_debug_session_info copies in 4 tool files
(centralized version in debug_helpers.py already exists)
- Dead gateway methods: send_emote, send_notice (matrix), send_reaction
(bluebubbles), _normalize_inbound_text (feishu), fetch_room_history
(matrix), _start_typing_indicator (signal), parse_feishu_post_content
- Dead constants: NOUS_API_BASE_URL, SKILLS_TOOL_DESCRIPTION,
FILE_TOOLS, VALID_ASPECT_RATIOS, MEMORY_DIR
- Unused UI code: _interactive_provider_selection,
_interactive_model_selection (superseded by prompt_toolkit picker)
Test suite verified: 609 tests covering affected files all pass.
Tests for removed functions deleted. Tests using removed utilities
(clear_read_tracker, MEMORY_DIR) updated to use internal APIs directly.
2026-04-13 16:32:04 -07:00
|
|
|
disable_session_yolo("agent:main:telegram:dm:chat-a")
|
|
|
|
|
disable_session_yolo("agent:main:telegram:dm:chat-b")
|
2026-04-10 16:55:51 +09:00
|
|
|
yield
|
|
|
|
|
monkeypatch.delenv("HERMES_YOLO_MODE", raising=False)
|
refactor: remove dead code — 1,784 lines across 77 files (#9180)
Deep scan with vulture, pyflakes, and manual cross-referencing identified:
- 41 dead functions/methods (zero callers in production)
- 7 production-dead functions (only test callers, tests deleted)
- 5 dead constants/variables
- ~35 unused imports across agent/, hermes_cli/, tools/, gateway/
Categories of dead code removed:
- Refactoring leftovers: _set_default_model, _setup_copilot_reasoning_selection,
rebuild_lookups, clear_session_context, get_logs_dir, clear_session
- Unused API surface: search_models_dev, get_pricing, skills_categories,
get_read_files_summary, clear_read_tracker, menu_labels, get_spinner_list
- Dead compatibility wrappers: schedule_cronjob, list_cronjobs, remove_cronjob
- Stale debug helpers: get_debug_session_info copies in 4 tool files
(centralized version in debug_helpers.py already exists)
- Dead gateway methods: send_emote, send_notice (matrix), send_reaction
(bluebubbles), _normalize_inbound_text (feishu), fetch_room_history
(matrix), _start_typing_indicator (signal), parse_feishu_post_content
- Dead constants: NOUS_API_BASE_URL, SKILLS_TOOL_DESCRIPTION,
FILE_TOOLS, VALID_ASPECT_RATIOS, MEMORY_DIR
- Unused UI code: _interactive_provider_selection,
_interactive_model_selection (superseded by prompt_toolkit picker)
Test suite verified: 609 tests covering affected files all pass.
Tests for removed functions deleted. Tests using removed utilities
(clear_read_tracker, MEMORY_DIR) updated to use internal APIs directly.
2026-04-13 16:32:04 -07:00
|
|
|
disable_session_yolo("agent:main:telegram:dm:chat-a")
|
|
|
|
|
disable_session_yolo("agent:main:telegram:dm:chat-b")
|
2026-04-10 16:55:51 +09:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def _make_runner():
|
|
|
|
|
runner = object.__new__(gateway_run.GatewayRunner)
|
|
|
|
|
runner.session_store = None
|
|
|
|
|
runner.config = None
|
|
|
|
|
return runner
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _make_event(chat_id: str) -> MessageEvent:
|
|
|
|
|
source = SessionSource(
|
|
|
|
|
platform=Platform.TELEGRAM,
|
|
|
|
|
user_id=f"user-{chat_id}",
|
|
|
|
|
chat_id=chat_id,
|
|
|
|
|
user_name="tester",
|
|
|
|
|
chat_type="dm",
|
|
|
|
|
)
|
|
|
|
|
return MessageEvent(text="/yolo", source=source)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
|
|
|
async def test_yolo_command_toggles_only_current_session(monkeypatch):
|
|
|
|
|
runner = _make_runner()
|
|
|
|
|
|
|
|
|
|
event_a = _make_event("chat-a")
|
|
|
|
|
session_a = runner._session_key_for_source(event_a.source)
|
|
|
|
|
session_b = runner._session_key_for_source(_make_event("chat-b").source)
|
|
|
|
|
|
|
|
|
|
result_on = await runner._handle_yolo_command(event_a)
|
|
|
|
|
|
|
|
|
|
assert "ON" in result_on
|
|
|
|
|
assert is_session_yolo_enabled(session_a) is True
|
|
|
|
|
assert is_session_yolo_enabled(session_b) is False
|
|
|
|
|
assert os.environ.get("HERMES_YOLO_MODE") is None
|
|
|
|
|
|
|
|
|
|
result_off = await runner._handle_yolo_command(event_a)
|
|
|
|
|
|
|
|
|
|
assert "OFF" in result_off
|
|
|
|
|
assert is_session_yolo_enabled(session_a) is False
|
|
|
|
|
assert os.environ.get("HERMES_YOLO_MODE") is None
|