Skip to content

[quality] scripts: add subprocess tests for verify-site-health.sh (6 cases) - #6909

Merged
hivecommons-hive[bot] merged 1 commit into
mainfrom
quality/verify-site-health-tests
Sep 13, 2026
Merged

hivecommons-hive[bot] merged 1 commit into
mainfrom
quality/verify-site-health-tests

Conversation

@hivecommons-hive

Copy link
Copy Markdown
Contributor

Test Improvement

Adds scripts/verify-site-health.test.ts — 6 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 defined in runbooks/slo.md.

The script polls ${site-url}/api/healthz and 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 via child_process.spawn (async — see note below), stops the server, and asserts on exit code + captured stdout. No network is required.

# Scenario Asserts
1 /api/healthz returns 200 exit 0, [verify-site-health] OK, returned 200, JSON body echoed
2 Site URL passed with trailing / exit 0, no doubled //api/healthz (the ${SITE_URL%/}/api/healthz strip works)
3 503 with JSON body exit 1, UNHEALTHY, returned 503, runbooks/deploy-rollback.md pointer shown
4 404 with plain-text body exit 1, returned 404, body echoed
5 500 with empty body exit 1, returned 500 (does not crash on empty response)
6 Connection refused (bind→close pattern) exit 1, could not reach branch, no 15s curl-timeout wait

Runs in ~200 ms locally:

$ npx vitest run scripts/verify-site-health.test.ts
 ✓ scripts/verify-site-health.test.ts (6 tests) 213ms
 Test Files  1 passed (1)
      Tests  6 passed (6)

One subtlety worth calling out for reviewers

child_process.spawnSync would 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-time fired. The tests use spawn + a Promise wrapper so both sides make forward progress. There's a // Async — MUST be async comment on runScript calling this out.

Scope

Refs #6842 — the issue lists 8 untested scripts/ files and recommends starting with update-version.js. That already landed in #6908 (via scripts/update-version.test.ts, 11 tests). This PR checks off verify-site-health.sh; 6 scripts remain (the four generate-*.mjs files, 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

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>
@kubestellar-prow kubestellar-prow Bot added the dco-signoff: yes Indicates the PR's author has signed the DCO. label Sep 13, 2026
@netlify

netlify Bot commented Sep 13, 2026 •

Copy link
Copy Markdown

❌ Deploy Preview for kubestellar-docs failed. Why did it fail? →

Name Link
🔨 Latest commit 0ca8c4b
🔍 Latest deploy log https://app.netlify.com/projects/kubestellar-docs/deploys/6aa66fc6b60e9e0008d5c687

@kubestellar-prow

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign kproche for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@kubestellar-prow kubestellar-prow Bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Sep 13, 2026
@kubestellar-prow

Copy link
Copy Markdown

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 /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions 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.

@hivecommons-hive
hivecommons-hive Bot merged commit 429820f into main Sep 13, 2026
11 of 16 checks passed
@kubestellar-prow
kubestellar-prow Bot deleted the quality/verify-site-health-tests branch September 13, 2026 09:42
@github-actions

Copy link
Copy Markdown
Contributor

Thank you for your contribution! Your PR has been merged.

Check out what's new:

Stay connected: Slack #kubestellar-dev | Multi-Cluster Survey

hivecommons-hive Bot added a commit that referenced this pull request Sep 16, 2026
…(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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

copilot dco-signoff: yes Indicates the PR's author has signed the DCO. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. typescript

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants