Skip to content

Dependency check - #92

Merged
Nabeelahh merged 2 commits into
Vaulty-X:mainfrom
Sadeequ:dependency-check
Jul 30, 2026
Merged

Dependency check#92
Nabeelahh merged 2 commits into
Vaulty-X:mainfrom
Sadeequ:dependency-check

Conversation

@Sadeequ

@Sadeequ Sadeequ commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Here's a full summary of the changes I made:

Summary of Changes

1. Backend/src/routes/health.routes.ts — Separated liveness and readiness endpoints

I rewrote the health routes to implement two distinct endpoints:

  • GET /health — A lightweight liveness probe that returns only success, message, uptime, and timestamp. It no longer performs any dependency checks, making it fast and suitable for load balancers and container orchestrators.
  • GET /health/ready — A readiness endpoint that checks Prisma ($queryRawUnsafe('SELECT 1')) and Redis (redis.status === 'ready') connectivity in parallel. It returns 200 with status: 'ok' when all dependencies are healthy, and 503 with status: 'degraded' when any critical dependency is unavailable. Error details are passed through redactError() to avoid leaking connection strings or secrets.

I also removed the checkWorkers function and the workers check from the readiness probe, since workers are a background concern and not a critical dependency for API readiness. The HealthCheck type and HealthStatus type were kept. The getBootstrappedWorkers import was removed since it's no longer needed.

2. Backend/src/middleware/requestId.ts — New request ID middleware (bonus)

I created a new middleware that generates a unique UUID for every incoming request via crypto.randomUUID(), attaches it to req.requestId for downstream use, and sets the X-Request-Id response header so clients can trace requests. This complements the health check work by making it easy to trace requests through logs when debugging dependency issues reported by the readiness endpoint.

3. Backend/src/middleware/index.ts — Added requestId export

I added the requestId export to the middleware barrel file so it's available for import from app.ts.

4. Backend/src/app.ts — Registered requestId middleware

I imported requestId from the middleware module and registered it early in the middleware chain (before rate limiting and routes) so every request gets an ID from the start.

5. Backend/tests/unit/health.test.ts — Rewrote unit tests

I rewrote the unit tests with jest.mock for ../../src/database and ../../src/config/redis to control Prisma and Redis states. The tests now cover:

  • Liveness endpoint returns 200 with uptime and no dependency checks ✅
  • Readiness endpoint returns 200 when both Prisma and Redis are healthy ✅
  • Readiness endpoint returns 503 when Prisma is unavailable ✅
  • Readiness endpoint returns 503 when Redis is unavailable ✅
  • Readiness endpoint returns 503 when both dependencies are unavailable ✅
  • Error details do not expose connection strings or secrets ✅

6. Backend/tests/integration/health.integration.test.ts — Rewrote integration tests

I rewrote the integration tests with the same mocking approach, covering the same healthy and simulated-unavailable-dependency scenarios, plus the existing 404 test.

All 12 health tests pass (6 unit + 6 integration). No changes were needed to Backend/src/config/index.ts or Backend/src/database/index.ts — the existing redactError utility and Prisma/Redis exports already supported the implementation.


RELATED ISSUE


CLOSES #81 ✔️

@Nabeelahh
Nabeelahh merged commit 81d8840 into Vaulty-X:main Jul 30, 2026
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Backend] Add dependency-aware readiness checks

2 participants