|
1 | 1 | import json |
2 | 2 | import os |
3 | 3 | import sys |
4 | | -import tempfile |
5 | 4 | from unittest.mock import AsyncMock, patch |
6 | 5 |
|
7 | 6 | import pytest |
8 | 7 |
|
9 | 8 | if sys.version_info < (3, 10): |
10 | 9 | pytest.skip('MCP requires Python 3.10+', allow_module_level=True) |
11 | 10 |
|
12 | | -import cycode.cli.apps.mcp.mcp_command as mcp_module |
13 | 11 | from cycode.cli.apps.mcp.mcp_command import ( |
14 | 12 | _build_scan_summary, |
15 | 13 | _sanitize_file_path, |
@@ -317,70 +315,6 @@ async def test_cycode_scan_tool_paths_not_found() -> None: |
317 | 315 | assert 'not found on disk' in parsed['error'] |
318 | 316 |
|
319 | 317 |
|
320 | | -@pytest.mark.anyio |
321 | | -async def test_cycode_scan_tool_paths_valid_invokes_scan() -> None: |
322 | | - from cycode.cli.apps.mcp.mcp_command import _cycode_scan_tool |
323 | | - from cycode.cli.cli_types import ScanTypeOption |
324 | | - |
325 | | - scan_result = {'scan_ids': ['abc'], 'detections': [], 'report_urls': [], 'errors': []} |
326 | | - |
327 | | - with ( |
328 | | - tempfile.TemporaryDirectory() as tmpdir, |
329 | | - patch.object(mcp_module, '_run_cycode_scan', return_value=scan_result) as mock_scan, |
330 | | - ): |
331 | | - result = await _cycode_scan_tool(ScanTypeOption.SECRET, paths=[tmpdir]) |
332 | | - |
333 | | - parsed = json.loads(result) |
334 | | - assert 'summary' in parsed |
335 | | - assert parsed['summary'] == 'No violations found.' |
336 | | - mock_scan.assert_called_once_with(ScanTypeOption.SECRET, [tmpdir]) |
337 | | - |
338 | | - |
339 | | -@pytest.mark.anyio |
340 | | -async def test_cycode_scan_tool_summary_included_on_success() -> None: |
341 | | - from cycode.cli.apps.mcp.mcp_command import _cycode_scan_tool |
342 | | - from cycode.cli.cli_types import ScanTypeOption |
343 | | - |
344 | | - scan_result = { |
345 | | - 'scan_ids': ['abc'], |
346 | | - 'detections': [ |
347 | | - {'severity': 'HIGH', 'type': 'secret'}, |
348 | | - {'severity': 'MEDIUM', 'type': 'secret'}, |
349 | | - ], |
350 | | - 'report_urls': [], |
351 | | - 'errors': [], |
352 | | - } |
353 | | - |
354 | | - with ( |
355 | | - tempfile.TemporaryDirectory() as tmpdir, |
356 | | - patch.object(mcp_module, '_run_cycode_scan', return_value=scan_result), |
357 | | - ): |
358 | | - result = await _cycode_scan_tool(ScanTypeOption.SECRET, paths=[tmpdir]) |
359 | | - |
360 | | - parsed = json.loads(result) |
361 | | - assert 'summary' in parsed |
362 | | - assert '2 violation' in parsed['summary'] |
363 | | - assert 'HIGH' in parsed['summary'] |
364 | | - assert 'MEDIUM' in parsed['summary'] |
365 | | - |
366 | | - |
367 | | -@pytest.mark.anyio |
368 | | -async def test_cycode_scan_tool_no_summary_on_error() -> None: |
369 | | - from cycode.cli.apps.mcp.mcp_command import _cycode_scan_tool |
370 | | - from cycode.cli.cli_types import ScanTypeOption |
371 | | - |
372 | | - error_result = {'error': 'Command timeout after 600 seconds'} |
373 | | - |
374 | | - with ( |
375 | | - tempfile.TemporaryDirectory() as tmpdir, |
376 | | - patch.object(mcp_module, '_run_cycode_scan', return_value=error_result), |
377 | | - ): |
378 | | - result = await _cycode_scan_tool(ScanTypeOption.SECRET, paths=[tmpdir]) |
379 | | - |
380 | | - parsed = json.loads(result) |
381 | | - assert 'error' in parsed |
382 | | - assert 'summary' not in parsed |
383 | | - |
384 | 318 |
|
385 | 319 | # --- _build_scan_summary --- |
386 | 320 |
|
|
0 commit comments