test(healthz): cover db_error field on the 503 degraded path (#320)#321
Merged
Conversation
The OpenAPI spec pins `db_error` on the /healthz 503 schema (see tests/api/openapi.test.js — operators rely on the field for debugging a degraded probe). But there was no behavioral assertion that the field actually appears when the SELECT 1 probe rejects; a future controller refactor could silently drop the field and the spec-shape test wouldn't catch the runtime divergence. Add a test that swaps `db.sequelize.query` to a rejecting stub, then drives /healthz end-to-end via supertest. Asserts the 503 status, the `status: 'degraded'` + `db: 'down'` shape, that the `db_error` field is a non-empty string, and that `migration` remains null (the SequelizeMeta probe never gets a chance to run when SELECT 1 already threw). Doesn't pin the error message — it varies by pg connection mode (no-host, no-password, refused, etc.). The structural assertion is enough to catch a regression. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #320.
Summary
Adds a behavioral test that stubs
db.sequelize.queryto reject, then drives/healthzend-to-end. Pins the 503 shape (status: 'degraded',db: 'down',db_errornon-empty string,migration: null) so a future controller refactor that drops the field would fail CI.Test plan
npm run lint && npm test— 782 passing (was 781).Proudly Made in Nebraska. Go Big Red! 🌽 https://xkcd.com/2347/