Skip to content

Add periodic file watcher for adversary YAML changes#3344

Open
deacon-mp wants to merge 1 commit into
masterfrom
fix/adversary-dynamic-ability-refresh
Open

Add periodic file watcher for adversary YAML changes#3344
deacon-mp wants to merge 1 commit into
masterfrom
fix/adversary-dynamic-ability-refresh

Conversation

@deacon-mp
Copy link
Copy Markdown
Contributor

Summary

  • Adds watch_adversary_files() to AppService, mirroring the existing watch_ability_files() pattern
  • Periodically scans plugin and data/adversaries/ directories for recently modified YAML files and reloads them into data_svc.ram['adversaries']
  • Registers the watcher as a background task in run_tasks() using the same ability_refresh config interval
  • Includes AST-level structural tests validating the method exists and is wired into run_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

  • Verify watch_adversary_files() is registered in run_tasks() (AST test)
  • Verify the method exists as an async function in app_svc.py (AST test)
  • Manual: start server, modify an adversary YAML in data/adversaries/, confirm it reloads within the refresh interval
  • Manual: create a new adversary YAML while server is running, confirm it appears via API

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.
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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() to AppService to scan plugin + data/adversaries/ directories and reload modified YAMLs.
  • Register the adversary watcher in server.py background 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 thread app/service/app_svc.py
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 thread app/service/app_svc.py
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 thread app/service/app_svc.py
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."""
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.

2 participants