forked from yusufkaraaslan/Skill_Seekers
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_mcp_server.py
More file actions
702 lines (550 loc) · 26.3 KB
/
test_mcp_server.py
File metadata and controls
702 lines (550 loc) · 26.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
#!/usr/bin/env python3
"""
Comprehensive test suite for Skill Seeker MCP Server
Tests all MCP tools and server functionality
"""
import json
import os
import shutil
import sys
import tempfile
import unittest
from pathlib import Path
from unittest.mock import MagicMock, patch
# CRITICAL: Import MCP package BEFORE adding project to path
# to avoid shadowing the installed mcp package with our local mcp/ directory
# WORKAROUND for shadowing issue: Temporarily change to /tmp to import external mcp
# This avoids our local mcp/ directory being in the import path
_original_dir = os.getcwd()
try:
os.chdir("/tmp") # Change away from project directory
from mcp.server import Server # noqa: F401
from mcp.types import TextContent, Tool # noqa: F401
MCP_AVAILABLE = True
except ImportError:
MCP_AVAILABLE = False
print("Warning: MCP package not available, skipping MCP tests")
finally:
os.chdir(_original_dir) # Restore original directory
# NOW add parent directory to path for importing our local modules
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
# Import our local MCP server module
if MCP_AVAILABLE:
# Import from installed package (new src/ layout)
try:
from skill_seekers.mcp import server as skill_seeker_server
except ImportError as e:
print(f"Warning: Could not import skill_seeker server: {e}")
skill_seeker_server = None
@unittest.skipUnless(MCP_AVAILABLE, "MCP package not installed")
class TestMCPServerInitialization(unittest.TestCase):
"""Test MCP server initialization"""
def test_server_import(self):
"""Test that server module can be imported"""
from mcp import server as mcp_server_module
self.assertIsNotNone(mcp_server_module)
def test_server_initialization(self):
"""Test server initializes correctly"""
import mcp.server
app = mcp.server.Server("test-skill-seeker")
self.assertEqual(app.name, "test-skill-seeker")
@unittest.skipUnless(MCP_AVAILABLE, "MCP package not installed")
class TestListTools(unittest.IsolatedAsyncioTestCase):
"""Test list_tools functionality"""
async def test_list_tools_returns_tools(self):
"""Test that list_tools returns all expected tools"""
tools = await skill_seeker_server.list_tools()
self.assertIsInstance(tools, list)
self.assertGreater(len(tools), 0)
# Check all expected tools are present
tool_names = [tool.name for tool in tools]
expected_tools = [
"generate_config",
"estimate_pages",
"scrape_docs",
"package_skill",
"list_configs",
"validate_config",
]
for expected in expected_tools:
self.assertIn(expected, tool_names, f"Missing tool: {expected}")
async def test_tool_schemas(self):
"""Test that all tools have valid schemas"""
tools = await skill_seeker_server.list_tools()
for tool in tools:
self.assertIsInstance(tool.name, str)
self.assertIsInstance(tool.description, str)
self.assertIn("inputSchema", tool.__dict__)
# Verify schema has required structure
schema = tool.inputSchema
self.assertEqual(schema["type"], "object")
self.assertIn("properties", schema)
@unittest.skipUnless(MCP_AVAILABLE, "MCP package not installed")
class TestGenerateConfigTool(unittest.IsolatedAsyncioTestCase):
"""Test generate_config tool"""
async def asyncSetUp(self):
"""Set up test environment"""
self.temp_dir = tempfile.mkdtemp()
self.original_cwd = os.getcwd()
os.chdir(self.temp_dir)
async def asyncTearDown(self):
"""Clean up test environment"""
os.chdir(self.original_cwd)
shutil.rmtree(self.temp_dir, ignore_errors=True)
async def test_generate_config_basic(self):
"""Test basic config generation"""
args = {
"name": "test-framework",
"url": "https://test-framework.dev/",
"description": "Test framework skill",
}
result = await skill_seeker_server.generate_config_tool(args)
self.assertIsInstance(result, list)
self.assertGreater(len(result), 0)
self.assertIsInstance(result[0], TextContent)
self.assertIn("✅", result[0].text)
# Verify config file was created
config_path = Path("configs/test-framework.json")
self.assertTrue(config_path.exists())
# Verify config content
with open(config_path) as f:
config = json.load(f)
self.assertEqual(config["name"], "test-framework")
self.assertEqual(config["base_url"], "https://test-framework.dev/")
self.assertEqual(config["description"], "Test framework skill")
async def test_generate_config_with_options(self):
"""Test config generation with custom options"""
args = {
"name": "custom-framework",
"url": "https://custom.dev/",
"description": "Custom skill",
"max_pages": 200,
"rate_limit": 1.0,
}
_result = await skill_seeker_server.generate_config_tool(args)
# Verify config has custom options
config_path = Path("configs/custom-framework.json")
with open(config_path) as f:
config = json.load(f)
self.assertEqual(config["max_pages"], 200)
self.assertEqual(config["rate_limit"], 1.0)
async def test_generate_config_defaults(self):
"""Test that default values are applied correctly"""
args = {"name": "default-test", "url": "https://test.dev/", "description": "Test defaults"}
_result = await skill_seeker_server.generate_config_tool(args)
config_path = Path("configs/default-test.json")
with open(config_path) as f:
config = json.load(f)
self.assertEqual(config["max_pages"], 100) # Default
self.assertEqual(config["rate_limit"], 0.5) # Default
@unittest.skipUnless(MCP_AVAILABLE, "MCP package not installed")
class TestEstimatePagesTool(unittest.IsolatedAsyncioTestCase):
"""Test estimate_pages tool"""
async def asyncSetUp(self):
"""Set up test environment"""
self.temp_dir = tempfile.mkdtemp()
self.original_cwd = os.getcwd()
os.chdir(self.temp_dir)
# Create a test config
os.makedirs("configs", exist_ok=True)
self.config_path = Path("configs/test.json")
config_data = {
"name": "test",
"base_url": "https://example.com/",
"selectors": {"main_content": "article", "title": "h1", "code_blocks": "pre"},
"rate_limit": 0.5,
"max_pages": 50,
}
with open(self.config_path, "w") as f:
json.dump(config_data, f)
async def asyncTearDown(self):
"""Clean up test environment"""
os.chdir(self.original_cwd)
shutil.rmtree(self.temp_dir, ignore_errors=True)
@patch("skill_seekers.mcp.tools.scraping_tools.run_subprocess_with_streaming")
async def test_estimate_pages_success(self, mock_streaming):
"""Test successful page estimation"""
# Mock successful subprocess run with streaming
# Returns (stdout, stderr, returncode)
mock_streaming.return_value = ("Estimated 50 pages", "", 0)
args = {"config_path": str(self.config_path)}
result = await skill_seeker_server.estimate_pages_tool(args)
self.assertIsInstance(result, list)
self.assertIsInstance(result[0], TextContent)
self.assertIn("50 pages", result[0].text)
# Should also have progress message
self.assertIn("Estimating page count", result[0].text)
@patch("skill_seekers.mcp.tools.scraping_tools.run_subprocess_with_streaming")
async def test_estimate_pages_with_max_discovery(self, mock_streaming):
"""Test page estimation with custom max_discovery"""
# Mock successful subprocess run with streaming
mock_streaming.return_value = ("Estimated 100 pages", "", 0)
args = {"config_path": str(self.config_path), "max_discovery": 500}
_result = await skill_seeker_server.estimate_pages_tool(args)
# Verify subprocess was called with correct args
mock_streaming.assert_called_once()
call_args = mock_streaming.call_args[0][0]
self.assertIn("--max-discovery", call_args)
self.assertIn("500", call_args)
@patch("skill_seekers.mcp.tools.scraping_tools.run_subprocess_with_streaming")
async def test_estimate_pages_error(self, mock_streaming):
"""Test error handling in page estimation"""
# Mock failed subprocess run with streaming
mock_streaming.return_value = ("", "Config file not found", 1)
args = {"config_path": "nonexistent.json"}
result = await skill_seeker_server.estimate_pages_tool(args)
self.assertIn("Error", result[0].text)
@unittest.skipUnless(MCP_AVAILABLE, "MCP package not installed")
class TestScrapeDocsTool(unittest.IsolatedAsyncioTestCase):
"""Test scrape_docs tool"""
async def asyncSetUp(self):
"""Set up test environment"""
self.temp_dir = tempfile.mkdtemp()
self.original_cwd = os.getcwd()
os.chdir(self.temp_dir)
# Create test config
os.makedirs("configs", exist_ok=True)
self.config_path = Path("configs/test.json")
config_data = {
"name": "test",
"base_url": "https://example.com/",
"selectors": {"main_content": "article", "title": "h1", "code_blocks": "pre"},
}
with open(self.config_path, "w") as f:
json.dump(config_data, f)
async def asyncTearDown(self):
"""Clean up test environment"""
os.chdir(self.original_cwd)
shutil.rmtree(self.temp_dir, ignore_errors=True)
@patch("skill_seekers.mcp.tools.scraping_tools.run_subprocess_with_streaming")
async def test_scrape_docs_basic(self, mock_streaming):
"""Test basic documentation scraping"""
# Mock successful subprocess run with streaming
mock_streaming.return_value = ("Scraping completed successfully", "", 0)
args = {"config_path": str(self.config_path)}
result = await skill_seeker_server.scrape_docs_tool(args)
self.assertIsInstance(result, list)
self.assertIn("success", result[0].text.lower())
@patch("skill_seekers.mcp.tools.scraping_tools.run_subprocess_with_streaming")
async def test_scrape_docs_with_skip_scrape(self, mock_streaming):
"""Test scraping with skip_scrape flag"""
# Mock successful subprocess run with streaming
mock_streaming.return_value = ("Using cached data", "", 0)
args = {"config_path": str(self.config_path), "skip_scrape": True}
_result = await skill_seeker_server.scrape_docs_tool(args)
# Verify --skip-scrape was passed
call_args = mock_streaming.call_args[0][0]
self.assertIn("--skip-scrape", call_args)
@patch("skill_seekers.mcp.tools.scraping_tools.run_subprocess_with_streaming")
async def test_scrape_docs_with_dry_run(self, mock_streaming):
"""Test scraping with dry_run flag"""
# Mock successful subprocess run with streaming
mock_streaming.return_value = ("Dry run completed", "", 0)
args = {"config_path": str(self.config_path), "dry_run": True}
_result = await skill_seeker_server.scrape_docs_tool(args)
call_args = mock_streaming.call_args[0][0]
self.assertIn("--dry-run", call_args)
@patch("skill_seekers.mcp.tools.scraping_tools.run_subprocess_with_streaming")
async def test_scrape_docs_with_enhance_local(self, mock_streaming):
"""Test scraping with local enhancement"""
# Mock successful subprocess run with streaming
mock_streaming.return_value = ("Scraping with enhancement", "", 0)
args = {"config_path": str(self.config_path), "enhance_local": True}
_result = await skill_seeker_server.scrape_docs_tool(args)
call_args = mock_streaming.call_args[0][0]
self.assertIn("--enhance-local", call_args)
@unittest.skipUnless(MCP_AVAILABLE, "MCP package not installed")
class TestPackageSkillTool(unittest.IsolatedAsyncioTestCase):
"""Test package_skill tool"""
async def asyncSetUp(self):
"""Set up test environment"""
self.temp_dir = tempfile.mkdtemp()
self.original_cwd = os.getcwd()
os.chdir(self.temp_dir)
# Create a mock skill directory
self.skill_dir = Path("output/test-skill")
self.skill_dir.mkdir(parents=True)
(self.skill_dir / "SKILL.md").write_text("# Test Skill")
(self.skill_dir / "references").mkdir()
(self.skill_dir / "references/index.md").write_text("# Index")
async def asyncTearDown(self):
"""Clean up test environment"""
os.chdir(self.original_cwd)
shutil.rmtree(self.temp_dir, ignore_errors=True)
@patch("subprocess.run")
async def test_package_skill_success(self, mock_run):
"""Test successful skill packaging"""
mock_result = MagicMock()
mock_result.returncode = 0
mock_result.stdout = "Package created: test-skill.zip"
mock_run.return_value = mock_result
args = {"skill_dir": str(self.skill_dir)}
result = await skill_seeker_server.package_skill_tool(args)
self.assertIsInstance(result, list)
self.assertIn("test-skill", result[0].text)
@patch("subprocess.run")
async def test_package_skill_error(self, mock_run):
"""Test error handling in skill packaging"""
mock_result = MagicMock()
mock_result.returncode = 1
mock_result.stderr = "Directory not found"
mock_run.return_value = mock_result
args = {"skill_dir": "nonexistent-dir"}
result = await skill_seeker_server.package_skill_tool(args)
self.assertIn("Error", result[0].text)
@unittest.skipUnless(MCP_AVAILABLE, "MCP package not installed")
class TestListConfigsTool(unittest.IsolatedAsyncioTestCase):
"""Test list_configs tool"""
async def asyncSetUp(self):
"""Set up test environment"""
self.temp_dir = tempfile.mkdtemp()
self.original_cwd = os.getcwd()
os.chdir(self.temp_dir)
# Create test configs
os.makedirs("configs", exist_ok=True)
configs = [
{"name": "test1", "description": "Test 1 skill", "base_url": "https://test1.dev/"},
{"name": "test2", "description": "Test 2 skill", "base_url": "https://test2.dev/"},
]
for config in configs:
path = Path(f"configs/{config['name']}.json")
with open(path, "w") as f:
json.dump(config, f)
async def asyncTearDown(self):
"""Clean up test environment"""
os.chdir(self.original_cwd)
shutil.rmtree(self.temp_dir, ignore_errors=True)
async def test_list_configs_success(self):
"""Test listing all configs"""
result = await skill_seeker_server.list_configs_tool({})
self.assertIsInstance(result, list)
self.assertIsInstance(result[0], TextContent)
self.assertIn("test1", result[0].text)
self.assertIn("test2", result[0].text)
self.assertIn("https://test1.dev/", result[0].text)
self.assertIn("https://test2.dev/", result[0].text)
async def test_list_configs_empty(self):
"""Test listing configs when directory is empty"""
# Remove all configs
for config_file in Path("configs").glob("*.json"):
config_file.unlink()
result = await skill_seeker_server.list_configs_tool({})
self.assertIn("No config files found", result[0].text)
async def test_list_configs_no_directory(self):
"""Test listing configs when directory doesn't exist"""
# Remove configs directory
shutil.rmtree("configs")
result = await skill_seeker_server.list_configs_tool({})
self.assertIn("No configs directory", result[0].text)
@unittest.skipUnless(MCP_AVAILABLE, "MCP package not installed")
class TestValidateConfigTool(unittest.IsolatedAsyncioTestCase):
"""Test validate_config tool"""
async def asyncSetUp(self):
"""Set up test environment"""
self.temp_dir = tempfile.mkdtemp()
self.original_cwd = os.getcwd()
os.chdir(self.temp_dir)
os.makedirs("configs", exist_ok=True)
async def asyncTearDown(self):
"""Clean up test environment"""
os.chdir(self.original_cwd)
shutil.rmtree(self.temp_dir, ignore_errors=True)
async def test_validate_valid_config(self):
"""Test validating a valid config"""
# Create valid config
config_path = Path("configs/valid.json")
valid_config = {
"name": "valid-test",
"base_url": "https://example.com/",
"selectors": {"main_content": "article", "title": "h1", "code_blocks": "pre"},
"rate_limit": 0.5,
"max_pages": 100,
}
with open(config_path, "w") as f:
json.dump(valid_config, f)
args = {"config_path": str(config_path)}
result = await skill_seeker_server.validate_config_tool(args)
self.assertIsInstance(result, list)
self.assertIn("✅", result[0].text)
self.assertIn("valid", result[0].text.lower())
async def test_validate_invalid_config(self):
"""Test validating an invalid config"""
# Create invalid config (missing required fields)
config_path = Path("configs/invalid.json")
invalid_config = {
"description": "Missing name field",
"sources": [
{"type": "invalid_type", "url": "https://example.com"} # Invalid source type
],
}
with open(config_path, "w") as f:
json.dump(invalid_config, f)
args = {"config_path": str(config_path)}
result = await skill_seeker_server.validate_config_tool(args)
# Should show error for invalid source type
self.assertIn("❌", result[0].text)
async def test_validate_nonexistent_config(self):
"""Test validating a nonexistent config"""
args = {"config_path": "configs/nonexistent.json"}
result = await skill_seeker_server.validate_config_tool(args)
self.assertIn("Error", result[0].text)
@unittest.skipUnless(MCP_AVAILABLE, "MCP package not installed")
class TestCallToolRouter(unittest.IsolatedAsyncioTestCase):
"""Test call_tool routing"""
async def test_call_tool_unknown(self):
"""Test calling an unknown tool"""
result = await skill_seeker_server.call_tool("unknown_tool", {})
self.assertIsInstance(result, list)
self.assertIn("Unknown tool", result[0].text)
async def test_call_tool_exception_handling(self):
"""Test that exceptions are caught and returned as errors"""
# Call with invalid arguments that should cause an exception
result = await skill_seeker_server.call_tool("generate_config", {})
self.assertIsInstance(result, list)
self.assertIn("Error", result[0].text)
@unittest.skipUnless(MCP_AVAILABLE, "MCP package not installed")
class TestMCPServerIntegration(unittest.IsolatedAsyncioTestCase):
"""Integration tests for MCP server"""
async def test_full_workflow_simulation(self):
"""Test complete workflow: generate config -> validate -> estimate"""
temp_dir = tempfile.mkdtemp()
original_cwd = os.getcwd()
os.chdir(temp_dir)
try:
# Step 1: Generate config using skill_seeker_server
generate_args = {
"name": "workflow-test",
"url": "https://workflow-test.dev/",
"description": "Workflow test skill",
}
result1 = await skill_seeker_server.generate_config_tool(generate_args)
self.assertIn("✅", result1[0].text)
# Step 2: Validate config
validate_args = {"config_path": "configs/workflow-test.json"}
result2 = await skill_seeker_server.validate_config_tool(validate_args)
self.assertIn("✅", result2[0].text)
# Step 3: List configs
result3 = await skill_seeker_server.list_configs_tool({})
self.assertIn("workflow-test", result3[0].text)
finally:
os.chdir(original_cwd)
shutil.rmtree(temp_dir, ignore_errors=True)
@unittest.skipUnless(MCP_AVAILABLE, "MCP package not installed")
class TestSubmitConfigTool(unittest.IsolatedAsyncioTestCase):
"""Test submit_config MCP tool"""
async def test_submit_config_requires_token(self):
"""Should error without GitHub token"""
args = {
"config_json": '{"name": "test", "description": "Test", "base_url": "https://example.com"}'
}
result = await skill_seeker_server.submit_config_tool(args)
self.assertIn("GitHub token required", result[0].text)
async def test_submit_config_validates_required_fields(self):
"""Should reject config missing required fields"""
args = {
"config_json": '{"name": "test"}', # Missing description, base_url
"github_token": "fake_token",
}
result = await skill_seeker_server.submit_config_tool(args)
self.assertIn("validation failed", result[0].text.lower())
# ConfigValidator detects missing config type (base_url/repo/pdf)
self.assertTrue(
"cannot detect" in result[0].text.lower() or "missing" in result[0].text.lower()
)
async def test_submit_config_validates_name_format(self):
"""Should reject invalid name characters"""
args = {
"config_json": '{"name": "React@2024!", "description": "Test", "base_url": "https://example.com"}',
"github_token": "fake_token",
}
result = await skill_seeker_server.submit_config_tool(args)
self.assertIn("validation failed", result[0].text.lower())
async def test_submit_config_validates_url_format(self):
"""Should reject invalid URL format"""
args = {
"config_json": '{"name": "test", "description": "Test", "base_url": "not-a-url"}',
"github_token": "fake_token",
}
result = await skill_seeker_server.submit_config_tool(args)
self.assertIn("validation failed", result[0].text.lower())
async def test_submit_config_accepts_legacy_format(self):
"""Should accept valid legacy config"""
valid_config = {
"name": "testframework",
"description": "Test framework docs",
"base_url": "https://docs.test.com/",
"selectors": {"main_content": "article", "title": "h1", "code_blocks": "pre code"},
"max_pages": 100,
}
args = {"config_json": json.dumps(valid_config), "github_token": "fake_token"}
# Mock GitHub API call
with patch("github.Github") as mock_gh:
mock_repo = MagicMock()
mock_issue = MagicMock()
mock_issue.html_url = "https://github.com/test/issue/1"
mock_issue.number = 1
mock_repo.create_issue.return_value = mock_issue
mock_gh.return_value.get_repo.return_value = mock_repo
result = await skill_seeker_server.submit_config_tool(args)
self.assertIn("Config submitted successfully", result[0].text)
self.assertIn("https://github.com", result[0].text)
async def test_submit_config_accepts_unified_format(self):
"""Should accept valid unified config"""
unified_config = {
"name": "testunified",
"description": "Test unified config",
"merge_mode": "rule-based",
"sources": [
{"type": "documentation", "base_url": "https://docs.test.com/", "max_pages": 100},
{"type": "github", "repo": "testorg/testrepo"},
],
}
args = {"config_json": json.dumps(unified_config), "github_token": "fake_token"}
with patch("github.Github") as mock_gh:
mock_repo = MagicMock()
mock_issue = MagicMock()
mock_issue.html_url = "https://github.com/test/issue/2"
mock_issue.number = 2
mock_repo.create_issue.return_value = mock_issue
mock_gh.return_value.get_repo.return_value = mock_repo
result = await skill_seeker_server.submit_config_tool(args)
self.assertIn("Config submitted successfully", result[0].text)
self.assertTrue("Unified" in result[0].text or "multi-source" in result[0].text)
async def test_submit_config_from_file_path(self):
"""Should accept config_path parameter"""
with tempfile.NamedTemporaryFile(mode="w", suffix=".json", delete=False) as f:
json.dump(
{"name": "testfile", "description": "From file", "base_url": "https://test.com/"}, f
)
temp_path = f.name
try:
args = {"config_path": temp_path, "github_token": "fake_token"}
with patch("github.Github") as mock_gh:
mock_repo = MagicMock()
mock_issue = MagicMock()
mock_issue.html_url = "https://github.com/test/issue/3"
mock_issue.number = 3
mock_repo.create_issue.return_value = mock_issue
mock_gh.return_value.get_repo.return_value = mock_repo
result = await skill_seeker_server.submit_config_tool(args)
self.assertIn("Config submitted successfully", result[0].text)
finally:
os.unlink(temp_path)
async def test_submit_config_detects_category(self):
"""Should auto-detect category from config name"""
args = {
"config_json": '{"name": "react-test", "description": "React", "base_url": "https://react.dev/"}',
"github_token": "fake_token",
}
with patch("github.Github") as mock_gh:
mock_repo = MagicMock()
mock_issue = MagicMock()
mock_issue.html_url = "https://github.com/test/issue/4"
mock_issue.number = 4
mock_repo.create_issue.return_value = mock_issue
mock_gh.return_value.get_repo.return_value = mock_repo
result = await skill_seeker_server.submit_config_tool(args)
# Verify category appears in result
self.assertTrue("web-frameworks" in result[0].text or "Category" in result[0].text)
if __name__ == "__main__":
unittest.main()