Fix Jenkins-update flow: redeploy_project pull + delete_image safety + delete_container

Bug fixes from product test:
1. redeploy_project: BUILD_FAILED now includes explicit image pull (stop → pull → start)
2. delete_image: Distinguishes running vs stopped containers, suggests system_prune for stopped refs
3. New tool delete_container: Verify stopped state before deletion, confirmation required

Tests added for all three paths plus stopped-container edge cases.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-04-21 07:09:21 +02:00
parent 81d5acd83e
commit 223075e602
7 changed files with 207 additions and 26 deletions
+33 -2
View File
@@ -255,7 +255,7 @@ async def test_delete_image_not_found():
@pytest.mark.asyncio
async def test_delete_image_in_use_blocked():
async def test_delete_image_in_use_by_running_blocked():
from mcp_synology_container.modules.images import register_images
client = AsyncMock()
@@ -265,7 +265,7 @@ async def test_delete_image_in_use_blocked():
if api == "SYNO.Docker.Image" and method == "list":
return SAMPLE_IMAGES
if api == "SYNO.Docker.Container":
return SAMPLE_CONTAINERS # nginx is in use
return SAMPLE_CONTAINERS # nginx is in use (running)
return {}
client.request.side_effect = mock_request
@@ -274,10 +274,41 @@ async def test_delete_image_in_use_blocked():
result = await tools["delete_image"](image_id="nginx:1.24", confirmed=True)
assert "Cannot delete" in result
assert "running" in result.lower()
assert "my-nginx" in result
client.post_request.assert_not_called()
@pytest.mark.asyncio
async def test_delete_image_in_use_by_stopped_blocked():
from mcp_synology_container.modules.images import register_images
client = AsyncMock()
client.post_request = AsyncMock(return_value={})
async def mock_request(api, method, **kwargs):
if api == "SYNO.Docker.Image" and method == "list":
return SAMPLE_IMAGES
if api == "SYNO.Docker.Container":
return {
"containers": [
{"name": "stopped-nginx", "image_id": "sha256:aaaa", "status": "exited"}
]
}
return {}
client.request.side_effect = mock_request
mcp, tools = make_mock_mcp()
register_images(mcp, make_config(), client)
result = await tools["delete_image"](image_id="nginx:1.24", confirmed=True)
assert "Cannot delete" in result
assert "stopped" in result.lower()
assert "stopped-nginx" in result
assert "system_prune" in result
client.post_request.assert_not_called()
@pytest.mark.asyncio
async def test_delete_image_by_hash():
import json