Files
FabledCurator/tests/test_api_ccip.py
T
bvandeusen de33bab41c
CI / lint (push) Failing after 2s
CI / frontend-build (push) Successful in 18s
CI / backend-lint-and-test (push) Successful in 25s
CI / integration (push) Successful in 3m26s
feat(ccip): read-only observability API for the crop/CCIP work (#114)
So the work can be checked through an API as the agent fills in vectors (same
pattern as /api/heads/metrics):
- GET /api/ccip/overview: regions by kind, images with figure CCIP vectors, the
  per-character reference counts (which characters have enough examples to match
  on), and the embedding versions present.
- GET /api/ccip/images/<id>: that image's stored regions (bbox, frame_time,
  has_ccip/has_siglip, versions) + the CCIP character matches it would get — for
  spot-checking detector + matcher output.

Read-only, no GPU. (Queue depth is already at /api/gpu/status.)

Tests: overview coverage counts + per-character refs; per-image regions + matches.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Ttrj5P7upUTueSfoJcxEqa
2026-06-29 12:54:35 -04:00

73 lines
2.4 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
pytestmark = pytest.mark.integration
def _ccip(slot: int) -> list[float]:
v = [0.0] * 768
v[slot] = 1.0
return v
async def _img(db, sha) -> ImageRecord:
img = ImageRecord(
path=f"/images/{sha}.jpg", sha256=sha, size_bytes=1, mime="image/jpeg",
width=1, height=1, origin="imported_filesystem", integrity_status="unknown",
)
db.add(img)
await db.flush()
return img
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"])