diff --git a/agents/conductors/bug/bug.sh b/agents/conductors/bug/bug.sh index 8bc13d9a..acad95e5 100755 --- a/agents/conductors/bug/bug.sh +++ b/agents/conductors/bug/bug.sh @@ -47,7 +47,7 @@ as_json=0 forward=() while [[ $# -gt 0 ]]; do case "$1" in - -h|--help) sed -n '2,45p' "${BASH_SOURCE[0]}" | sed -n 's/^# \{0,1\}//p'; exit 0 ;; + -h|--help) awk 'NR==1{next} /^#/{sub(/^# ?/,""); print; next} {exit}' "${BASH_SOURCE[0]}"; exit 0 ;; --check-health) check_health=1; shift ;; --json) as_json=1; shift ;; *) forward+=("$1"); shift ;; diff --git a/agents/conductors/build/build.sh b/agents/conductors/build/build.sh index cb0d2f38..58a563c2 100755 --- a/agents/conductors/build/build.sh +++ b/agents/conductors/build/build.sh @@ -94,7 +94,7 @@ while [[ $# -gt 0 ]]; do --rehearsal-run-id=*) rehearsal_run_id="${1#*=}"; shift ;; --dry-run) dry_run=1; shift ;; --json) json_only=1; shift ;; - -h|--help) sed -n '2,40p' "${BASH_SOURCE[0]}" | sed 's/^# \{0,1\}//'; exit 0 ;; + -h|--help) awk 'NR==1{next} /^#/{sub(/^# ?/,""); print; next} {exit}' "${BASH_SOURCE[0]}"; exit 0 ;; --) shift; forward=("$@"); break ;; -*) echo "build agent: unknown flag '$1'" >&2; exit 5 ;; *) if [[ -z "$action" ]]; then action="$1"; else forward+=("$1"); fi; shift ;; diff --git a/agents/conductors/feature/feature.sh b/agents/conductors/feature/feature.sh index 76bec009..00383f83 100755 --- a/agents/conductors/feature/feature.sh +++ b/agents/conductors/feature/feature.sh @@ -46,7 +46,7 @@ as_json=0 forward=() while [[ $# -gt 0 ]]; do case "$1" in - -h|--help) sed -n '2,40p' "${BASH_SOURCE[0]}" | sed 's/^# \{0,1\}//'; exit 0 ;; + -h|--help) awk 'NR==1{next} /^#/{sub(/^# ?/,""); print; next} {exit}' "${BASH_SOURCE[0]}"; exit 0 ;; --check-health) check_health=1; shift ;; --json) as_json=1; shift ;; *) forward+=("$1"); shift ;; diff --git a/tests/test_agent_help_text.py b/tests/test_agent_help_text.py new file mode 100644 index 00000000..4d07748e --- /dev/null +++ b/tests/test_agent_help_text.py @@ -0,0 +1,48 @@ +"""The feature, build and bug agents print their header comment as ``--help``. + +The help is the script's leading comment block, printed up to the first +non-comment line, so it neither leaks shell code nor stops short of the end of +the header. +""" + +import subprocess +from pathlib import Path + +import pytest + +ROOT = Path(__file__).resolve().parents[1] +AGENTS = ["feature", "build", "bug"] + + +def _help(agent: str) -> str: + script = ROOT / "agents" / "conductors" / agent / f"{agent}.sh" + proc = subprocess.run( + ["bash", str(script), "--help"], + capture_output=True, + text=True, + timeout=30, + ) + assert proc.returncode == 0, proc.stderr + return proc.stdout + + +@pytest.mark.parametrize("agent", AGENTS) +def test_help_prints_header_only(agent): + out = _help(agent) + lines = out.splitlines() + assert lines, f"{agent} --help printed nothing" + assert "Usage:" in out + # The header ends with the exit codes; nothing after them is printed. + tail = out.rstrip("\n").split("\n\n")[-1] + assert tail.startswith("Exit codes:"), tail + assert not [line for line in lines if line.startswith("set ")] + assert not [line for line in lines if line.startswith("#")] + assert not [line for line in lines if line.startswith(("source ", "HERE=", "HEART_ISSUES_REPO="))] + + +def test_build_help_names_every_option_and_the_exit_codes(): + out = _help("build") + for flag in ("--rehearsal-run-id", "--dry-run", "--json", "--force", "--accept-red"): + assert flag in out, flag + assert "Exit codes:" in out + assert "5 invalid mode/action" in out