Skip to content

Conversation

@arjun-krishna1
Copy link
Contributor

Verification

Here's a verification checklist for this fix:

Verification

List the steps needed to make sure the duplicate config_files fix works

  • Run a basic garak scan and check the report:
    python -m garak -t test.Blank -p test.Test
    head -1 ~/.local/share/garak/garak_runs/garak.*.report.jsonl | python -c "import sys, json; d = json.load(sys.stdin); print('config_files:', d.get('_config.config_files'))"

Reset config_files list at start of load_config() since it already
includes garak.core.yaml in its settings_files and will reload
everything. This prevents duplication when load_base_config() is
called before load_config() in the CLI flow.
Copy link
Collaborator

@jmartin-tech jmartin-tech left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clearing a global variable does not remove the impacts the previous file may have already had on state. This method does not clear all package configurable state before processing.

At this time _config package global values are treated as common state and the files loaded are stored in config_files. A solution to duplicate entries in config_files would need to account for this. I would suggest some set logic and guards to avoid duplicate processing of files may be needed.

@arjun-krishna1
Copy link
Contributor Author

Clearing a global variable does not remove the impacts the previous file may have already had on state. This method does not clear all package configurable state before processing.

At this time _config package global values are treated as common state and the files loaded are stored in config_files. A solution to duplicate entries in config_files would need to account for this. I would suggest some set logic and guards to avoid duplicate processing of files may be needed.

Understood @jmartin-tech , updated to stop duplicate processing of config files instead

@leondz leondz self-requested a review January 12, 2026 08:17
leondz

This comment was marked as outdated.

Copy link
Collaborator

@leondz leondz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm - strange test failure though

@jmartin-tech
Copy link
Collaborator

Looking closer at the test failure, test_function.py is failing due to retained global state of _config across tests in that file. A short term fix to would be to add a fixture similar to the one recently added in test_config.py

garak/tests/test_config.py

Lines 98 to 108 in 7849f3b

@pytest.fixture(autouse=True)
def reload_config(request):
def reload():
if _config.transient.reportfile is not None:
_config.transient.reportfile.close()
if os.path.exists(_config.transient.report_filename):
os.remove(_config.transient.report_filename)
importlib.reload(_config)
request.addfinalizer(reload)
reload()

This fixture clears and reimports _config. This further exposes that design of the _config package needs some work if garak is used in an environment that will need to maintain state for multiple runs. The cli usage pattern masks this issue at this time.

@jmartin-tech
Copy link
Collaborator

#1549 addresses the global state issues that cause the test failure in this PR. Once that PR lands merging main into this branch should enable passing tests.

@arjun-krishna1
Copy link
Contributor Author

#1549 addresses the global state issues that cause the test failure in this PR. Once that PR lands merging main into this branch should enable passing tests.

@jmartin-tech are we good to re-run the tests? I can't seem to do it on my end

@leondz
Copy link
Collaborator

leondz commented Jan 22, 2026

Re-running

@jmartin-tech
Copy link
Collaborator

A commit is required to get tests to update to use the latest code, this can simply be a merge of main to the PR branch or a rebase.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants