Save autoscaling policies without a preview step

This commit is contained in:
2026-10-07 15:56:13 -04:00
parent 7ede98ff87
commit daf78bc11c
12 changed files with 127 additions and 124 deletions
+5 -5
View File
@@ -12,7 +12,7 @@ async function setup(mode = 'create-destroy') {
const scaling = await import('../../src/lib/server/autoscaling/index.js');
db().prepare("INSERT INTO server_keys(id,game,pluto_key) VALUES('key-1','t6','test-key')").run();
const input = { ...settings, mode };
const saved = scaling.saveScaling(input, undefined, undefined, scaling.previewScaling(input).token);
const saved = scaling.saveScaling(input);
return { db, scaling, saved, input };
}
@@ -22,7 +22,7 @@ it('deletes policy evidence atomically while preserving lobbies, keys, and unrel
await scaling.runAutoscaling();
db().prepare("INSERT INTO server_keys(id,game,pluto_key) VALUES('other-key','t5','other-key')").run();
const otherSettings = { ...settings, game: 't5', mapSlug: 'theater', mode: 'off' };
const other = scaling.saveScaling(otherSettings, undefined, undefined, scaling.previewScaling(otherSettings).token);
const other = scaling.saveScaling(otherSettings);
for (const table of ['autoscaling_decisions', 'autoscaling_members', 'autoscaling_samples']) expect(db().prepare(`SELECT COUNT(*) AS n FROM ${table} WHERE policy_id=?`).get(saved.id)).toEqual({ n: 1 });
scaling.deleteScaling(saved.id, saved.revision);
expect(scaling.getScalingPolicy(saved.id)).toBeUndefined();
@@ -31,7 +31,7 @@ it('deletes policy evidence atomically while preserving lobbies, keys, and unrel
expect(db().prepare('SELECT name FROM servers').all()).toEqual([{ name: 't6_zombie_town_1' }]);
expect(db().prepare('SELECT COUNT(*) AS n FROM server_keys').get()).toEqual({ n: 2 });
expect(db().prepare('PRAGMA foreign_key_check').all()).toEqual([]);
expect(scaling.saveScaling({ ...settings, mode: 'off' }, undefined, undefined, scaling.previewScaling({ ...settings, mode: 'off' }).token).id).not.toBe(saved.id);
expect(scaling.saveScaling({ ...settings, mode: 'off' }).id).not.toBe(saved.id);
});
it.each(['off', 'create-destroy'])('deletes a settled %s policy even after key loss and releases ownership', async mode => {
@@ -47,7 +47,7 @@ it.each(['off', 'create-destroy'])('deletes a settled %s policy even after key l
it('rejects stale revisions and preserves the latest settings', async () => {
const { scaling, saved } = await setup();
const off = { ...settings, mode: 'off' };
const edited = scaling.saveScaling(off, saved.id, saved.revision, scaling.previewScaling(off, saved.id, saved.revision).token);
const edited = scaling.saveScaling(off, saved.id, saved.revision);
expect(() => scaling.deleteScaling(saved.id, saved.revision)).toThrow('changed');
expect(scaling.getScalingPolicy(saved.id)).toEqual(edited);
expect(() => scaling.deleteScaling('missing', 1)).toThrow('not found');
@@ -60,7 +60,7 @@ it('blocks deletion with pending intent, then keeps Provisioning history after p
expect(() => scaling.deleteScaling(saved.id, saved.revision)).toThrow('outstanding Provisioning');
expect(scaling.getScalingPolicy(saved.id)?.mode).toBe('create-destroy');
const off = { ...settings, mode: 'off' };
const paused = scaling.saveScaling(off, saved.id, saved.revision, scaling.previewScaling(off, saved.id, saved.revision).token);
const paused = scaling.saveScaling(off, saved.id, saved.revision);
scaling.deleteScaling(saved.id, paused.revision);
const { getDeployment } = await import('../../src/lib/server/provisioning/history.js');
expect(getDeployment(id)).toMatchObject({ deployment: { state: 'cancelled' }, sources: [expect.objectContaining({ kind: 'autoscaling', source_id: saved.id, label: 'Deleted autoscaling policy', href: null })] });