Repository navigation
[quality] scripts: add subprocess tests for verify-site-health.sh (6 cases) - #6909
Conversation
Adds vitest subprocess-style tests for scripts/verify-site-health.sh — the runbook script cited from runbooks/deploy-rollback.md's 'Detecting a bad deploy' step and the SLO in runbooks/slo.md. Each test starts a fresh in-process HTTP server on 127.0.0.1 with an ephemeral port, runs the script against it via async child_process.spawn, and asserts on exit code + captured stdout. No network required. Coverage: - 200 OK -> exit 0, body echoed - trailing slash on site URL is stripped (no doubled //api/healthz) - 503 with JSON body -> exit 1, runbook pointer shown - 404 with plain-text body -> exit 1 - 500 with empty body -> exit 1 (no crash) - connection refused -> exit 1, 'could not reach' branch Runs in ~200ms locally. Same subprocess-harness pattern used by scripts/update-version.test.ts. Refs #6842 (one of 8 untested scripts; verify-site-health.sh checked off, 7 remain — update-version.js already landed in #6908). Signed-off-by: hive-quality <quality@hive>
❌ Deploy Preview for kubestellar-docs failed. Why did it fail? →
|
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
Hi @kubestellar-hive[bot]. Thanks for your PR. I'm waiting for a kubestellar member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
|
Thank you for your contribution! Your PR has been merged. Check out what's new:
Stay connected: Slack #kubestellar-dev | Multi-Cluster Survey |
…(6 cases) (#6972) Adds scripts/netlify-ignore.test.ts covering the Netlify per-build ignore hook, mirroring the subprocess-harness pattern established by scripts/verify-site-health.test.ts (PR #6909). The exit-code contract is the entire point of the script — exit 0 skips the deploy-preview build (used to short-circuit chore/hive-snapshot* automation branches so Netlify preview minutes aren't consumed on throwaway branches), exit 1 proceeds. Inverting either arm silently breaks previews site-wide or wastes runner minutes, a failure mode with no user-facing signal until the bill or the missing preview is noticed. Cases (all four exit-code arms + both env-var surfaces + two glob-narrowness guards): 1. BRANCH=chore/hive-snapshot-abc — exit 0 (skip) 2. HEAD=chore/hive-snapshot-xyz — exit 0 (skip) via HEAD arm 3. BRANCH=main — exit 1 (build) 4. BRANCH="" HEAD="" — exit 1: empty envs must not glob-match 5. BRANCH=chore/hive-snap — exit 1: prefix alone must not match 6. BRANCH=chore/something-else — exit 1: unrelated chore branch All 6 pass locally against HEAD (vitest run scripts/netlify-ignore.test.ts). No production script change; no CI wiring change. Refs #6842 Signed-off-by: kubestellar-hive[bot] <[email protected]> Co-authored-by: kubestellar-hive[bot] <[email protected]>
Test Improvement
Adds
scripts/verify-site-health.test.ts— 6 vitest subprocess-style tests forscripts/verify-site-health.sh, the runbook script cited fromrunbooks/deploy-rollback.md's "Detecting a bad deploy" step and the SLO defined inrunbooks/slo.md.The script polls
${site-url}/api/healthzand exits 0 on HTTP 200, 1 on any other status or on network failure. Before this PR it had zero automated tests, so any refactor of the curl invocation, exit-code discipline, or the trailing-slash strip could silently regress and a deploy responder running the script during a real incident would be the first to notice.What the tests cover
Each test starts a fresh in-process HTTP server on
127.0.0.1:0(ephemeral port), runs the script against it viachild_process.spawn(async — see note below), stops the server, and asserts on exit code + captured stdout. No network is required./api/healthzreturns 200[verify-site-health] OK,returned 200, JSON body echoed///api/healthz(the${SITE_URL%/}/api/healthzstrip works)UNHEALTHY,returned 503,runbooks/deploy-rollback.mdpointer shownreturned 404, body echoedreturned 500(does not crash on empty response)could not reachbranch, no 15s curl-timeout waitRuns in ~200 ms locally:
One subtlety worth calling out for reviewers
child_process.spawnSyncwould block the parent's event loop, and the in-process HTTP server (same event loop) would never accept curl's connection — every non-first test would deadlock until curl's 15 s--max-timefired. The tests usespawn+ a Promise wrapper so both sides make forward progress. There's a// Async — MUST be asynccomment onrunScriptcalling this out.Scope
Refs #6842 — the issue lists 8 untested
scripts/files and recommends starting withupdate-version.js. That already landed in #6908 (viascripts/update-version.test.ts, 11 tests). This PR checks offverify-site-health.sh; 6 scripts remain (the fourgenerate-*.mjsfiles,create-version-branches.sh,migrate-version.sh,netlify-ignore.sh— the last is being covered by #6844). The issue stays open.Same subprocess-harness pattern as
scripts/update-version.test.ts. No production script edited.Filed by quality agent (ACMM L4/L6 — full mode)
— hive: agent=quality backend=copilot model=claude-opus-4.7