Give the healthcheck a self-test and a machine-readable mode #11

Merged
kami merged 3 commits from orchestra/06G4FT0MB733H2ZCZ237WFHFD8 into master 2026-08-28 12:42:28 +02:00
3 changed files with 99 additions and 4 deletions
+54 -4
View File
@@ -1,14 +1,64 @@
# Task 06G4E6F69AKP2PA00S28D7ASBC # Task 06G4FT0MB733H2ZCZ237WFHFD8
Add a --quiet flag to the healthcheck script Give the healthcheck a self-test and a machine-readable mode
- Project: test-e2e - Project: test-e2e
- Source: gitea:test-e2e/7 - Source: gitea:test-e2e/10
- Priority: 0 - Priority: 0
## Instructions ## Instructions
scripts/orchestra_e2e_healthcheck.sh already handles --help. Add a --quiet flag alongside it that suppresses the success line and still exits 0. Leave the default behaviour and the --help output unchanged. Three pieces of work, in order. Plan them as exactly three phases in that order.
## Phase 1 — a self-test for the healthcheck
New file `scripts/orchestra_e2e_selftest.sh`, executable, `#!/usr/bin/env bash`.
It runs `scripts/orchestra_e2e_healthcheck.sh`, then asserts:
- exit status is 0
- stdout contains `OK`
On failure it prints which assertion failed and exits 1. On success it prints `selftest: ok` and exits 0.
Verification for this phase is automated only. The one check is:
- run: ["bash", "-n", "scripts/orchestra_e2e_selftest.sh"]
Do not add a manual step to this phase.
## Phase 2 — `--json` on the healthcheck
`scripts/orchestra_e2e_healthcheck.sh --json` prints exactly one line:
{"status":"ok","checks":1}
and exits 0. Without `--json` the existing human output is unchanged, and `--help` keeps working. `--json` and `--help` together behave as `--help`.
Verification for this phase must include both an automated check and a manual step. The JSON shape is a judgement a human confirms by reading it, so state the manual step as the exact command a human runs and the exact line they should see.
## Phase 3 — teach the self-test about `--json`
Extend `scripts/orchestra_e2e_selftest.sh` to run the healthcheck twice: once plain and once with `--json`. Assert the plain run still contains `OK`, and assert the `--json` run prints one line beginning with `{"status":`.
Verification for this phase is automated only:
- run: ["bash", "-n", "scripts/orchestra_e2e_selftest.sh"]
- run: ["bash", "scripts/orchestra_e2e_healthcheck.sh"]
## Constraints
The project's verification policy allows exactly two command shapes:
["bash", "-n", "<one file>"]
["bash", "scripts/orchestra_e2e_healthcheck.sh"]
A `run:` line outside those is refused when the plan seals, not later.
## Research first
Before planning, establish at least three findings and label their confidence honestly: at least one `fact`, one `inference`, and one `assumption`. The plan must cite at least two of them in References.
## Completion ## Completion
+8
View File
@@ -2,6 +2,7 @@
main() { main() {
local quiet= local quiet=
local json=
for arg in "$@"; do for arg in "$@"; do
if [ "$arg" = --help ]; then if [ "$arg" = --help ]; then
printf 'Usage: %s [--quiet]\n\n' "${0##*/}" printf 'Usage: %s [--quiet]\n\n' "${0##*/}"
@@ -11,9 +12,16 @@ main() {
exit 0 exit 0
elif [ "$arg" = --quiet ]; then elif [ "$arg" = --quiet ]; then
quiet=1 quiet=1
elif [ "$arg" = --json ]; then
json=1
fi fi
done done
if [ -n "$json" ]; then
printf '{"status":"ok","checks":1}\n'
exit 0
fi
[ -n "$quiet" ] || printf 'OK - all healthchecks passed\n' [ -n "$quiet" ] || printf 'OK - all healthchecks passed\n'
exit 0 exit 0
} }
+37
View File
@@ -0,0 +1,37 @@
#!/usr/bin/env bash
# Self-test for the Orchestra E2E healthcheck.
here=$(cd "$(dirname "$0")" && pwd)
healthcheck="$here/orchestra_e2e_healthcheck.sh"
# fail <assertion> <captured stdout>: always echo what the healthcheck printed,
# so a red run is diagnosable without rerunning it by hand.
fail() {
printf 'selftest: FAILED %s\n' "$1" >&2
printf 'selftest: healthcheck stdout was:\n%s\n' "$2" >&2
exit 1
}
# plain run
out=$(bash "$healthcheck")
status=$?
[ "$status" -eq 0 ] || fail "plain run exit status: want 0, got $status" "$out"
case "$out" in
*OK*) ;;
*) fail "plain run stdout contains OK" "$out" ;;
esac
# --json run
jout=$(bash "$healthcheck" --json)
jstatus=$?
[ "$jstatus" -eq 0 ] || fail "--json run exit status: want 0, got $jstatus" "$jout"
jlines=$(printf '%s\n' "$jout" | wc -l)
[ "$jlines" -eq 1 ] || fail "--json run line count: want 1, got $jlines" "$jout"
case "$jout" in
'{"status":'*) ;;
*) fail '--json run stdout prefix: want {"status":' "$jout" ;;
esac
printf 'selftest: ok\n'