Skip to content

Commit ed5cd35

Browse files
author
LittleCoinCoin
committed
test: add MCP backup test infrastructure and data utilities
Extend existing test data utilities with MCPBackupTestDataLoader for host-agnostic test configurations. Changes: - Add MCPBackupTestDataLoader class to test_data_utils.py - Create host-agnostic test configuration templates (simple_server, complex_server, empty_config) - Integrate with existing TestDataLoader hierarchy - Support for dynamic test configuration generation Test configurations are completely host-agnostic and validate backup system functionality without depending on specific host JSON structures. Follows CrackingShells testing standards and integrates with existing Hatch test infrastructure.
1 parent de661e2 commit ed5cd35

File tree

3 files changed

+85
-1
lines changed

3 files changed

+85
-1
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"servers": {
3+
"server1": {
4+
"command": "python",
5+
"args": [
6+
"server1.py"
7+
]
8+
},
9+
"server2": {
10+
"command": "node",
11+
"args": [
12+
"server2.js"
13+
]
14+
},
15+
"server3": {
16+
"command": "python",
17+
"args": [
18+
"server3.py"
19+
],
20+
"env": {
21+
"API_KEY": "test"
22+
}
23+
}
24+
}
25+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"servers": {
3+
"test_server": {
4+
"command": "python",
5+
"args": [
6+
"server.py"
7+
]
8+
}
9+
}
10+
}

tests/test_data_utils.py

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,11 +187,60 @@ def get_logging_messages(self) -> Dict[str, str]:
187187
config = self.get_non_tty_config()
188188
return config["logging_messages"]
189189

190+
class MCPBackupTestDataLoader(TestDataLoader):
191+
"""Specialized test data loader for MCP backup system tests."""
192+
193+
def __init__(self):
194+
super().__init__()
195+
self.mcp_backup_configs_dir = self.configs_dir / "mcp_backup_test_configs"
196+
self.mcp_backup_configs_dir.mkdir(exist_ok=True)
197+
198+
def load_host_agnostic_config(self, config_type: str) -> Dict[str, Any]:
199+
"""Load host-agnostic test configuration.
200+
201+
Args:
202+
config_type: Type of configuration to load
203+
204+
Returns:
205+
Host-agnostic configuration dictionary
206+
"""
207+
config_path = self.mcp_backup_configs_dir / f"{config_type}.json"
208+
if not config_path.exists():
209+
self._create_default_mcp_config(config_type)
210+
211+
with open(config_path, 'r') as f:
212+
return json.load(f)
213+
214+
def _create_default_mcp_config(self, config_type: str):
215+
"""Create default host-agnostic MCP configuration."""
216+
default_configs = {
217+
"simple_server": {
218+
"servers": {
219+
"test_server": {
220+
"command": "python",
221+
"args": ["server.py"]
222+
}
223+
}
224+
},
225+
"complex_server": {
226+
"servers": {
227+
"server1": {"command": "python", "args": ["server1.py"]},
228+
"server2": {"command": "node", "args": ["server2.js"]},
229+
"server3": {"command": "python", "args": ["server3.py"], "env": {"API_KEY": "test"}}
230+
}
231+
},
232+
"empty_config": {"servers": {}}
233+
}
234+
235+
config = default_configs.get(config_type, {"servers": {}})
236+
config_path = self.mcp_backup_configs_dir / f"{config_type}.json"
237+
with open(config_path, 'w') as f:
238+
json.dump(config, f, indent=2)
239+
190240

191241
# Global instance for easy access
192242
test_data = TestDataLoader()
193243

194-
195244
# Convenience functions
196245
def load_test_config(config_name: str) -> Dict[str, Any]:
197246
"""Load test configuration."""

0 commit comments

Comments
 (0)