Skip to content

fix: pool config+health (#596), SEP-24 contracts (#603), async PDF queue (#595), SOS Maestro E2E (#607)#1

Closed
Creed1759 wants to merge 1 commit into
mainfrom
fix/596-603-595-607-pool-anchor-contracts-pdf-queue-sos-e2e
Closed

fix: pool config+health (#596), SEP-24 contracts (#603), async PDF queue (#595), SOS Maestro E2E (#607)#1
Creed1759 wants to merge 1 commit into
mainfrom
fix/596-603-595-607-pool-anchor-contracts-pdf-queue-sos-e2e

Conversation

@Creed1759

Copy link
Copy Markdown
Owner

Summary

Closes DogStark#596, DogStark#603, DogStark#595, DogStark#607 — four independent issues solved in one pass.


DogStark#596 — PostgreSQL connection pool configuration & monitoring

What: The pool was created with default/misconfigured settings and the /health endpoint had no pool visibility.

How:

  • Replaced old env vars (DB_POOL_SIZE, DB_IDLE_TIMEOUT) with DB_POOL_MAX (default 20), DB_IDLE_TIMEOUT_MS (default 10000), DB_CONNECTION_TIMEOUT_MS (default 3000)
  • Added getPoolStats() returning { total, idle, waiting }
  • GET /api/health now returns pool stats alongside the existing response
  • A console.warn fires on every new connection when waiting > 5
  • New integration test in backend/tests/integration/poolExhaustion.test.ts verifies requests fail fast (not hang) after connectionTimeoutMillis

DogStark#603 — SEP-24 anchor contract tests

What: Anchor API changes could silently break the deposit/withdrawal flow.

How:

  • Added backend/services/__tests__/stellarAnchorService.contract.test.ts
  • Lightweight consumer-driven contracts using an inline mock provider (no extra Pact dependency)
  • Contracts cover: stellar.toml shape, /deposit/interactive request/response, /withdraw/interactive with amount, /transaction poll (pending & complete states), terminal-status caching (no re-poll after completion), and the SEP-24 /info response shape
  • If the anchor changes its API shape, the relevant assertion fails before the real integration breaks

DogStark#595 — Async PDF generation via Redis job queue

What: Synchronous PDF generation in the HTTP request timed out for large reports.

How:

  • Rewrote backend/server/routes/reports.ts with three endpoints:
    • POST /api/reports/pets/:petId/health → returns 202 { jobId } immediately
    • GET /api/reports/:jobId/status → returns { status, recordCount, filename, error }
    • GET /api/reports/:jobId/download → streams PDF once complete
  • PDF generation runs in setImmediate (background, non-blocking)
  • Job state stored in Redis with 1-hour TTL using the existing getRedisClient()
  • Graceful synchronous fallback if Redis is unavailable
  • Failed jobs return a typed error that allows client-side retry
  • DocumentVaultScreen.tsx updated: new "Generate Health Report" button enqueues the job, polls /status every 2 s with an activity indicator, and shows a "Download PDF" button when status === 'complete'

DogStark#607 — Maestro E2E flow for Emergency SOS

What: No Maestro coverage for the highest-stakes feature in the app.

How:

  • Added .maestro/flows/sos.yaml with three scenarios:
    1. Full activation — hold SOS button → countdown → contacts notified
    2. Cancel during countdown — hold → confirm dialog visible → tap cancel → no SOS sent
    3. No contacts configured — SOS fires → shows "Add Emergency Contact" prompt
  • Mock scripts in .maestro/scripts/ intercept POST /api/emergency/sos and GET /api/emergency/contacts so no real alerts are dispatched during CI
  • Run with: maestro test .maestro/flows/sos.yaml

…+health, SEP-24 contracts, async PDF queue, SOS Maestro E2E

Close DogStark#596 — PostgreSQL connection pool hardening
- Replaced DB_POOL_SIZE/DB_IDLE_TIMEOUT env vars with DB_POOL_MAX,
  DB_IDLE_TIMEOUT_MS, DB_CONNECTION_TIMEOUT_MS (all configurable)
- New defaults: max=20, idleTimeoutMillis=10000, connectionTimeoutMillis=3000
- Added getPoolStats() helper (total/idle/waiting counts)
- /api/health now returns pool stats in response body
- Emits a console WARN when waiting > 5 on every new connection
- Added backend/tests/integration/poolExhaustion.test.ts: verifies
  requests fail fast (not hang) after connectionTimeoutMillis

Close DogStark#603 — SEP-24 anchor contract tests
- Added backend/services/__tests__/stellarAnchorService.contract.test.ts
- Consumer-driven contracts using a lightweight mock provider (no Pact
  dependency needed — mock shapes are the contract)
- Covers: stellar.toml shape, /deposit/interactive request/response,
  /withdraw/interactive with amount, /transaction poll (pending & complete),
  terminal-status cache (no re-poll), and SEP-24 /info shape
- If anchor API changes its response shape, the corresponding assertion fails

Close DogStark#595 — Async PDF generation via Redis job queue
- Rewrote backend/server/routes/reports.ts from synchronous GET to:
    POST /api/reports/pets/:petId/health → 202 { jobId }
    GET  /api/reports/:jobId/status      → { status, recordCount, filename, error }
    GET  /api/reports/:jobId/download    → streams PDF when complete
- Jobs stored in Redis with 1-hour TTL using existing getRedisClient()
- PDF generation runs in setImmediate (background, non-blocking)
- Graceful fallback to synchronous generation if Redis is unavailable
- Failed jobs return typed error with retry possible
- DocumentVaultScreen.tsx updated: 'Generate Health Report' button enqueues
  job, polls every 2 s with progress indicator, shows Download PDF on complete

Close DogStark#607 — Maestro E2E flow for Emergency SOS
- Added .maestro/flows/sos.yaml covering three scenarios:
    1. Full activation: hold SOS → countdown → contacts notified
    2. Cancellation: hold → confirm dialog → tap cancel → no SOS sent
    3. No contacts: hold → SOS fires → shows 'Add Emergency Contact' prompt
- Mock scripts in .maestro/scripts/ intercept API calls so no real
  alerts are sent during test runs
- Runnable with: maestro test .maestro/flows/sos.yaml
@Creed1759 Creed1759 closed this Jun 26, 2026
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.

Implement connection pooling configuration and monitoring for PostgreSQL in backend/config/

1 participant