Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyrit/datasets/jailbreak/text_jailbreak.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
4 changes: 4 additions & 0 deletions tests/unit/datasets/test_jailbreak_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
6 changes: 6 additions & 0 deletions tests/unit/scenarios/test_jailbreak.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down