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.
69 lines
2.1 KiB
Python
69 lines
2.1 KiB
Python
"""Ad Clone keyframe vision — segment_subject (SAM 3.1), optional and gated."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import io
|
|
import os
|
|
|
|
from app.domains.adclone.vision import segment_subject
|
|
|
|
|
|
def _write_jpeg(path: str, width: int = 64, height: int = 64) -> None:
|
|
from PIL import Image
|
|
|
|
Image.new("RGB", (width, height), (5, 5, 5)).save(path, "JPEG")
|
|
|
|
|
|
def test_unconfigured_returns_none(tmp_path, monkeypatch):
|
|
monkeypatch.delenv("MODEL_API_KEY", raising=False)
|
|
monkeypatch.delenv("SAM_API_KEY", raising=False)
|
|
frame = tmp_path / "frame.jpg"
|
|
_write_jpeg(str(frame))
|
|
assert segment_subject(str(frame)) is None
|
|
|
|
|
|
def test_configured_no_match_returns_none(tmp_path, monkeypatch):
|
|
monkeypatch.setenv("MODEL_API_KEY", "k")
|
|
frame = tmp_path / "frame.jpg"
|
|
_write_jpeg(str(frame))
|
|
|
|
from app.domains.routing.providers import sam_segment
|
|
|
|
def _fake_segment_image(image_url, phrase, **kw):
|
|
assert image_url.startswith("data:image/jpeg;base64,")
|
|
return sam_segment.decode_boxes("")
|
|
|
|
monkeypatch.setattr(sam_segment, "sam_segment_image", _fake_segment_image)
|
|
assert segment_subject(str(frame)) is None
|
|
|
|
|
|
def test_configured_match_returns_result(tmp_path, monkeypatch):
|
|
monkeypatch.setenv("MODEL_API_KEY", "k")
|
|
frame = tmp_path / "frame.jpg"
|
|
_write_jpeg(str(frame))
|
|
|
|
from app.domains.routing.providers import sam_segment
|
|
|
|
example = "<0f>0<|box;x1=1;y1=1;x2=10;y2=10;w=64;h=64|>"
|
|
|
|
def _fake_segment_image(image_url, phrase, **kw):
|
|
return sam_segment.decode_boxes(example)
|
|
|
|
monkeypatch.setattr(sam_segment, "sam_segment_image", _fake_segment_image)
|
|
result = segment_subject(str(frame), "a cardboard box")
|
|
assert result is not None and result.matched is True
|
|
|
|
|
|
def test_call_failure_degrades_to_none(tmp_path, monkeypatch):
|
|
monkeypatch.setenv("MODEL_API_KEY", "k")
|
|
frame = tmp_path / "frame.jpg"
|
|
_write_jpeg(str(frame))
|
|
|
|
from app.domains.routing.providers import sam_segment
|
|
|
|
def _boom(image_url, phrase, **kw):
|
|
raise RuntimeError("network down")
|
|
|
|
monkeypatch.setattr(sam_segment, "sam_segment_image", _boom)
|
|
assert segment_subject(str(frame)) is None
|