fix(tools): remove unnecessary crontab requirement from cronjob tool (#1638)

* fix(tools): remove unnecessary crontab requirement from cronjob tool

The hermes cron system is internal — it uses a JSON-based scheduler
ticked by the gateway (cron/scheduler.py), not system crontab.

The check for shutil.which('crontab') was preventing the cronjob tool
from being available in environments without crontab installed (e.g.
minimal Ubuntu containers).

Changes:
- Remove shutil.which('crontab') check from check_cronjob_requirements()
- Remove unused shutil import
- Update docstring to clarify internal scheduler is used
- Update tests to reflect new behavior and add coverage for all
  session modes (interactive, gateway, exec_ask)

Fixes #1589

* test: add HERMES_EXEC_ASK coverage for cronjob requirements

Adds missing test for the exec_ask session mode, complementing
the cherry-picked fix from PR #1633.

---------

Co-authored-by: Bartok9 <bartokmagic@proton.me>
This commit is contained in:
Teknium
2026-03-17 01:40:02 -07:00
committed by GitHub
parent 4b96d10bc3
commit 949fac192f
2 changed files with 30 additions and 12 deletions

View File

@@ -62,22 +62,44 @@ class TestScanCronPrompt:
class TestCronjobRequirements:
def test_requires_crontab_binary_even_in_interactive_mode(self, monkeypatch):
def test_requires_no_crontab_binary(self, monkeypatch):
"""Cron is internal (JSON-based scheduler), no system crontab needed."""
monkeypatch.setenv("HERMES_INTERACTIVE", "1")
monkeypatch.delenv("HERMES_GATEWAY_SESSION", raising=False)
monkeypatch.delenv("HERMES_EXEC_ASK", raising=False)
monkeypatch.setattr("shutil.which", lambda name: None)
# Even with no crontab in PATH, the cronjob tool should be available
# because hermes uses an internal scheduler, not system crontab.
assert check_cronjob_requirements() is True
assert check_cronjob_requirements() is False
def test_accepts_interactive_mode_when_crontab_exists(self, monkeypatch):
def test_accepts_interactive_mode(self, monkeypatch):
monkeypatch.setenv("HERMES_INTERACTIVE", "1")
monkeypatch.delenv("HERMES_GATEWAY_SESSION", raising=False)
monkeypatch.delenv("HERMES_EXEC_ASK", raising=False)
monkeypatch.setattr("shutil.which", lambda name: "/usr/bin/crontab")
assert check_cronjob_requirements() is True
def test_accepts_gateway_session(self, monkeypatch):
monkeypatch.delenv("HERMES_INTERACTIVE", raising=False)
monkeypatch.setenv("HERMES_GATEWAY_SESSION", "1")
monkeypatch.delenv("HERMES_EXEC_ASK", raising=False)
assert check_cronjob_requirements() is True
def test_accepts_exec_ask(self, monkeypatch):
monkeypatch.delenv("HERMES_INTERACTIVE", raising=False)
monkeypatch.delenv("HERMES_GATEWAY_SESSION", raising=False)
monkeypatch.setenv("HERMES_EXEC_ASK", "1")
assert check_cronjob_requirements() is True
def test_rejects_when_no_session_env(self, monkeypatch):
"""Without any session env vars, cronjob tool should not be available."""
monkeypatch.delenv("HERMES_INTERACTIVE", raising=False)
monkeypatch.delenv("HERMES_GATEWAY_SESSION", raising=False)
monkeypatch.delenv("HERMES_EXEC_ASK", raising=False)
assert check_cronjob_requirements() is False
# =========================================================================
# schedule_cronjob

View File

@@ -8,7 +8,6 @@ Compatibility wrappers remain for direct Python callers and legacy tests.
import json
import os
import re
import shutil
import sys
from pathlib import Path
from typing import Any, Dict, List, Optional
@@ -414,13 +413,10 @@ def check_cronjob_requirements() -> bool:
"""
Check if cronjob tools can be used.
Requires 'crontab' executable to be present in the system PATH.
Available in interactive CLI mode and gateway/messaging platforms.
The cron system is internal (JSON file-based scheduler ticked by the gateway),
so no external crontab executable is required.
"""
# Ensure the system can actually install and manage cron entries.
if not shutil.which("crontab"):
return False
return bool(
os.getenv("HERMES_INTERACTIVE")
or os.getenv("HERMES_GATEWAY_SESSION")