Fix initial artifact deployment and drift file replacement
This commit is contained in:
@@ -22,6 +22,55 @@ afterEach(async () => {
|
||||
});
|
||||
|
||||
describe('drift scanning', () => {
|
||||
it('replaces a seeded config once instead of planning both removal and installation', async () => {
|
||||
const { seedServerRegistry } = await import('../../src/lib/server/fleet/servers.js');
|
||||
const { createScript } = await import('../../src/lib/server/fleet/scripts.js');
|
||||
const { scanServerDrift, runDriftDeployment } = await import('../../src/lib/server/fleet/drift.js');
|
||||
const { db } = await import('../../src/lib/server/db/index.js');
|
||||
const { getPromotedServerConfig } = await import('../../src/lib/server/fleet/server-config.js');
|
||||
await seedServerRegistry();
|
||||
const server = 't5_zombie_theater_1';
|
||||
const { script, version } = createScript({ name: 'baseline', kind: 'baseline', scopeType: 'game', scopeValue: 't5',
|
||||
content: Buffer.from('set sv_voice "1"\n') });
|
||||
db().prepare('UPDATE scripts SET current_version_id = ? WHERE id = ?').run(version.id, script.id);
|
||||
const path = join(fixture.t5, server, 'configs', 'dedicated_sp.cfg');
|
||||
await writeFile(path, 'seeded config');
|
||||
expect(await scanServerDrift(server)).toEqual([expect.objectContaining({ kind: 'config', driftKind: 'replace' })]);
|
||||
expect(await runDriftDeployment({ servers: [server] })).toMatchObject({ totalRemoved: 0, totalRestored: 1 });
|
||||
expect(await readFile(path)).toEqual(getPromotedServerConfig('t5', 'zombie_theater'));
|
||||
expect(await scanServerDrift(server)).toEqual([]);
|
||||
});
|
||||
|
||||
it.each(['identical', 'different'])('reconciles an existing %s scoped file in one pass with an update audit', async (mode) => {
|
||||
const { seedServerRegistry } = await import('../../src/lib/server/fleet/servers.js');
|
||||
const { createScript } = await import('../../src/lib/server/fleet/scripts.js');
|
||||
const { scanServerDrift, runDriftDeployment } = await import('../../src/lib/server/fleet/drift.js');
|
||||
const { getServerScript } = await import('../../src/lib/server/fleet/inventory.js');
|
||||
const { db } = await import('../../src/lib/server/db/index.js');
|
||||
const { destOfKind } = await import('../../src/lib/server/config.js');
|
||||
await seedServerRegistry();
|
||||
const server = 't5_zombie_theater_1';
|
||||
const content = Buffer.from('main(){}\n');
|
||||
const before = mode === 'identical' ? content : Buffer.from('old bytes');
|
||||
const { script, version } = createScript({ name: 'spawn fix', kind: 'script', scopeType: 'game', scopeValue: 't5',
|
||||
targetRelPath: 'zm_spawn_fix.gsc', content });
|
||||
db().prepare('UPDATE scripts SET current_version_id = ? WHERE id = ?').run(version.id, script.id);
|
||||
const target = join(destOfKind(server, 'script'), 'zm_spawn_fix.gsc');
|
||||
await writeFile(target, before);
|
||||
expect(await scanServerDrift(server)).toEqual([expect.objectContaining({ relPath: 'zm_spawn_fix.gsc', driftKind: 'replace' })]);
|
||||
expect(await runDriftDeployment({ servers: [server], dryRun: true })).toMatchObject({ totalRemoved: 0, totalRestored: 1, deploymentId: null });
|
||||
expect(await readFile(target)).toEqual(before);
|
||||
expect(getServerScript(server, 'zm_spawn_fix.gsc')).toBeUndefined();
|
||||
const result = await runDriftDeployment({ servers: [server] });
|
||||
expect(result).toMatchObject({ totalRemoved: 0, totalRestored: 1 });
|
||||
expect(await readFile(target)).toEqual(content);
|
||||
expect(getServerScript(server, 'zm_spawn_fix.gsc')?.script_version_id).toBe(version.id);
|
||||
expect(db().prepare('SELECT verb, content_before, content_after FROM deployment_files WHERE deployment_id = ?').all(result.deploymentId))
|
||||
.toEqual([{ verb: 'updated', content_before: before, content_after: content }]);
|
||||
expect(await scanServerDrift(server)).toEqual([]);
|
||||
expect((await runDriftDeployment({ servers: [server] })).deploymentId).toBeNull();
|
||||
});
|
||||
|
||||
it('detects untracked files across script, config, and plugin destinations', async () => {
|
||||
const { seedServerRegistry } = await import('../../src/lib/server/fleet/servers.js');
|
||||
const { scanServerDrift } = await import('../../src/lib/server/fleet/drift.js');
|
||||
|
||||
Reference in New Issue
Block a user