Skip to content

Commit 5e53b65

Browse files
test(attempt): add regression tests for reverse_translation_outputs schema
Fixes #1201 The original issue reported `reverse_translation_outputs` appearing with unexpected values when no translation was active. Investigation confirms that `_postprocess_attempt()` already gates population behind `this_attempt.lang != self.lang`, so the field is correctly empty (`[]`) in non-translation runs. `as_dict()` always serializes the key (even when empty) to give consumers a stable schema. These two tests make that contract explicit: - `test_asdict_always_includes_reverse_translation_outputs`: the key is always present in the serialized dict, never absent. - `test_asdict_reverse_translation_outputs_empty_when_no_translation`: the value is `[]` when no translation is configured. Signed-off-by: Varun Nuthalapati <nuthalapativarun@gmail.com>
1 parent 2e9b3f5 commit 5e53b65

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

tests/test_attempt.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -646,3 +646,22 @@ def test_attempt_prompt_no_str():
646646
def test_attempt_asdict():
647647
a = garak.attempt.Attempt()
648648
a.as_dict()
649+
650+
651+
def test_asdict_always_includes_reverse_translation_outputs():
652+
# reverse_translation_outputs must always be present in as_dict() output,
653+
# even when empty, so consumers can rely on a stable schema (issue #1201).
654+
a = garak.attempt.Attempt()
655+
d = a.as_dict()
656+
assert "reverse_translation_outputs" in d
657+
assert d["reverse_translation_outputs"] == []
658+
659+
660+
def test_asdict_reverse_translation_outputs_empty_when_no_translation():
661+
# When no translation is active (lang stays at default), as_dict() must
662+
# serialize reverse_translation_outputs as [] — not omitted, not populated
663+
# with spurious values (regression guard for issue #1201).
664+
a = garak.attempt.Attempt()
665+
a.prompt = garak.attempt.Message("test prompt", lang="en")
666+
d = a.as_dict()
667+
assert d["reverse_translation_outputs"] == []

0 commit comments

Comments
 (0)