11# Copyright (c) Microsoft Corporation.
22# Licensed under the MIT license.
33
4- """Unit tests for :class:`ModalityFeedbackRouter `."""
4+ """Unit tests for :class:`_ModalityFeedbackRouter `."""
55
66from __future__ import annotations
77
1010
1111import pytest
1212
13- from pyrit .executor .attack .component import ModalityFeedbackRouter
13+ from pyrit .executor .attack .component . modality_router import _ModalityFeedbackRouter
1414from pyrit .models import Message , MessagePiece
1515from pyrit .prompt_target .common .target_capabilities import TargetCapabilities
1616from pyrit .prompt_target .common .target_configuration import TargetConfiguration
@@ -53,23 +53,23 @@ def _make_response(*, data_type: PromptDataType, value: str = "some-value") -> M
5353# ---------------------------------------------------------------------------
5454class TestValidateFirstTurnSeed :
5555 def test_text_only_target_no_seed_required (self ):
56- router = ModalityFeedbackRouter (
56+ router = _ModalityFeedbackRouter (
5757 adversarial_chat = _build_target (input_modalities = [{"text" }]),
5858 objective_target = _build_target (input_modalities = [{"text" }]),
5959 )
6060
6161 router .validate_first_turn_seed (next_message = None )
6262
6363 def test_multimodal_target_with_text_allowed_no_seed_required (self ):
64- router = ModalityFeedbackRouter (
64+ router = _ModalityFeedbackRouter (
6565 adversarial_chat = _build_target (input_modalities = [{"text" }]),
6666 objective_target = _build_target (input_modalities = [{"text" }, {"text" , "image_path" }]),
6767 )
6868
6969 router .validate_first_turn_seed (next_message = None )
7070
7171 def test_edit_only_target_without_next_message_raises (self ):
72- router = ModalityFeedbackRouter (
72+ router = _ModalityFeedbackRouter (
7373 adversarial_chat = _build_target (input_modalities = [{"text" }]),
7474 objective_target = _build_target (input_modalities = [{"text" , "image_path" }]),
7575 )
@@ -78,7 +78,7 @@ def test_edit_only_target_without_next_message_raises(self):
7878 router .validate_first_turn_seed (next_message = None )
7979
8080 def test_edit_only_target_with_text_only_next_message_raises (self ):
81- router = ModalityFeedbackRouter (
81+ router = _ModalityFeedbackRouter (
8282 adversarial_chat = _build_target (input_modalities = [{"text" }]),
8383 objective_target = _build_target (input_modalities = [{"text" , "image_path" }]),
8484 )
@@ -88,7 +88,7 @@ def test_edit_only_target_with_text_only_next_message_raises(self):
8888 router .validate_first_turn_seed (next_message = next_message )
8989
9090 def test_edit_only_target_with_media_seed_passes (self ):
91- router = ModalityFeedbackRouter (
91+ router = _ModalityFeedbackRouter (
9292 adversarial_chat = _build_target (input_modalities = [{"text" }]),
9393 objective_target = _build_target (input_modalities = [{"text" , "image_path" }]),
9494 )
@@ -120,7 +120,7 @@ def test_edit_only_target_with_media_seed_passes(self):
120120class TestBuildAdversarialInputMessage :
121121 @pytest .mark .parametrize ("media_type" , ["image_path" , "audio_path" , "video_path" ])
122122 def test_text_only_adversarial_falls_back_to_text (self , media_type ):
123- router = ModalityFeedbackRouter (
123+ router = _ModalityFeedbackRouter (
124124 adversarial_chat = _build_target (input_modalities = [{"text" }]),
125125 objective_target = _build_target (input_modalities = [{"text" }, {"text" , media_type }]),
126126 )
@@ -137,7 +137,7 @@ def test_text_only_adversarial_falls_back_to_text(self, media_type):
137137
138138 @pytest .mark .parametrize ("media_type" , ["image_path" , "audio_path" , "video_path" ])
139139 def test_multimodal_adversarial_attaches_media (self , media_type ):
140- router = ModalityFeedbackRouter (
140+ router = _ModalityFeedbackRouter (
141141 adversarial_chat = _build_target (input_modalities = [{"text" }, {"text" , media_type }]),
142142 objective_target = _build_target (input_modalities = [{"text" }]),
143143 )
@@ -157,7 +157,7 @@ def test_multimodal_adversarial_attaches_media(self, media_type):
157157 assert msg .message_pieces [0 ].conversation_id == msg .message_pieces [1 ].conversation_id
158158
159159 def test_no_last_response_returns_text_only (self ):
160- router = ModalityFeedbackRouter (
160+ router = _ModalityFeedbackRouter (
161161 adversarial_chat = _build_target (input_modalities = [{"text" }, {"text" , "image_path" }]),
162162 objective_target = _build_target (input_modalities = [{"text" }]),
163163 )
@@ -172,7 +172,7 @@ def test_no_last_response_returns_text_only(self):
172172
173173 def test_response_media_type_not_supported_falls_back (self ):
174174 # Adversarial accepts {text, image_path} but the response is audio_path.
175- router = ModalityFeedbackRouter (
175+ router = _ModalityFeedbackRouter (
176176 adversarial_chat = _build_target (input_modalities = [{"text" }, {"text" , "image_path" }]),
177177 objective_target = _build_target (input_modalities = [{"text" }, {"text" , "audio_path" }]),
178178 )
@@ -213,7 +213,7 @@ def _make_placeholder_message() -> Message:
213213 )
214214
215215 def test_replaces_placeholder_only (self ):
216- router = ModalityFeedbackRouter (
216+ router = _ModalityFeedbackRouter (
217217 adversarial_chat = _build_target (input_modalities = [{"text" }]),
218218 objective_target = _build_target (input_modalities = [{"text" , "image_path" }]),
219219 )
@@ -232,7 +232,7 @@ def test_replaces_placeholder_only(self):
232232 assert filled .message_pieces [1 ].original_value_data_type == "image_path"
233233
234234 def test_does_not_mutate_input_message (self ):
235- router = ModalityFeedbackRouter (
235+ router = _ModalityFeedbackRouter (
236236 adversarial_chat = _build_target (input_modalities = [{"text" }]),
237237 objective_target = _build_target (input_modalities = [{"text" , "image_path" }]),
238238 )
@@ -248,7 +248,7 @@ def test_does_not_mutate_input_message(self):
248248 assert message .message_pieces [0 ].original_value == ""
249249
250250 def test_filled_pieces_share_conversation_id (self ):
251- router = ModalityFeedbackRouter (
251+ router = _ModalityFeedbackRouter (
252252 adversarial_chat = _build_target (input_modalities = [{"text" }]),
253253 objective_target = _build_target (input_modalities = [{"text" , "image_path" }]),
254254 )
@@ -268,7 +268,7 @@ def test_filled_pieces_share_conversation_id(self):
268268# ---------------------------------------------------------------------------
269269class TestBuildObjectiveInputMessage :
270270 def test_turn_zero_text_only_target (self ):
271- router = ModalityFeedbackRouter (
271+ router = _ModalityFeedbackRouter (
272272 adversarial_chat = _build_target (input_modalities = [{"text" }]),
273273 objective_target = _build_target (input_modalities = [{"text" }]),
274274 )
@@ -283,7 +283,7 @@ def test_turn_zero_text_only_target(self):
283283 assert msg .get_value () == "adversarial prompt"
284284
285285 def test_turn_zero_edit_only_target_raises_defensive (self ):
286- router = ModalityFeedbackRouter (
286+ router = _ModalityFeedbackRouter (
287287 adversarial_chat = _build_target (input_modalities = [{"text" }]),
288288 objective_target = _build_target (input_modalities = [{"text" , "image_path" }]),
289289 )
@@ -296,7 +296,7 @@ def test_turn_zero_edit_only_target_raises_defensive(self):
296296 )
297297
298298 def test_turn_n_attaches_prev_media_when_supported (self ):
299- router = ModalityFeedbackRouter (
299+ router = _ModalityFeedbackRouter (
300300 adversarial_chat = _build_target (input_modalities = [{"text" }]),
301301 objective_target = _build_target (input_modalities = [{"text" }, {"text" , "image_path" }]),
302302 )
@@ -314,7 +314,7 @@ def test_turn_n_attaches_prev_media_when_supported(self):
314314 assert msg .message_pieces [1 ].original_value == "/tmp/prev.png"
315315
316316 def test_turn_n_text_only_target_drops_media (self ):
317- router = ModalityFeedbackRouter (
317+ router = _ModalityFeedbackRouter (
318318 adversarial_chat = _build_target (input_modalities = [{"text" }]),
319319 objective_target = _build_target (input_modalities = [{"text" }]),
320320 )
@@ -330,7 +330,7 @@ def test_turn_n_text_only_target_drops_media(self):
330330 assert msg .get_value () == "refine this further"
331331
332332 def test_turn_n_no_prev_response_returns_text_only (self ):
333- router = ModalityFeedbackRouter (
333+ router = _ModalityFeedbackRouter (
334334 adversarial_chat = _build_target (input_modalities = [{"text" }]),
335335 objective_target = _build_target (input_modalities = [{"text" }, {"text" , "image_path" }]),
336336 )
@@ -346,7 +346,7 @@ def test_turn_n_no_prev_response_returns_text_only(self):
346346
347347 @pytest .mark .parametrize ("media_type" , ["image_path" , "audio_path" , "video_path" ])
348348 def test_turn_n_generic_media_types (self , media_type ):
349- router = ModalityFeedbackRouter (
349+ router = _ModalityFeedbackRouter (
350350 adversarial_chat = _build_target (input_modalities = [{"text" }]),
351351 objective_target = _build_target (input_modalities = [{"text" }, {"text" , media_type }]),
352352 )
@@ -367,15 +367,15 @@ def test_turn_n_generic_media_types(self, media_type):
367367# ---------------------------------------------------------------------------
368368class TestProperties :
369369 def test_objective_target_requires_media_on_first_turn_when_text_excluded (self ):
370- router = ModalityFeedbackRouter (
370+ router = _ModalityFeedbackRouter (
371371 adversarial_chat = _build_target (input_modalities = [{"text" }]),
372372 objective_target = _build_target (input_modalities = [{"text" , "image_path" }]),
373373 )
374374
375375 assert router .objective_target_requires_media_on_first_turn is True
376376
377377 def test_objective_does_not_require_media_when_text_allowed (self ):
378- router = ModalityFeedbackRouter (
378+ router = _ModalityFeedbackRouter (
379379 adversarial_chat = _build_target (input_modalities = [{"text" }]),
380380 objective_target = _build_target (input_modalities = [{"text" }, {"text" , "image_path" }]),
381381 )
0 commit comments