diff --git a/packages/core/src/session/index.ts b/packages/core/src/session/index.ts index 70157369..7b660544 100644 --- a/packages/core/src/session/index.ts +++ b/packages/core/src/session/index.ts @@ -370,10 +370,14 @@ export namespace Session { * the only mutual exclusion in this design. `ended` and `failed` are * terminal, so their entries are empty rather than absent — a state with no * exits is a fact worth writing down. + * + * `starting → ended` is a run stopped before it went live — the person + * stopping it while its game downloads, say. Nothing failed, so `failed` + * would be a lie, and it never reached `live`, so it was never billed. */ export const NEXT_STATES: Record = { requested: ['starting'], - starting: ['live', 'failed'], + starting: ['live', 'ended', 'failed'], live: ['ended', 'failed'], ended: [], failed: [] diff --git a/packages/core/src/session/session.test.ts b/packages/core/src/session/session.test.ts index 8b00caf7..42c6324e 100644 --- a/packages/core/src/session/session.test.ts +++ b/packages/core/src/session/session.test.ts @@ -1200,4 +1200,17 @@ describe('Session end reasons', () => { expect(ended.session?.endReason).toBe('idle'); expect((await Session.fromID(run.session.id))?.endReason).toBe('idle'); }); + + test('a run stopped before it went live ends, with its reason, and was never billed', async () => { + const run = await requestedRun('ses-stopped-starting', 5472); + await report(run, 'starting'); + + // Stopped while its game downloaded: nothing failed, and it never + // reached `live`, which is where billing starts. + const ended = await report(run, 'ended', 'user'); + expect(ended.outcome).toBe('moved'); + expect(ended.session?.state).toBe('ended'); + expect(ended.session?.endReason).toBe('user'); + expect(ended.session?.timeStarted).toBeNull(); + }); });