Skip to content
Merged
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
13 changes: 9 additions & 4 deletions garak/buffs/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"""Base classes for buffs."""

from collections.abc import Iterable
import copy
import logging
from typing import List

Expand Down Expand Up @@ -51,12 +52,16 @@ def _derive_new_attempt(
status=source_attempt.status,
prompt=source_attempt.prompt,
probe_classname=source_attempt.probe_classname,
probe_params=source_attempt.probe_params,
targets=source_attempt.targets,
notes=source_attempt.notes,
detector_results=source_attempt.detector_results,
probe_params=copy.deepcopy(source_attempt.probe_params),
targets=copy.deepcopy(source_attempt.targets),
notes=copy.deepcopy(source_attempt.notes),
detector_results=copy.deepcopy(source_attempt.detector_results),
goal=source_attempt.goal,
seq=seq,
reverse_translation_outputs=copy.deepcopy(
source_attempt.reverse_translation_outputs
),
intent=source_attempt.intent,
)
new_attempt.notes["buff_creator"] = self.__class__.__name__
new_attempt.notes["buff_source_attempt_uuid"] = str(
Expand Down
39 changes: 39 additions & 0 deletions tests/buffs/test_buffs.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,42 @@ def test_paraphrase_transform_conversation_and_lang(mocker):
assert paraphrased.lang == "en"
# Verify conversations history contains the paraphrased message
assert paraphrased.conversations[0].turns[0].content.text == "Paraphrased text"


def test_derive_new_attempt_preserves_attributes():
buff = garak.buffs.base.Buff()
orig_attempt = attempt.Attempt(
intent="DirectIntent",
reverse_translation_outputs={"en": ["test output"]},
notes={"custom_note": "value"},
detector_results={"detector_a": [0.0, 1.0]},
targets=["target1"],
probe_params={"param1": "val1"},
)
derived = buff._derive_new_attempt(orig_attempt)

# Verify attributes preserved
assert derived.intent == "DirectIntent"
assert derived.reverse_translation_outputs == {"en": ["test output"]}
assert derived.notes["custom_note"] == "value"
assert derived.detector_results == {"detector_a": [0.0, 1.0]}
assert derived.targets == ["target1"]
assert derived.probe_params == {"param1": "val1"}
assert derived.notes["buff_creator"] == "Buff"

# Verify deep copy isolation: mutating derived doesn't affect orig
derived.notes["custom_note"] = "mutated"
assert orig_attempt.notes["custom_note"] == "value"
assert "buff_creator" not in orig_attempt.notes

derived.reverse_translation_outputs["en"].append("new output")
assert orig_attempt.reverse_translation_outputs == {"en": ["test output"]}

derived.detector_results["detector_a"].append(0.5)
assert orig_attempt.detector_results["detector_a"] == [0.0, 1.0]

derived.targets.append("target2")
assert orig_attempt.targets == ["target1"]

derived.probe_params["param1"] = "mutated_val"
assert orig_attempt.probe_params["param1"] == "val1"
Loading