genblaze-runway 0.2.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,76 @@
1
+ # Python
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+ *.so
6
+
7
+ # Distribution / packaging
8
+ dist/
9
+ build/
10
+ *.egg-info/
11
+ *.egg
12
+ wheels/
13
+ /MANIFEST
14
+
15
+ # Virtual environments
16
+ .venv/
17
+ venv/
18
+ env/
19
+ ENV/
20
+
21
+ # IDE / editors
22
+ .vscode/
23
+ .idea/
24
+ *.swp
25
+ *.swo
26
+ *~
27
+ .project
28
+ .settings/
29
+
30
+ # Testing / coverage
31
+ .pytest_cache/
32
+ .coverage
33
+ .coverage.*
34
+ htmlcov/
35
+ coverage.xml
36
+ *.cover
37
+
38
+ # Type checking
39
+ .mypy_cache/
40
+ .pytype/
41
+ .pyre/
42
+
43
+ # Linting
44
+ .ruff_cache/
45
+
46
+ # OS files
47
+ .DS_Store
48
+ Thumbs.db
49
+ ehthumbs.db
50
+
51
+ # Environment / secrets
52
+ .env
53
+ .env.*
54
+ !.env.example
55
+ *.pem
56
+ *.key
57
+ credentials.json
58
+
59
+ # Jupyter
60
+ .ipynb_checkpoints/
61
+
62
+ # MkDocs build output
63
+ site/
64
+
65
+ # Claude Code — local/ephemeral
66
+ .claude/settings.local.json
67
+ .claude/worktrees/
68
+ CLAUDE.local.md
69
+
70
+ # Hypothesis test cache
71
+ .hypothesis/
72
+
73
+ # Temp files
74
+ *.tmp
75
+ *.bak
76
+ *.log
@@ -0,0 +1,105 @@
1
+ Metadata-Version: 2.4
2
+ Name: genblaze-runway
3
+ Version: 0.2.0
4
+ Summary: Runway Gen video provider adapter for genblaze
5
+ Project-URL: Documentation, https://github.com/backblaze-labs/genblaze
6
+ Project-URL: Repository, https://github.com/backblaze-labs/genblaze
7
+ Project-URL: Issues, https://github.com/backblaze-labs/genblaze/issues
8
+ License-Expression: MIT
9
+ Classifier: Development Status :: 3 - Alpha
10
+ Classifier: License :: OSI Approved :: MIT License
11
+ Classifier: Typing :: Typed
12
+ Requires-Python: >=3.11
13
+ Requires-Dist: genblaze-core<0.3,>=0.2.0
14
+ Requires-Dist: runwayml>=0.6
15
+ Provides-Extra: dev
16
+ Requires-Dist: pytest>=7.0; extra == 'dev'
17
+ Description-Content-Type: text/markdown
18
+
19
+ <!-- last_verified: 2026-04-22 -->
20
+ # genblaze-runway
21
+
22
+ **[Runway](https://runwayml.com) Gen-4 / Gen-3 video provider adapter for [genblaze](https://github.com/backblaze-labs/genblaze) — text-to-video AI pipelines with SHA-256 provenance manifests on every render.**
23
+
24
+ `genblaze-runway` wraps the [Runway ML API](https://dev.runwayml.com) (Gen-4 Turbo, Gen-3a Turbo) as a genblaze provider. Compose Runway video generations into multi-step AI pipelines, persist outputs to [Backblaze B2](https://www.backblaze.com/cloud-storage?utm_source=github&utm_medium=referral&utm_campaign=ai_artifacts&utm_content=genblaze) or any S3-compatible store, and emit a tamper-evident provenance manifest for every run.
25
+
26
+ ## Why genblaze-runway
27
+
28
+ - **Runway Gen-4 Turbo, unified API** — same `Pipeline` API as Sora, Veo, Luma, Flux.
29
+ - **Provenance by default** — every render gets a SHA-256-verified manifest with prompt, model, params, timestamps.
30
+ - **Production-ready** — timeouts, retries, progress streaming, step caching, moderation hooks.
31
+ - **Composable** — chain Runway outputs into downstream FFmpeg transforms or AV compositors.
32
+ - **Durable storage** — drop the `genblaze-s3` sink in for B2 / AWS S3 / R2 / MinIO persistence.
33
+
34
+ ## Models
35
+
36
+ | Model | Notes |
37
+ |---|---|
38
+ | `gen4_turbo` | Latest Runway video model — fast, highest quality |
39
+ | `gen3a_turbo` | Previous generation — still supported |
40
+
41
+ ## Install
42
+
43
+ ```bash
44
+ pip install genblaze-runway
45
+ ```
46
+
47
+ Registers the `runway` provider via entry points; [`genblaze-core`](https://pypi.org/project/genblaze-core/) discovers it automatically.
48
+
49
+ ## Quickstart — Gen-4 Turbo text-to-video
50
+
51
+ ```bash
52
+ pip install genblaze-core genblaze-runway
53
+ export RUNWAYML_API_SECRET="..."
54
+ ```
55
+
56
+ ```python
57
+ from genblaze_core import Modality, Pipeline
58
+ from genblaze_runway import RunwayProvider
59
+
60
+ run, manifest = (
61
+ Pipeline("runway-demo")
62
+ .step(RunwayProvider(), model="gen4_turbo",
63
+ prompt="A timelapse of wildflowers blooming in a meadow, soft morning light, macro detail",
64
+ modality=Modality.VIDEO, duration=10)
65
+ .run(timeout=300)
66
+ )
67
+ print(run.steps[0].assets[0].url, manifest.canonical_hash)
68
+ assert manifest.verify()
69
+ ```
70
+
71
+ ## Persist to Backblaze B2
72
+
73
+ ```python
74
+ from genblaze_core import KeyStrategy, ObjectStorageSink
75
+ from genblaze_s3 import S3StorageBackend
76
+
77
+ storage = ObjectStorageSink(
78
+ S3StorageBackend.for_backblaze("my-bucket"),
79
+ key_strategy=KeyStrategy.HIERARCHICAL,
80
+ )
81
+ # pass sink=storage to .run(…) — assets + manifest uploaded to B2
82
+ ```
83
+
84
+ [Backblaze B2](https://www.backblaze.com/cloud-storage?utm_source=github&utm_medium=referral&utm_campaign=ai_artifacts&utm_content=genblaze) is the recommended default sink for large AI-generated video.
85
+
86
+ ## Credentials
87
+
88
+ | Env var | Where to get it |
89
+ |---|---|
90
+ | `RUNWAYML_API_SECRET` | https://dev.runwayml.com/ |
91
+
92
+ ## Documentation
93
+
94
+ - **Main repo**: https://github.com/backblaze-labs/genblaze
95
+ - **Example**: [`runway_video_pipeline.py`](https://github.com/backblaze-labs/genblaze/blob/main/examples/runway_video_pipeline.py)
96
+
97
+ ## Related packages
98
+
99
+ - [`genblaze-core`](https://pypi.org/project/genblaze-core/) — the pipeline SDK
100
+ - [`genblaze-s3`](https://pypi.org/project/genblaze-s3/) — durable storage on Backblaze B2 and other S3-compatible backends
101
+ - Other video providers: [`genblaze-openai`](https://pypi.org/project/genblaze-openai/) (Sora) · [`genblaze-google`](https://pypi.org/project/genblaze-google/) (Veo) · [`genblaze-luma`](https://pypi.org/project/genblaze-luma/) (Dream Machine) · [`genblaze-decart`](https://pypi.org/project/genblaze-decart/) (Lucy)
102
+
103
+ ## License
104
+
105
+ MIT
@@ -0,0 +1,87 @@
1
+ <!-- last_verified: 2026-04-22 -->
2
+ # genblaze-runway
3
+
4
+ **[Runway](https://runwayml.com) Gen-4 / Gen-3 video provider adapter for [genblaze](https://github.com/backblaze-labs/genblaze) — text-to-video AI pipelines with SHA-256 provenance manifests on every render.**
5
+
6
+ `genblaze-runway` wraps the [Runway ML API](https://dev.runwayml.com) (Gen-4 Turbo, Gen-3a Turbo) as a genblaze provider. Compose Runway video generations into multi-step AI pipelines, persist outputs to [Backblaze B2](https://www.backblaze.com/cloud-storage?utm_source=github&utm_medium=referral&utm_campaign=ai_artifacts&utm_content=genblaze) or any S3-compatible store, and emit a tamper-evident provenance manifest for every run.
7
+
8
+ ## Why genblaze-runway
9
+
10
+ - **Runway Gen-4 Turbo, unified API** — same `Pipeline` API as Sora, Veo, Luma, Flux.
11
+ - **Provenance by default** — every render gets a SHA-256-verified manifest with prompt, model, params, timestamps.
12
+ - **Production-ready** — timeouts, retries, progress streaming, step caching, moderation hooks.
13
+ - **Composable** — chain Runway outputs into downstream FFmpeg transforms or AV compositors.
14
+ - **Durable storage** — drop the `genblaze-s3` sink in for B2 / AWS S3 / R2 / MinIO persistence.
15
+
16
+ ## Models
17
+
18
+ | Model | Notes |
19
+ |---|---|
20
+ | `gen4_turbo` | Latest Runway video model — fast, highest quality |
21
+ | `gen3a_turbo` | Previous generation — still supported |
22
+
23
+ ## Install
24
+
25
+ ```bash
26
+ pip install genblaze-runway
27
+ ```
28
+
29
+ Registers the `runway` provider via entry points; [`genblaze-core`](https://pypi.org/project/genblaze-core/) discovers it automatically.
30
+
31
+ ## Quickstart — Gen-4 Turbo text-to-video
32
+
33
+ ```bash
34
+ pip install genblaze-core genblaze-runway
35
+ export RUNWAYML_API_SECRET="..."
36
+ ```
37
+
38
+ ```python
39
+ from genblaze_core import Modality, Pipeline
40
+ from genblaze_runway import RunwayProvider
41
+
42
+ run, manifest = (
43
+ Pipeline("runway-demo")
44
+ .step(RunwayProvider(), model="gen4_turbo",
45
+ prompt="A timelapse of wildflowers blooming in a meadow, soft morning light, macro detail",
46
+ modality=Modality.VIDEO, duration=10)
47
+ .run(timeout=300)
48
+ )
49
+ print(run.steps[0].assets[0].url, manifest.canonical_hash)
50
+ assert manifest.verify()
51
+ ```
52
+
53
+ ## Persist to Backblaze B2
54
+
55
+ ```python
56
+ from genblaze_core import KeyStrategy, ObjectStorageSink
57
+ from genblaze_s3 import S3StorageBackend
58
+
59
+ storage = ObjectStorageSink(
60
+ S3StorageBackend.for_backblaze("my-bucket"),
61
+ key_strategy=KeyStrategy.HIERARCHICAL,
62
+ )
63
+ # pass sink=storage to .run(…) — assets + manifest uploaded to B2
64
+ ```
65
+
66
+ [Backblaze B2](https://www.backblaze.com/cloud-storage?utm_source=github&utm_medium=referral&utm_campaign=ai_artifacts&utm_content=genblaze) is the recommended default sink for large AI-generated video.
67
+
68
+ ## Credentials
69
+
70
+ | Env var | Where to get it |
71
+ |---|---|
72
+ | `RUNWAYML_API_SECRET` | https://dev.runwayml.com/ |
73
+
74
+ ## Documentation
75
+
76
+ - **Main repo**: https://github.com/backblaze-labs/genblaze
77
+ - **Example**: [`runway_video_pipeline.py`](https://github.com/backblaze-labs/genblaze/blob/main/examples/runway_video_pipeline.py)
78
+
79
+ ## Related packages
80
+
81
+ - [`genblaze-core`](https://pypi.org/project/genblaze-core/) — the pipeline SDK
82
+ - [`genblaze-s3`](https://pypi.org/project/genblaze-s3/) — durable storage on Backblaze B2 and other S3-compatible backends
83
+ - Other video providers: [`genblaze-openai`](https://pypi.org/project/genblaze-openai/) (Sora) · [`genblaze-google`](https://pypi.org/project/genblaze-google/) (Veo) · [`genblaze-luma`](https://pypi.org/project/genblaze-luma/) (Dream Machine) · [`genblaze-decart`](https://pypi.org/project/genblaze-decart/) (Lucy)
84
+
85
+ ## License
86
+
87
+ MIT
@@ -0,0 +1,5 @@
1
+ """Runway video provider adapter for genblaze."""
2
+
3
+ from genblaze_runway.provider import RunwayProvider
4
+
5
+ __all__ = ["RunwayProvider"]
@@ -0,0 +1,9 @@
1
+ """Shared Runway error mapping — used by provider.py."""
2
+
3
+ from genblaze_core.models.enums import ProviderErrorCode
4
+ from genblaze_core.providers.base import classify_api_error
5
+
6
+
7
+ def map_runway_error(exc: Exception) -> ProviderErrorCode:
8
+ """Map a Runway API exception to a ProviderErrorCode."""
9
+ return classify_api_error(exc)
@@ -0,0 +1,260 @@
1
+ """RunwayProvider — adapter for the Runway Gen video API.
2
+
3
+ Uses the runwayml Python SDK with async task-based workflow:
4
+ client.image_to_video.create() → poll task → get output URL
5
+
6
+ Models, pricing, and parameter handling are driven by the ``ModelRegistry``
7
+ returned from ``create_registry()``. Users can override pricing or register
8
+ new models via::
9
+
10
+ provider = RunwayProvider(models=my_registry)
11
+
12
+ Docs: https://docs.runwayml.com/
13
+ """
14
+
15
+ from __future__ import annotations
16
+
17
+ from typing import Any
18
+
19
+ from genblaze_core.exceptions import ProviderError
20
+ from genblaze_core.models.asset import Asset, VideoMetadata
21
+ from genblaze_core.models.enums import Modality, ProviderErrorCode
22
+ from genblaze_core.models.step import Step
23
+ from genblaze_core.providers import (
24
+ BaseProvider,
25
+ ModelRegistry,
26
+ ModelSpec,
27
+ ProviderCapabilities,
28
+ by_model_and_param,
29
+ route_images,
30
+ validate_asset_url,
31
+ )
32
+ from genblaze_core.runnable.config import RunnableConfig
33
+
34
+ from ._errors import map_runway_error
35
+
36
+ _VALID_DURATIONS = frozenset({5, 10})
37
+ _VALID_RATIOS = frozenset({"16:9", "9:16"})
38
+
39
+ # Per-generation pricing keyed by (model, duration) in USD.
40
+ _RUNWAY_PRICING: dict[tuple[str, Any], float] = {
41
+ ("gen4_turbo", 5): 0.50,
42
+ ("gen4_turbo", 10): 1.00,
43
+ ("gen3a_turbo", 5): 0.25,
44
+ ("gen3a_turbo", 10): 0.50,
45
+ }
46
+
47
+
48
+ def _check_ratio(params: dict[str, Any]) -> None:
49
+ """Validate the (post-alias) Runway-native ``ratio`` value."""
50
+ ratio = params.get("ratio")
51
+ if ratio is not None and ratio not in _VALID_RATIOS:
52
+ raise ProviderError(
53
+ f"Invalid ratio={ratio!r}. Must be one of {set(_VALID_RATIOS)}",
54
+ error_code=ProviderErrorCode.INVALID_INPUT,
55
+ )
56
+
57
+
58
+ def _check_duration(params: dict[str, Any]) -> None:
59
+ """Validate ``duration`` with Runway-specific error wording."""
60
+ if "duration" not in params:
61
+ return
62
+ try:
63
+ dur = int(params["duration"])
64
+ except (TypeError, ValueError) as exc:
65
+ raise ProviderError(
66
+ f"Invalid duration={params['duration']!r}. Must be one of {set(_VALID_DURATIONS)}",
67
+ error_code=ProviderErrorCode.INVALID_INPUT,
68
+ ) from exc
69
+ if dur not in _VALID_DURATIONS:
70
+ raise ProviderError(
71
+ f"Invalid duration={dur}. Must be one of {set(_VALID_DURATIONS)}",
72
+ error_code=ProviderErrorCode.INVALID_INPUT,
73
+ )
74
+ params["duration"] = dur
75
+
76
+
77
+ def _runway_spec(model_id: str) -> ModelSpec:
78
+ """Build the per-model spec.
79
+
80
+ All Runway models share the same shape: ``aspect_ratio`` aliases to
81
+ ``ratio``, ``duration`` must be 5 or 10, the first chained image becomes
82
+ ``prompt_image``, and pricing is keyed on ``(model, duration)``.
83
+ """
84
+ # Validation lives in ``param_constraints`` rather than ``param_schemas``
85
+ # so the connector can keep its bespoke "Invalid duration=…" wording the
86
+ # public tests assert on.
87
+ return ModelSpec(
88
+ model_id=model_id,
89
+ modality=Modality.VIDEO,
90
+ pricing=by_model_and_param("duration", _RUNWAY_PRICING),
91
+ param_aliases={"aspect_ratio": "ratio"},
92
+ param_constraints=(_check_duration, _check_ratio),
93
+ input_mapping=route_images(slots=("prompt_image",)),
94
+ )
95
+
96
+
97
+ class RunwayProvider(BaseProvider):
98
+ """Provider adapter for Runway video generation (Gen-3, Gen-4).
99
+
100
+ Models: ``gen4_turbo``, ``gen3a_turbo``.
101
+
102
+ Auth: Set RUNWAYML_API_SECRET env var or pass api_secret.
103
+
104
+ Args:
105
+ api_secret: Runway API secret. Falls back to RUNWAYML_API_SECRET env var.
106
+ poll_interval: Seconds between task status polls (default 5).
107
+ models: Optional custom ``ModelRegistry`` — overrides the class default.
108
+ """
109
+
110
+ name = "runway"
111
+
112
+ @classmethod
113
+ def create_registry(cls) -> ModelRegistry:
114
+ defaults = {mid: _runway_spec(mid) for mid in ("gen4_turbo", "gen3a_turbo")}
115
+ return ModelRegistry(defaults=defaults)
116
+
117
+ def get_capabilities(self) -> ProviderCapabilities:
118
+ """Runway: video generation from text and/or image inputs."""
119
+ return ProviderCapabilities(
120
+ supported_modalities=[Modality.VIDEO],
121
+ supported_inputs=["text", "image"],
122
+ accepts_chain_input=True,
123
+ max_duration=10.0,
124
+ models=self._models.known(),
125
+ output_formats=["video/mp4"],
126
+ )
127
+
128
+ def __init__(
129
+ self,
130
+ api_secret: str | None = None,
131
+ poll_interval: float = 5.0,
132
+ *,
133
+ models: ModelRegistry | None = None,
134
+ ):
135
+ super().__init__(models=models)
136
+ self.poll_interval = poll_interval
137
+ self._api_secret = api_secret
138
+ self._client: Any = None
139
+
140
+ def normalize_params(self, params: dict, modality: Any = None) -> dict:
141
+ """Map standard params to Runway-native names.
142
+
143
+ Kept for backward compatibility with callers that invoke it directly;
144
+ ``prepare_payload`` also performs the alias via the model spec.
145
+ """
146
+ p = dict(params)
147
+ if "aspect_ratio" in p and "ratio" not in p:
148
+ p["ratio"] = p.pop("aspect_ratio")
149
+ return p
150
+
151
+ def _get_client(self):
152
+ if self._client is None:
153
+ try:
154
+ from runwayml import RunwayML
155
+ except ImportError as exc:
156
+ raise ProviderError(
157
+ "runwayml package not installed. Run: pip install runwayml"
158
+ ) from exc
159
+ kwargs: dict = {}
160
+ if self._api_secret:
161
+ kwargs["api_key"] = self._api_secret
162
+ self._client = RunwayML(**kwargs)
163
+ return self._client
164
+
165
+ def submit(self, step: Step, config: RunnableConfig | None = None) -> Any:
166
+ """Create a video generation task."""
167
+ client = self._get_client()
168
+ try:
169
+ payload = self.prepare_payload(step)
170
+
171
+ # Translate canonical 'prompt' to Runway's 'prompt_text'; only the
172
+ # SDK-recognized keys are forwarded to image_to_video.create.
173
+ request: dict = {
174
+ "model": step.model,
175
+ "prompt_text": payload.get("prompt", step.prompt or ""),
176
+ }
177
+ for key in ("duration", "ratio", "seed", "watermark", "prompt_image"):
178
+ if key in payload:
179
+ request[key] = payload[key]
180
+ if "watermark" in request:
181
+ request["watermark"] = bool(request["watermark"])
182
+
183
+ task = client.image_to_video.create(**request)
184
+ return task.id
185
+ except ProviderError:
186
+ raise
187
+ except Exception as exc:
188
+ raise ProviderError(
189
+ f"Runway submit failed: {exc}",
190
+ error_code=map_runway_error(exc),
191
+ ) from exc
192
+
193
+ def poll(self, prediction_id: Any, config: RunnableConfig | None = None) -> bool:
194
+ """Check if the Runway task is complete."""
195
+ client = self._get_client()
196
+ try:
197
+ task = client.tasks.retrieve(prediction_id)
198
+ if task.status in ("SUCCEEDED", "FAILED"):
199
+ self._cache_poll_result(prediction_id, task)
200
+ return True
201
+ return False
202
+ except Exception as exc:
203
+ raise ProviderError(
204
+ f"Runway poll failed: {exc}",
205
+ error_code=map_runway_error(exc),
206
+ ) from exc
207
+
208
+ def fetch_output(self, prediction_id: Any, step: Step) -> Step:
209
+ """Fetch the completed video URL."""
210
+ client = self._get_client()
211
+ try:
212
+ task = self._get_cached_poll_result(prediction_id)
213
+ if task is None:
214
+ task = client.tasks.retrieve(prediction_id)
215
+
216
+ step.provider_payload = {
217
+ "runway": {
218
+ "task_id": task.id,
219
+ "status": task.status,
220
+ }
221
+ }
222
+
223
+ if task.status == "FAILED":
224
+ error_msg = getattr(task, "failure", None) or "Video generation failed"
225
+ raise ProviderError(
226
+ str(error_msg),
227
+ error_code=ProviderErrorCode.UNKNOWN,
228
+ )
229
+
230
+ # Task output contains the video URL
231
+ output = getattr(task, "output", None)
232
+ if output and isinstance(output, list) and len(output) > 0:
233
+ url = str(output[0])
234
+ validate_asset_url(url)
235
+ step.assets.append(Asset(url=url, media_type="video/mp4"))
236
+ elif output and isinstance(output, str):
237
+ validate_asset_url(output)
238
+ step.assets.append(Asset(url=output, media_type="video/mp4"))
239
+ else:
240
+ raise ProviderError("Runway task completed but no output URL found")
241
+
242
+ # Pricing is keyed on (model, duration); default duration is 5s
243
+ # when the user didn't specify one. Mutate step.params so the
244
+ # registry strategy sees the effective value, matching the legacy
245
+ # behavior where 5s was assumed for cost.
246
+ duration = int(step.params.get("duration", 5))
247
+ step.params.setdefault("duration", duration)
248
+ for a in step.assets:
249
+ a.video = VideoMetadata(has_audio=False)
250
+ a.duration = a.duration or float(duration)
251
+
252
+ self._apply_registry_pricing(step)
253
+ return step
254
+ except ProviderError:
255
+ raise
256
+ except Exception as exc:
257
+ raise ProviderError(
258
+ f"Runway fetch_output failed: {exc}",
259
+ error_code=map_runway_error(exc),
260
+ ) from exc
File without changes
@@ -0,0 +1,39 @@
1
+ [build-system]
2
+ requires = ["hatchling"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "genblaze-runway"
7
+ version = "0.2.0"
8
+ description = "Runway Gen video provider adapter for genblaze"
9
+ readme = "README.md"
10
+ requires-python = ">=3.11"
11
+ license = "MIT"
12
+ classifiers = [
13
+ "Development Status :: 3 - Alpha",
14
+ "License :: OSI Approved :: MIT License",
15
+ "Typing :: Typed",
16
+ ]
17
+ dependencies = [
18
+ "genblaze-core>=0.2.0,<0.3",
19
+ "runwayml>=0.6",
20
+ ]
21
+
22
+ [project.urls]
23
+ Documentation = "https://github.com/backblaze-labs/genblaze"
24
+ Repository = "https://github.com/backblaze-labs/genblaze"
25
+ Issues = "https://github.com/backblaze-labs/genblaze/issues"
26
+
27
+ [project.optional-dependencies]
28
+ dev = [
29
+ "pytest>=7.0",
30
+ ]
31
+
32
+ [project.entry-points."genblaze.providers"]
33
+ runway = "genblaze_runway:RunwayProvider"
34
+
35
+ [tool.hatch.build.targets.wheel]
36
+ packages = ["genblaze_runway"]
37
+
38
+ [tool.pytest.ini_options]
39
+ testpaths = ["tests"]
File without changes
@@ -0,0 +1,169 @@
1
+ """Tests for RunwayProvider (mocked — no real API calls)."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from types import SimpleNamespace
6
+ from unittest.mock import MagicMock, patch
7
+
8
+ import pytest
9
+ from genblaze_core.exceptions import ProviderError
10
+ from genblaze_core.models.enums import StepStatus
11
+ from genblaze_core.models.step import Step
12
+ from genblaze_core.testing import ProviderComplianceTests
13
+
14
+
15
+ @pytest.fixture
16
+ def mock_runway():
17
+ """Patch runwayml with a mock client."""
18
+ mock_client = MagicMock()
19
+ mock_client.image_to_video.create.return_value = SimpleNamespace(id="task-abc")
20
+ mock_client.tasks.retrieve.return_value = SimpleNamespace(
21
+ id="task-abc",
22
+ status="SUCCEEDED",
23
+ output=["https://runway-output.com/video.mp4"],
24
+ )
25
+
26
+ with patch.dict("sys.modules", {"runwayml": MagicMock()}):
27
+ from genblaze_runway import RunwayProvider
28
+
29
+ provider = RunwayProvider(api_secret="test-key")
30
+ provider._client = mock_client
31
+ yield provider, mock_client
32
+
33
+
34
+ def test_submit_returns_task_id(mock_runway):
35
+ provider, client = mock_runway
36
+ step = Step(provider="runway", model="gen4_turbo", prompt="a sunset")
37
+ task_id = provider.submit(step)
38
+ assert task_id == "task-abc"
39
+ client.image_to_video.create.assert_called_once()
40
+
41
+
42
+ def test_poll_returns_true_on_succeeded(mock_runway):
43
+ provider, _ = mock_runway
44
+ assert provider.poll("task-abc") is True
45
+
46
+
47
+ def test_poll_returns_false_on_running(mock_runway):
48
+ provider, client = mock_runway
49
+ client.tasks.retrieve.return_value = SimpleNamespace(id="task-abc", status="RUNNING")
50
+ assert provider.poll("task-abc") is False
51
+
52
+
53
+ def test_fetch_output_attaches_asset(mock_runway):
54
+ provider, _ = mock_runway
55
+ step = Step(provider="runway", model="gen4_turbo", prompt="a sunset")
56
+ result = provider.fetch_output("task-abc", step)
57
+ assert len(result.assets) == 1
58
+ assert result.assets[0].media_type == "video/mp4"
59
+ assert "runway-output.com" in result.assets[0].url
60
+
61
+
62
+ def test_fetch_output_failed_raises(mock_runway):
63
+ provider, client = mock_runway
64
+ client.tasks.retrieve.return_value = SimpleNamespace(
65
+ id="task-abc", status="FAILED", failure="Content moderation"
66
+ )
67
+ step = Step(provider="runway", model="gen4_turbo", prompt="bad")
68
+ with pytest.raises(ProviderError, match="Content moderation"):
69
+ provider.fetch_output("task-abc", step)
70
+
71
+
72
+ def test_invoke_full_lifecycle(mock_runway):
73
+ provider, _ = mock_runway
74
+ step = Step(provider="runway", model="gen4_turbo", prompt="a sunset")
75
+ result = provider.invoke(step)
76
+ assert result.status == StepStatus.SUCCEEDED
77
+ assert len(result.assets) == 1
78
+
79
+
80
+ def test_invalid_duration_raises(mock_runway):
81
+ provider, _ = mock_runway
82
+ step = Step(provider="runway", model="gen4_turbo", prompt="test", params={"duration": 7})
83
+ with pytest.raises(ProviderError, match="Invalid duration"):
84
+ provider.submit(step)
85
+
86
+
87
+ def test_cost_tracked(mock_runway):
88
+ """Cost is set based on model and duration."""
89
+ provider, _ = mock_runway
90
+ step = Step(provider="runway", model="gen4_turbo", prompt="a sunset", params={"duration": 10})
91
+ result = provider.fetch_output("task-abc", step)
92
+ assert result.cost_usd is not None
93
+ assert result.cost_usd == 1.00
94
+
95
+
96
+ def test_cost_tracked_default_duration(mock_runway):
97
+ """Default 5s duration uses 5s price."""
98
+ provider, _ = mock_runway
99
+ step = Step(provider="runway", model="gen4_turbo", prompt="a sunset")
100
+ result = provider.fetch_output("task-abc", step)
101
+ assert result.cost_usd == 0.50
102
+
103
+
104
+ def test_cost_none_unknown_model(mock_runway):
105
+ """Cost stays None for unknown model."""
106
+ provider, _ = mock_runway
107
+ step = Step(provider="runway", model="unknown-model", prompt="a sunset")
108
+ result = provider.fetch_output("task-abc", step)
109
+ assert result.cost_usd is None
110
+
111
+
112
+ def test_aspect_ratio_alias(mock_runway):
113
+ """Standard 'aspect_ratio' param is mapped to 'ratio' via normalize_params."""
114
+ provider, client = mock_runway
115
+ # normalize_params maps aspect_ratio → ratio
116
+ params = provider.normalize_params({"aspect_ratio": "16:9"})
117
+ step = Step(
118
+ provider="runway",
119
+ model="gen4_turbo",
120
+ prompt="test",
121
+ params=params,
122
+ )
123
+ provider.submit(step)
124
+ call_kwargs = client.image_to_video.create.call_args[1]
125
+ assert call_kwargs["ratio"] == "16:9"
126
+
127
+
128
+ def test_invalid_aspect_ratio_alias_raises(mock_runway):
129
+ """Invalid aspect_ratio via alias is validated after normalization."""
130
+ provider, _ = mock_runway
131
+ # normalize_params maps aspect_ratio → ratio
132
+ params = provider.normalize_params({"aspect_ratio": "4:3"})
133
+ step = Step(
134
+ provider="runway",
135
+ model="gen4_turbo",
136
+ prompt="test",
137
+ params=params,
138
+ )
139
+ with pytest.raises(ProviderError, match="Invalid ratio"):
140
+ provider.submit(step)
141
+
142
+
143
+ # --- Compliance harness ---
144
+
145
+
146
+ class TestRunwayCompliance(ProviderComplianceTests):
147
+ """Verify RunwayProvider satisfies the genblaze provider contract."""
148
+
149
+ @pytest.fixture(autouse=True)
150
+ def _patch_sdk(self):
151
+ with patch.dict("sys.modules", {"runwayml": MagicMock()}):
152
+ yield
153
+
154
+ def make_provider(self):
155
+ from genblaze_runway import RunwayProvider
156
+
157
+ mock_client = MagicMock()
158
+ mock_client.image_to_video.create.return_value = SimpleNamespace(id="task-abc")
159
+ mock_client.tasks.retrieve.return_value = SimpleNamespace(
160
+ id="task-abc",
161
+ status="SUCCEEDED",
162
+ output=["https://runway-output.com/video.mp4"],
163
+ )
164
+ provider = RunwayProvider(api_secret="test-key")
165
+ provider._client = mock_client
166
+ return provider
167
+
168
+ def make_step(self):
169
+ return Step(provider="runway", model="gen4_turbo", prompt="test prompt")