mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-11-17 04:11:35 +00:00
_validate_cron_script_path only checked that a no_agent/monitor script path was relative and contained within scripts_dir, never that the file actually existed — so a misplaced script registered fine and only failed at every fire with a generic "Script not found" from scheduler_script.py, dropping once-only jobs from jobs.json on failure. The error messages also hardcoded "~/.hermes/scripts/" even though resolution goes through get_hermes_home(), which is per-profile — actively misleading users running non-default profiles into placing scripts in the wrong directory. Now the validator resolves the file and returns a "Script file not found" error naming the actual resolved scripts_dir, surfacing the mistake at creation time instead of at every scheduled fire.
36 lines
1.7 KiB
Python
36 lines
1.7 KiB
Python
"""Tests for tools/cronjob_job_args.py::_validate_cron_script_path (issue #105761).
|
|
|
|
Regression coverage: the validator used to accept a script path that pointed
|
|
at a file that doesn't exist, only failing later at every cron fire with a
|
|
generic "Script not found" error from cron/scheduler_script.py. It also
|
|
hardcoded "~/.hermes/scripts/" in its messages even though resolution goes
|
|
through get_hermes_home(), which is per-profile.
|
|
"""
|
|
|
|
from hermes_constants import get_hermes_home
|
|
from tools.cronjob_job_args import _validate_cron_script_path
|
|
|
|
|
|
class TestValidateCronScriptPath:
|
|
def test_missing_script_file_is_rejected_at_creation_time(self):
|
|
error = _validate_cron_script_path("does_not_exist.sh")
|
|
assert error is not None
|
|
assert "not found" in error.lower()
|
|
|
|
def test_existing_script_file_passes(self):
|
|
scripts_dir = get_hermes_home() / "scripts"
|
|
scripts_dir.mkdir(parents=True, exist_ok=True)
|
|
(scripts_dir / "real.sh").write_text("#!/bin/sh\necho hi\n")
|
|
assert _validate_cron_script_path("real.sh") is None
|
|
|
|
def test_missing_file_error_names_the_resolved_scripts_dir(self):
|
|
# The resolved dir must appear literally so the message stays correct
|
|
# under profiles, where get_hermes_home() is not the global ~/.hermes.
|
|
scripts_dir = get_hermes_home() / "scripts"
|
|
error = _validate_cron_script_path("missing.py")
|
|
assert str(scripts_dir) in error
|
|
|
|
def test_absolute_path_error_names_the_resolved_scripts_dir_not_global_literal(self):
|
|
scripts_dir = get_hermes_home() / "scripts"
|
|
error = _validate_cron_script_path("/etc/passwd")
|
|
assert str(scripts_dir) in error
|