Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion agents/conductors/bug/bug.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 ;;
Expand Down
2 changes: 1 addition & 1 deletion agents/conductors/build/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 ;;
Expand Down
2 changes: 1 addition & 1 deletion agents/conductors/feature/feature.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 ;;
Expand Down
48 changes: 48 additions & 0 deletions tests/test_agent_help_text.py
Original file line number Diff line number Diff line change
@@ -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
Loading