(overrides: Partial<SessionDeps> = {})
| 48 | } |
| 49 | |
| 50 | function makeDeps(overrides: Partial<SessionDeps> = {}): SessionDeps & { |
| 51 | rows: Map<string, InternalSessionRow> |
| 52 | admits: AdmitRecord[] |
| 53 | _tick: (n: Date) => void |
| 54 | _now: () => Date |
| 55 | } { |
| 56 | const rows = new Map<string, InternalSessionRow>() |
| 57 | const admits: AdmitRecord[] = [] |
| 58 | let currentNow = new Date('2026-04-17T12:00:00Z') |
| 59 | let instanceCounter = 0 |
| 60 | |
| 61 | const newInstanceId = () => `inst-${++instanceCounter}` |
| 62 | |
| 63 | const deps: SessionDeps & { |
| 64 | rows: Map<string, InternalSessionRow> |
| 65 | admits: AdmitRecord[] |
| 66 | _tick: (n: Date) => void |
| 67 | _now: () => Date |
| 68 | } = { |
| 69 | rows, |
| 70 | admits, |
| 71 | _tick: (n: Date) => { |
| 72 | currentNow = n |
| 73 | }, |
| 74 | _now: () => currentNow, |
| 75 | isWaitingRoomEnabled: () => true, |
| 76 | graceMs: GRACE_MS, |
| 77 | sessionLengthMs: SESSION_LEN, |
| 78 | // Test default: instant-admit disabled (capacity 0) so existing FIFO |
| 79 | // queue tests stay green. Tests that exercise instant admission opt in |
| 80 | // via `getInstantAdmitCapacity: () => N`. |
| 81 | getInstantAdmitCapacity: () => 0, |
| 82 | activeCountForModel: async (model) => { |
| 83 | let n = 0 |
| 84 | for (const r of rows.values()) { |
| 85 | if (r.status === 'active' && r.model === model) n++ |
| 86 | } |
| 87 | return n |
| 88 | }, |
| 89 | listRecentPremiumAdmits: async ({ userId, models, since, accessTier }) => { |
| 90 | return admits |
| 91 | .filter( |
| 92 | (a) => |
| 93 | a.user_id === userId && |
| 94 | models.includes(a.model) && |
| 95 | a.admitted_at.getTime() >= since.getTime() && |
| 96 | (!accessTier || (a.access_tier ?? 'full') === accessTier), |
| 97 | ) |
| 98 | .sort((a, b) => a.admitted_at.getTime() - b.admitted_at.getTime()) |
| 99 | .map((a) => ({ |
| 100 | admittedAt: a.admitted_at, |
| 101 | model: a.model, |
| 102 | sessionUnits: a.session_units ?? 1, |
| 103 | })) |
| 104 | }, |
| 105 | promoteQueuedUser: async ({ userId, model, sessionLengthMs, now }) => { |
| 106 | const row = rows.get(userId) |
| 107 | if (!row || row.status !== 'queued' || row.model !== model) return null |
no test coverage detected