Add Prettier and ESLint tooling (Refs #77)
This commit is contained in:
@@ -4,8 +4,13 @@ import schema from '../../src/lib/server/db/schema.sql?raw';
|
||||
import { newFixture, type Fixture } from '../helpers/fixture.js';
|
||||
|
||||
let fixture: Fixture;
|
||||
beforeEach(async () => { vi.resetModules(); fixture = await newFixture([]); });
|
||||
afterEach(async () => { await fixture.cleanup(); });
|
||||
beforeEach(async () => {
|
||||
vi.resetModules();
|
||||
fixture = await newFixture([]);
|
||||
});
|
||||
afterEach(async () => {
|
||||
await fixture.cleanup();
|
||||
});
|
||||
|
||||
it('migrates idle, occupied and duplicate legacy keys without releasing unresolved assignments', async () => {
|
||||
const previous = new Database(fixture.dbPath);
|
||||
@@ -24,7 +29,10 @@ it('migrates idle, occupied and duplicate legacy keys without releasing unresolv
|
||||
['t5_zombie_moon_2', 'idle-key'],
|
||||
['t6_zombie_town_1', 't6-key']
|
||||
];
|
||||
for (const [server, credential] of cases) previous.prepare('INSERT INTO server_keys(server_id,pluto_key,updated_at) VALUES(?,?,?)').run(server, credential, '2026-01-01');
|
||||
for (const [server, credential] of cases)
|
||||
previous
|
||||
.prepare('INSERT INTO server_keys(server_id,pluto_key,updated_at) VALUES(?,?,?)')
|
||||
.run(server, credential, '2026-01-01');
|
||||
previous.exec(`INSERT INTO servers(name,game,desired_state) VALUES('t5_zombie_theater_1','t5','running'),('t5_zombie_pentagon_1','t5','stopped');
|
||||
INSERT INTO native_instances(id,server,host_id,library_id,image,port,created_at)
|
||||
VALUES('native','t5_zombie_cosmodrome_1','host','library','image',28960,'2026-01-01');
|
||||
@@ -47,7 +55,7 @@ it('migrates idle, occupied and duplicate legacy keys without releasing unresolv
|
||||
expect(db().pragma('foreign_key_check')).toEqual([]);
|
||||
closeDb();
|
||||
}
|
||||
const duplicate = pool.listServerKeys().find(key => key.assigned_servers.length === 2)!;
|
||||
const duplicate = pool.listServerKeys().find((key) => key.assigned_servers.length === 2)!;
|
||||
expect(duplicate.assigned_servers).toEqual(['t5_zombie_pentagon_1', 't5_zombie_theater_1']);
|
||||
expect(duplicate.updated_at).toBe('2026-01-01');
|
||||
expect(pool.reserveServerKey('t5_zombie_theater_2', 't5')).toBe('idle-key');
|
||||
@@ -75,18 +83,54 @@ it('recovers actual launch credentials and holds both sides of an unresolved leg
|
||||
('kino','t5_zombie_theater_1','host',2,'library','image',28960,'2026-01-01'),
|
||||
('five','t5_zombie_pentagon_1','host',1,'library','image',28961,'2026-01-01'),
|
||||
('queued','t5_zombie_cosmodrome_1','host',1,'library','image',28962,'2026-01-01');`);
|
||||
function operation(id: string, instance: string, generation: number, kind: string, state: string, key: string, staged = false, nextGeneration?: number) {
|
||||
const payload = JSON.stringify({ game: 't5', env: { PLUTO_SERVER_KEY: key }, nextGeneration });
|
||||
previous.prepare(`INSERT INTO ec_host_operations(id,host_id,instance_id,generation,kind,state,payload,created_at,updated_at)
|
||||
VALUES(?,'host',?,?,?,?,?,'2026-01-01','2026-01-01')`).run(id, instance, generation, kind, state, staged ? '{}' : payload);
|
||||
if (staged) previous.prepare('INSERT INTO ec_host_operation_payloads(operation_id,payload) VALUES(?,?)').run(id, payload);
|
||||
function operation(
|
||||
id: string,
|
||||
instance: string,
|
||||
generation: number,
|
||||
kind: string,
|
||||
state: string,
|
||||
key: string,
|
||||
staged = false,
|
||||
nextGeneration?: number
|
||||
) {
|
||||
const payload = JSON.stringify({
|
||||
game: 't5',
|
||||
env: { PLUTO_SERVER_KEY: key },
|
||||
nextGeneration
|
||||
});
|
||||
previous
|
||||
.prepare(
|
||||
`INSERT INTO ec_host_operations(id,host_id,instance_id,generation,kind,state,payload,created_at,updated_at)
|
||||
VALUES(?,'host',?,?,?,?,?,'2026-01-01','2026-01-01')`
|
||||
)
|
||||
.run(id, instance, generation, kind, state, staged ? '{}' : payload);
|
||||
if (staged)
|
||||
previous
|
||||
.prepare('INSERT INTO ec_host_operation_payloads(operation_id,payload) VALUES(?,?)')
|
||||
.run(id, payload);
|
||||
}
|
||||
operation('obsolete-kino', 'kino', 1, 'instance.create', 'completed', 'obsolete-key');
|
||||
operation('actual-kino', 'kino', 1, 'instance.rebuild', 'completed', 'actual-key', true, 2);
|
||||
operation('original-five', 'five', 1, 'instance.create', 'completed', 'original-key');
|
||||
operation('unknown-five', 'five', 1, 'instance.rebuild', 'unknown', 'pending-key', true, 2);
|
||||
operation('unknown-creation', 'queued', 1, 'instance.create', 'unknown', 'unknown-creation-key');
|
||||
operation('failed-new-key', 'kino', 2, 'instance.rebuild', 'failed', 'never-applied-key', true, 3);
|
||||
operation(
|
||||
'unknown-creation',
|
||||
'queued',
|
||||
1,
|
||||
'instance.create',
|
||||
'unknown',
|
||||
'unknown-creation-key'
|
||||
);
|
||||
operation(
|
||||
'failed-new-key',
|
||||
'kino',
|
||||
2,
|
||||
'instance.rebuild',
|
||||
'failed',
|
||||
'never-applied-key',
|
||||
true,
|
||||
3
|
||||
);
|
||||
previous.close();
|
||||
|
||||
const pool = await import('../../src/lib/server/fleet/server-keys.js');
|
||||
@@ -95,11 +139,21 @@ it('recovers actual launch credentials and holds both sides of an unresolved leg
|
||||
expect(pool.getServerKey('t5_zombie_cosmodrome_1')).toBe('unknown-creation-key');
|
||||
expect(pool.serverKeyPool('t5')).toEqual({ total: 5, available: 1 });
|
||||
expect(pool.serverKeyPool('t5', 't5_zombie_pentagon_1')).toEqual({ total: 5, available: 2 });
|
||||
expect(() => pool.reserveServerKey('t5_zombie_moon_2', 't5', 'original-key')).toThrow('already reserved');
|
||||
expect(() => pool.reserveServerKey('t5_zombie_moon_2', 't5', 'original-key')).toThrow(
|
||||
'already reserved'
|
||||
);
|
||||
const { db, closeDb } = await import('../../src/lib/server/db/index.js');
|
||||
expect(db().prepare(`SELECT k.pluto_key,l.is_current FROM server_key_leases l JOIN server_keys k ON k.id=l.key_id
|
||||
WHERE l.server_id='t5_zombie_pentagon_1' ORDER BY l.is_current`).all())
|
||||
.toEqual([{ pluto_key: 'original-key', is_current: 0 }, { pluto_key: 'pending-key', is_current: 1 }]);
|
||||
expect(
|
||||
db()
|
||||
.prepare(
|
||||
`SELECT k.pluto_key,l.is_current FROM server_key_leases l JOIN server_keys k ON k.id=l.key_id
|
||||
WHERE l.server_id='t5_zombie_pentagon_1' ORDER BY l.is_current`
|
||||
)
|
||||
.all()
|
||||
).toEqual([
|
||||
{ pluto_key: 'original-key', is_current: 0 },
|
||||
{ pluto_key: 'pending-key', is_current: 1 }
|
||||
]);
|
||||
expect(db().pragma('foreign_key_check')).toEqual([]);
|
||||
closeDb();
|
||||
expect(pool.serverKeyPool('t5')).toEqual({ total: 5, available: 1 });
|
||||
|
||||
Reference in New Issue
Block a user