hypercli-sdk 0.9.9__tar.gz → 0.10.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.
Files changed (77) hide show
  1. {hypercli_sdk-0.9.9 → hypercli_sdk-0.10.0}/PKG-INFO +1 -1
  2. {hypercli_sdk-0.9.9 → hypercli_sdk-0.10.0}/hypercli/__init__.py +1 -1
  3. {hypercli_sdk-0.9.9 → hypercli_sdk-0.10.0}/hypercli/agents.py +19 -1
  4. {hypercli_sdk-0.9.9 → hypercli_sdk-0.10.0}/hypercli/http.py +3 -2
  5. {hypercli_sdk-0.9.9 → hypercli_sdk-0.10.0}/hypercli/renders.py +22 -31
  6. {hypercli_sdk-0.9.9 → hypercli_sdk-0.10.0}/pyproject.toml +1 -1
  7. {hypercli_sdk-0.9.9 → hypercli_sdk-0.10.0}/tests/test_agents.py +31 -0
  8. {hypercli_sdk-0.9.9 → hypercli_sdk-0.10.0}/tests/test_parity_audit.py +44 -12
  9. hypercli_sdk-0.10.0/tests/test_render_catalog.py +88 -0
  10. {hypercli_sdk-0.9.9 → hypercli_sdk-0.10.0}/tests/test_renders_subscription.py +25 -20
  11. {hypercli_sdk-0.9.9 → hypercli_sdk-0.10.0}/.gitignore +0 -0
  12. {hypercli_sdk-0.9.9 → hypercli_sdk-0.10.0}/README.md +0 -0
  13. {hypercli_sdk-0.9.9 → hypercli_sdk-0.10.0}/hypercli/acp.py +0 -0
  14. {hypercli_sdk-0.9.9 → hypercli_sdk-0.10.0}/hypercli/agent.py +0 -0
  15. {hypercli_sdk-0.9.9 → hypercli_sdk-0.10.0}/hypercli/billing.py +0 -0
  16. {hypercli_sdk-0.9.9 → hypercli_sdk-0.10.0}/hypercli/chat_integrations.py +0 -0
  17. {hypercli_sdk-0.9.9 → hypercli_sdk-0.10.0}/hypercli/client.py +0 -0
  18. {hypercli_sdk-0.9.9 → hypercli_sdk-0.10.0}/hypercli/config.py +0 -0
  19. {hypercli_sdk-0.9.9 → hypercli_sdk-0.10.0}/hypercli/files.py +0 -0
  20. {hypercli_sdk-0.9.9 → hypercli_sdk-0.10.0}/hypercli/instances.py +0 -0
  21. {hypercli_sdk-0.9.9 → hypercli_sdk-0.10.0}/hypercli/job/__init__.py +0 -0
  22. {hypercli_sdk-0.9.9 → hypercli_sdk-0.10.0}/hypercli/job/base.py +0 -0
  23. {hypercli_sdk-0.9.9 → hypercli_sdk-0.10.0}/hypercli/job/comfyui.py +0 -0
  24. {hypercli_sdk-0.9.9 → hypercli_sdk-0.10.0}/hypercli/job/gradio.py +0 -0
  25. {hypercli_sdk-0.9.9 → hypercli_sdk-0.10.0}/hypercli/jobs.py +0 -0
  26. {hypercli_sdk-0.9.9 → hypercli_sdk-0.10.0}/hypercli/keys.py +0 -0
  27. {hypercli_sdk-0.9.9 → hypercli_sdk-0.10.0}/hypercli/logs.py +0 -0
  28. {hypercli_sdk-0.9.9 → hypercli_sdk-0.10.0}/hypercli/mcp.py +0 -0
  29. {hypercli_sdk-0.9.9 → hypercli_sdk-0.10.0}/hypercli/models.py +0 -0
  30. {hypercli_sdk-0.9.9 → hypercli_sdk-0.10.0}/hypercli/routines.py +0 -0
  31. {hypercli_sdk-0.9.9 → hypercli_sdk-0.10.0}/hypercli/runners.py +0 -0
  32. {hypercli_sdk-0.9.9 → hypercli_sdk-0.10.0}/hypercli/sessions.py +0 -0
  33. {hypercli_sdk-0.9.9 → hypercli_sdk-0.10.0}/hypercli/shell.py +0 -0
  34. {hypercli_sdk-0.9.9 → hypercli_sdk-0.10.0}/hypercli/user.py +0 -0
  35. {hypercli_sdk-0.9.9 → hypercli_sdk-0.10.0}/hypercli/voice.py +0 -0
  36. {hypercli_sdk-0.9.9 → hypercli_sdk-0.10.0}/hypercli/voice_stream.py +0 -0
  37. {hypercli_sdk-0.9.9 → hypercli_sdk-0.10.0}/hypercli/voice_transcription.py +0 -0
  38. {hypercli_sdk-0.9.9 → hypercli_sdk-0.10.0}/hypercli/workspaces.py +0 -0
  39. {hypercli_sdk-0.9.9 → hypercli_sdk-0.10.0}/hypercli/x402.py +0 -0
  40. {hypercli_sdk-0.9.9 → hypercli_sdk-0.10.0}/tests/integration/conftest.py +0 -0
  41. {hypercli_sdk-0.9.9 → hypercli_sdk-0.10.0}/tests/integration/test_agents.py +0 -0
  42. {hypercli_sdk-0.9.9 → hypercli_sdk-0.10.0}/tests/integration/test_auth.py +0 -0
  43. {hypercli_sdk-0.9.9 → hypercli_sdk-0.10.0}/tests/integration/test_billing.py +0 -0
  44. {hypercli_sdk-0.9.9 → hypercli_sdk-0.10.0}/tests/integration/test_instances.py +0 -0
  45. {hypercli_sdk-0.9.9 → hypercli_sdk-0.10.0}/tests/integration/test_jobs_dryrun.py +0 -0
  46. {hypercli_sdk-0.9.9 → hypercli_sdk-0.10.0}/tests/integration/test_keys.py +0 -0
  47. {hypercli_sdk-0.9.9 → hypercli_sdk-0.10.0}/tests/integration/test_renders.py +0 -0
  48. {hypercli_sdk-0.9.9 → hypercli_sdk-0.10.0}/tests/test_acp.py +0 -0
  49. {hypercli_sdk-0.9.9 → hypercli_sdk-0.10.0}/tests/test_agent_files_source.py +0 -0
  50. {hypercli_sdk-0.9.9 → hypercli_sdk-0.10.0}/tests/test_agent_lifecycle.py +0 -0
  51. {hypercli_sdk-0.9.9 → hypercli_sdk-0.10.0}/tests/test_apply_params.py +0 -0
  52. {hypercli_sdk-0.9.9 → hypercli_sdk-0.10.0}/tests/test_bootstrap_agents_e2e_user.py +0 -0
  53. {hypercli_sdk-0.9.9 → hypercli_sdk-0.10.0}/tests/test_bootstrap_console_test_key.py +0 -0
  54. {hypercli_sdk-0.9.9 → hypercli_sdk-0.10.0}/tests/test_bootstrap_dev_test_keys.py +0 -0
  55. {hypercli_sdk-0.9.9 → hypercli_sdk-0.10.0}/tests/test_chat_integrations.py +0 -0
  56. {hypercli_sdk-0.9.9 → hypercli_sdk-0.10.0}/tests/test_claw.py +0 -0
  57. {hypercli_sdk-0.9.9 → hypercli_sdk-0.10.0}/tests/test_coding_agents.py +0 -0
  58. {hypercli_sdk-0.9.9 → hypercli_sdk-0.10.0}/tests/test_config.py +0 -0
  59. {hypercli_sdk-0.9.9 → hypercli_sdk-0.10.0}/tests/test_exec_shell_dryrun.py +0 -0
  60. {hypercli_sdk-0.9.9 → hypercli_sdk-0.10.0}/tests/test_file_transport.py +0 -0
  61. {hypercli_sdk-0.9.9 → hypercli_sdk-0.10.0}/tests/test_graph_to_api.py +0 -0
  62. {hypercli_sdk-0.9.9 → hypercli_sdk-0.10.0}/tests/test_http.py +0 -0
  63. {hypercli_sdk-0.9.9 → hypercli_sdk-0.10.0}/tests/test_jobs.py +0 -0
  64. {hypercli_sdk-0.9.9 → hypercli_sdk-0.10.0}/tests/test_keys.py +0 -0
  65. {hypercli_sdk-0.9.9 → hypercli_sdk-0.10.0}/tests/test_models.py +0 -0
  66. {hypercli_sdk-0.9.9 → hypercli_sdk-0.10.0}/tests/test_public_surface.py +0 -0
  67. {hypercli_sdk-0.9.9 → hypercli_sdk-0.10.0}/tests/test_repository_integrity.py +0 -0
  68. {hypercli_sdk-0.9.9 → hypercli_sdk-0.10.0}/tests/test_routines.py +0 -0
  69. {hypercli_sdk-0.9.9 → hypercli_sdk-0.10.0}/tests/test_runner_control_url.py +0 -0
  70. {hypercli_sdk-0.9.9 → hypercli_sdk-0.10.0}/tests/test_runner_placement.py +0 -0
  71. {hypercli_sdk-0.9.9 → hypercli_sdk-0.10.0}/tests/test_runners.py +0 -0
  72. {hypercli_sdk-0.9.9 → hypercli_sdk-0.10.0}/tests/test_sessions.py +0 -0
  73. {hypercli_sdk-0.9.9 → hypercli_sdk-0.10.0}/tests/test_status.py +0 -0
  74. {hypercli_sdk-0.9.9 → hypercli_sdk-0.10.0}/tests/test_voice.py +0 -0
  75. {hypercli_sdk-0.9.9 → hypercli_sdk-0.10.0}/tests/test_voice_stream.py +0 -0
  76. {hypercli_sdk-0.9.9 → hypercli_sdk-0.10.0}/tests/test_voice_transcription.py +0 -0
  77. {hypercli_sdk-0.9.9 → hypercli_sdk-0.10.0}/tests/test_workspaces.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: hypercli-sdk
3
- Version: 0.9.9
3
+ Version: 0.10.0
4
4
  Summary: Python SDK for HyperCLI - GPU orchestration and HyperAgent API
5
5
  Project-URL: Homepage, https://hypercli.com
6
6
  Project-URL: Documentation, https://docs.hypercli.com
@@ -157,7 +157,7 @@ from .acp import (
157
157
  AmbiguousDeliveryError,
158
158
  RetryableACPError,
159
159
  )
160
- __version__ = "0.9.9"
160
+ __version__ = "0.10.0"
161
161
  __all__ = [
162
162
  "CHAT_INTEGRATIONS",
163
163
  "build_chat_integration_config",
@@ -1867,6 +1867,9 @@ class Agent:
1867
1867
  handle: str | None = None,
1868
1868
  runtime: ManagedAgentRuntime | None = None,
1869
1869
  reset_image: bool | None = None,
1870
+ soul: str | None | object = _UNSET,
1871
+ role: str | None | object = _UNSET,
1872
+ ui: dict | None = None,
1870
1873
  ) -> "Agent":
1871
1874
  agent = self._require_deployments().update(
1872
1875
  self.id,
@@ -1876,6 +1879,9 @@ class Agent:
1876
1879
  handle=handle,
1877
1880
  runtime=runtime,
1878
1881
  reset_image=reset_image,
1882
+ soul=soul,
1883
+ role=role,
1884
+ ui=ui,
1879
1885
  )
1880
1886
  self.__dict__.update(agent.__dict__)
1881
1887
  self._deployments = agent._deployments
@@ -2463,6 +2469,7 @@ class Deployments:
2463
2469
  runtime_scopes: list[str] | None = None,
2464
2470
  docker: dict | None | object = _UNSET,
2465
2471
  executor: str | None = None,
2472
+ meta: dict = None,
2466
2473
  meta_ui: dict = None,
2467
2474
  runner: dict = None,
2468
2475
  dry_run: bool = False,
@@ -2522,8 +2529,10 @@ class Deployments:
2522
2529
  body["size"] = size
2523
2530
  if runtime is not None:
2524
2531
  body["runtime"] = runtime
2532
+ if meta is not None:
2533
+ body["meta"] = copy.deepcopy(meta)
2525
2534
  if meta_ui:
2526
- body["meta"] = {"ui": copy.deepcopy(meta_ui)}
2535
+ body.setdefault("meta", {})["ui"] = copy.deepcopy(meta_ui)
2527
2536
  if tags:
2528
2537
  body["tags"] = list(tags)
2529
2538
  if runner is not None:
@@ -3358,8 +3367,17 @@ class Deployments:
3358
3367
  handle: str | None = None,
3359
3368
  runtime: ManagedAgentRuntime | None = None,
3360
3369
  reset_image: bool | None = None,
3370
+ soul: str | None | object = _UNSET,
3371
+ role: str | None | object = _UNSET,
3372
+ ui: dict | None = None,
3361
3373
  ) -> Agent:
3362
3374
  body: dict[str, Any] = {}
3375
+ if soul is not _UNSET:
3376
+ body["soul"] = soul
3377
+ if role is not _UNSET:
3378
+ body["role"] = role
3379
+ if ui is not None:
3380
+ body["ui"] = copy.deepcopy(ui)
3363
3381
  if name is not None:
3364
3382
  body["name"] = name
3365
3383
  if handle is not None:
@@ -160,10 +160,11 @@ class HTTPClient:
160
160
  )
161
161
  return _handle_response(resp)
162
162
 
163
- def post(self, path: str, json: dict = None) -> Any:
163
+ def post(self, path: str, json: dict = None, *, retries: int = 3) -> Any:
164
+ """POST with a total attempt budget; retries=1 disables automatic retries."""
164
165
  resp = request_with_retry(
165
166
  "post", f"{self.base_url}{path}",
166
- headers=self.headers, timeout=self.timeout, json=json
167
+ headers=self.headers, timeout=self.timeout, json=json, retries=retries
167
168
  )
168
169
  return _handle_response(resp)
169
170
 
@@ -65,7 +65,6 @@ class Renders:
65
65
  def __init__(self, http: "HTTPClient", auth_http: "HTTPClient" | None = None):
66
66
  self._http = http
67
67
  self._auth_http = auth_http or http
68
- self._auth_me_cache: dict[str, Any] | None = None
69
68
 
70
69
  @staticmethod
71
70
  def _parse_render_timestamp(value: Any) -> float | None:
@@ -80,39 +79,30 @@ class Renders:
80
79
  return None
81
80
  return None
82
81
 
83
- def _auth_me(self) -> dict[str, Any]:
84
- if self._auth_me_cache is None:
85
- self._auth_me_cache = self._auth_http.get("/api/auth/me")
86
- return self._auth_me_cache
82
+ def catalog(self) -> dict[str, Any]:
83
+ """Discover the same deployment catalog used by render admission."""
84
+ return self._http.get("/agents/flow/catalog")
87
85
 
88
- def _supports_subscription_family(self, family: str, resource: str | None = None) -> bool:
89
- try:
90
- auth_me = self._auth_me()
91
- except APIError:
92
- return False
93
- capabilities = set(auth_me.get("capabilities") or [])
94
- if f"{family}:*" in capabilities:
95
- return True
96
- if resource and f"{family}:{resource}" in capabilities:
97
- return True
98
- if not auth_me.get("has_active_subscription"):
99
- return False
100
- if auth_me.get("auth_type") == "user":
101
- return True
102
- return False
86
+ def submit(self, family: str, template: str, inputs: dict[str, Any] | None = None) -> Render:
87
+ """Submit upstream input names; media values are owned file_id bindings."""
88
+ params = {"family": family, "template": template, "inputs": inputs or {}}
89
+ if self._has_included_render():
90
+ return Render.from_dict(self._http.post("/agents/flow/catalog", json=params, retries=1))
91
+ return self.create(params)
92
+
93
+ def _has_included_render(self) -> bool:
94
+ access = self._auth_http.get("/agents/flow/access")
95
+ if not isinstance(access, dict) or type(access.get("render")) is not bool:
96
+ raise ValueError("Invalid render entitlement response")
97
+ return access["render"]
103
98
 
104
99
  def _post_flow(self, flow_type: str, payload: dict[str, Any]) -> dict[str, Any]:
105
- primary = f"/agents/flow/{flow_type}" if self._supports_subscription_family("flows", flow_type) else f"/api/flow/{flow_type}"
106
- try:
107
- return self._http.post(primary, json=payload)
108
- except APIError as exc:
109
- if primary.startswith("/agents/flow/") and exc.status_code in {403, 404}:
110
- return self._http.post(f"/api/flow/{flow_type}", json=payload)
111
- raise
100
+ primary = f"/agents/flow/{flow_type}" if self._has_included_render() else f"/api/flow/{flow_type}"
101
+ return self._http.post(primary, json=payload, retries=1)
112
102
 
113
103
  def _get_render(self, render_id: str, *, status: bool = False) -> dict[str, Any]:
114
104
  suffix = "/status" if status else ""
115
- primary = f"/agents/flow/renders/{render_id}{suffix}" if self._supports_subscription_family("flows") else f"/api/flow/renders/{render_id}{suffix}"
105
+ primary = f"/agents/flow/renders/{render_id}{suffix}" if self._has_included_render() else f"/api/flow/renders/{render_id}{suffix}"
116
106
  try:
117
107
  return self._http.get(primary)
118
108
  except APIError as exc:
@@ -121,7 +111,7 @@ class Renders:
121
111
  raise
122
112
 
123
113
  def _delete_render(self, render_id: str) -> dict:
124
- primary = f"/agents/flow/renders/{render_id}" if self._supports_subscription_family("flows") else f"/api/flow/renders/{render_id}"
114
+ primary = f"/agents/flow/renders/{render_id}" if self._has_included_render() else f"/api/flow/renders/{render_id}"
125
115
  try:
126
116
  return self._http.delete(primary)
127
117
  except APIError as exc:
@@ -153,7 +143,8 @@ class Renders:
153
143
  if tags:
154
144
  params["tag"] = list(tags)
155
145
 
156
- data = self._http.get("/api/renders", params=params or None)
146
+ path = "/agents/flow/renders" if type in (None, "comfyui") and self._has_included_render() else "/api/renders"
147
+ data = self._http.get(path, params=params or None)
157
148
  # Handle paginated response
158
149
  items = data.get("items", data) if isinstance(data, dict) else data
159
150
  return [Render.from_dict(r) for r in items]
@@ -186,7 +177,7 @@ class Renders:
186
177
  if tags:
187
178
  payload["tags"] = list(tags)
188
179
 
189
- data = self._http.post("/api/renders", json=payload)
180
+ data = self._http.post("/api/renders", json=payload, retries=1)
190
181
  return Render.from_dict(data)
191
182
 
192
183
  def cancel(self, render_id: str) -> dict:
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "hypercli-sdk"
7
- version = "0.9.9"
7
+ version = "0.10.0"
8
8
  description = "Python SDK for HyperCLI - GPU orchestration and HyperAgent API"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.10"
@@ -2219,6 +2219,37 @@ def test_agents_update_and_resize(agents_client):
2219
2219
  assert patch_calls[1] == ("/deployments/agent-123", {"size": "large"})
2220
2220
 
2221
2221
 
2222
+ def test_agents_metadata_create_and_update_pass_canonical_fields_and_null_clears(agents_client):
2223
+ calls = []
2224
+
2225
+ def fake_post(path, json=None):
2226
+ calls.append(("POST", path, json))
2227
+ return {"id": "agent-123", "user_id": "user-456", "state": "stopped", "meta": json.get("meta")}
2228
+
2229
+ def fake_patch(path, json=None):
2230
+ calls.append(("PATCH", path, json))
2231
+ return {"id": "agent-123", "user_id": "user-456", "state": "stopped", "meta": {}}
2232
+
2233
+ agents_client._post = fake_post
2234
+ agents_client._patch = fake_patch
2235
+ agents_client.create(meta={"soul": "# Soul", "role": "research", "ui": {"user": "U"}})
2236
+ agents_client.update("agent-123", soul=None, role=None, ui={"user": ""})
2237
+ agent = Agent(id="agent-123", user_id="user-456", state="stopped", _deployments=agents_client)
2238
+ agent.update(soul="Runtime", role="self")
2239
+
2240
+ assert calls[0][2]["meta"] == {"soul": "# Soul", "role": "research", "ui": {"user": "U"}}
2241
+ assert calls[1] == (
2242
+ "PATCH",
2243
+ "/deployments/agent-123",
2244
+ {"soul": None, "role": None, "ui": {"user": ""}},
2245
+ )
2246
+ assert calls[2] == (
2247
+ "PATCH",
2248
+ "/deployments/agent-123",
2249
+ {"soul": "Runtime", "role": "self"},
2250
+ )
2251
+
2252
+
2222
2253
  def test_agents_update_sends_runtime_and_reset_image(agents_client):
2223
2254
  patch_calls = []
2224
2255
 
@@ -7,6 +7,7 @@ import pytest
7
7
  from hypercli.agents import Deployments
8
8
  from hypercli.billing import Billing
9
9
  from hypercli.keys import ApiKey
10
+ from hypercli.http import APIError
10
11
  from hypercli.renders import Renders
11
12
  from hypercli.user import AuthMe, RuntimeIdentity, UserAPI
12
13
  from hypercli.workspaces import WorkspacesAPI
@@ -16,16 +17,21 @@ from hypercli.x402 import X402Client
16
17
  class DummyHTTP:
17
18
  def __init__(self):
18
19
  self.calls = []
19
- self.auth_me = {"auth_type": "user", "capabilities": [], "has_active_subscription": True}
20
+ self.access = {"render": False}
21
+ self.post_error = None
20
22
 
21
23
  def get(self, path, params=None):
22
24
  self.calls.append(("get", path, params))
23
- if path == "/api/auth/me":
24
- return self.auth_me
25
- return {"id": "render-123", "state": "queued"}
25
+ assert path == "/agents/flow/access"
26
+ if isinstance(self.access, Exception):
27
+ raise self.access
28
+ return self.access
26
29
 
27
- def post(self, path, json=None):
30
+ def post(self, path, json=None, *, retries):
31
+ assert retries == 1
28
32
  self.calls.append(("post", path, json))
33
+ if self.post_error:
34
+ raise self.post_error
29
35
  return {"id": "render-123", "state": "queued"}
30
36
 
31
37
  def patch(self, path, json=None):
@@ -39,7 +45,6 @@ class DummyHTTP:
39
45
 
40
46
  def make_renders():
41
47
  http = DummyHTTP()
42
- http.auth_me = {"auth_type": "api_key", "capabilities": [], "has_active_subscription": False}
43
48
  return Renders(http), http
44
49
 
45
50
 
@@ -67,15 +72,42 @@ def test_text_to_speech_routes_through_flow_transport():
67
72
 
68
73
  def test_audio_to_text_uses_subscription_route_when_supported():
69
74
  renders, http = make_renders()
70
- http.auth_me = {
71
- "auth_type": "orchestra_key",
72
- "capabilities": ["flows:*"],
73
- "has_active_subscription": True,
74
- }
75
+ http.access = {"render": True}
75
76
 
76
77
  renders.audio_to_text(audio_url="https://example.com/a.mp3")
77
78
 
78
- assert ("post", "/agents/flow/audio-to-text", {"audio_url": "https://example.com/a.mp3"}) in http.calls
79
+ assert http.calls == [
80
+ ("get", "/agents/flow/access", None),
81
+ ("post", "/agents/flow/audio-to-text", {"audio_url": "https://example.com/a.mp3"}),
82
+ ]
83
+
84
+
85
+ def test_media_flow_rechecks_entitlement_without_billing_or_account_scopes():
86
+ renders, http = make_renders()
87
+ http.access = {"render": True}
88
+ renders.text_to_speech("hello")
89
+ # A restricted/revoked credential must fail, not reuse cached access or pay.
90
+ http.access = APIError(403, "Flow access denied")
91
+ with pytest.raises(APIError):
92
+ renders.text_to_speech("again")
93
+ assert [(method, path) for method, path, _ in http.calls] == [
94
+ ("get", "/agents/flow/access"),
95
+ ("post", "/agents/flow/text-to-speech"),
96
+ ("get", "/agents/flow/access"),
97
+ ]
98
+
99
+
100
+ @pytest.mark.parametrize("status", [403, 404, 503])
101
+ def test_media_rejection_never_silently_falls_back_to_paid_route(status):
102
+ renders, http = make_renders()
103
+ http.access = {"render": True}
104
+ http.post_error = APIError(status, "Rejected")
105
+ with pytest.raises(APIError):
106
+ renders.audio_to_text(audio_url="https://example.com/a.mp3")
107
+ assert http.calls == [
108
+ ("get", "/agents/flow/access", None),
109
+ ("post", "/agents/flow/audio-to-text", {"audio_url": "https://example.com/a.mp3"}),
110
+ ]
79
111
 
80
112
 
81
113
  def test_speaking_video_wan_removed():
@@ -0,0 +1,88 @@
1
+ from hypercli.renders import Renders
2
+ from hypercli.http import APIError
3
+ from hypercli.http import HTTPClient
4
+ import httpx
5
+ import pytest
6
+
7
+
8
+ def test_catalog_transport_and_submission_preserve_upstream_input_names():
9
+ for subscription in (False, True):
10
+ class HTTP:
11
+ calls = []
12
+
13
+ def get(self, path):
14
+ self.calls.append(("GET", path))
15
+ if path == "/agents/flow/access":
16
+ return {"render": subscription}
17
+ return {"qwen21": {"templates": {"sample": {"inputs": {}}}}}
18
+
19
+ def post(self, path, json, *, retries):
20
+ assert retries == 1
21
+ self.calls.append(("POST", path, json))
22
+ return {"id": "render-1", "state": "pending"}
23
+
24
+ http = HTTP()
25
+ renders = Renders(http)
26
+ assert "qwen21" in renders.catalog()
27
+ assert http.calls == [("GET", "/agents/flow/catalog")]
28
+ values = {"seed": 0, "switch": False, "images.image_5_1": {"file_id": "owned"}}
29
+ renders.submit("qwen21", "sample", values)
30
+ _, path, payload = http.calls[-1]
31
+ assert path == ("/agents/flow/catalog" if subscription else "/api/renders")
32
+ assert (payload if subscription else payload["params"]) == {"family": "qwen21", "template": "sample", "inputs": values}
33
+
34
+
35
+ @pytest.mark.parametrize("reply", [APIError(403, "denied"), APIError(404, "missing"), {}, {"render": "true"}])
36
+ def test_failed_entitlement_discovery_never_submits_paid(reply):
37
+ class HTTP:
38
+ def get(self, path):
39
+ assert path == "/agents/flow/access"
40
+ if isinstance(reply, Exception):
41
+ raise reply
42
+ return reply
43
+ def post(self, *args, **kwargs):
44
+ pytest.fail("discovery failure must not submit any render")
45
+ with pytest.raises((APIError, ValueError)):
46
+ Renders(HTTP()).submit("qwen21", "sample")
47
+
48
+
49
+ @pytest.mark.parametrize("included", [False, True])
50
+ def test_real_transport_submissions_are_attempted_once(monkeypatch, included):
51
+ posts = []
52
+ monkeypatch.setattr(httpx.Client, "get", lambda self, url, **kwargs: httpx.Response(200, json={"render": included}))
53
+ def post(self, url, **kwargs):
54
+ posts.append(url)
55
+ raise httpx.ReadTimeout("response lost after acceptance")
56
+ monkeypatch.setattr(httpx.Client, "post", post)
57
+ http = HTTPClient("https://unit.invalid", "unit")
58
+ try:
59
+ renders = Renders(http)
60
+ for submit in (lambda: renders.submit("qwen21", "sample"),
61
+ lambda: renders.create_flow("text-to-image", prompt="42"),
62
+ lambda: renders.create({})):
63
+ with pytest.raises(httpx.ReadTimeout):
64
+ submit()
65
+ assert posts == [
66
+ "https://unit.invalid" + ("/agents/flow/catalog" if included else "/api/renders"),
67
+ "https://unit.invalid" + ("/agents/flow" if included else "/api/flow") + "/text-to-image",
68
+ "https://unit.invalid/api/renders",
69
+ ]
70
+ finally:
71
+ http.close()
72
+
73
+
74
+ def test_real_transport_get_still_retries(monkeypatch):
75
+ calls = []
76
+ def get(self, url, **kwargs):
77
+ calls.append(url)
78
+ if len(calls) == 1:
79
+ raise httpx.ConnectError("transient")
80
+ return httpx.Response(200, json={"render": False} if url.endswith("/access") else {})
81
+ monkeypatch.setattr(httpx.Client, "get", get)
82
+ monkeypatch.setattr("hypercli.http.time.sleep", lambda _: None)
83
+ http = HTTPClient("https://unit.invalid", "unit")
84
+ try:
85
+ assert Renders(http).catalog() == {}
86
+ assert calls == ["https://unit.invalid/agents/flow/catalog"] * 2
87
+ finally:
88
+ http.close()
@@ -1,6 +1,6 @@
1
+ import pytest
1
2
  from hypercli.http import APIError
2
3
  from hypercli.renders import Renders
3
- from hypercli.http import APIError
4
4
 
5
5
 
6
6
  class DummyHTTP:
@@ -10,15 +10,18 @@ class DummyHTTP:
10
10
 
11
11
  def get(self, path, params=None):
12
12
  self.calls.append(("get", path, params))
13
- if path == "/api/auth/me":
14
- return self.auth_me
13
+ if path == "/agents/flow/access":
14
+ if path in self.fail_once:
15
+ raise self.fail_once.pop(path)
16
+ return {"render": True}
15
17
  if path.endswith("/status"):
16
18
  render_id = path.split("/")[-2]
17
19
  return {"id": render_id, "state": "running", "progress": 0.5}
18
20
  render_id = path.split("/")[-1]
19
21
  return {"id": render_id, "state": "queued"}
20
22
 
21
- def post(self, path, json=None):
23
+ def post(self, path, json=None, *, retries):
24
+ assert retries == 1
22
25
  self.calls.append(("post", path, json))
23
26
  if self.fail_once.get(path):
24
27
  error = self.fail_once.pop(path)
@@ -56,7 +59,7 @@ def test_create_flow_uses_subscription_route_when_available():
56
59
  render = renders.create_flow("text-to-image", prompt="hello")
57
60
 
58
61
  assert render.render_id == "render-123"
59
- assert http.calls[0] == ("get", "/api/auth/me", None)
62
+ assert http.calls[0] == ("get", "/agents/flow/access", None)
60
63
  assert http.calls[1] == ("post", "/agents/flow/text-to-image", {"prompt": "hello"})
61
64
 
62
65
 
@@ -72,25 +75,25 @@ def test_create_flow_uses_subscription_route_for_scoped_runtime_key_without_orch
72
75
  render = renders.create_flow("text-to-image", prompt="hello")
73
76
 
74
77
  assert render.render_id == "render-123"
75
- assert http.calls[0] == ("get", "/api/auth/me", None)
78
+ assert http.calls[0] == ("get", "/agents/flow/access", None)
76
79
  assert http.calls[1] == ("post", "/agents/flow/text-to-image", {"prompt": "hello"})
77
80
 
78
81
 
79
- def test_create_flow_falls_back_to_paid_route_on_subscription_rejection():
82
+ @pytest.mark.parametrize("status", [403, 404, 503])
83
+ def test_create_flow_never_retries_paid_route_on_subscription_rejection(status):
80
84
  http = DummyHTTP()
81
85
  http.auth_me = {
82
86
  "auth_type": "orchestra_key",
83
87
  "capabilities": ["flows:*"],
84
88
  "has_active_subscription": True,
85
89
  }
86
- http.fail_once["/agents/flow/text-to-image"] = APIError(403, "Active paid subscription required")
90
+ http.fail_once["/agents/flow/text-to-image"] = APIError(status, "Rejected")
87
91
  renders = Renders(http)
88
92
 
89
- render = renders.create_flow("text-to-image", prompt="hello")
90
-
91
- assert render.render_id == "render-123"
93
+ with pytest.raises(APIError):
94
+ renders.create_flow("text-to-image", prompt="hello")
92
95
  assert http.calls[1] == ("post", "/agents/flow/text-to-image", {"prompt": "hello"})
93
- assert http.calls[2] == ("post", "/api/flow/text-to-image", {"prompt": "hello"})
96
+ assert len(http.calls) == 2
94
97
 
95
98
 
96
99
  def test_get_status_and_cancel_prefer_subscription_render_routes():
@@ -114,7 +117,7 @@ def test_get_status_and_cancel_prefer_subscription_render_routes():
114
117
  assert ("delete", "/agents/flow/renders/render-123", None) in http.calls
115
118
 
116
119
 
117
- def test_flow_only_keys_fallback_to_api_flow_render_routes_when_auth_me_is_denied():
120
+ def test_flow_only_keys_use_fresh_entitlement_without_auth_me():
118
121
  calls = []
119
122
 
120
123
  class FlowHTTP:
@@ -122,6 +125,8 @@ def test_flow_only_keys_fallback_to_api_flow_render_routes_when_auth_me_is_denie
122
125
  calls.append(("get", path, params))
123
126
  if path == "/api/auth/me":
124
127
  raise APIError(status_code=403, detail="Access denied", response_text='{"detail":"Access denied"}')
128
+ if path == "/agents/flow/access":
129
+ return {"render": True}
125
130
  return {"id": "render-123", "state": "queued"}
126
131
 
127
132
  def delete(self, path):
@@ -137,9 +142,9 @@ def test_flow_only_keys_fallback_to_api_flow_render_routes_when_auth_me_is_denie
137
142
  assert render.render_id == "render-123"
138
143
  assert status.render_id == "render-123"
139
144
  assert cancelled["status"] == "cancelled"
140
- assert ("get", "/api/flow/renders/render-123", None) in calls
141
- assert ("get", "/api/flow/renders/render-123/status", None) in calls
142
- assert ("delete", "/api/flow/renders/render-123", None) in calls
145
+ assert ("get", "/agents/flow/renders/render-123", None) in calls
146
+ assert ("get", "/agents/flow/renders/render-123/status", None) in calls
147
+ assert ("delete", "/agents/flow/renders/render-123", None) in calls
143
148
 
144
149
 
145
150
  def test_wait_allows_queue_grace(monkeypatch):
@@ -154,8 +159,8 @@ def test_wait_allows_queue_grace(monkeypatch):
154
159
 
155
160
  def fake_get(path, params=None):
156
161
  http.calls.append(("get", path, params))
157
- if path == "/api/auth/me":
158
- return http.auth_me
162
+ if path == "/agents/flow/access":
163
+ return {"render": True}
159
164
  calls["count"] += 1
160
165
  if calls["count"] <= 3:
161
166
  return {"id": "render-123", "state": "running", "started_at": None}
@@ -184,8 +189,8 @@ def test_wait_allows_recent_active_grace(monkeypatch):
184
189
 
185
190
  def fake_get(path, params=None):
186
191
  http.calls.append(("get", path, params))
187
- if path == "/api/auth/me":
188
- return http.auth_me
192
+ if path == "/agents/flow/access":
193
+ return {"render": True}
189
194
  calls["count"] += 1
190
195
  if calls["count"] == 1:
191
196
  return {"id": "render-123", "state": "running", "started_at": None}
File without changes
File without changes