Files
timmy-home/tests/test_bezalel_gemma4.py
Alexander Whitestone 6790170732
Some checks failed
Smoke Test / smoke (pull_request) Failing after 33s
Add tests/test_bezalel_gemma4.py
2026-04-21 11:33:36 +00:00

148 lines
4.5 KiB
Python

#!/usr/bin/env python3
"""
Tests for bezalel_gemma4_vps.py — GPU provisioning and wiring scaffold.
Covers pure functions that don't need live API calls.
"""
import json
import sys
from pathlib import Path
sys.path.insert(0, str(Path(__file__).parent.parent / "scripts"))
from bezalel_gemma4_vps import (
build_deploy_mutation,
build_runpod_endpoint,
parse_deploy_response,
update_config_text,
)
class TestBuildDeployMutation:
"""build_deploy_mutation() returns valid GraphQL."""
def test_contains_gpu_type(self):
result = build_deploy_mutation(name="test-pod")
assert "NVIDIA L40S" in result
def test_contains_pod_name(self):
result = build_deploy_mutation(name="my-gemma4")
assert "my-gemma4" in result
def test_contains_ollama_image(self):
result = build_deploy_mutation(name="test")
assert "ollama/ollama:latest" in result
def test_custom_gpu_type(self):
result = build_deploy_mutation(name="test", gpu_type="NVIDIA A100")
assert "NVIDIA A100" in result
def test_contains_port(self):
result = build_deploy_mutation(name="test")
assert "11434" in result
def test_contains_volume_mount(self):
result = build_deploy_mutation(name="test")
assert "/root/.ollama" in result
class TestBuildRunpodEndpoint:
"""build_runpod_endpoint() constructs correct URL."""
def test_basic_url(self):
url = build_runpod_endpoint("abc123")
assert url == "https://abc123-11434.proxy.runpod.net/v1"
def test_custom_port(self):
url = build_runpod_endpoint("abc123", port=8080)
assert "8080" in url
assert url == "https://abc123-8080.proxy.runpod.net/v1"
def test_is_openai_compatible(self):
url = build_runpod_endpoint("abc123")
assert url.endswith("/v1")
class TestParseDeployResponse:
"""parse_deploy_response() extracts pod info from RunPod response."""
def test_valid_response(self):
payload = {
"data": {
"podFindAndDeployOnDemand": {
"id": "pod-abc123",
"desiredStatus": "RUNNING",
"machineId": "m-xyz",
}
}
}
result = parse_deploy_response(payload)
assert result["pod_id"] == "pod-abc123"
assert result["desired_status"] == "RUNNING"
assert "pod-abc123" in result["base_url"]
def test_missing_pod_id_raises(self):
import pytest
payload = {"data": {"podFindAndDeployOnDemand": {"desiredStatus": "RUNNING"}}}
with pytest.raises(ValueError, match="pod id"):
parse_deploy_response(payload)
def test_empty_response_raises(self):
import pytest
payload = {"data": {}}
with pytest.raises(ValueError):
parse_deploy_response(payload)
class TestUpdateConfigText:
"""update_config_text() wires Big Brain provider into Hermes config."""
def test_adds_new_provider(self):
config = "model:\n default: mimo-v2-pro\n"
result = update_config_text(config, base_url="https://gpu-11434.proxy.runpod.net/v1")
assert "Big Brain" in result
assert "gpu-11434" in result
def test_replaces_existing_provider(self):
config_yaml = """model:
default: mimo-v2-pro
custom_providers:
- name: Big Brain
base_url: https://old-url.com/v1
api_key: ""
model: gemma3:latest
"""
result = update_config_text(config_yaml, base_url="https://new-url.com/v1", model="gemma4:latest")
assert "new-url.com" in result
assert "gemma4:latest" in result
assert "old-url.com" not in result
def test_custom_provider_name(self):
config = "model:\n default: test\n"
result = update_config_text(config, base_url="https://x.com/v1", provider_name="Custom Brain")
assert "Custom Brain" in result
def test_preserves_existing_config(self):
config_yaml = """model:
default: mimo-v2-pro
agent:
max_turns: 30
"""
result = update_config_text(config_yaml, base_url="https://x.com/v1")
assert "max_turns: 30" in result
assert "mimo-v2-pro" in result
def test_valid_yaml_output(self):
import yaml
config = "model:\n default: test\n"
result = update_config_text(config, base_url="https://x.com/v1")
parsed = yaml.safe_load(result)
assert isinstance(parsed, dict)
assert len(parsed["custom_providers"]) == 1
if __name__ == "__main__":
import pytest
pytest.main([__file__, "-v"])