Some checks are pending
build-images / api (push) Waiting to run
build-images / worker-gpu (push) Waiting to run
build-images / web (push) Waiting to run
codeql / Analyze (javascript-typescript) (push) Waiting to run
codeql / Analyze (python) (push) Waiting to run
perf / API hot-path micro-smoke (budgeted) (push) Waiting to run
perf / Desktop engine crates (release build check) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (comfy-workflow-schema) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (effects-core) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (eventbus-types) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (growth-analytics) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (trends-schema) (push) Waiting to run
vision2026-ci / API phase modules (ruff + pytest) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (provider-adapter-kit) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (publishing-connectors) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (render-core) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (shot-template-schema) (push) Waiting to run
vision2026-ci / Python SDK resource tests (push) Waiting to run
vision2026-ci / Desktop engine crates (test + clippy + fmt) (push) Waiting to run
vision2026-ci / Alembic upgrade + drift check (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (caption-engine) (push) Waiting to run
Paid, hosted product at menivor.com, now retired as a company project. Fresh squashed history of the cleaned working tree (secret-scanned, no .env, no customer data, no outreach logs). Built on MoneyPrinterTurbo (MIT, harry0703) — see NOTICE.
144 lines
4.3 KiB
Python
144 lines
4.3 KiB
Python
"""Server-to-server Prism client contract tests with no network."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import httpx
|
|
import pytest
|
|
|
|
from app.domains.gateway.prism_client import PrismClient, PrismClientError
|
|
|
|
|
|
def test_generate_forwards_auth_correlation_and_hard_cost_cap():
|
|
seen: list[httpx.Request] = []
|
|
|
|
def handler(request: httpx.Request) -> httpx.Response:
|
|
seen.append(request)
|
|
return httpx.Response(
|
|
200,
|
|
json={
|
|
"id": "gen_1",
|
|
"correlation_id": "gateway_job-1",
|
|
"status": "queued",
|
|
"model": "model-a",
|
|
"provider": "provider-a",
|
|
"modality": "video",
|
|
"cost_micros": 400_000,
|
|
"attempts": [],
|
|
},
|
|
)
|
|
|
|
client = PrismClient(
|
|
"http://prism.test",
|
|
"secret",
|
|
client=httpx.Client(
|
|
base_url="http://prism.test", transport=httpx.MockTransport(handler)
|
|
),
|
|
)
|
|
result = client.generate(
|
|
model="model-a",
|
|
prompt="a prompt",
|
|
modality="video",
|
|
duration_seconds=5,
|
|
aspect_ratio="16:9",
|
|
image_url="",
|
|
max_cost_micros=420_000,
|
|
correlation_id="gateway_job-1",
|
|
)
|
|
|
|
assert result["id"] == "gen_1"
|
|
request = seen[0]
|
|
assert request.headers["Authorization"] == "Bearer secret"
|
|
assert request.headers["X-Correlation-ID"] == "gateway_job-1"
|
|
body = __import__("json").loads(request.content)
|
|
assert body["routing"]["max_cost_micros"] == 420_000
|
|
assert body["routing"]["fallback"] == "equivalent"
|
|
assert body["image_url"] is None
|
|
assert body["aspect_ratio"] == "16:9"
|
|
|
|
|
|
def test_submit_5xx_is_marked_ambiguous():
|
|
client = PrismClient(
|
|
"http://prism.test",
|
|
"secret",
|
|
transport=httpx.MockTransport(
|
|
lambda _request: httpx.Response(
|
|
503, json={"error": {"message": "upstream unavailable"}}
|
|
)
|
|
),
|
|
)
|
|
|
|
with pytest.raises(PrismClientError) as error:
|
|
client.generate(
|
|
model="model-a",
|
|
prompt="a prompt",
|
|
modality="video",
|
|
max_cost_micros=420_000,
|
|
correlation_id="gateway_job-1",
|
|
)
|
|
assert error.value.may_have_been_accepted is True
|
|
assert error.value.acceptance == "unknown"
|
|
|
|
|
|
def test_generation_forwards_the_same_correlation_id_on_recovery_lookup():
|
|
seen: list[httpx.Request] = []
|
|
|
|
def handler(request: httpx.Request) -> httpx.Response:
|
|
seen.append(request)
|
|
return httpx.Response(
|
|
200, json={"id": "gen_1", "correlation_id": "gateway_job-1"}
|
|
)
|
|
|
|
client = PrismClient(
|
|
"http://prism.test",
|
|
"secret",
|
|
transport=httpx.MockTransport(handler),
|
|
)
|
|
client.generation("gen_1", correlation_id="gateway_job-1")
|
|
assert seen[0].headers["X-Correlation-ID"] == "gateway_job-1"
|
|
|
|
|
|
def test_generation_by_correlation_recovers_without_another_submit():
|
|
seen: list[httpx.Request] = []
|
|
|
|
def handler(request: httpx.Request) -> httpx.Response:
|
|
seen.append(request)
|
|
return httpx.Response(
|
|
200,
|
|
json={
|
|
"id": "gen_recovered",
|
|
"correlation_id": "gateway_lost-response",
|
|
"status": "running",
|
|
},
|
|
)
|
|
|
|
client = PrismClient(
|
|
"http://prism.test",
|
|
"secret",
|
|
transport=httpx.MockTransport(handler),
|
|
)
|
|
recovered = client.generation_by_correlation("gateway_lost-response")
|
|
|
|
assert recovered["id"] == "gen_recovered"
|
|
assert len(seen) == 1
|
|
assert seen[0].method == "GET"
|
|
assert seen[0].url.path == "/v1/generation/by-correlation"
|
|
assert seen[0].url.params["correlation_id"] == "gateway_lost-response"
|
|
|
|
|
|
def test_generation_maps_prism_error_without_leaking_response_body():
|
|
transport = httpx.MockTransport(
|
|
lambda _request: httpx.Response(
|
|
404, json={"error": {"message": "generation not found"}}
|
|
)
|
|
)
|
|
client = PrismClient(
|
|
"http://prism.test",
|
|
"secret",
|
|
client=httpx.Client(base_url="http://prism.test", transport=transport),
|
|
)
|
|
|
|
with pytest.raises(PrismClientError) as error:
|
|
client.generation("gen_missing")
|
|
assert error.value.status_code == 404
|
|
assert error.value.message == "generation not found"
|