Fix native provisioning scheduling and progress reporting

This commit is contained in:
2026-10-04 14:50:59 -04:00
parent 1bbee98b62
commit 2adadb0d05
18 changed files with 569 additions and 84 deletions
+31
View File
@@ -44,6 +44,37 @@ afterEach(async () => {
});
describe('reviewed drift plans', () => {
it('reads files in bounded batches and preserves deterministic scan order', async () => {
const { seedServerRegistry } = await import('../../src/lib/server/fleet/servers.js');
await seedServerRegistry();
const { destOfKind } = await import('../../src/lib/server/config.js');
const destination = destOfKind('t5_zombie_theater_1', 'plugin');
const names = Array.from({ length: 12 }, (_, i) => `batch-${String(i).padStart(2, '0')}.dll`);
await Promise.all(names.map(name => writeFile(join(destination, name), name)));
const files = await import('../../src/lib/server/backends/files.js');
const original = files.readFile;
let release!: () => void;
const gate = new Promise<void>(resolve => { release = resolve; });
let active = 0; let peak = 0;
const read = vi.spyOn(files, 'readFile').mockImplementation(async path => {
if (!path.includes('batch-')) return original(path);
peak = Math.max(peak, ++active);
try { await gate; return await original(path); }
finally { active--; }
});
const { scanServerDrift } = await import('../../src/lib/server/fleet/drift.js');
const scan = scanServerDrift('t5_zombie_theater_1');
try {
await vi.waitFor(() => expect(active).toBe(4));
expect(read.mock.calls.filter(([path]) => path.includes('batch-'))).toHaveLength(4);
release();
const result = await scan;
expect(result.filter(entry => entry.relPath.startsWith('batch-')).map(entry => entry.relPath)).toEqual(names);
expect(peak).toBe(4);
expect(active).toBe(0);
} finally { release(); await scan; read.mockRestore(); }
});
it('keeps live deletions, replacements, and inventory unchanged until activation', async () => {
const { seedServerRegistry } = await import('../../src/lib/server/fleet/servers.js');
const { createScript } = await import('../../src/lib/server/fleet/scripts.js');