Skip to main content

What Happened

Sparki’s web app had a latent bug: if the server environment was misconfigured with a URL like sparki.tools instead of https://sparki.tools, the entire login system and API would silently crash on startup. Users would hit a blank or broken app with no useful error message. This is the kind of mistake that happens during a hosting migration, a staging environment setup, or when a new engineer sets up their .env file from memory rather than from the template.

What Was Fixed

A small validation helper (ensureValidUrl) now sits between environment variables and the clients that consume them. If an invalid URL is detected, it logs a clear warning and falls back to a known-safe default rather than crashing. The fix was applied to all seven places in the codebase that construct URLs from environment variables.

What Was Built: Smoke Test Suite

A smoke test suite was added — 25 automated tests that run on every code push and verify:
  1. The URL validator behaves correctly for all edge cases (missing protocol, empty string, undefined)
  2. The API client and auth client initialize without errors
  3. Every critical page in the dashboard renders without entering an error state
These tests complete in under 10 seconds and now gate the CI pipeline — nothing can merge unless they pass.

Business Impact

  • Deployment confidence: Engineers can ship knowing that a misconfigured URL will be caught before it affects users.
  • Faster incident detection: If this bug ever regressed, it would be caught in CI in seconds rather than discovered by a user.
  • Onboarding safety net: New engineers or new environments with malformed .env files get an explicit warning, not a cryptic crash.

Action Items

  • Audit .env.example in all other Sparki services (api-engine, auth-shield) for similar bare-hostname patterns
  • Add the ensureValidUrl pattern to the shared common-ts-lib so other frontend apps can use it
  • Consider a startup health-check endpoint that validates all required env vars on boot