multi script beta
This commit is contained in:
+116
-19
@@ -37,11 +37,9 @@ describe('scope options', () => {
|
||||
describe('promote creates a deployment', () => {
|
||||
it('records deployment_files for every landed server and marks beta servers done, others pending', async () => {
|
||||
await seedFleet();
|
||||
const { createScript, getScript } = await import('../../src/lib/server/fleet/scripts.js');
|
||||
const { createScript, getScript, getLatestVersion } = await import('../../src/lib/server/fleet/scripts.js');
|
||||
const { openBeta, promoteBeta } = await import('../../src/lib/server/fleet/beta.js');
|
||||
const { db } = await import('../../src/lib/server/db/index.js');
|
||||
// The reconcileBetaState only fires from the beta-runner; short-circuit
|
||||
// that in the test by flipping beta state manually.
|
||||
|
||||
// A game-scoped script matches both fixture servers.
|
||||
const { script } = createScript({
|
||||
@@ -51,16 +49,15 @@ describe('promote creates a deployment', () => {
|
||||
scopeValue: 't5',
|
||||
content: Buffer.from('main(){}\n')
|
||||
});
|
||||
const version = getLatestVersion(script.id)!;
|
||||
|
||||
// Open the beta on ONE server; promotion should still write to the
|
||||
// other server (via scope) and mark it pending for restart.
|
||||
const { betaId } = await openBeta({
|
||||
scriptId: script.id,
|
||||
scriptVersionId: script.current_version_id ?? (await import('../../src/lib/server/fleet/scripts.js')).getLatestVersion(script.id)!.id,
|
||||
scripts: [{ scriptId: script.id, scriptVersionId: version.id }],
|
||||
servers: ['t5_kino_1'],
|
||||
waitForHealth: false,
|
||||
waitForMatch: false,
|
||||
triggerKind: 'mark-required'
|
||||
waitForMatch: false
|
||||
});
|
||||
|
||||
// Force all beta_servers to 'ready' and beta to 'ready-promote'.
|
||||
@@ -72,13 +69,20 @@ describe('promote creates a deployment', () => {
|
||||
|
||||
expect(result.deploymentId).toMatch(/^dep-.*-promote-\d+$/);
|
||||
expect(new Set(result.landed)).toEqual(new Set(['t5_kino_1', 't5_ascension_1']));
|
||||
expect(result.scriptIds).toEqual([script.id]);
|
||||
|
||||
// Deployment row is action='promote' with the new columns populated.
|
||||
// Deployment row is action='promote'. The multi-script schema stores
|
||||
// scripts in deployment_scripts, not the legacy singular columns.
|
||||
const dep = db().prepare(`SELECT * FROM deployments WHERE id = ?`).get(result.deploymentId) as any;
|
||||
expect(dep.action).toBe('promote');
|
||||
expect(dep.script_id).toBe(script.id);
|
||||
expect(dep.beta_id).toBe(betaId);
|
||||
expect(dep.prior_version_id).toBeNull(); // never promoted before
|
||||
expect(dep.script_id).toBeNull(); // new promotes populate deployment_scripts
|
||||
|
||||
const depScripts = db().prepare(`SELECT * FROM deployment_scripts WHERE deployment_id = ?`).all(result.deploymentId) as any[];
|
||||
expect(depScripts.length).toBe(1);
|
||||
expect(depScripts[0].script_id).toBe(script.id);
|
||||
expect(depScripts[0].script_version_id).toBe(version.id);
|
||||
expect(depScripts[0].prior_version_id).toBeNull(); // never promoted before
|
||||
|
||||
// deployment_files has one row per landed server.
|
||||
const files = db().prepare(`SELECT * FROM deployment_files WHERE deployment_id = ?`).all(result.deploymentId) as any[];
|
||||
@@ -100,7 +104,7 @@ describe('promote creates a deployment', () => {
|
||||
|
||||
// Script's current_version_id and beta state land.
|
||||
const after = getScript(script.id)!;
|
||||
expect(after.current_version_id).toBeGreaterThan(0);
|
||||
expect(after.current_version_id).toBe(version.id);
|
||||
const beta = db().prepare(`SELECT state FROM betas WHERE id = ?`).get(betaId) as any;
|
||||
expect(beta.state).toBe('promoted');
|
||||
});
|
||||
@@ -123,12 +127,10 @@ describe('rollback beta on ready-promote marks version test-failed', () => {
|
||||
const v = getLatestVersion(script.id)!;
|
||||
|
||||
const { betaId } = await openBeta({
|
||||
scriptId: script.id,
|
||||
scriptVersionId: v.id,
|
||||
scripts: [{ scriptId: script.id, scriptVersionId: v.id }],
|
||||
servers: ['t5_kino_1'],
|
||||
waitForHealth: false,
|
||||
waitForMatch: false,
|
||||
triggerKind: 'mark-required'
|
||||
waitForMatch: false
|
||||
});
|
||||
|
||||
// Force ready-promote so the state machine gate is closed.
|
||||
@@ -162,12 +164,10 @@ describe('rollback promote deployment', () => {
|
||||
const v = getLatestVersion(script.id)!;
|
||||
|
||||
const { betaId } = await openBeta({
|
||||
scriptId: script.id,
|
||||
scriptVersionId: v.id,
|
||||
scripts: [{ scriptId: script.id, scriptVersionId: v.id }],
|
||||
servers: ['t5_kino_1'],
|
||||
waitForHealth: false,
|
||||
waitForMatch: false,
|
||||
triggerKind: 'mark-required'
|
||||
waitForMatch: false
|
||||
});
|
||||
db().prepare(`UPDATE beta_servers SET stage = 'ready', restarted_at = ? WHERE beta_id = ?`)
|
||||
.run(new Date().toISOString(), betaId);
|
||||
@@ -180,6 +180,7 @@ describe('rollback promote deployment', () => {
|
||||
const result = await rollbackPromoteDeployment(promote.deploymentId);
|
||||
expect(result.deploymentId).toMatch(/^dep-.*-rollback-/);
|
||||
expect(new Set(result.affectedServers)).toEqual(new Set(['t5_kino_1', 't5_ascension_1']));
|
||||
expect(result.scriptIds).toEqual([script.id]);
|
||||
|
||||
// Script's current_version_id reverted (was null before the promote).
|
||||
expect(getScript(script.id)!.current_version_id).toBeNull();
|
||||
@@ -199,3 +200,99 @@ describe('rollback promote deployment', () => {
|
||||
await expect(rollbackPromoteDeployment(promote.deploymentId)).rejects.toMatchObject({ kind: 'already-rolled-back' });
|
||||
});
|
||||
});
|
||||
|
||||
describe('multi-script beta', () => {
|
||||
it('open + promote + rollback bundle two scripts as one atomic unit', async () => {
|
||||
await seedFleet();
|
||||
const {
|
||||
createScript,
|
||||
getScript,
|
||||
getLatestVersion
|
||||
} = await import('../../src/lib/server/fleet/scripts.js');
|
||||
const {
|
||||
openBeta,
|
||||
promoteBeta,
|
||||
listBetaScripts
|
||||
} = await import('../../src/lib/server/fleet/beta.js');
|
||||
const { rollbackPromoteDeployment } = await import('../../src/lib/server/fleet/rollback.js');
|
||||
const { heldByBeta } = await import('../../src/lib/server/fleet/servers.js');
|
||||
const { db } = await import('../../src/lib/server/db/index.js');
|
||||
|
||||
// Two scripts, both scope=game=t5 so they both land on both fixture servers.
|
||||
const a = createScript({
|
||||
name: 'hud',
|
||||
targetRelPath: 'hud.gsc',
|
||||
scopeType: 'game',
|
||||
scopeValue: 't5',
|
||||
content: Buffer.from('hud(){}\n')
|
||||
});
|
||||
const b = createScript({
|
||||
name: 'flag',
|
||||
targetRelPath: 'flag.gsc',
|
||||
scopeType: 'game',
|
||||
scopeValue: 't5',
|
||||
content: Buffer.from('flag(){}\n')
|
||||
});
|
||||
const va = getLatestVersion(a.script.id)!;
|
||||
const vb = getLatestVersion(b.script.id)!;
|
||||
|
||||
const { betaId } = await openBeta({
|
||||
scripts: [
|
||||
{ scriptId: a.script.id, scriptVersionId: va.id },
|
||||
{ scriptId: b.script.id, scriptVersionId: vb.id }
|
||||
],
|
||||
servers: ['t5_kino_1', 't5_ascension_1'],
|
||||
waitForHealth: false,
|
||||
waitForMatch: false
|
||||
});
|
||||
|
||||
// Both scripts are joined to the beta.
|
||||
const bundle = listBetaScripts(betaId);
|
||||
expect(bundle.length).toBe(2);
|
||||
expect(new Set(bundle.map((r) => r.script_id))).toEqual(new Set([a.script.id, b.script.id]));
|
||||
|
||||
// Both target rel paths are held on both servers.
|
||||
const held1 = heldByBeta('t5_kino_1');
|
||||
expect(held1.get('hud.gsc')).toBe(betaId);
|
||||
expect(held1.get('flag.gsc')).toBe(betaId);
|
||||
|
||||
// Force ready-promote and simulate tested transition (the beta-runner
|
||||
// would do this for real).
|
||||
db().prepare(`UPDATE beta_servers SET stage = 'ready', restarted_at = ? WHERE beta_id = ?`)
|
||||
.run(new Date().toISOString(), betaId);
|
||||
db().prepare(`UPDATE betas SET state = 'ready-promote' WHERE id = ?`).run(betaId);
|
||||
db().prepare(`UPDATE script_versions SET state = 'tested' WHERE id IN (?, ?)`).run(va.id, vb.id);
|
||||
|
||||
const promote = await promoteBeta(betaId);
|
||||
expect(new Set(promote.scriptIds)).toEqual(new Set([a.script.id, b.script.id]));
|
||||
|
||||
// ONE deployment, TWO deployment_scripts rows.
|
||||
const dep = db().prepare(`SELECT * FROM deployments WHERE id = ?`).get(promote.deploymentId) as any;
|
||||
expect(dep.action).toBe('promote');
|
||||
expect(dep.beta_id).toBe(betaId);
|
||||
const depScripts = db()
|
||||
.prepare(`SELECT * FROM deployment_scripts WHERE deployment_id = ? ORDER BY script_id`)
|
||||
.all(promote.deploymentId) as any[];
|
||||
expect(depScripts.length).toBe(2);
|
||||
|
||||
// Two files per server (hud + flag) → 4 deployment_files rows.
|
||||
const files = db().prepare(`SELECT * FROM deployment_files WHERE deployment_id = ?`).all(promote.deploymentId) as any[];
|
||||
expect(files.length).toBe(4);
|
||||
|
||||
// Both scripts' current_version_id updated.
|
||||
expect(getScript(a.script.id)!.current_version_id).toBe(va.id);
|
||||
expect(getScript(b.script.id)!.current_version_id).toBe(vb.id);
|
||||
|
||||
// Rollback the whole promote — both scripts revert together.
|
||||
const rb = await rollbackPromoteDeployment(promote.deploymentId);
|
||||
expect(new Set(rb.scriptIds)).toEqual(new Set([a.script.id, b.script.id]));
|
||||
expect(getScript(a.script.id)!.current_version_id).toBeNull();
|
||||
expect(getScript(b.script.id)!.current_version_id).toBeNull();
|
||||
|
||||
// The rollback deployment mirrors both scripts.
|
||||
const rbScripts = db()
|
||||
.prepare(`SELECT * FROM deployment_scripts WHERE deployment_id = ?`)
|
||||
.all(rb.deploymentId) as any[];
|
||||
expect(rbScripts.length).toBe(2);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user