Files
FabledCurator/tests/test_api_ccip.py
T
bvandeusenandClaude Opus 5.5 ff70f837d0
CI and images / lint (push) Successful in 2s
CI and images / extension-version (push) Successful in 2s
CI and images / frontend-build (push) Successful in 20s
CI and images / backend-lint-and-test (push) Successful in 30s
CI and images / integration (push) Successful in 2m18s
CI and images / sign-extension (push) Successful in 3s
CI and images / build-agent (push) Successful in 6s
CI and images / build-web (push) Successful in 1m44s
CI and images / smoke-web (push) Successful in 56s
CI and images / promote (push) Skipped
refactor: test row factories and the fetch stub have one copy each (3109)
tests/factories.py holds image_row/make_image/make_image_async/make_tag. The
17 byte-identical _img/_tag helpers (15 modules) now import them under their
old names, so no call site changed. frontend/test/support/stubFetch.js
replaces 15 copies that differed only in formatting. Copies whose bodies
differ (other defaults, other columns, a url-only stub) are left as they
are; folding those needs a look at each caller.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LVjrnpQjRgHdvq95rASoiR
2026-09-24 16:39:38 -04:00

64 lines
2.1 KiB
Python

"""CCIP/region observability API (#114) — coverage overview + per-image detail."""
import pytest
from backend.app.models import ImageRecord, ImageRegion, TagKind
from backend.app.models.tag import image_tag
from backend.app.services.tag_service import TagService
from tests.factories import make_image_async as _img
pytestmark = pytest.mark.integration
def _ccip(slot: int) -> list[float]:
v = [0.0] * 768
v[slot] = 1.0
return v
async def _figure(db, image_id, ccip):
db.add(ImageRegion(
image_record_id=image_id, kind="figure", rx=0.0, ry=0.0, rw=1.0, rh=1.0,
ccip_embedding=ccip, embedding_version="ccip-test",
))
@pytest.mark.asyncio
async def test_overview_reports_coverage(client, db):
raven = await TagService(db).find_or_create("Raven", TagKind.character)
ref = await _img(db, "a" * 64)
await _figure(db, ref.id, _ccip(0))
await db.execute(image_tag.insert().values(
image_record_id=ref.id, tag_id=raven.id, source="manual",
))
q = await _img(db, "b" * 64)
await _figure(db, q.id, _ccip(0))
await db.commit()
body = await (await client.get("/api/ccip/overview")).get_json()
assert body["regions_by_kind"].get("figure", 0) >= 2
assert body["images_with_figure_ccip"] >= 2
assert any(
c["name"] == "Raven" and c["n_refs"] >= 1
for c in body["character_references"]
)
assert "ccip-test" in body["embedding_versions"]
@pytest.mark.asyncio
async def test_image_detail_shows_regions_and_matches(client, db):
raven = await TagService(db).find_or_create("Raven", TagKind.character)
ref = await _img(db, "c" * 64)
await _figure(db, ref.id, _ccip(0))
await db.execute(image_tag.insert().values(
image_record_id=ref.id, tag_id=raven.id, source="manual",
))
q = await _img(db, "d" * 64)
await _figure(db, q.id, _ccip(0))
await db.commit()
body = await (await client.get(f"/api/ccip/images/{q.id}")).get_json()
assert len(body["regions"]) == 1
r = body["regions"][0]
assert r["kind"] == "figure" and r["has_ccip"] is True and r["has_siglip"] is False
assert any(m["tag_id"] == raven.id for m in body["ccip_matches"])