Add Prettier and ESLint tooling (Refs #77)

This commit is contained in:
2026-10-09 15:56:13 -04:00
parent 8ed059b8d3
commit 16469e2d43
711 changed files with 99737 additions and 28286 deletions
+46 -15
View File
@@ -18,12 +18,14 @@ afterEach(async () => {
describe('sweep', () => {
it('leaves history cleanup to the retention requester', async () => {
const retention = await import('../../src/lib/server/retention.js');
const prune = vi.spyOn(retention,'pruneHistory');
const prune = vi.spyOn(retention, 'pruneHistory');
try {
const { sweep } = await import('../../src/lib/server/pipeline/sweep.js');
await sweep();
expect(prune).not.toHaveBeenCalled();
} finally { prune.mockRestore(); }
} finally {
prune.mockRestore();
}
});
it('emits server state only when state, players, or error changes', async () => {
@@ -32,12 +34,21 @@ describe('sweep', () => {
const { db } = await import('../../src/lib/server/db/index.js');
const { subscribe } = await import('../../src/lib/server/pipeline/bus.js');
await seedServerRegistry();
db().prepare("INSERT INTO deployments (id, action, started_at, triggered_by) VALUES ('changes', 'test', ?, 'ui')")
db()
.prepare(
"INSERT INTO deployments (id, action, started_at, triggered_by) VALUES ('changes', 'test', ?, 'ui')"
)
.run(new Date().toISOString());
db().prepare(`INSERT INTO deployment_servers (deployment_id, server, files_changed, restart_state)
VALUES ('changes', 't5_zombie_theater_1', 1, 'pending')`).run();
db()
.prepare(
`INSERT INTO deployment_servers (deployment_id, server, files_changed, restart_state)
VALUES ('changes', 't5_zombie_theater_1', 1, 'pending')`
)
.run();
const events = vi.fn();
const unsubscribe = subscribe(event => { if (event.type === 'server-state') events(event); });
const unsubscribe = subscribe((event) => {
if (event.type === 'server-state') events(event);
});
try {
await sweep();
expect(events).toHaveBeenCalledTimes(1);
@@ -49,17 +60,26 @@ describe('sweep', () => {
db().prepare('UPDATE server_deployments SET checked_at = ?').run(checkedAt);
await sweep();
expect(events).toHaveBeenCalledTimes(1);
expect(db().prepare("SELECT checked_at, attempts FROM deployment_servers WHERE deployment_id = 'changes'").get())
.toEqual({ checked_at: checkedAt, attempts: 1 });
expect(
db()
.prepare(
"SELECT checked_at, attempts FROM deployment_servers WHERE deployment_id = 'changes'"
)
.get()
).toEqual({ checked_at: checkedAt, attempts: 1 });
db().prepare('UPDATE server_deployments SET players = 2').run();
await sweep();
expect(events).toHaveBeenCalledTimes(2);
expect(events).toHaveBeenLastCalledWith(expect.objectContaining({ state: 'pending', players: 2 }));
expect(events).toHaveBeenLastCalledWith(
expect.objectContaining({ state: 'pending', players: 2 })
);
db().prepare("UPDATE server_deployments SET error = 'Waiting for players'").run();
await sweep();
expect(events).toHaveBeenCalledTimes(3);
expect(events).toHaveBeenLastCalledWith(expect.objectContaining({ error: 'Waiting for players' }));
expect(events).toHaveBeenLastCalledWith(
expect.objectContaining({ error: 'Waiting for players' })
);
db().prepare("UPDATE server_deployments SET state = 'failed'").run();
await sweep();
expect(events).toHaveBeenCalledTimes(4);
@@ -69,8 +89,12 @@ describe('sweep', () => {
db().prepare("UPDATE server_deployments SET state = 'done'").run();
await sweep();
expect(events).toHaveBeenCalledTimes(5);
expect(events).toHaveBeenLastCalledWith(expect.objectContaining({ state: 'done', error: null }));
} finally { unsubscribe(); }
expect(events).toHaveBeenLastCalledWith(
expect.objectContaining({ state: 'done', error: null })
);
} finally {
unsubscribe();
}
});
it('queues pending rows in Provisioning even when integrations are unset', async () => {
@@ -80,7 +104,10 @@ describe('sweep', () => {
await seedServerRegistry();
const depId = 'dep-test-001';
db().prepare("INSERT INTO deployments (id, action, started_at, triggered_by) VALUES (?, 'test', ?, 'ui')")
db()
.prepare(
"INSERT INTO deployments (id, action, started_at, triggered_by) VALUES (?, 'test', ?, 'ui')"
)
.run(depId, new Date().toISOString());
db()
.prepare(
@@ -99,13 +126,17 @@ describe('sweep', () => {
await sweep();
const rows = db()
.prepare("SELECT restart_state FROM deployment_servers WHERE deployment_id = ?")
.prepare('SELECT restart_state FROM deployment_servers WHERE deployment_id = ?')
.all(depId) as Array<{ restart_state: string }>;
expect(rows.length).toBe(2);
for (const r of rows) expect(r.restart_state).toBe('pending');
const operations = db().prepare('SELECT state, stage FROM server_deployments').all();
expect(operations).toHaveLength(2);
for (const operation of operations) expect(operation).toEqual({ state: 'waiting', stage: 'Waiting to verify the server is empty' });
for (const operation of operations)
expect(operation).toEqual({
state: 'waiting',
stage: 'Waiting to verify the server is empty'
});
});
it('is a no-op when nothing is pending', async () => {