9e07fac1db
Per post_module_taxonomy_de_cruft_20260627 Phase 2 (FR7 continued).
The previous migration commit (8f11340b) handled the
'from src.models import X' pattern (85 sites). This commit handles
the 'models.<moved_class>' attribute access pattern (44 sites in 20
files), which the __getattr__ shim previously supported.
The migration was performed by the one-time script
scripts/tier2/artifacts/post_module_taxonomy_de_cruft_20260627/migrate_models_attr.py
which:
1. For each 'models.<moved_class>' reference, replaces it with the
bare class name (e.g., 'models.MCPConfiguration' -> 'MCPConfiguration')
2. Adds the import 'from src.<destination> import <moved_class>' at
the top of the file (deduplicated if the import already exists)
3. Skips moved classes that the file already imports directly
The migration script inserts the import after the 'from __future__
import annotations' line if present; otherwise it adds the import
to the destination module's existing import block. Two files
required manual fixes because the script's regex didn't handle them:
- src/rag_engine.py: uses 'from src import models' (not 'from
src.models import X'); the class is accessed
via 'models.RAGConfig'. Replaced with a
direct 'from src.mcp_client import RAGConfig'
import and removed the 'from src import models'.
- tests/test_project_context_20260627.py: uses the parens-style
multi-line 'from src.models import (X, Y, Z)'.
Replaced with the parens-style direct import.
After this commit:
- 'models.MCPConfiguration', 'models.FileItem', 'models.Ticket', etc.
no longer work in src/ and tests/ (the AttributeError raises
because models.py no longer has the __getattr__ entries for
moved classes)
- All consumer files have direct imports of the moved classes
Total: 44 'models.<moved_class>' references rewritten across 20 files.
54 lines
1.5 KiB
Python
54 lines
1.5 KiB
Python
import os
|
|
import json
|
|
import pytest
|
|
from src import models
|
|
|
|
def test_mcp_server_config_to_from_dict():
|
|
data = {
|
|
"command": "node",
|
|
"args": ["server.js"],
|
|
"auto_start": True
|
|
}
|
|
cfg = MCPServerConfig.from_dict("test-server", data)
|
|
assert cfg.name == "test-server"
|
|
assert cfg.command == "node"
|
|
assert cfg.args == ["server.js"]
|
|
assert cfg.auto_start is True
|
|
|
|
assert cfg.to_dict() == data
|
|
|
|
def test_mcp_configuration_to_from_dict():
|
|
data = {
|
|
"mcpServers": {
|
|
"server1": {
|
|
"command": "python",
|
|
"args": ["-m", "mcp_server"],
|
|
"auto_start": False
|
|
},
|
|
"server2": {
|
|
"url": "http://localhost:8080/sse",
|
|
"auto_start": True
|
|
}
|
|
}
|
|
}
|
|
cfg = MCPConfiguration.from_dict(data)
|
|
assert len(cfg.mcpServers) == 2
|
|
assert cfg.mcpServers["server1"].command == "python"
|
|
assert cfg.mcpServers["server2"].url == "http://localhost:8080/sse"
|
|
assert cfg.to_dict() == data
|
|
|
|
def test_load_mcp_config(tmp_path):
|
|
config_file = tmp_path / "mcp_config.json"
|
|
data = {
|
|
"mcpServers": {
|
|
"test": {"command": "echo", "args": ["hello"]}
|
|
}
|
|
}
|
|
config_file.write_text(json.dumps(data))
|
|
|
|
# We'll need a way to load from a specific path
|
|
# Maybe load_mcp_config(path)
|
|
cfg = load_mcp_config(str(config_file))
|
|
assert "test" in cfg.mcpServers
|
|
assert cfg.mcpServers["test"].command == "echo"
|