Add Prettier and ESLint tooling (Refs #77)
This commit is contained in:
@@ -1,9 +1,18 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { defaultPlan, parseBetaPlan, requirement, type BetaPlan } from '../../src/lib/beta-plan.js';
|
||||
import { applySample, applyGameEvent, coveragePassed, emptyMetrics, evaluateRequirements } from '../../src/lib/server/fleet/beta-evaluation.js';
|
||||
import {
|
||||
applySample,
|
||||
applyGameEvent,
|
||||
coveragePassed,
|
||||
emptyMetrics,
|
||||
evaluateRequirements
|
||||
} from '../../src/lib/server/fleet/beta-evaluation.js';
|
||||
import { gameEvent } from '../helpers/telemetry.js';
|
||||
|
||||
const planWith = (...kinds: Parameters<typeof requirement>[0][]): BetaPlan => ({ ...defaultPlan(), requirements: kinds.map((k, i) => requirement(k, `r${i}`)) });
|
||||
const planWith = (...kinds: Parameters<typeof requirement>[0][]): BetaPlan => ({
|
||||
...defaultPlan(),
|
||||
requirements: kinds.map((k, i) => requirement(k, `r${i}`))
|
||||
});
|
||||
|
||||
describe('beta requirement evaluation', () => {
|
||||
it('credits heartbeat participation during a long round without completing a match', () => {
|
||||
@@ -29,18 +38,44 @@ describe('beta requirement evaluation', () => {
|
||||
expect(parseBetaPlan(defaultPlan())).toEqual(defaultPlan());
|
||||
expect(() => parseBetaPlan({ ...defaultPlan(), requirements: [] })).toThrow();
|
||||
expect(() => parseBetaPlan({ ...defaultPlan(), timeoutHours: NaN })).toThrow();
|
||||
expect(() => parseBetaPlan({ ...defaultPlan(), requirements: [requirement('round', 'same'), requirement('round', 'same')] })).toThrow();
|
||||
expect(() =>
|
||||
parseBetaPlan({
|
||||
...defaultPlan(),
|
||||
requirements: [requirement('round', 'same'), requirement('round', 'same')]
|
||||
})
|
||||
).toThrow();
|
||||
for (const kind of ['feature', 'restart-budget', 'clean-logs']) {
|
||||
expect(() => parseBetaPlan({ ...defaultPlan(), requirements: [{ ...requirement('round', 'r'), kind }] })).toThrow();
|
||||
expect(() =>
|
||||
parseBetaPlan({
|
||||
...defaultPlan(),
|
||||
requirements: [{ ...requirement('round', 'r'), kind }]
|
||||
})
|
||||
).toThrow();
|
||||
}
|
||||
expect(() => parseBetaPlan({ ...defaultPlan(), requirements: [{ ...requirement('round', 'r'), target: 1.5 }] })).toThrow();
|
||||
expect(() => parseBetaPlan({ ...defaultPlan(), requirements: [requirement('manual', 'constructor')] })).toThrow();
|
||||
expect(() =>
|
||||
parseBetaPlan({
|
||||
...defaultPlan(),
|
||||
requirements: [{ ...requirement('round', 'r'), target: 1.5 }]
|
||||
})
|
||||
).toThrow();
|
||||
expect(() =>
|
||||
parseBetaPlan({
|
||||
...defaultPlan(),
|
||||
requirements: [requirement('manual', 'constructor')]
|
||||
})
|
||||
).toThrow();
|
||||
});
|
||||
|
||||
it('uses qualifying round and population together within the same game, including the final report', () => {
|
||||
const plan = planWith('round', 'matches');
|
||||
plan.requirements[0].minPlayers = 4;
|
||||
plan.requirements[1] = { ...plan.requirements[1], target: 2, minRound: 25, minPlayers: 4, minMinutes: 1 };
|
||||
plan.requirements[1] = {
|
||||
...plan.requirements[1],
|
||||
target: 2,
|
||||
minRound: 25,
|
||||
minPlayers: 4,
|
||||
minMinutes: 1
|
||||
};
|
||||
const m = emptyMetrics();
|
||||
applyGameEvent(plan, m, gameEvent('game_start'), 0);
|
||||
applyGameEvent(plan, m, gameEvent('round_change', 30, 1), 1000);
|
||||
@@ -77,12 +112,22 @@ describe('beta requirement evaluation', () => {
|
||||
applyGameEvent(plan, m, gameEvent('game_start'), 60_000);
|
||||
applyGameEvent(plan, m, gameEvent('game_end', 1), 120_000);
|
||||
expect(m.values.r0 ?? 0).toBe(0);
|
||||
applyGameEvent(plan, m, gameEvent('game_end', 30, 4, 't5_zombie_theater_1', 'zombie_moon'), 180_000);
|
||||
applyGameEvent(
|
||||
plan,
|
||||
m,
|
||||
gameEvent('game_end', 30, 4, 't5_zombie_theater_1', 'zombie_moon'),
|
||||
180_000
|
||||
);
|
||||
expect(m.values.r0 ?? 0).toBe(0);
|
||||
});
|
||||
|
||||
it('derives participation only from game reports, even when rounds are many minutes apart', () => {
|
||||
const plan = planWith('populated-minutes', 'player-hours', 'population', 'sustained-population');
|
||||
const plan = planWith(
|
||||
'populated-minutes',
|
||||
'player-hours',
|
||||
'population',
|
||||
'sustained-population'
|
||||
);
|
||||
plan.requirements[3].minPlayers = 4;
|
||||
const m = emptyMetrics();
|
||||
applySample(plan, m, 0, true);
|
||||
@@ -115,9 +160,16 @@ describe('beta requirement evaluation', () => {
|
||||
});
|
||||
|
||||
it('requires each selected coverage group even when many servers on one map pass', () => {
|
||||
const servers = [{ game: 't5', map: 'a', passed: true }, { game: 't5', map: 'a', passed: true }, { game: 't6', map: 'b', passed: false }];
|
||||
expect(coveragePassed({ ...defaultPlan(), scope: 'quorum', quorum: 2 }, servers)).toBe(true);
|
||||
for (const scope of ['all', 'map', 'game', 'map-game'] as const) expect(coveragePassed({ ...defaultPlan(), scope }, servers)).toBe(false);
|
||||
const servers = [
|
||||
{ game: 't5', map: 'a', passed: true },
|
||||
{ game: 't5', map: 'a', passed: true },
|
||||
{ game: 't6', map: 'b', passed: false }
|
||||
];
|
||||
expect(coveragePassed({ ...defaultPlan(), scope: 'quorum', quorum: 2 }, servers)).toBe(
|
||||
true
|
||||
);
|
||||
for (const scope of ['all', 'map', 'game', 'map-game'] as const)
|
||||
expect(coveragePassed({ ...defaultPlan(), scope }, servers)).toBe(false);
|
||||
servers[2].passed = true;
|
||||
expect(coveragePassed({ ...defaultPlan(), scope: 'map-game' }, servers)).toBe(true);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user