feat: Refactor imports to use pod_executor and add container verification script

This commit is contained in:
Hans Aschauer 2026-03-05 06:45:00 +01:00
parent 17577d3fba
commit 114381b71c
19 changed files with 79 additions and 79 deletions

View file

@ -10,7 +10,7 @@ import pytest
def test_parse_memory_string_megabytes():
"""Test parsing memory string with megabytes suffix."""
from mcp_forge.security.resource_limits import parse_memory_string
from pod_executor.security.resource_limits import parse_memory_string
result = parse_memory_string("512m")
assert result == 536870912 # 512 * 1024 * 1024
@ -18,7 +18,7 @@ def test_parse_memory_string_megabytes():
def test_parse_memory_string_gigabytes():
"""Test parsing memory string with gigabytes suffix."""
from mcp_forge.security.resource_limits import parse_memory_string
from pod_executor.security.resource_limits import parse_memory_string
result = parse_memory_string("2g")
assert result == 2147483648 # 2 * 1024 * 1024 * 1024
@ -26,7 +26,7 @@ def test_parse_memory_string_gigabytes():
def test_parse_memory_string_kilobytes():
"""Test parsing memory string with kilobytes suffix."""
from mcp_forge.security.resource_limits import parse_memory_string
from pod_executor.security.resource_limits import parse_memory_string
result = parse_memory_string("1024k")
assert result == 1048576 # 1024 * 1024
@ -34,7 +34,7 @@ def test_parse_memory_string_kilobytes():
def test_parse_memory_string_case_insensitive():
"""Test that memory string parsing is case-insensitive."""
from mcp_forge.security.resource_limits import parse_memory_string
from pod_executor.security.resource_limits import parse_memory_string
assert parse_memory_string("512M") == 536870912
assert parse_memory_string("2G") == 2147483648
@ -43,7 +43,7 @@ def test_parse_memory_string_case_insensitive():
def test_parse_memory_string_invalid_format_raises_value_error():
"""Test that invalid format raises ValueError."""
from mcp_forge.security.resource_limits import parse_memory_string
from pod_executor.security.resource_limits import parse_memory_string
with pytest.raises(ValueError) as exc_info:
parse_memory_string("invalid")
@ -58,7 +58,7 @@ def test_parse_memory_string_invalid_format_raises_value_error():
def test_parse_memory_string_negative_value_raises_value_error():
"""Test that negative values raise ValueError."""
from mcp_forge.security.resource_limits import parse_memory_string
from pod_executor.security.resource_limits import parse_memory_string
with pytest.raises(ValueError) as exc_info:
parse_memory_string("-512m")
@ -67,7 +67,7 @@ def test_parse_memory_string_negative_value_raises_value_error():
def test_parse_memory_string_zero_value_raises_value_error():
"""Test that zero value raises ValueError."""
from mcp_forge.security.resource_limits import parse_memory_string
from pod_executor.security.resource_limits import parse_memory_string
with pytest.raises(ValueError) as exc_info:
parse_memory_string("0m")
@ -76,7 +76,7 @@ def test_parse_memory_string_zero_value_raises_value_error():
def test_parse_cpu_quota_valid_value():
"""Test that valid CPU quota values are accepted."""
from mcp_forge.security.resource_limits import parse_cpu_quota
from pod_executor.security.resource_limits import parse_cpu_quota
result = parse_cpu_quota(50000)
assert result == 50000
@ -87,7 +87,7 @@ def test_parse_cpu_quota_valid_value():
def test_parse_cpu_quota_max_limit():
"""Test that CPU quota has a reasonable maximum (10 cores)."""
from mcp_forge.security.resource_limits import parse_cpu_quota
from pod_executor.security.resource_limits import parse_cpu_quota
# Should accept up to 1000000 (10 cores)
result = parse_cpu_quota(1000000)
@ -101,7 +101,7 @@ def test_parse_cpu_quota_max_limit():
def test_parse_cpu_quota_negative_raises_value_error():
"""Test that negative CPU quota raises ValueError."""
from mcp_forge.security.resource_limits import parse_cpu_quota
from pod_executor.security.resource_limits import parse_cpu_quota
with pytest.raises(ValueError) as exc_info:
parse_cpu_quota(-1)
@ -110,7 +110,7 @@ def test_parse_cpu_quota_negative_raises_value_error():
def test_parse_cpu_quota_zero_raises_value_error():
"""Test that zero CPU quota raises ValueError."""
from mcp_forge.security.resource_limits import parse_cpu_quota
from pod_executor.security.resource_limits import parse_cpu_quota
with pytest.raises(ValueError) as exc_info:
parse_cpu_quota(0)
@ -119,7 +119,7 @@ def test_parse_cpu_quota_zero_raises_value_error():
def test_parse_storage_string_same_as_memory():
"""Test that storage parsing works the same as memory parsing."""
from mcp_forge.security.resource_limits import parse_storage_string
from pod_executor.security.resource_limits import parse_storage_string
assert parse_storage_string("1g") == 1073741824
assert parse_storage_string("512m") == 536870912
@ -128,7 +128,7 @@ def test_parse_storage_string_same_as_memory():
def test_resource_limits_class_initialization():
"""Test ResourceLimits class initializes correctly."""
from mcp_forge.security.resource_limits import ResourceLimits
from pod_executor.security.resource_limits import ResourceLimits
limits = ResourceLimits(
memory="512m",
@ -145,7 +145,7 @@ def test_resource_limits_class_initialization():
def test_resource_limits_validates_memory():
"""Test that ResourceLimits validates memory string."""
from mcp_forge.security.resource_limits import ResourceLimits
from pod_executor.security.resource_limits import ResourceLimits
with pytest.raises(ValueError):
ResourceLimits(
@ -158,7 +158,7 @@ def test_resource_limits_validates_memory():
def test_resource_limits_validates_storage():
"""Test that ResourceLimits validates storage string."""
from mcp_forge.security.resource_limits import ResourceLimits
from pod_executor.security.resource_limits import ResourceLimits
with pytest.raises(ValueError):
ResourceLimits(
@ -171,7 +171,7 @@ def test_resource_limits_validates_storage():
def test_resource_limits_validates_cpu_quota():
"""Test that ResourceLimits validates CPU quota."""
from mcp_forge.security.resource_limits import ResourceLimits
from pod_executor.security.resource_limits import ResourceLimits
with pytest.raises(ValueError):
ResourceLimits(
@ -184,7 +184,7 @@ def test_resource_limits_validates_cpu_quota():
def test_resource_limits_to_podman_params():
"""Test conversion to Podman container parameters."""
from mcp_forge.security.resource_limits import ResourceLimits
from pod_executor.security.resource_limits import ResourceLimits
limits = ResourceLimits(
memory="512m",
@ -205,7 +205,7 @@ def test_resource_limits_to_podman_params():
def test_resource_limits_default_timeout():
"""Test that ResourceLimits has a default timeout."""
from mcp_forge.security.resource_limits import ResourceLimits
from pod_executor.security.resource_limits import ResourceLimits
limits = ResourceLimits(
memory="512m",
@ -218,7 +218,7 @@ def test_resource_limits_default_timeout():
def test_parse_memory_string_with_spaces():
"""Test parsing memory strings that have spaces."""
from mcp_forge.security.resource_limits import parse_memory_string
from pod_executor.security.resource_limits import parse_memory_string
# Should handle spaces gracefully (strip them)
result = parse_memory_string(" 512m ")
@ -227,7 +227,7 @@ def test_parse_memory_string_with_spaces():
def test_parse_memory_string_bytes_suffix():
"""Test parsing memory string with bytes suffix (no multiplier)."""
from mcp_forge.security.resource_limits import parse_memory_string
from pod_executor.security.resource_limits import parse_memory_string
# Just a number (bytes) - should this be supported?
# Based on architecture, we support k, m, g suffixes
@ -238,7 +238,7 @@ def test_parse_memory_string_bytes_suffix():
def test_resource_limits_storage_quota_in_podman_params():
"""Test that storage limits are included in Podman params."""
from mcp_forge.security.resource_limits import ResourceLimits
from pod_executor.security.resource_limits import ResourceLimits
limits = ResourceLimits(
memory="512m",
@ -256,7 +256,7 @@ def test_resource_limits_storage_quota_in_podman_params():
def test_cpu_quota_explanation():
"""Test that CPU quota values have clear meaning."""
from mcp_forge.security.resource_limits import parse_cpu_quota
from pod_executor.security.resource_limits import parse_cpu_quota
# 100000 = 100% of one CPU core
# 50000 = 50% of one CPU core
@ -269,7 +269,7 @@ def test_cpu_quota_explanation():
def test_parse_memory_with_decimal():
"""Test parsing memory strings with decimal values."""
from mcp_forge.security.resource_limits import parse_memory_string
from pod_executor.security.resource_limits import parse_memory_string
# Should handle decimals
result = parse_memory_string("1.5g")