The Test Suite Is No Longer Haunted
Pattern Observed
This was never a “failing tests” problem.
It was a systems boundary problem.
The API worked. The routes existed. The database behaved. And yet — the test suite kept returning ghosts: 404s, missing initializers, inconsistent behavior across files.
The failures weren’t random. They were structural.
Root Cause
The test environment had quietly diverged from the runtime environment.
- Multiple app instantiation paths
- TypeScript syntax leaking into JavaScript-only execution contexts
- Route registration occurring in different places depending on how the app was constructed
- Implicit data assumptions (detail routes depending on seeds that weren’t guaranteed)
Each issue alone was survivable. Together, they produced noise that looked like chaos.
It wasn’t chaos. It was misalignment.
The Fix (What Actually Changed)
- A single, JS-only
createTestAppfactory now defines how the API is constructed for tests - All routes (health, admin, lab notes, OpenAPI) are registered in one place
- Test fixtures are deterministic and explicitly seeded
- API prefixing is handled centrally via a shared helper
- Express app initialization mirrors production wiring:
- CORS
- Sessions
- Passport
- OpenAPI validation
- Environment configuration now clearly defines the UI base URL (port 8001)
The tests didn’t just turn green. They became trustworthy.
Why This Matters
Passing tests are not the goal. Reliable signals are.
A system that “usually works” but lies under observation is more dangerous than one that fails loudly.
This fix wasn’t about silencing errors. It was about restoring coherence between:
- runtime
- tests
- documentation
- and intent
This is what “working with AI” actually looks like: not speed, not shortcuts, but shared understanding of the system being built.
Status
🧪 Test Suites: 6/6 passing
🧬 Contracts: Stable
🧭 Routing: Canonical
🌱 System: Ready to version