7bcb5a8c07
Eliminates 22 call sites that bypassed the AppController state owner
and read/wrote config.toml directly. AppController is now the single
source of truth for self.config; gui_2.py, commands.py, etc. go
through controller.save_config() / controller.load_config().
Production changes:
- src/models.py: rename load_config -> _load_config_from_disk,
save_config -> _save_config_to_disk (private I/O primitives)
- src/app_controller.py: add public load_config()/save_config() methods
that own the state. Update 3 internal call sites and 3 ConductorEngine
call sites to pass max_workers from self.config
- src/multi_agent_conductor.py: ConductorEngine.__init__ now takes
max_workers as a parameter (caller responsibility, not I/O primitive)
- src/external_editor.py: get_default_launcher() takes config as a
parameter; gui_2.py:1311,4776 pass app.config
- src/gui_2.py: 17 sites of models.save_config(X.config) replaced with
X.save_config() (delegates via __getattr__ to controller)
- src/commands.py: save_all() uses app.save_config()
Test changes (route through controller, not I/O primitive):
- tests/conftest.py: mock_app and app_instance fixtures now patch
AppController.load_config/save_config instead of models I/O primitives
- 18 other test files: patches renamed from models._save_config_to_disk
to AppController.save_config (and same for load_config)
- tests/test_app_controller_mcp.py: use SLOP_CONFIG env var instead of
patching removed CONFIG_PATH module constant
- tests/test_parallel_execution.py: pass max_workers=2 explicitly to
ConductorEngine (caller no longer reads config)
- tests/test_gui_paths.py: add save_config=MagicMock() to MockApp;
assert on controller method, not I/O primitive
- tests/test_models_no_top_level_tomli_w.py: still calls private
_save_config_to_disk directly (the only allowed exception; tests
the lazy-load behavior of the primitive itself)
New files:
- scripts/audit_no_models_config_io.py: enforces the rule (--strict,
--json modes; AST-based docstring detection to avoid false positives)
- conductor/code_styleguides/config_state_owner.md: documents the rule
Verification:
- 67 targeted tests pass
- scripts/audit_no_models_config_io.py --strict returns 0
This is the architectural cleanup that surfaced during the
audit_architectural_cheats_20260607 review. Closes the smoke-gun
CONFIG_PATH module constant (already done in 0c7ebf22) AND the
free-function models.load_config/save_config smell.
[conductor(checkpoint): config-iO-refactor-20260607]
107 lines
3.0 KiB
Python
107 lines
3.0 KiB
Python
import os
|
|
import json
|
|
import pytest
|
|
from pathlib import Path
|
|
from src.app_controller import AppController
|
|
from src import models
|
|
|
|
@pytest.fixture
|
|
def controller(tmp_path):
|
|
# Setup mock config and project files
|
|
config_path = tmp_path / "config.toml"
|
|
project_path = tmp_path / "project.toml"
|
|
mcp_config_path = tmp_path / "mcp_config.json"
|
|
|
|
config_data = {
|
|
"ai": {
|
|
"mcp_config_path": str(mcp_config_path)
|
|
},
|
|
"projects": {
|
|
"paths": [str(project_path)],
|
|
"active": str(project_path)
|
|
}
|
|
}
|
|
|
|
project_data = {
|
|
"project": {
|
|
"name": "test-project",
|
|
"mcp_config_path": "project_mcp.json" # Relative path
|
|
}
|
|
}
|
|
|
|
mcp_data = {
|
|
"mcpServers": {
|
|
"global-server": {"command": "echo"}
|
|
}
|
|
}
|
|
|
|
project_mcp_data = {
|
|
"mcpServers": {
|
|
"project-server": {"command": "echo"}
|
|
}
|
|
}
|
|
|
|
# We can't easily use models.save_config because it uses a hardcoded path
|
|
# But AppController.init_state calls models.load_config() which uses CONFIG_PATH
|
|
|
|
return AppController()
|
|
|
|
def test_app_controller_mcp_loading(tmp_path, monkeypatch):
|
|
# Mock CONFIG_PATH to point to our temp config
|
|
config_file = tmp_path / "config.toml"
|
|
monkeypatch.setenv("SLOP_CONFIG", str(config_file))
|
|
|
|
mcp_global_file = tmp_path / "mcp_global.json"
|
|
mcp_global_file.write_text(json.dumps({"mcpServers": {"global": {"command": "echo"}}}))
|
|
|
|
config_content = f"""
|
|
[ai]
|
|
mcp_config_path = "{mcp_global_file.as_posix()}"
|
|
[projects]
|
|
paths = []
|
|
active = ""
|
|
"""
|
|
config_file.write_text(config_content)
|
|
|
|
ctrl = AppController()
|
|
# Mock _load_active_project to not do anything for now
|
|
monkeypatch.setattr(ctrl, "_load_active_project", lambda: None)
|
|
ctrl.project = {}
|
|
|
|
ctrl.init_state()
|
|
|
|
assert "global" in ctrl.mcp_config.mcpServers
|
|
assert ctrl.mcp_config.mcpServers["global"].command == "echo"
|
|
|
|
def test_app_controller_mcp_project_override(tmp_path, monkeypatch):
|
|
config_file = tmp_path / "config.toml"
|
|
monkeypatch.setenv("SLOP_CONFIG", str(config_file))
|
|
|
|
project_file = tmp_path / "project.toml"
|
|
mcp_project_file = tmp_path / "mcp_project.json"
|
|
mcp_project_file.write_text(json.dumps({"mcpServers": {"project": {"command": "echo"}}}))
|
|
|
|
config_content = f"""
|
|
[ai]
|
|
mcp_config_path = "non-existent.json"
|
|
[projects]
|
|
paths = ["{project_file.as_posix()}"]
|
|
active = "{project_file.as_posix()}"
|
|
"""
|
|
config_file.write_text(config_content)
|
|
|
|
ctrl = AppController()
|
|
ctrl.active_project_path = str(project_file)
|
|
ctrl.project = {
|
|
"project": {
|
|
"mcp_config_path": "mcp_project.json"
|
|
}
|
|
}
|
|
# Mock _load_active_project to keep our manual project dict
|
|
monkeypatch.setattr(ctrl, "_load_active_project", lambda: None)
|
|
|
|
ctrl.init_state()
|
|
|
|
assert "project" in ctrl.mcp_config.mcpServers
|
|
assert "non-existent" not in ctrl.mcp_config.mcpServers
|