Files
daedalus/python/tests/test_hello.py
T
hermes-pi ec9848b169 daedalus 0.4.0: bash script interface (help() dispatch) + hello_bash
- bash/daedalus_common.sh (new): the shared interface for bash scripts
  (SPEC item 6.10) - a script sources its sibling helper, defines help()
  (usage) and main(), and ends with daedalus_bash_dispatch "$@" which
  routes help/-h/--help to help() and everything else to main()
  unchanged (clear fallback errors when a script forgets either)
- completion for bash scripts (SPEC item 3.13.5.2): after a completed
  script name daedalus offers --help, -h, help, prefix-filtered, written
  itself on the fd-8 argcomplete protocol - no script runs on TAB;
  scripts without the interface get the shell default
- bash/hello_bash.sh (new, category test): sample script through the
  interface, the bash twin of hello, with tests; registry entry, README
  row, CHANGELOG bullet
- tests: bash/tests/test_bash_interface.py (helper behavior, bash -n,
  enforcement of the interface for every registered .sh),
  test_hello_bash.py (direct and daedalus runs, help routing, SPEC 3.1
  pass-through, completion probes including the user's
  daedalus hello_bash<TAB><TAB> case), completions units + e2e harness
- README/INSTALL/SPEC updated (6.10, 3.13.5.2, tree, boilerplate with
  shellcheck directive); autotest green (212 tests)

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
2026-11-18 22:35:11 +01:00

62 lines
2.1 KiB
Python

"""Tests for hello: version resolution, output, and end-to-end runs.
Pure functions, main with argument lists, and the category-prefixed CLI
form (daedalus agent rule 5.6).
"""
import os
import subprocess
import sys
import pytest
from daedalus import REPO_ROOT
from daedalus.hello import hello
def test_main_prints_hello_and_version(capsys):
"""main prints the greeting with a resolved version and exits 0."""
assert hello.main([]) == 0
out = capsys.readouterr().out.strip()
assert out.startswith("hello from daedalus ")
assert hello.UNKNOWN not in out
def test_app_version_from_metadata(monkeypatch):
"""An installed daedalus resolves its version from the metadata."""
monkeypatch.setattr(hello.importlib.metadata, "version",
lambda _name: "9.9.9")
assert hello.app_version() == "9.9.9"
def test_app_version_falls_back_to_pyproject(monkeypatch):
"""A checkout that is not installed reads pyproject.toml (SPEC item 3.9.2)."""
def not_found(_name):
raise hello.importlib.metadata.PackageNotFoundError(_name)
monkeypatch.setattr(hello.importlib.metadata, "version", not_found)
assert hello.app_version() == "0.4.0"
def test_help_exits_zero(capsys):
"""hello --help shows the script's own usage (SPEC item 3.1.1)."""
with pytest.raises(SystemExit) as excinfo:
hello.main(["--help"])
assert excinfo.value.code == 0
assert "usage: hello" in capsys.readouterr().out
def run_cli(*args: str) -> subprocess.CompletedProcess:
"""Run the real daedalus CLI from outside the repo."""
env = {**os.environ, "PYTHONPATH": str(REPO_ROOT)}
return subprocess.run([sys.executable, "-m", "daedalus", *args],
capture_output=True, text=True, check=False,
cwd=REPO_ROOT.parent, env=env)
@pytest.mark.parametrize("argv", (["hello"], ["test", "hello"]))
def test_daedalus_runs_hello(argv):
"""daedalus hello and daedalus test hello both print the greeting (SPEC item 3.2)."""
result = run_cli(*argv)
assert result.returncode == 0, result.stderr
assert result.stdout.startswith("hello from daedalus ")