smoke.test.ts39 lines · main
| 1 | import { describe, expect, it } from 'bun:test'; |
| 2 | |
| 3 | describe('realtime smoke', () => { |
| 4 | it('env module loads with defaults', async () => { |
| 5 | const { env } = await import('./env.js'); |
| 6 | expect(env.BRIVEN_ENV).toMatch(/^(development|staging|production)$/); |
| 7 | expect(env.BRIVEN_REALTIME_PORT).toBeGreaterThan(0); |
| 8 | }); |
| 9 | |
| 10 | it('subscription caps have sane defaults', async () => { |
| 11 | const { env } = await import('./env.js'); |
| 12 | // Per-WS cap: high enough that a normal app doesn't hit it (dozens |
| 13 | // of useQuery hooks), low enough that a runaway loop is bounded |
| 14 | // before memory pressure shows up. |
| 15 | expect(env.BRIVEN_REALTIME_MAX_SUBS_PER_WS).toBeGreaterThanOrEqual(50); |
| 16 | expect(env.BRIVEN_REALTIME_MAX_SUBS_PER_WS).toBeLessThanOrEqual(1000); |
| 17 | // Per-project cap: aligned with the year-one 10k concurrent target |
| 18 | // so a misconfig doesn't accidentally clamp Team customers below |
| 19 | // their tier ceiling. |
| 20 | expect(env.BRIVEN_REALTIME_MAX_SUBS_PER_PROJECT).toBeGreaterThanOrEqual( |
| 21 | env.BRIVEN_REALTIME_MAX_SUBS_PER_WS, |
| 22 | ); |
| 23 | }); |
| 24 | |
| 25 | it('per-project hard cap configuration is consistent', async () => { |
| 26 | const { env } = await import('./env.js'); |
| 27 | // Invariant 1: env ceiling must be at least the per-ws cap, else a |
| 28 | // single legitimate client could exceed the project cap with one |
| 29 | // socket — that would invalidate the tier-aware enforcement |
| 30 | // (index.ts message handler reads tierCap ?? env-ceiling). |
| 31 | expect(env.BRIVEN_REALTIME_MAX_SUBS_PER_PROJECT).toBeGreaterThanOrEqual( |
| 32 | env.BRIVEN_REALTIME_MAX_SUBS_PER_WS, |
| 33 | ); |
| 34 | // Invariant 2: env ceiling is the FLOOR for paid tiers. A metadata |
| 35 | // outage falls back to this number; it must never sit below the |
| 36 | // lowest tier's concurrentSubscriptions (free=100). |
| 37 | expect(env.BRIVEN_REALTIME_MAX_SUBS_PER_PROJECT).toBeGreaterThanOrEqual(100); |
| 38 | }); |
| 39 | }); |