Add periodic file watcher for adversary YAML changes#3344
Open
deacon-mp wants to merge 1 commit into
Open
Conversation
Adversary YAML files modified on disk (by plugins, imports, or manual edits) were not reflected in the running server until a full restart. This mirrors the existing watch_ability_files() pattern by adding watch_adversary_files() that periodically scans plugin and data directories for recently modified adversary YAML files and reloads them into data_svc.ram. Registered as a background task in run_tasks() alongside the ability file watcher, using the same ability_refresh interval from conf.
4 tasks
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a periodic watcher to reload adversary YAML changes at runtime, aligning adversary behavior with the existing ability file watcher to reduce the need for server restarts.
Changes:
- Add
watch_adversary_files()toAppServiceto scan plugin +data/adversaries/directories and reload modified YAMLs. - Register the adversary watcher in
server.pybackground tasks. - Add tests that validate (via AST) the method exists and is wired into
run_tasks().
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| tests/services/test_watch_adversary_files.py | Adds AST-based structure tests (and some data_svc YAML load checks) for adversary watcher integration. |
| server.py | Starts app_svc.watch_adversary_files() as a background asyncio task. |
| app/service/app_svc.py | Implements watch_adversary_files() to reload recently modified adversary YAML files. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+225
to
+226
| plugins = [p for p in await self.get_service('data_svc').locate('plugins', dict(enabled=True)) if p.data_dir] | ||
| plugins.append(Plugin(data_dir='data')) |
Comment on lines
+229
to
+230
| files = (os.path.join(rt, fle) for rt, _, f in os.walk(p.data_dir+'/adversaries') for fle in f if | ||
| time.time() - os.stat(os.path.join(rt, fle)).st_mtime < int(self.get_config('ability_refresh'))) |
Comment on lines
+225
to
+228
| plugins = [p for p in await self.get_service('data_svc').locate('plugins', dict(enabled=True)) if p.data_dir] | ||
| plugins.append(Plugin(data_dir='data')) | ||
| while True: | ||
| for p in plugins: |
Comment on lines
+91
to
+93
| async def test_load_yaml_file_stores_adversary(self, adversary_dir, data_svc): | ||
| """Writing a new adversary YAML and calling load_yaml_file should | ||
| insert or update it in data_svc.ram['adversaries'].""" |
Comment on lines
+110
to
+111
| async def test_reload_updates_existing_adversary(self, adversary_dir, data_svc): | ||
| """Reloading a modified YAML should update the adversary in RAM.""" |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
watch_adversary_files()toAppService, mirroring the existingwatch_ability_files()patterndata/adversaries/directories for recently modified YAML files and reloads them intodata_svc.ram['adversaries']run_tasks()using the sameability_refreshconfig intervalrun_tasks()Problem
Adversary YAML files modified on disk (by plugins, imports, or manual edits) were not reflected in the running server until a full restart. The ability watcher already existed for ability files but there was no equivalent for adversary profiles.
Test plan
watch_adversary_files()is registered inrun_tasks()(AST test)app_svc.py(AST test)data/adversaries/, confirm it reloads within the refresh interval