"""Validation tests for the Ideogram4CaptionBuilderInvocation region bbox contract.
The caption builder forwards each region's bbox verbatim into the structured JSON, so a malformed box
(wrong length or out-of-range coordinate) would emit a prompt the model may misapply. The Ideogram4Region
model must reject such boxes up front.
"""
import pytest
from pydantic import ValidationError
from invokeai.app.invocations.ideogram4.ideogram4_caption import Ideogram4Region
def test_valid_bbox_is_accepted():
region = Ideogram4Region(prompt="a cat", bbox=[0, 0, 1000, 1000])
assert region.bbox == [0, 0, 1000, 1000]
def test_none_bbox_is_accepted():
region = Ideogram4Region(prompt="a cat", bbox=None)
assert region.bbox is None
@pytest.mark.parametrize(
"bbox",
[
[0, 0, 1000],
[0, 0, 1000, 1000, 7],
[-1, 0, 1000, 1000],
[0, 0, 1000, 1001],
[900, 900, 100, 100],
[0, 900, 1000, 100],
],
)
def test_malformed_bbox_is_rejected(bbox: list[int]):
with pytest.raises(ValidationError):
Ideogram4Region(prompt="a cat", bbox=bbox)