Queue native collection launches before async placement

This commit is contained in:
2026-10-05 11:35:50 -04:00
parent 1405114a14
commit 7c76851252
34 changed files with 1324 additions and 244 deletions
@@ -79,23 +79,46 @@ describe('large native collection admission', () => {
expect(preview.ready).toBe(true);
expect(preview.servers).toHaveLength(serverCount);
expect(new Set(preview.servers.map(server => server.name)).size).toBe(serverCount);
expect(new Set(preview.servers.map(server => server.port)).size).toBe(serverCount);
expect(preview.servers.every(server => server.port === null)).toBe(true);
expect(db().prepare('SELECT * FROM ec_host_ports').all()).toHaveLength(0);
const native = await import('../../src/lib/server/provisioning/native.js');
const validateSelection = vi.spyOn(native, 'nativeLaunchSelection');
manifestParses = 0;
const result = queueCollection({ previewId: preview.id,
keys: Object.fromEntries(preview.servers.map(server => [server.name!, 'key-' + server.name])) });
const queueParses = manifestParses;
expect(result).toMatchObject({ ok: true, collectionId: expect.any(String) });
expect(queueCollection({ previewId: preview.id })).toEqual(result);
expect(validateSelection).toHaveBeenCalledTimes(1);
expect(getCollection(result.collectionId!)?.collection).toMatchObject({ total: serverCount, queued: serverCount });
const instances = db().prepare('SELECT host_id,library_id,port FROM native_instances ORDER BY port').all();
expect(instances).toEqual(Array.from({ length: serverCount }, (_, index) => ({
host_id: hostId, library_id: libraryId, port: 28960 + index
})));
expect(db().prepare('SELECT * FROM ec_host_ports').all()).toHaveLength(serverCount * 2);
expect(db().prepare('SELECT host_id,library_id,port FROM native_instances').all()).toEqual([]);
expect(db().prepare('SELECT * FROM ec_host_ports').all()).toEqual([]);
const intents = db().prepare('SELECT selection FROM native_creation_intents').all() as { selection: string }[];
expect(intents).toHaveLength(serverCount);
expect(intents.every(intent => JSON.parse(intent.selection).libraryId === libraryId)).toBe(true);
expect(db().prepare('SELECT * FROM server_collection_members').all()).toHaveLength(serverCount);
expect(previewParses, 'Preview must use library metadata without reading the full manifest').toBe(0);
expect(queueParses, 'Queue admission must use library metadata without reading the full manifest').toBe(0);
}, 30_000);
it.each(['newer game files', 'deleted pinned host'])('rejects %s after review before queueing any collection work', async change => {
const { saveBlueprint } = await import('../../src/lib/server/fleet/launch-recipes.js');
const { previewCollection, queueCollection } = await import('../../src/lib/server/fleet/collections.js');
const { db } = await import('../../src/lib/server/db/index.js');
const blueprint = saveBlueprint({ name: 'Reviewed native selection', entries: [{ game: 't5', mapSlug: 'theater', count: 2 }] });
const preview = previewCollection(blueprint.id, 'fill', { hostId, libraryId, image });
if (change === 'newer game files') {
const { createLibraryImport } = await import('../../src/lib/server/game-files/index.js');
const newer = createLibraryImport({ hostId, game: 't5' });
db().prepare("UPDATE game_file_versions SET state='ready',published_at=? WHERE id=?")
.run(new Date(Date.now() + 1000).toISOString(), newer.id);
} else db().prepare('UPDATE ec_hosts SET deleted_at=? WHERE id=?').run(new Date().toISOString(), hostId);
expect(() => queueCollection({ previewId: preview.id,
keys: Object.fromEntries(preview.servers.map(server => [server.name!, 'key-' + server.name])) }))
.toThrow(change === 'newer game files' ? /game files changed/ : /host was not found/);
expect(db().prepare('SELECT id FROM server_launch_collections').all()).toEqual([]);
expect(db().prepare('SELECT deployment_id FROM native_creation_intents').all()).toEqual([]);
expect(db().prepare('SELECT server_id FROM server_keys').all()).toEqual([]);
});
});