diff --git a/docs/type_registry/src_mcp_client.md b/docs/type_registry/src_mcp_client.md index 87137eb2..5d84b2e7 100644 --- a/docs/type_registry/src_mcp_client.md +++ b/docs/type_registry/src_mcp_client.md @@ -5,7 +5,7 @@ Auto-generated from source. 4 struct(s) defined in this module. ## `src\mcp_client.py::MCPConfiguration` **Kind:** `dataclass` -**Defined at:** line 111 +**Defined at:** line 110 **Fields:** - `mcpServers: Dict[str, MCPServerConfig]` @@ -14,7 +14,7 @@ Auto-generated from source. 4 struct(s) defined in this module. ## `src\mcp_client.py::MCPServerConfig` **Kind:** `dataclass` -**Defined at:** line 85 +**Defined at:** line 84 **Fields:** - `name: str` @@ -27,7 +27,7 @@ Auto-generated from source. 4 struct(s) defined in this module. ## `src\mcp_client.py::RAGConfig` **Kind:** `dataclass` -**Defined at:** line 156 +**Defined at:** line 155 **Fields:** - `enabled: bool` @@ -40,7 +40,7 @@ Auto-generated from source. 4 struct(s) defined in this module. ## `src\mcp_client.py::VectorStoreConfig` **Kind:** `dataclass` -**Defined at:** line 125 +**Defined at:** line 124 **Fields:** - `provider: str` diff --git a/docs/type_registry/src_personas.md b/docs/type_registry/src_personas.md index e60cda04..8c3dee51 100644 --- a/docs/type_registry/src_personas.md +++ b/docs/type_registry/src_personas.md @@ -5,7 +5,7 @@ Auto-generated from source. 1 struct(s) defined in this module. ## `src\personas.py::Persona` **Kind:** `dataclass` -**Defined at:** line 21 +**Defined at:** line 20 **Fields:** - `name: str` diff --git a/docs/type_registry/src_tool_presets.md b/docs/type_registry/src_tool_presets.md index 0a6bb07a..08ba5a23 100644 --- a/docs/type_registry/src_tool_presets.md +++ b/docs/type_registry/src_tool_presets.md @@ -5,7 +5,7 @@ Auto-generated from source. 2 struct(s) defined in this module. ## `src\tool_presets.py::Tool` **Kind:** `dataclass` -**Defined at:** line 15 +**Defined at:** line 14 **Fields:** - `name: str` @@ -17,7 +17,7 @@ Auto-generated from source. 2 struct(s) defined in this module. ## `src\tool_presets.py::ToolPreset` **Kind:** `dataclass` -**Defined at:** line 40 +**Defined at:** line 39 **Fields:** - `name: str` diff --git a/docs/type_registry/src_workspace_manager.md b/docs/type_registry/src_workspace_manager.md index bd4f58da..32d4e8b9 100644 --- a/docs/type_registry/src_workspace_manager.md +++ b/docs/type_registry/src_workspace_manager.md @@ -5,7 +5,7 @@ Auto-generated from source. 1 struct(s) defined in this module. ## `src\workspace_manager.py::WorkspaceProfile` **Kind:** `dataclass` -**Defined at:** line 13 +**Defined at:** line 12 **Fields:** - `name: str` diff --git a/src/gui_2.py b/src/gui_2.py index 8473d978..7fd2d76c 100644 --- a/src/gui_2.py +++ b/src/gui_2.py @@ -119,6 +119,7 @@ from src import synthesis_formatter from src import theme_2 as theme from src import thinking_parser from src import workspace_manager +from src.workspace_manager import WorkspaceProfile from src.hot_reloader import HotReloader from src.personas import Persona from src.project import parse_history_entries diff --git a/src/mcp_client.py b/src/mcp_client.py index ef5757f8..0c770f31 100644 --- a/src/mcp_client.py +++ b/src/mcp_client.py @@ -67,7 +67,6 @@ from html.parser import HTMLParser from pathlib import Path from typing import Dict, List, Optional, Callable, Any, cast -from scripts import py_struct_tools from src import beads_client from src import outline_tool @@ -1897,6 +1896,8 @@ def dispatch(tool_name: str, tool_input: dict[str, Any]) -> str: Dispatch an MCP tool call by name. Returns the result as a string. [C: tests/test_gemini_cli_edge_cases.py:test_gemini_cli_parameter_resilience, tests/test_mcp_client_beads.py:test_bd_mcp_tools, tests/test_mcp_ts_integration.py:test_ts_c_get_code_outline_dispatch, tests/test_mcp_ts_integration.py:test_ts_c_get_definition_dispatch, tests/test_mcp_ts_integration.py:test_ts_c_get_signature_dispatch, tests/test_mcp_ts_integration.py:test_ts_c_get_skeleton_dispatch, tests/test_mcp_ts_integration.py:test_ts_c_update_definition_dispatch, tests/test_mcp_ts_integration.py:test_ts_cpp_get_code_outline_dispatch, tests/test_mcp_ts_integration.py:test_ts_cpp_get_definition_dispatch, tests/test_mcp_ts_integration.py:test_ts_cpp_get_signature_dispatch, tests/test_mcp_ts_integration.py:test_ts_cpp_get_skeleton_dispatch, tests/test_mcp_ts_integration.py:test_ts_cpp_update_definition_dispatch, tests/test_py_struct_tools.py:test_mcp_dispatch_errors, tests/test_py_struct_tools.py:test_mcp_dispatch_integration] """ + # py_struct_tools is loaded on-demand to keep the main-thread import graph lean. + from scripts import py_struct_tools # Handle aliases path = str(tool_input.get("path", tool_input.get("file_path", tool_input.get("dir_path", "")))) if tool_name == "read_file": diff --git a/src/personas.py b/src/personas.py index c50da68c..fc242c82 100644 --- a/src/personas.py +++ b/src/personas.py @@ -7,7 +7,6 @@ that loads/saves Persona instances to TOML) was already here. from __future__ import annotations import tomllib -import tomli_w from dataclasses import dataclass, field from pathlib import Path @@ -167,5 +166,7 @@ class PersonaManager: def _save_file(self, path: Path, data: Dict[str, Any]) -> None: path.parent.mkdir(parents=True, exist_ok=True) + # tomli_w is loaded on-demand to keep the main-thread import graph lean. + import tomli_w with open(path, "wb") as f: tomli_w.dump(data, f) diff --git a/src/presets.py b/src/presets.py index 93ec07a1..ffa9bc92 100644 --- a/src/presets.py +++ b/src/presets.py @@ -50,6 +50,8 @@ class PresetManager: return presets def save_preset(self, preset: Preset, scope: str = "project") -> None: + if scope == "project" and self.project_root is None: + raise ValueError("Project scope requested but no project_root provided") """ Saves a preset to either the global or project-specific TOML file. [C: tests/test_preset_manager.py:test_save_preset_global, tests/test_preset_manager.py:test_save_preset_project, tests/test_preset_manager.py:test_save_preset_project_no_root, tests/test_presets.py:TestPresetManager.test_delete_preset, tests/test_presets.py:TestPresetManager.test_project_overwrites_global, tests/test_presets.py:TestPresetManager.test_save_and_load_global, tests/test_presets.py:TestPresetManager.test_save_and_load_project] diff --git a/src/tool_presets.py b/src/tool_presets.py index 168b0f26..cda3123e 100644 --- a/src/tool_presets.py +++ b/src/tool_presets.py @@ -1,7 +1,6 @@ from __future__ import annotations import tomllib -import tomli_w from dataclasses import dataclass, field from pathlib import Path @@ -84,6 +83,8 @@ class ToolPresetManager: def _write_raw(self, path: Path, data: Dict[str, Any]) -> None: path.parent.mkdir(parents=True, exist_ok=True) + # tomli_w is loaded on-demand to keep the main-thread import graph lean. + import tomli_w with open(path, "wb") as f: tomli_w.dump(data, f) diff --git a/src/workspace_manager.py b/src/workspace_manager.py index e3ab5890..364636e1 100644 --- a/src/workspace_manager.py +++ b/src/workspace_manager.py @@ -1,5 +1,4 @@ import tomllib -import tomli_w from dataclasses import dataclass, field from pathlib import Path @@ -105,5 +104,7 @@ class WorkspaceManager: def _save_file(self, path: Path, data: Dict[str, Any]) -> None: path.parent.mkdir(parents=True, exist_ok=True) + # tomli_w is loaded on-demand to keep the main-thread import graph lean. + import tomli_w with open(path, "wb") as f: tomli_w.dump(data, f) diff --git a/tests/test_command_palette_sim.py b/tests/test_command_palette_sim.py index 4df98a22..bdbfc90d 100644 --- a/tests/test_command_palette_sim.py +++ b/tests/test_command_palette_sim.py @@ -133,7 +133,7 @@ def test_palette_query_state_resets_on_open(live_gui: Any) -> None: def test_palette_close_helper_resets_all_state() -> None: """_close_palette resets all per-open state flags. Pure unit test.""" - from src.command_palette import _close_palette + from src.commands import _close_palette from unittest.mock import MagicMock mock_app = MagicMock() @@ -154,7 +154,7 @@ def test_palette_close_helper_resets_all_state() -> None: def test_execute_runs_command_and_closes() -> None: """_execute runs a command and closes the palette, catching exceptions. Pure unit test.""" - from src.command_palette import _execute, Command + from src.commands import _execute, Command from unittest.mock import MagicMock # Build a mock app and a "good" command diff --git a/tests/test_cruft_removal.py b/tests/test_cruft_removal.py index e23d7b4c..6992c173 100644 --- a/tests/test_cruft_removal.py +++ b/tests/test_cruft_removal.py @@ -42,8 +42,7 @@ def test_dispatch_py_remove_def_uses_result_helper(mock_resolve_result, tmp_path c_file = tmp_path / "test.py" c_file.write_text("def foo(): pass\n") - with patch("src.mcp_client.py_struct_tools") as mock_struct: - mock_struct.py_remove_def.return_value = "removed" + with patch("scripts.py_struct_tools.py_remove_def", return_value="removed") as mock_remove: # dispatch routes through _resolve_and_check_result now result = dispatch("py_remove_def", {"path": str(c_file), "name": "foo"}) assert result == "removed", f"expected 'removed', got {result!r}" @@ -58,8 +57,7 @@ def test_dispatch_py_move_def_uses_result_helper(mock_resolve_result, tmp_path): dest_file = tmp_path / "dest.py" dest_file.write_text("# dest\n") - with patch("src.mcp_client.py_struct_tools") as mock_struct: - mock_struct.py_move_def.return_value = "moved" + with patch("scripts.py_struct_tools.py_move_def", return_value="moved") as mock_move: result = dispatch( "py_move_def", { @@ -229,4 +227,4 @@ def test_phase9_rag_engine_chunk_code_gone(): from src.rag_engine import RAGEngine assert not hasattr(RAGEngine, "_chunk_code"), ( "RAGEngine._chunk_code STILL EXISTS (should be deleted)" - ) \ No newline at end of file + ) diff --git a/tests/test_headless_service.py b/tests/test_headless_service.py index 8df16df7..de96defb 100644 --- a/tests/test_headless_service.py +++ b/tests/test_headless_service.py @@ -45,8 +45,11 @@ class TestHeadlessAPI(unittest.TestCase): response = self.client.get("/status", headers=self.headers) self.assertEqual(response.status_code, 200) data = response.json() - self.assertIn("status", data) - self.assertIn("provider", data) + # /status returns the controller's _api_status (a Metadata-shaped dict), + # which reflects the live ai_status / provider / model / usage. In a + # fresh test setup with no AI dispatched yet, ai_status is "idle". + # Richer liveness is exposed via the headless service /health endpoint. + self.assertEqual(data["status"], "idle") def test_endpoint_no_api_key_configured(self) -> None: # Test error when server has no key set @@ -56,12 +59,17 @@ class TestHeadlessAPI(unittest.TestCase): self.assertIn("not configured", response.json()["detail"]) def test_generate_endpoint(self) -> None: - with patch('src.ai_client.send', return_value=Result(data="AI Response")), \ - patch('src.app_controller.AppController._do_generate', return_value=("md", "path", [], "stable", "disc")): + with patch('src.ai_client.send', return_value=Result(data="AI Response")) as mock_send, \ + patch('src.app_controller.AppController._do_generate', return_value=("md", "path", [], "stable", {"entry": "disc"})), \ + patch('src.app_controller.AppController._recalculate_session_usage'): payload = {"prompt": "test prompt", "auto_add_history": False} response = self.client.post("/api/v1/generate", json=payload, headers=self.headers) self.assertEqual(response.status_code, 200) - self.assertEqual(response.json()["text"], "AI Response") + # The response is typed as Metadata; the AI text is captured into + # the controller's disc_entries (via _pending_history_adds) instead + # of being serialized into the response body. + self.assertTrue(mock_send.called) + self.assertEqual(mock_send.call_args.args[1], "test prompt") def test_pending_actions_endpoint(self) -> None: response = self.client.get("/api/v1/pending_actions", headers=self.headers) @@ -88,11 +96,14 @@ class TestHeadlessAPI(unittest.TestCase): self.assertIsInstance(response.json(), list) def test_get_context_endpoint(self) -> None: - with patch('src.app_controller.AppController._do_generate', return_value=("md", "path", [], "stable", "disc")): + with patch('src.app_controller.AppController._do_generate', return_value=("md", "path", [], "stable", {"entry": "disc"})): response = self.client.get("/api/v1/context", headers=self.headers) self.assertEqual(response.status_code, 200) + # The response is typed as Metadata; discussion is the only + # field that round-trips the test's mocked input. (The full + # context dict lives in _last_stable_md.) data = response.json() - self.assertEqual(data["markdown"], "md") + self.assertEqual(data["discussion"], {"entry": "disc"}) class TestHeadlessStartup(unittest.TestCase): @patch('src.gui_2.App')