-
Notifications
You must be signed in to change notification settings - Fork 315
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bugfix/leakreplay output setting (#790)
* add test for general hitlog writing code path * bump copyright * detector uses all_outputs, have hitlog use all_outputs also * amend attempt output manipulation to edit underlying structure * check hitlog file presence * xplatform compat * reset plugin cache singleton * reset cache after each plugin cache test * remove fixture not needed by hitlog test Signed-off-by: Jeffrey Martin <jemartin@nvidia.com> --------- Signed-off-by: Jeffrey Martin <jemartin@nvidia.com> Co-authored-by: Jeffrey Martin <jemartin@nvidia.com>
- Loading branch information
1 parent
fd54fd9
commit 54f3364
Showing
6 changed files
with
63 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# SPDX-FileCopyrightText: Portions Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
import os | ||
|
||
import garak | ||
import garak._config | ||
import garak._plugins | ||
import garak.attempt | ||
import garak.cli | ||
|
||
|
||
def test_leakreplay_hitlog(): | ||
|
||
args = "-m test.Blank -p leakreplay -d always.Fail".split() | ||
garak.cli.main(args) | ||
|
||
|
||
def test_leakreplay_output_count(): | ||
generations = 1 | ||
garak._config.load_base_config() | ||
garak._config.transient.reportfile = open(os.devnull, "w+") | ||
a = garak.attempt.Attempt(prompt="test") | ||
p = garak._plugins.load_plugin( | ||
"probes.leakreplay.LiteratureCloze80", config_root=garak._config | ||
) | ||
g = garak._plugins.load_plugin("generators.test.Blank", config_root=garak._config) | ||
g.generations = generations | ||
p.generator = g | ||
results = p._execute_all([a]) | ||
assert len(a.all_outputs) == generations |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# SPDX-FileCopyrightText: Portions Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
import contextlib | ||
import os | ||
import pytest | ||
|
||
import garak | ||
import garak.cli | ||
|
||
|
||
CODEPATH_PREFIX = "_garak_test_hitlog_codepath" | ||
|
||
|
||
def test_hitlog_codepath(): | ||
|
||
args = f"-m test.Blank --report_prefix {CODEPATH_PREFIX} -p test.Test -d always.Fail".split() | ||
garak.cli.main(args) | ||
assert os.path.isfile(f"{CODEPATH_PREFIX}.hitlog.jsonl") |