fix(xai): route video models by modality
This commit is contained in:
@@ -25,6 +25,43 @@ def test_xai_provider_registers():
|
||||
assert provider.default_model() == "grok-imagine-video"
|
||||
|
||||
|
||||
def test_xai_provider_lists_text_and_current_image_video_models():
|
||||
from plugins.video_gen.xai import XAIVideoGenProvider
|
||||
|
||||
models = XAIVideoGenProvider().list_models()
|
||||
ids = [model["id"] for model in models]
|
||||
|
||||
assert ids[0] == "grok-imagine-video"
|
||||
assert ids[1] == "grok-imagine-video-1.5-preview"
|
||||
assert models[1]["modalities"] == ["image"]
|
||||
assert models[1]["aliases"] == ["grok-imagine-video-1.5-2026-05-30"]
|
||||
|
||||
|
||||
def test_xai_routes_default_models_by_modality():
|
||||
from plugins.video_gen.xai import _resolve_model_for_modality
|
||||
|
||||
assert _resolve_model_for_modality(
|
||||
"grok-imagine-video",
|
||||
modality="text",
|
||||
explicit_model=False,
|
||||
) == "grok-imagine-video"
|
||||
assert _resolve_model_for_modality(
|
||||
"grok-imagine-video",
|
||||
modality="image",
|
||||
explicit_model=False,
|
||||
) == "grok-imagine-video-1.5-preview"
|
||||
assert _resolve_model_for_modality(
|
||||
"grok-imagine-video-1.5-preview",
|
||||
modality="text",
|
||||
explicit_model=False,
|
||||
) == "grok-imagine-video"
|
||||
assert _resolve_model_for_modality(
|
||||
"grok-imagine-video-1.5-preview",
|
||||
modality="text",
|
||||
explicit_model=True,
|
||||
) == "grok-imagine-video-1.5-preview"
|
||||
|
||||
|
||||
def test_xai_capabilities_text_and_image_only():
|
||||
"""xAI was previously advertised with edit/extend operations. The
|
||||
simplified surface only exposes text-to-video and image-to-video —
|
||||
|
||||
@@ -56,7 +56,7 @@ class _FakeAsyncClient:
|
||||
return _FakeResponse(200, {
|
||||
"status": "done",
|
||||
"video": {"url": "https://xai-cdn/out.mp4", "duration": 8},
|
||||
"model": "grok-imagine-video",
|
||||
"model": self.posts[-1]["json"]["model"],
|
||||
})
|
||||
|
||||
|
||||
@@ -113,6 +113,7 @@ class TestXAIPayload:
|
||||
provider, captured = xai_provider
|
||||
provider.generate("a dog at sunset")
|
||||
payload = _last_post(captured)["json"]
|
||||
assert payload["model"] == "grok-imagine-video"
|
||||
assert payload["prompt"] == "a dog at sunset"
|
||||
assert "image" not in payload
|
||||
assert "reference_images" not in payload
|
||||
@@ -121,8 +122,31 @@ class TestXAIPayload:
|
||||
provider, captured = xai_provider
|
||||
provider.generate("animate this", image_url="https://example.com/cat.png")
|
||||
payload = _last_post(captured)["json"]
|
||||
assert payload["model"] == "grok-imagine-video-1.5-preview"
|
||||
assert payload["image"] == {"url": "https://example.com/cat.png"}
|
||||
|
||||
def test_local_image_path_is_sent_as_data_uri(self, xai_provider, tmp_path):
|
||||
provider, captured = xai_provider
|
||||
image_path = tmp_path / "frame.png"
|
||||
image_path.write_bytes(b"\x89PNG\r\n\x1a\nfake")
|
||||
|
||||
provider.generate("animate this", image_url=str(image_path))
|
||||
|
||||
payload = _last_post(captured)["json"]
|
||||
assert payload["model"] == "grok-imagine-video-1.5-preview"
|
||||
assert payload["image"]["url"].startswith("data:image/png;base64,")
|
||||
|
||||
def test_explicit_model_override_is_honored_for_image(self, xai_provider):
|
||||
provider, captured = xai_provider
|
||||
provider.generate(
|
||||
"animate this",
|
||||
image_url="https://example.com/cat.png",
|
||||
model="grok-imagine-video",
|
||||
_model_override_explicit=True,
|
||||
)
|
||||
payload = _last_post(captured)["json"]
|
||||
assert payload["model"] == "grok-imagine-video"
|
||||
|
||||
def test_reference_images_payload(self, xai_provider):
|
||||
provider, captured = xai_provider
|
||||
provider.generate(
|
||||
|
||||
@@ -82,7 +82,7 @@ def matrix_env(tmp_path, monkeypatch):
|
||||
return _Resp({
|
||||
"status": "done",
|
||||
"video": {"url": "https://xai-cdn/out.mp4", "duration": 8},
|
||||
"model": "grok-imagine-video",
|
||||
"model": xai_calls[-1]["json"].get("model", "grok-imagine-video"),
|
||||
})
|
||||
import plugins.video_gen.xai as xai_plugin
|
||||
monkeypatch.setattr(xai_plugin.httpx, "AsyncClient", lambda: _Client())
|
||||
@@ -202,6 +202,7 @@ def test_xai_text_only_via_tool_surface(matrix_env):
|
||||
assert len(xai_calls) == 1
|
||||
assert xai_calls[0]["url"].endswith("/videos/generations")
|
||||
payload = xai_calls[0]["json"] or {}
|
||||
assert payload["model"] == "grok-imagine-video"
|
||||
assert "image" not in payload
|
||||
assert "reference_images" not in payload
|
||||
|
||||
@@ -221,6 +222,26 @@ def test_xai_text_plus_image_via_tool_surface(matrix_env):
|
||||
assert len(xai_calls) == 1
|
||||
assert xai_calls[0]["url"].endswith("/videos/generations")
|
||||
payload = xai_calls[0]["json"] or {}
|
||||
assert payload["model"] == "grok-imagine-video-1.5-preview"
|
||||
assert payload["image"] == {"url": "https://example.com/img.png"}
|
||||
|
||||
|
||||
def test_xai_explicit_model_override_via_tool_surface(matrix_env):
|
||||
home, _, xai_calls = matrix_env
|
||||
|
||||
result = _invoke_tool(
|
||||
home,
|
||||
{"video_gen": {"provider": "xai"}},
|
||||
{
|
||||
"prompt": "animate this",
|
||||
"image_url": "https://example.com/img.png",
|
||||
"model": "grok-imagine-video",
|
||||
},
|
||||
)
|
||||
assert result["success"] is True
|
||||
|
||||
payload = xai_calls[0]["json"] or {}
|
||||
assert payload["model"] == "grok-imagine-video"
|
||||
assert payload["image"] == {"url": "https://example.com/img.png"}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user