Skip to content

Commit a2648d9

Browse files
committed
test: guard graph write stream plans
1 parent cc7931d commit a2648d9

1 file changed

Lines changed: 49 additions & 0 deletions

File tree

tests/test_inference_worker_failures.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,55 @@ def test_comp_stream_preview_is_marked_preview_only(self):
212212
payload = emitted[0][1]
213213
self.assertEqual(payload.get("semantics"), "preview_only")
214214

215+
def test_stream_graph_write_frame_initializes_all_matching_image_plans(self):
216+
worker = InferenceWorker.__new__(InferenceWorker)
217+
worker._graph_start_frame = 10
218+
worker._graph_stream_saved_paths = {}
219+
worker._graph_fps = 25.0
220+
emitted = []
221+
worker.graph_stream_preview = SimpleNamespace(emit=lambda *args: emitted.append(args))
222+
223+
with tempfile.TemporaryDirectory() as tmp_dir:
224+
tmp_path = Path(tmp_dir)
225+
source_path = tmp_path / "clip.mp4"
226+
source_path.write_bytes(b"0")
227+
worker._graph_source_path = str(source_path)
228+
alpha_dir = tmp_path / "alpha_out"
229+
review_dir = tmp_path / "review_out"
230+
worker._graph_write_plans = {
231+
("corridor_1", "alpha"): [
232+
{
233+
"node_id": "write_alpha",
234+
"stream_label": "alpha",
235+
"write_cfg": {"output_dir": str(alpha_dir), "output_format": "png"},
236+
"initialized": False,
237+
"closed": False,
238+
},
239+
{
240+
"node_id": "write_review",
241+
"stream_label": "alpha",
242+
"write_cfg": {"output_dir": str(review_dir), "output_format": "png"},
243+
"initialized": False,
244+
"closed": False,
245+
},
246+
]
247+
}
248+
249+
frame = np.array([[0.0, 0.5], [1.0, 0.25]], dtype=np.float32)
250+
worker._stream_graph_write_frame("corridor_1", "alpha", frame, 2, is_video=True)
251+
252+
plans = worker._graph_write_plans[("corridor_1", "alpha")]
253+
for plan, out_dir in zip(plans, (alpha_dir, review_dir)):
254+
self.assertTrue(plan["initialized"])
255+
self.assertEqual(plan["out_dir"], out_dir)
256+
self.assertIn(out_dir / "0002.png", plan["created_paths"])
257+
self.assertTrue((out_dir / "0002.png").exists())
258+
self.assertEqual(worker._graph_stream_saved_paths[plan["node_id"]], out_dir / "0001.png")
259+
260+
self.assertEqual([event[0] for event in emitted], ["write_alpha", "write_review"])
261+
self.assertEqual([event[2] for event in emitted], [12, 12])
262+
self.assertTrue(all(event[1].get("semantics") == "production_safe" for event in emitted))
263+
215264
def test_sam3_node_uses_persisted_masks_like_sam(self):
216265
worker = InferenceWorker.__new__(InferenceWorker)
217266
worker.cancel_flag = SimpleNamespace(is_set=lambda: False)

0 commit comments

Comments
 (0)