Private
Public Access
0
0
Files
manual_slop/tests/test_log_management_ui.py
T
ed 94cfb1b5ff test(fix): Update tests to route config through AppController/env var
Four test files had patches/monkeypatches that referenced the
removed src.models.load_config or src.models.CONFIG_PATH module
constant. These all stem from the config I/O refactor (commit
7bcb5a8c) that renamed load_config/save_config to private I/O
primitives.

- tests/test_external_editor_gui.py: 2 sites changed from
  monkeypatch.setattr(models_module, 'load_config', ...) to
  monkeypatch.setattr('src.app_controller.AppController.load_config', ...)
- tests/test_external_mcp_e2e.py: CONFIG_PATH monkeypatch changed
  to SLOP_CONFIG env var (the only supported override path)
- tests/test_log_management_ui.py: same CONFIG_PATH -> SLOP_CONFIG fix
- tests/test_gen_send_empty_context.py: _StubController now receives
  ui_selected_context_files and _pending_generation_action from the
  app_instance BEFORE being assigned as controller (App.__getattr__
  delegates to controller, so attrs must be on the stub first)

Also: deleted tests/artifacts/manualslop_layout.ini (gitignored
stale file from March 4 referencing pre-refactor window names like
"Projects"/"Files"/"Screenshots" that no longer exist in the code).
Repo-root manualslop_layout.ini still references the same old
window names; user should run the existing "Reset Layout" command
(or delete it manually) to regenerate with the current window
catalog (Context Hub / AI Settings Hub / Discussion Hub / etc.).

Verified: 13 targeted tests pass:
- test_external_editor_gui.py (5/5)
- test_external_mcp_e2e.py (1/1)
- test_log_management_ui.py (2/2)
- test_gen_send_empty_context.py (5/5)
2026-06-07 21:21:38 -04:00

105 lines
3.4 KiB
Python

import pytest
from unittest.mock import MagicMock, patch
from pathlib import Path
from src import gui_2
from src.gui_2 import App
@pytest.fixture
def mock_config(tmp_path: Path) -> Path:
config_path = tmp_path / "config.toml"
config_path.write_text("""[projects]
paths = []
active = ""
[ai]
provider = "gemini"
model = "model"
""", encoding="utf-8")
return config_path
@pytest.fixture
def mock_project(tmp_path: Path) -> Path:
project_path = tmp_path / "project.toml"
project_path.write_text("""[project]
name = "test"
[discussion]
roles = ["User", "AI"]
active = "main"
[discussion.discussions.main]
history = []
""", encoding="utf-8")
return project_path
@pytest.fixture
def app_instance(mock_config: Path, mock_project: Path, monkeypatch: pytest.MonkeyPatch) -> App:
monkeypatch.setenv("SLOP_CONFIG", str(mock_config))
monkeypatch.setattr("src.gui_2.filedialog", MagicMock())
with patch("src.project_manager.load_project") as mock_load, \
patch("src.session_logger.open_session"), \
patch("src.session_logger.reset_session"):
mock_load.return_value = {
"project": {"name": "test"},
"discussion": {"roles": ["User", "AI"], "active": "main", "discussions": {"main": {"history": []}}},
"files": {"paths": []},
"screenshots": {"paths": []}
}
# Mock the __init__ to do nothing, then set the fields we need manually
with patch.object(App, '__init__', lambda self: None):
app = App()
app.show_windows = {"Log Management": False}
app.ui_state = MagicMock()
app.ui_files_base_dir = "."
app.files = []
app.controller = MagicMock()
app.controller.event_queue = MagicMock()
# Since we bypassed __init__, we need to bind the method manually
# but python allows calling it directly.
return app
def test_log_management_init(app_instance: App) -> None:
app = app_instance
assert "Log Management" in app.show_windows
assert app.show_windows["Log Management"] is False
assert hasattr(gui_2, "render_log_management")
assert callable(gui_2.render_log_management)
def test_render_log_management_logic(app_instance: App) -> None:
app = app_instance
app.show_windows["Log Management"] = True
# Mock LogRegistry
with patch("src.log_registry.LogRegistry") as MockRegistry, \
patch("src.gui_2.imscope") as mock_imscope, \
patch("src.gui_2.imgui.begin_table") as mock_begin_table, \
patch("src.gui_2.imgui.text") as mock_text, \
patch("src.gui_2.imgui.end_table"), \
patch("src.gui_2.imgui.push_style_color"), \
patch("src.gui_2.imgui.pop_style_color"), \
patch("src.gui_2.imgui.table_setup_column"), \
patch("src.gui_2.imgui.table_headers_row"), \
patch("src.gui_2.imgui.table_next_row"), \
patch("src.gui_2.imgui.table_next_column"), \
patch("src.gui_2.imgui.same_line"), \
patch("src.gui_2.imgui.text_colored"), \
patch("src.gui_2.imgui.separator"), \
patch("src.gui_2.imgui.button", return_value=False):
mock_reg = MockRegistry.return_value
mock_reg.data = {
"session_1": {
"start_time": "2023-01-01",
"whitelisted": False,
"metadata": {"reason": "test", "size_kb": 10, "message_count": 5}
}
}
app._log_registry = mock_reg
mock_window_cm = MagicMock()
mock_window_cm.__enter__.return_value = (True, True)
mock_imscope.window.return_value = mock_window_cm
mock_begin_table.return_value = True
gui_2.render_log_management(app)
mock_imscope.window.assert_called_with("Log Management", app.show_windows["Log Management"])
mock_begin_table.assert_called()
mock_text.assert_any_call("session_1")