Skip to content

Commit 78f0c66

Browse files
authored
hitlogs should use same paths as other reporting. add test for this (#387)
1 parent 7af3327 commit 78f0c66

File tree

2 files changed

+27
-14
lines changed

2 files changed

+27
-14
lines changed

garak/evaluators/base.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import json
88
import logging
9+
import os
910
from typing import List
1011

1112
from colorama import Fore, Style
@@ -64,16 +65,14 @@ def evaluate(self, attempts: List[garak.attempt.Attempt]) -> None:
6465
if not self.test(score): # if we don't pass
6566
if not _config.transient.hitlogfile:
6667
if not _config.system.report_prefix:
67-
hitlog_filename = (
68-
f"garak.{_config.transient.run_id}.hitlog.jsonl"
69-
)
68+
hitlog_filename = f"{_config.transient.report_dir}/garak.{_config.transient.run_id}.hitlog.jsonl"
7069
else:
7170
hitlog_filename = (
7271
_config.system.report_prefix + ".hitlog.jsonl"
7372
)
7473
logging.info("hit log in %s", hitlog_filename)
7574
_config.transient.hitlogfile = open(
76-
_config.transient.report_dir + "/" + hitlog_filename,
75+
hitlog_filename,
7776
"w",
7877
buffering=1,
7978
encoding="utf-8",

tests/test_config.py

+24-10
Original file line numberDiff line numberDiff line change
@@ -431,16 +431,6 @@ def test_probespec_loading():
431431
]
432432

433433

434-
@pytest.fixture(scope="session", autouse=True)
435-
def cleanup(request):
436-
"""Cleanup a testing directory once we are finished."""
437-
438-
def remove_laurelhurst_log():
439-
os.remove("laurelhurst.report.jsonl")
440-
441-
request.addfinalizer(remove_laurelhurst_log)
442-
443-
444434
def test_buff_config_assertion():
445435
importlib.reload(_config)
446436
import garak._plugins
@@ -462,3 +452,27 @@ def test_tag_filter():
462452
assert "probes.lmrc.SexualContent" in _config.parse_plugin_spec(
463453
"all", "probes", probe_tag_filter="risk-cards:lmrc:sexual_content"
464454
)
455+
456+
457+
def test_report_prefix_with_hitlog_no_explode():
458+
importlib.reload(_config)
459+
460+
garak.cli.main(
461+
"-m test.Blank --report_prefix kjsfhgkjahpsfdg -p test.Blank -d always.Fail".split()
462+
)
463+
assert os.path.isfile("kjsfhgkjahpsfdg.report.jsonl")
464+
assert os.path.isfile("kjsfhgkjahpsfdg.report.html")
465+
assert os.path.isfile("kjsfhgkjahpsfdg.hitlog.jsonl")
466+
467+
468+
@pytest.fixture(scope="session", autouse=True)
469+
def cleanup(request):
470+
"""Cleanup a testing directory once we are finished."""
471+
472+
def remove_laurelhurst_log():
473+
os.remove("laurelhurst.report.jsonl")
474+
os.remove("kjsfhgkjahpsfdg.report.jsonl")
475+
os.remove("kjsfhgkjahpsfdg.report.html")
476+
os.remove("kjsfhgkjahpsfdg.hitlog.jsonl")
477+
478+
request.addfinalizer(remove_laurelhurst_log)

0 commit comments

Comments
 (0)