Adds `_validate_schedule_for_add()` to `CronService.add_job` so that invalid or misplaced `tz` values are rejected before a job is persisted, regardless of which caller (CLI, tool, etc.) invoked the service. Surfaces the resulting `ValueError` in `nanobot cron add` via a `try/except` so the CLI exits cleanly with a readable error message. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
30 lines
715 B
Python
30 lines
715 B
Python
from typer.testing import CliRunner
|
|
|
|
from nanobot.cli.commands import app
|
|
|
|
runner = CliRunner()
|
|
|
|
|
|
def test_cron_add_rejects_invalid_timezone(monkeypatch, tmp_path) -> None:
|
|
monkeypatch.setattr("nanobot.config.loader.get_data_dir", lambda: tmp_path)
|
|
|
|
result = runner.invoke(
|
|
app,
|
|
[
|
|
"cron",
|
|
"add",
|
|
"--name",
|
|
"demo",
|
|
"--message",
|
|
"hello",
|
|
"--cron",
|
|
"0 9 * * *",
|
|
"--tz",
|
|
"America/Vancovuer",
|
|
],
|
|
)
|
|
|
|
assert result.exit_code == 1
|
|
assert "Error: unknown timezone 'America/Vancovuer'" in result.stdout
|
|
assert not (tmp_path / "cron" / "jobs.json").exists()
|