Skip to content

CubeLoop — a Pythonic, async-native agent harness core designed for high performance, readability, and production-grade persistence.

fix(images): FauxImagesProvider honors pre-set abort signal

xf gong5f94577dae61
diff --git a/cubepi/providers/images/faux.py b/cubepi/providers/images/faux.py
index 0ac3d95..cefc7cb 100644
--- a/cubepi/providers/images/faux.py
+++ b/cubepi/providers/images/faux.py
@@ -38,6 +38,18 @@ class FauxImagesProvider(BaseImagesProvider):
*,
options: ImagesOptions | None = None,
) -> AssistantImages:
+ # Honor a pre-set abort signal the same way the real provider does
+ # — return ``stop_reason="aborted"`` without the happy-path image
+ # so tests / local flows that exercise cancellation behave the same
+ # against Faux as they would against ``OpenAIImagesProvider``.
+ if options and options.signal and options.signal.is_set():
+ return AssistantImages(
+ api=model.api,
+ provider_id=model.provider_id,
+ model=model.id,
+ output=[],
+ stop_reason="aborted",
+ )
if self._raise is not None:
raise self._raise(
f"injected by FauxImagesProvider for {model.provider_id}/{model.id}"
diff --git a/tests/providers/images/test_faux_provider.py b/tests/providers/images/test_faux_provider.py
index 2bd8363..1bd5be1 100644
--- a/tests/providers/images/test_faux_provider.py
+++ b/tests/providers/images/test_faux_provider.py
@@ -58,3 +58,48 @@ def test_inherits_from_base_images_provider():
assert hasattr(p, "subscribe_request")
assert hasattr(p, "subscribe_response")
assert not hasattr(p, "subscribe_chunk")
+
+
+async def test_pre_set_signal_returns_aborted_matching_real_provider():
+ """Faux must short-circuit a pre-set signal the same way the real
+ OpenAIImagesProvider does — otherwise tests that exercise abort
+ behavior with Faux would silently pass while the production code
+ path actually aborts."""
+ import asyncio
+
+ from cubepi.providers.images.types import ImagesOptions
+
+ p = FauxImagesProvider(png_b64=_png_b64())
+ model = p.model("faux-1")
+ signal = asyncio.Event()
+ signal.set() # pre-set
+
+ out = await p.generate_images(
+ model,
+ ImagesContext(prompt="x"),
+ options=ImagesOptions(signal=signal),
+ )
+ assert out.stop_reason == "aborted"
+ assert out.output == []
+
+
+async def test_unset_signal_still_returns_happy_path_image():
+ """Sanity guard: signal present but never set must NOT abort —
+ Faux returns the deterministic image as usual."""
+ import asyncio
+
+ from cubepi.providers.images.types import ImagesOptions
+
+ p = FauxImagesProvider(png_b64=_png_b64())
+ model = p.model("faux-1")
+ signal = asyncio.Event() # never set
+ out = await p.generate_images(
+ model,
+ ImagesContext(prompt="x"),
+ options=ImagesOptions(signal=signal),
+ )
+ assert out.stop_reason == "stop"
+ assert len(out.output) == 1
+ assert out.output[0].media_type == "image/png"