Skip to content

The agent that grows with you

test(fal): trim the billing-409 salvage to two invariant tests

teknium1acf9177c70d8
diff --git a/tests/plugins/video_gen/test_fal_plugin.py b/tests/plugins/video_gen/test_fal_plugin.py
index eec18e03185..821d2db24d9 100644
--- a/tests/plugins/video_gen/test_fal_plugin.py
+++ b/tests/plugins/video_gen/test_fal_plugin.py
@@ -29,54 +29,6 @@ def test_fal_provider_registers():
assert DEFAULT_MODEL in {"pixverse-v6", "ltx-2.3"}
-def test_managed_billing_error_preserves_structured_diagnostic(monkeypatch):
- """Video and image callers share the same Nous billing diagnosis."""
- from plugins.video_gen import fal as fal_plugin
-
- class Response:
- status_code = 409
-
- @staticmethod
- def json():
- return {
- "error": {
- "code": "BILLING_ERROR",
- "message": "Charge authorization failed",
- "details": {
- "upstreamPayload": {
- "code": "unsupported_pricing_meter",
- "error": "Unsupported resolver usage meter",
- }
- },
- }
- }
-
- class BillingError(RuntimeError):
- def __init__(self):
- super().__init__("gateway billing failure")
- self.response = Response()
-
- error = BillingError()
- client = Mock()
- client.submit.side_effect = error
- monkeypatch.setattr(fal_plugin, "_load_fal_client", lambda: object())
- monkeypatch.setattr(
- fal_plugin, "_resolve_managed_fal_video_gateway", lambda: object()
- )
- monkeypatch.setattr(
- fal_plugin, "_get_managed_fal_video_client", lambda gateway: client
- )
-
- with pytest.raises(ValueError) as exc_info:
- fal_plugin._submit_fal_video_request("fal-ai/video", {"prompt": "x"})
-
- message = str(exc_info.value)
- assert "BILLING_ERROR" in message
- assert "unsupported_pricing_meter" in message
- assert "Nous Portal billing" in message
- assert "may not yet be enabled" not in message
-
-
def test_kling_4k_uses_start_image_url():
"""Kling v3 4K's image-to-video endpoint expects start_image_url,
not image_url. The family must declare image_param_key='start_image_url'."""
@@ -209,10 +161,9 @@ class TestFamilyRouting:
fake.submit = _submit # type: ignore
monkeypatch.setitem(sys.modules, "fal_client", fake)
- # Pin the stub directly so the clean test environment does not attempt
- # to auto-install the optional fal-client distribution.
+ # Reset the lazy global so it picks up our stub
from plugins.video_gen import fal as fal_plugin
- fal_plugin._fal_client = fake
+ fal_plugin._fal_client = None
# Also reset the managed client cache
fal_plugin._managed_fal_video_client = None
fal_plugin._managed_fal_video_client_config = None
@@ -581,7 +532,7 @@ class TestUpscalePass:
monkeypatch.setitem(sys.modules, "fal_client", fake)
from plugins.video_gen import fal as fal_plugin
- fal_plugin._fal_client = fake
+ fal_plugin._fal_client = None
fal_plugin._managed_fal_video_client = None
fal_plugin._managed_fal_video_client_config = None
diff --git a/tests/tools/test_fal_common.py b/tests/tools/test_fal_common.py
index 2d04232c482..f1507d47bbe 100644
--- a/tests/tools/test_fal_common.py
+++ b/tests/tools/test_fal_common.py
@@ -350,6 +350,12 @@ class TestManagedFalSyncClientSubmit:
)
client._maybe_retry_request.assert_not_called()
+ # Negative arm: an unkeyed submit keeps the SDK's retry ladder (transport errors, 429, ingress 5xx).
+ client._maybe_retry_request = MagicMock(return_value=response)
+ client.submit("my-app", {"prompt": "hello"})
+ client._maybe_retry_request.assert_called_once()
+ assert http_client.request.call_count == 1
+
def test_submit_with_path(self):
client, _, _ = self._make_client()
response = MagicMock()
diff --git a/tests/tools/test_image_generation.py b/tests/tools/test_image_generation.py
index da250fcd8b5..2579d2ac445 100644
--- a/tests/tools/test_image_generation.py
+++ b/tests/tools/test_image_generation.py
@@ -430,11 +430,6 @@ class TestExtractHttpStatus:
class TestManagedGatewayErrorTranslation:
"""4xx from the Nous managed gateway should be translated to a user-actionable message."""
- @pytest.fixture(autouse=True)
- def _skip_optional_fal_dependency(self, image_tool, monkeypatch):
- """These unit tests replace the managed client and need no FAL SDK."""
- monkeypatch.setattr(image_tool, "_load_fal_client", lambda: None)
-
def test_4xx_translates_to_value_error_with_remediation(self, image_tool, monkeypatch):
"""403 from managed gateway → ValueError mentioning FAL_KEY + hermes tools."""
from unittest.mock import MagicMock
diff --git a/tests/tools/test_managed_media_gateways.py b/tests/tools/test_managed_media_gateways.py
index 8d4171fc71e..4d3da246665 100644
--- a/tests/tools/test_managed_media_gateways.py
+++ b/tests/tools/test_managed_media_gateways.py
@@ -74,9 +74,6 @@ def _install_fake_tools_package():
get_session_info=lambda: {},
)
)
- lazy_deps_module = types.ModuleType("tools.lazy_deps")
- setattr(lazy_deps_module, "ensure", lambda *args, **kwargs: None)
- sys.modules["tools.lazy_deps"] = lazy_deps_module
sys.modules["tools.managed_tool_gateway"] = _load_tool_module(
"tools.managed_tool_gateway",
"managed_tool_gateway.py",
diff --git a/tests/tools/test_video_generation_tool_surface_matrix.py b/tests/tools/test_video_generation_tool_surface_matrix.py
index d32d9b08ce7..96f7e74f129 100644
--- a/tests/tools/test_video_generation_tool_surface_matrix.py
+++ b/tests/tools/test_video_generation_tool_surface_matrix.py
@@ -59,8 +59,6 @@ def matrix_env(tmp_path, monkeypatch):
fake_fal.submit = _submit # type: ignore
monkeypatch.setitem(__import__("sys").modules, "fal_client", fake_fal)
- import tools.fal_common as fal_common
- monkeypatch.setattr(fal_common, "import_fal_client", lambda: fake_fal)
# httpx stub for xAI
import httpx
@@ -102,7 +100,11 @@ def matrix_env(tmp_path, monkeypatch):
async def _no_sleep(*a, **k): return None
monkeypatch.setattr(asyncio, "sleep", _no_sleep)
- # Force discovery.
+ # Reset FAL plugin's lazy fal_client cache so it picks up the stub
+ from plugins.video_gen import fal as fal_plugin
+ fal_plugin._fal_client = None
+
+ # Force discovery
from hermes_cli.plugins import _ensure_plugins_discovered
_ensure_plugins_discovered(force=True)
diff --git a/tools/fal_common.py b/tools/fal_common.py
index 7670329dc24..2410cfd2957 100644
--- a/tools/fal_common.py
+++ b/tools/fal_common.py
@@ -134,11 +134,7 @@ class _ManagedFalSyncClient:
if has_idempotency_key:
response = self._http_client.request("POST", url, **request_kwargs)
else:
- retry_request = self._maybe_retry_request
- if retry_request is None: # guarded in __init__; keeps static analysis honest
- raise RuntimeError("fal_client.client request helpers are required")
- response = retry_request(
- self._http_client, "POST", url, **request_kwargs)
+ response = self._maybe_retry_request(self._http_client, "POST", url, **request_kwargs)
self._raise_for_status(response)
data = response.json()
return self._request_handle_class(