From fb80b565e3e7655166920275f42e1c04a023821e Mon Sep 17 00:00:00 2001 From: kami Date: Fri, 28 Aug 2026 16:42:36 +0400 Subject: [PATCH] orchestra: pre-release WIP snapshot (orchestra-06g4gbsq2wrgd5hgypyzz4tyh0-ec8111ad) --- scripts/flags.sh | 36 ++++++++++++++++++++++++++++ scripts/orchestra_e2e_healthcheck.sh | 29 +++------------------- scripts/orchestra_e2e_selftest.sh | 8 ++++++- 3 files changed, 46 insertions(+), 27 deletions(-) create mode 100644 scripts/flags.sh diff --git a/scripts/flags.sh b/scripts/flags.sh new file mode 100644 index 0000000..5e4fbcc --- /dev/null +++ b/scripts/flags.sh @@ -0,0 +1,36 @@ +#!/usr/bin/env bash +# Flag parsing for orchestra_e2e_healthcheck.sh. Sourced, not executed. +# parse_flags sets quiet, json and strict; it exits 0 on --help, and exits 1 +# under --strict on the first unrecognised argument. + +parse_flags() { + quiet= + json= + strict= + unset unknown + for arg in "$@"; do + if [ "$arg" = --help ]; then + printf 'Usage: %s [--quiet]\n\n' "${0##*/}" + printf 'Healthcheck script for Orchestra E2E tests.\n' + printf 'Exits 0 with a success message if all checks pass.\n' + printf ' --quiet Suppress the success message; still exits 0.\n' + exit 0 + elif [ "$arg" = --quiet ]; then + quiet=1 + elif [ "$arg" = --json ]; then + json=1 + elif [ "$arg" = --strict ]; then + strict=1 + else + # Keep the first unrecognised argument only. ${unknown+x} tests set-ness, + # so an empty-string argument is recorded too. + [ -n "${unknown+x}" ] || unknown=$arg + fi + done + + # Deferred past the loop so --help still wins from any position. + if [ -n "$strict" ] && [ -n "${unknown+x}" ]; then + printf 'unknown flag: %s\n' "$unknown" >&2 + exit 1 + fi +} diff --git a/scripts/orchestra_e2e_healthcheck.sh b/scripts/orchestra_e2e_healthcheck.sh index a944f04..89f7057 100755 --- a/scripts/orchestra_e2e_healthcheck.sh +++ b/scripts/orchestra_e2e_healthcheck.sh @@ -1,32 +1,9 @@ #!/usr/bin/env bash -main() { - local quiet= - local json= - local strict= - local unknown= - for arg in "$@"; do - if [ "$arg" = --help ]; then - printf 'Usage: %s [--quiet]\n\n' "${0##*/}" - printf 'Healthcheck script for Orchestra E2E tests.\n' - printf 'Exits 0 with a success message if all checks pass.\n' - printf ' --quiet Suppress the success message; still exits 0.\n' - exit 0 - elif [ "$arg" = --quiet ]; then - quiet=1 - elif [ "$arg" = --json ]; then - json=1 - elif [ "$arg" = --strict ]; then - strict=1 - else - [ -n "$unknown" ] || unknown=$arg - fi - done +. "$(dirname "$0")/flags.sh" - if [ -n "$strict" ] && [ -n "$unknown" ]; then - printf 'unknown flag: %s\n' "$unknown" >&2 - exit 2 - fi +main() { + parse_flags "$@" if [ -n "$json" ]; then printf '{"status":"ok","checks":1}\n' diff --git a/scripts/orchestra_e2e_selftest.sh b/scripts/orchestra_e2e_selftest.sh index dedf463..ad0dec7 100755 --- a/scripts/orchestra_e2e_selftest.sh +++ b/scripts/orchestra_e2e_selftest.sh @@ -38,7 +38,7 @@ esac sout=$(bash "$healthcheck" --strict --nonsense 2>&1) sstatus=$? -[ "$sstatus" -eq 2 ] || fail "--strict --nonsense exit status: want 2, got $sstatus" "$sout" +[ "$sstatus" -eq 1 ] || fail "--strict --nonsense exit status: want 1, got $sstatus" "$sout" # --strict alone is accepted gout=$(bash "$healthcheck" --strict) @@ -46,4 +46,10 @@ gstatus=$? [ "$gstatus" -eq 0 ] || fail "--strict run exit status: want 0, got $gstatus" "$gout" +# --strict rejects an empty-string argument too +eout=$(bash "$healthcheck" --strict "" 2>&1) +estatus=$? + +[ "$estatus" -eq 1 ] || fail "--strict '' exit status: want 1, got $estatus" "$eout" + printf 'selftest: ok\n'