Files
triggershell/tests/test_config.py
T
valknarandClaude Sonnet 5 80c11d3bd3 Externalize auth secrets to .env and rename default config to triggershell.yml
sessionSecret was previously baked directly into the scaffolded config file;
`triggershell init` now generates a .env with TRIGGERSHELL_SESSION_SECRET
instead and references it via ${VAR} interpolation, keeping the actual
secret out of the (often committed) config file. `triggershell dev/start/
validate` load that .env automatically without overriding real env vars.

Also renames the default config filename from triggershell.config.yaml to
triggershell.yml throughout the CLI, app, docs, and examples.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-08-15 19:15:03 +02:00

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.yml"
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"