mirror of
https://github.com/nestriness/nestri.git
synced 2026-11-18 21:19:50 +02:00
feat(session): a run stopped before it went live can end
A run stopped while its game is still downloading has failed at nothing, and never reached live, where billing starts. Until now the only way out of starting was failed, so a host that honoured the stop had to report a stop the person asked for as a failure.
This commit is contained in:
@@ -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<Info['state'], readonly Info['state'][]> = {
|
||||
requested: ['starting'],
|
||||
starting: ['live', 'failed'],
|
||||
starting: ['live', 'ended', 'failed'],
|
||||
live: ['ended', 'failed'],
|
||||
ended: [],
|
||||
failed: []
|
||||
|
||||
@@ -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();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user