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({ 'hud.gsc': 'v1' }, ['t5_kino_1', 't5_ascension_1']); // No integrations → sweep marks rows manual, exercising that branch. delete process.env.KOMODO_ADDRESS; delete process.env.RCON_PASSWORD; }); afterEach(async () => { await fixture.cleanup(); }); describe('sweep', () => { it('marks all pending rows manual when integrations are unset', async () => { const { doPush } = await import('../../src/lib/server/fleet/push.js'); const { sweep } = await import('../../src/lib/server/pipeline/sweep.js'); const { seedServerRegistry } = await import('../../src/lib/server/fleet/servers.js'); const { db } = await import('../../src/lib/server/db/index.js'); await seedServerRegistry(); const push = await doPush({ patterns: ['*'] }); expect(push.deploymentId).not.toBeNull(); await sweep(); const rows = db() .prepare("SELECT restart_state FROM deployment_servers WHERE deployment_id = ?") .all(push.deploymentId!) as Array<{ restart_state: string }>; for (const r of rows) expect(r.restart_state).toBe('manual'); }); it('is a no-op when nothing is pending', async () => { const { sweep } = await import('../../src/lib/server/pipeline/sweep.js'); const { seedServerRegistry } = await import('../../src/lib/server/fleet/servers.js'); await seedServerRegistry(); // No deployments → no pending rows. Should return zero counts. const result = await sweep(); expect(result).toEqual({ checked: 0, restarted: 0, held: 0, failed: 0 }); }); });