A Python CLI (typer) that bootstraps Node/pnpm and launches a Next.js 16 web app for running configured shell scripts: YAML config validated by a shared Zod schema, dynamic per-script forms mapped to shadcn controls, argv-safe execa execution with live WebSocket streaming, SQLite/Drizzle run history, and optional argon2 session + API token auth. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
71 lines
1.7 KiB
Python
71 lines
1.7 KiB
Python
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
from triggershell.config import ConfigError, preflight_check
|
|
|
|
|
|
def write(tmp_path: Path, content: str) -> Path:
|
|
path = tmp_path / "triggershell.config.yaml"
|
|
path.write_text(content)
|
|
return path
|
|
|
|
|
|
def test_missing_file_raises(tmp_path: Path) -> None:
|
|
with pytest.raises(ConfigError, match="not found"):
|
|
preflight_check(tmp_path / "missing.yaml")
|
|
|
|
|
|
def test_invalid_yaml_raises(tmp_path: Path) -> None:
|
|
path = write(tmp_path, "scripts: [this is not: valid: yaml")
|
|
with pytest.raises(ConfigError, match="parse YAML"):
|
|
preflight_check(path)
|
|
|
|
|
|
def test_non_mapping_root_raises(tmp_path: Path) -> None:
|
|
path = write(tmp_path, "- just\n- a\n- list\n")
|
|
with pytest.raises(ConfigError, match="mapping"):
|
|
preflight_check(path)
|
|
|
|
|
|
def test_empty_file_is_ok(tmp_path: Path) -> None:
|
|
path = write(tmp_path, "")
|
|
data = preflight_check(path)
|
|
assert data == {}
|
|
|
|
|
|
def test_script_missing_id_raises(tmp_path: Path) -> None:
|
|
path = write(tmp_path, "scripts:\n - name: no id here\n")
|
|
with pytest.raises(ConfigError, match="missing a non-empty 'id'"):
|
|
preflight_check(path)
|
|
|
|
|
|
def test_duplicate_script_id_raises(tmp_path: Path) -> None:
|
|
path = write(
|
|
tmp_path,
|
|
"""
|
|
scripts:
|
|
- id: dup
|
|
name: One
|
|
- id: dup
|
|
name: Two
|
|
""",
|
|
)
|
|
with pytest.raises(ConfigError, match="duplicate script id"):
|
|
preflight_check(path)
|
|
|
|
|
|
def test_valid_minimal_config_passes(tmp_path: Path) -> None:
|
|
path = write(
|
|
tmp_path,
|
|
"""
|
|
scripts:
|
|
- id: hello
|
|
name: Hello
|
|
command: echo
|
|
""",
|
|
)
|
|
data = preflight_check(path)
|
|
assert len(data["scripts"]) == 1
|
|
assert data["scripts"][0]["id"] == "hello"
|