Unify UI workflows and streamline fleet management
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
import { afterEach, beforeEach, describe, 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 () => { await fixture.cleanup(); });
|
||||
|
||||
describe('server detail data', () => {
|
||||
it('filters history before the global limit and includes the matching rollout members', async () => {
|
||||
const { db } = await import('../../src/lib/server/db/index.js');
|
||||
const handle = db();
|
||||
handle.exec("INSERT INTO servers (name, komodo_name) VALUES ('target', 'target'), ('other', 'other')");
|
||||
handle.transaction(() => {
|
||||
const deployment = handle.prepare("INSERT INTO deployments (id, action, started_at) VALUES (?, 'promote', ?)");
|
||||
const member = handle.prepare("INSERT INTO deployment_servers (deployment_id, server, files_changed, restart_state) VALUES (?, ?, 1, 'done')");
|
||||
deployment.run('older-target', '2026-01-01');
|
||||
member.run('older-target', 'target'); member.run('older-target', 'other');
|
||||
for (let n = 0; n < 501; n++) { deployment.run('other-' + n, '2026-09-18'); member.run('other-' + n, 'other'); }
|
||||
})();
|
||||
const { GET } = await import('../../src/routes/api/campaigns/+server.js');
|
||||
const all = await (await GET({ url: new URL('http://localhost/api/campaigns') })).json();
|
||||
expect(all.deployments).toHaveLength(500);
|
||||
const filtered = await (await GET({ url: new URL('http://localhost/api/campaigns?server=target') })).json();
|
||||
expect(filtered.deployments.map((row: { id: string }) => row.id)).toEqual(['older-target']);
|
||||
expect(filtered.deployments[0].servers).toHaveLength(2);
|
||||
expect((await (await GET({ url: new URL('http://localhost/api/campaigns?server=unknown') })).json()).deployments).toEqual([]);
|
||||
});
|
||||
it('identifies plugins, scripts, composed configs and unknown inventory files', async () => {
|
||||
const { db } = await import('../../src/lib/server/db/index.js');
|
||||
db().exec("INSERT INTO servers (name, komodo_name) VALUES ('target', 'target')");
|
||||
const { createScript } = await import('../../src/lib/server/fleet/scripts.js');
|
||||
const { recordScript } = await import('../../src/lib/server/fleet/inventory.js');
|
||||
const { version } = createScript({ name:'Plugin', kind:'plugin', targetRelPath:'native.bin', content:Buffer.from('plugin') });
|
||||
recordScript('target','native.bin',version.id,'hash',6,'beta');
|
||||
recordScript('target','dedicated_zm.cfg',null,'hash',10,'compose');
|
||||
recordScript('target','main.gsc',null,'hash',10,'beta');
|
||||
recordScript('target','unknown.dat',null,'hash',10,'manual');
|
||||
const { GET } = await import('../../src/routes/api/servers/[name]/scripts/+server.js');
|
||||
const body = await (await GET({ params: {name:'target'} })).json();
|
||||
expect(Object.fromEntries(body.scripts.map((file: {relPath:string;kind:string}) => [file.relPath,file.kind]))).toEqual({
|
||||
'dedicated_zm.cfg':'config','main.gsc':'script','native.bin':'plugin','unknown.dat':'file'
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user