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
+56 -17
View File
@@ -2,13 +2,24 @@ import { afterEach, beforeEach, expect, it, vi } from 'vitest';
import { newFixture, type Fixture } from '../helpers/fixture.js';
let fixture: Fixture;
beforeEach(async () => { vi.resetModules(); fixture = await newFixture([]); });
afterEach(async () => { vi.restoreAllMocks(); await fixture.cleanup(); });
beforeEach(async () => {
vi.resetModules();
fixture = await newFixture([]);
});
afterEach(async () => {
vi.restoreAllMocks();
await fixture.cleanup();
});
async function setup() {
const database = await import('../../src/lib/server/db/index.js');
database.db().prepare(`INSERT INTO servers(name,game_port,last_error,last_reply_snippet)
VALUES ('server',28960,'bad-reply:unrecognized status','private reply 192.0.2.123:28960')`).run();
database
.db()
.prepare(
`INSERT INTO servers(name,game_port,last_error,last_reply_snippet)
VALUES ('server',28960,'bad-reply:unrecognized status','private reply 192.0.2.123:28960')`
)
.run();
return database;
}
@@ -22,7 +33,8 @@ it('excludes both snippet fields from list/detail/page snapshots and initial and
const { statusEntry } = await import('../../src/lib/server/pipeline/worker.js');
const { emit } = await import('../../src/lib/server/pipeline/bus.js');
const safe = (text: string) => {
for (const value of ['replySnippet', 'last_reply_snippet', 'private reply', '192.0.2.123']) expect(text).not.toContain(value);
for (const value of ['replySnippet', 'last_reply_snippet', 'private reply', '192.0.2.123'])
expect(text).not.toContain(value);
};
safe(await list().text());
safe(await detail({ params: { name: 'server' } }).text());
@@ -36,7 +48,9 @@ it('excludes both snippet fields from list/detail/page snapshots and initial and
const live = decoder.decode((await reader.read()).value);
expect(live).toContain('event: server-status');
safe(live);
} finally { await reader.cancel(); }
} finally {
await reader.cancel();
}
});
it('serves saved failure diagnostics without caching or probing and omits successful or missing evidence', async () => {
@@ -59,15 +73,29 @@ it('sanitizes manually probed failures before persistence and clears them on suc
const { db } = await setup();
const rcon = await import('../../src/lib/server/integrations/rcon.js');
const probe = vi.spyOn(rcon, 'rconStatusResult');
probe.mockResolvedValue({ ok: false, endpoint: null, reason: 'bad-reply', detail: 'unrecognized status',
rawReply: 'unrecognized player 192.0.2.123:28960' });
probe.mockResolvedValue({
ok: false,
endpoint: null,
reason: 'bad-reply',
detail: 'unrecognized status',
rawReply: 'unrecognized player 192.0.2.123:28960'
});
const { POST } = await import('../../src/routes/api/servers/[name]/probe-rcon/+server.js');
await POST({ params: { name: 'server' } } as never);
expect(db().prepare("SELECT last_reply_snippet FROM servers WHERE name='server'").get())
.toEqual({ last_reply_snippet: 'unrecognized player [redacted]' });
probe.mockResolvedValue({ ok: true, endpoint: { host: 'agent', port: 1 }, status: { players: 0, map: null, gametype: null, roster: [] } });
expect(await (await POST({ params: { name: 'server' } } as never)).json()).not.toHaveProperty('rawReply');
expect(db().prepare("SELECT last_reply_snippet FROM servers WHERE name='server'").get()).toEqual({ last_reply_snippet: null });
expect(
db().prepare("SELECT last_reply_snippet FROM servers WHERE name='server'").get()
).toEqual({ last_reply_snippet: 'unrecognized player [redacted]' });
probe.mockResolvedValue({
ok: true,
endpoint: { host: 'agent', port: 1 },
status: { players: 0, map: null, gametype: null, roster: [] }
});
expect(await (await POST({ params: { name: 'server' } } as never)).json()).not.toHaveProperty(
'rawReply'
);
expect(
db().prepare("SELECT last_reply_snippet FROM servers WHERE name='server'").get()
).toEqual({ last_reply_snippet: null });
});
it('discards legacy plain text and hex snippets and unsafe error details once during upgrade', async () => {
@@ -76,9 +104,20 @@ it('discards legacy plain text and hex snippets and unsafe error details once du
UPDATE servers SET last_error='bad-reply:print reply not recognized: "player 192.0.2.123:28960"';
INSERT INTO servers(name,last_reply_snippet) VALUES ('legacy-hex','0000 31 39 32 2e 30 2e 32 2e 31 32 33 3a 32 38 39 36 192.0.2.123:2896');`);
closeDb();
expect(db().prepare('SELECT last_reply_snippet FROM servers').all()).toEqual([{ last_reply_snippet: null }, { last_reply_snippet: null }]);
expect(db().prepare("SELECT last_error FROM servers WHERE name='server'").get()).toEqual({ last_error: 'bad-reply:unparseable print reply' });
db().prepare("UPDATE servers SET last_reply_snippet='new sanitized failure' WHERE name='server'").run();
expect(db().prepare('SELECT last_reply_snippet FROM servers').all()).toEqual([
{ last_reply_snippet: null },
{ last_reply_snippet: null }
]);
expect(db().prepare("SELECT last_error FROM servers WHERE name='server'").get()).toEqual({
last_error: 'bad-reply:unparseable print reply'
});
db()
.prepare(
"UPDATE servers SET last_reply_snippet='new sanitized failure' WHERE name='server'"
)
.run();
closeDb();
expect(db().prepare("SELECT last_reply_snippet FROM servers WHERE name='server'").get()).toEqual({ last_reply_snippet: 'new sanitized failure' });
expect(
db().prepare("SELECT last_reply_snippet FROM servers WHERE name='server'").get()
).toEqual({ last_reply_snippet: 'new sanitized failure' });
});