Fix installs stuck as "Uninstalling"; remove a failed install's record
An uninstall whose export failed was cancelled, but its install stayed "uninstalling" for good. It now goes back to live (or waiting for the proxy), like a failed or hand-cancelled uninstall. Uninstall is refused for a failed install (nothing of it is on the server, so the export always failed) and for one still installing. A failed install's page offers "Remove the record" instead, which also clears records already stuck from before. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -243,6 +243,40 @@ describe('scheduled updates (§8)', () => {
|
||||
expect((await db.install.findUnique({ where: { id: 'inst-0' } })).releasedAt).toEqual(at);
|
||||
expect(await db.job.findFirst({ where: { type: 'purge', deploymentId: d.id } })).toBeTruthy();
|
||||
});
|
||||
|
||||
test('uninstall: when the export fails the uninstall is cancelled and the install is live again, not stuck uninstalling', async () => {
|
||||
const { server, deployments } = await liveDeployments(1);
|
||||
const d = deployments[0];
|
||||
const at = new Date(NOW.getTime() + 5 * H);
|
||||
const { uninstallJob } = await jobs.scheduleUninstall({ deploymentId: d.id, totp: totpNow(), confirm: 'c0', at }, admin, NOW);
|
||||
const job = (await jobs.poll(server, { agentApiVersion: 1, agentVersion: '1.0.0', mode: 'church', runningJobId: null }, at)).jobs[0];
|
||||
await jobs.receiveReport(server, signedReport(job, 'failed'), at);
|
||||
expect(await db.job.findUnique({ where: { id: uninstallJob.id } })).toMatchObject({ status: 'cancelled' });
|
||||
expect(await db.deployment.findUnique({ where: { id: d.id } })).toMatchObject({ status: 'live' });
|
||||
});
|
||||
|
||||
test('a failed install isn\'t uninstalled: its record is removed instead, and the short name is free', async () => {
|
||||
const { server } = await joinServer();
|
||||
await servers.setServerConfig(server.id, { TRUST_PROXY: 'loopback' });
|
||||
const { deployment } = await jobs.newInstall({ customerId: 'cust-1', serverId: server.id, shortName: 'hope', domain: 'events.hope.co.za' }, admin, NOW);
|
||||
await expect(jobs.removeFailedInstall(deployment.id)).rejects.toMatchObject({ code: 'NOT_FAILED' });
|
||||
const [job] = (await jobs.poll(server, { agentApiVersion: 1, agentVersion: '1.0.0', mode: 'church', runningJobId: null }, NOW)).jobs;
|
||||
await jobs.receiveReport(server, signedReport(job, 'failed'), NOW);
|
||||
await expect(jobs.scheduleUninstall({ deploymentId: deployment.id, totp: totpNow(), confirm: 'hope' }, admin, NOW)).rejects.toMatchObject({ code: 'NOT_INSTALLED' });
|
||||
expect(await jobs.neverInstalled(await db.deployment.findUnique({ where: { id: deployment.id } }))).toBe(true);
|
||||
await jobs.removeFailedInstall(deployment.id);
|
||||
expect(await db.deployment.findUnique({ where: { id: deployment.id } })).toBeNull();
|
||||
});
|
||||
|
||||
test('a failed install stuck "uninstalling" from before 2.3.2 can have its record removed; a live one can\'t', async () => {
|
||||
const { server, deployments } = await liveDeployments(1);
|
||||
await expect(jobs.removeFailedInstall(deployments[0].id)).rejects.toMatchObject({ code: 'NOT_FAILED' });
|
||||
const stuck = await db.deployment.create({ data: { id: 'dep-stuck', serverId: server.id, customerId: 'cust-1', product: 'events', shortName: 'stuck', domain: 'events.stuck.co.za', webPort: 20010, apiPort: 20011, status: 'uninstalling' } });
|
||||
await db.job.create({ data: { id: 'job-inst', serverId: server.id, type: 'install', deploymentId: stuck.id, status: 'failed', args: {}, notBefore: NOW, expiresAt: NOW, createdAt: NOW } });
|
||||
await db.job.create({ data: { id: 'job-un', serverId: server.id, type: 'uninstall', deploymentId: stuck.id, status: 'cancelled', args: {}, notBefore: NOW, expiresAt: NOW, createdAt: new Date(NOW.getTime() + H) } });
|
||||
await jobs.removeFailedInstall(stuck.id);
|
||||
expect(await db.deployment.findUnique({ where: { id: stuck.id } })).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
describe('ports and alerts', () => {
|
||||
|
||||
Reference in New Issue
Block a user