From 843107c902f3e36e5fda1c3d32fec3c716de010a Mon Sep 17 00:00:00 2001 From: biefan <70761325+biefan@users.noreply.github.com> Date: Tue, 17 Mar 2026 06:47:36 +0000 Subject: [PATCH] Include subdirectory jailbreak templates in listings --- pyrit/datasets/jailbreak/text_jailbreak.py | 2 +- tests/unit/datasets/test_jailbreak_text.py | 4 ++++ tests/unit/scenarios/test_jailbreak.py | 6 ++++++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/pyrit/datasets/jailbreak/text_jailbreak.py b/pyrit/datasets/jailbreak/text_jailbreak.py index 87e7b40b99..a5e872da24 100644 --- a/pyrit/datasets/jailbreak/text_jailbreak.py +++ b/pyrit/datasets/jailbreak/text_jailbreak.py @@ -222,7 +222,7 @@ def get_jailbreak_templates(cls, num_templates: Optional[int] = None) -> list[st ValueError: If no jailbreak templates are found in the jailbreak directory. ValueError: If n is larger than the number of templates that exist. """ - jailbreak_template_names = [str(f.stem) + ".yaml" for f in JAILBREAK_TEMPLATES_PATH.glob("*.yaml")] + jailbreak_template_names = sorted(cls._get_template_cache().keys()) if not jailbreak_template_names: raise ValueError("No jailbreak templates found in the jailbreak directory") diff --git a/tests/unit/datasets/test_jailbreak_text.py b/tests/unit/datasets/test_jailbreak_text.py index 658eb0f960..cff56c44a3 100644 --- a/tests/unit/datasets/test_jailbreak_text.py +++ b/tests/unit/datasets/test_jailbreak_text.py @@ -82,6 +82,10 @@ def test_get_file_name_subdirectory(): assert "{{ prompt }}" not in result +def test_get_jailbreak_templates_includes_subdirectory_templates(): + assert "nova.yaml" in TextJailBreak.get_jailbreak_templates() + + def test_all_templates_render_without_syntax_errors(jailbreak_dir): """Test that all jailbreak templates can be successfully rendered with a test prompt.""" yaml_files = [f for f in jailbreak_dir.rglob("*.yaml") if "multi_parameter" not in f.parts] diff --git a/tests/unit/scenarios/test_jailbreak.py b/tests/unit/scenarios/test_jailbreak.py index 666dc5cffe..b5aac940b2 100644 --- a/tests/unit/scenarios/test_jailbreak.py +++ b/tests/unit/scenarios/test_jailbreak.py @@ -179,6 +179,12 @@ def test_init_raises_exception_when_both_num_and_which_jailbreaks(self, mock_ran with pytest.raises(ValueError): Jailbreak(num_templates=mock_random_num_templates, jailbreak_names=mock_templates) + def test_init_accepts_subdirectory_jailbreak_names(self, mock_objective_scorer, mock_memory_seed_groups): + """Test that explicit jailbreak names can reference templates stored in subdirectories.""" + with patch.object(Jailbreak, "_resolve_seed_groups", return_value=mock_memory_seed_groups): + scenario = Jailbreak(objective_scorer=mock_objective_scorer, jailbreak_names=["nova.yaml"]) + assert scenario._jailbreaks == ["nova.yaml"] + @pytest.mark.asyncio async def test_init_raises_exception_when_no_datasets_available(self, mock_objective_target, mock_objective_scorer): """Test that initialization raises ValueError when datasets are not available in memory."""