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
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
63 lines
2.1 KiB
Python
63 lines
2.1 KiB
Python
"""Region storage/service for the crop pipeline (#114)."""
|
|
import pytest
|
|
|
|
from backend.app.models import ImageRecord
|
|
from backend.app.services.ml.regions import RegionService
|
|
from tests.factories import make_image_async as _img
|
|
|
|
pytestmark = pytest.mark.integration
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_replace_and_get_regions(db):
|
|
img = await _img(db, "a" * 64)
|
|
svc = RegionService(db)
|
|
n = await svc.replace_regions(img.id, ["figure"], [
|
|
{"kind": "figure", "bbox": (0.1, 0.1, 0.3, 0.4),
|
|
"score": 0.9, "detector_version": "det-v1", "frame_time": 42.5},
|
|
])
|
|
await db.commit()
|
|
assert n == 1
|
|
regs = await svc.get_regions(img.id)
|
|
assert len(regs) == 1
|
|
r = regs[0]
|
|
assert r.kind == "figure"
|
|
assert r.rw == pytest.approx(0.3) and r.rh == pytest.approx(0.4)
|
|
assert r.score == pytest.approx(0.9)
|
|
assert r.frame_time == pytest.approx(42.5) # video frame timestamp
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_replace_is_scoped_by_kind(db):
|
|
img = await _img(db, "b" * 64)
|
|
svc = RegionService(db)
|
|
await svc.replace_regions(img.id, ["figure"], [
|
|
{"kind": "figure", "bbox": (0.0, 0.0, 0.5, 0.5)},
|
|
])
|
|
await svc.replace_regions(img.id, ["concept"], [
|
|
{"kind": "concept", "bbox": (0.5, 0.5, 0.2, 0.2)},
|
|
])
|
|
await db.commit()
|
|
# Re-running the figure detector must NOT wipe the concept region.
|
|
await svc.replace_regions(img.id, ["figure"], [
|
|
{"kind": "figure", "bbox": (0.1, 0.1, 0.4, 0.4)},
|
|
])
|
|
await db.commit()
|
|
kinds = sorted(r.kind for r in await svc.get_regions(img.id))
|
|
assert kinds == ["concept", "figure"]
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_ccip_vector_round_trips(db):
|
|
img = await _img(db, "c" * 64)
|
|
svc = RegionService(db)
|
|
await svc.replace_regions(img.id, ["figure"], [
|
|
{"kind": "figure", "bbox": (0.0, 0.0, 0.5, 0.5),
|
|
"ccip_embedding": [0.1] * 768, "embedding_version": "ccip-test"},
|
|
])
|
|
await db.commit()
|
|
r = (await svc.get_regions(img.id, kinds=["figure"]))[0]
|
|
assert r.ccip_embedding is not None
|
|
assert len(list(r.ccip_embedding)) == 768
|
|
assert r.siglip_embedding is None
|