New install: a failed or removed install's short name can be used again

Found in the VM test: after a failed install, retrying with the same
short name was refused, and the unique short name per product would
have blocked it anyway. A failed install's record is replaced; a removed
one keeps its history under another name.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-17 15:39:36 +02:00
co-authored by Claude Opus 5.5
parent b0d81ed195
commit 016d1ea17e
2 changed files with 29 additions and 1 deletions
+8 -1
View File
@@ -387,7 +387,14 @@ async function newInstall(input, admin, now = new Date()) {
if (!server) throw fail(404, 'NOT_FOUND', 'Server not found.');
const release = await releaseFor(product, input.version || null);
await preflight(server, product, release.version, now);
if (await prisma.deployment.findFirst({ where: { shortName, status: { not: 'removed' } } })) throw fail(409, 'SHORT_NAME_TAKEN', `The short name ${shortName} is already used.`);
if (await prisma.deployment.findFirst({ where: { shortName, status: { notIn: ['removed', 'failed'] } } })) throw fail(409, 'SHORT_NAME_TAKEN', `The short name ${shortName} is already used.`);
// The name is free again after a failed install (its ports were already freed) or an uninstall.
// A failed install's record goes; a removed one keeps its history under another name (the
// database allows one install per short name and product). Found in the VM test.
await prisma.deployment.deleteMany({ where: { shortName, product, status: 'failed' } });
for (const old of await prisma.deployment.findMany({ where: { shortName, product, status: 'removed' } })) {
await prisma.deployment.update({ where: { id: old.id }, data: { shortName: `${shortName}~removed-${old.id.slice(0, 8)}` } });
}
const warnings = [];
const dnsOk = await dnsPointsAtCentral(domain);
if (dnsOk === false) warnings.push(`${domain} doesn't point at the central server yet (the install still runs).`);
+21
View File
@@ -264,3 +264,24 @@ describe('ports and alerts', () => {
expect(servers.serverProblems({ ...base, lastStats: { disks: [] } }, ram, [], NOW).map(p => p.type)).toEqual(['ram_high']);
});
});
describe('reusing a short name (found in the VM test)', () => {
test('after a failed install the same short name can be used again', async () => {
const { server } = await joinServer();
await servers.setServerConfig(server.id, { TRUST_PROXY: 'loopback' });
const first = await jobs.newInstall({ customerId: 'cust-1', serverId: server.id, shortName: 'hope', domain: 'events.hope.co.za' }, admin, NOW);
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);
const again = await jobs.newInstall({ customerId: 'cust-1', serverId: server.id, shortName: 'hope', domain: 'events.hope.co.za' }, admin, NOW);
expect(again.deployment.id).not.toBe(first.deployment.id);
expect(await db.deployment.findUnique({ where: { id: first.deployment.id } })).toBeNull();
expect(again.deployment).toMatchObject({ webPort: 20000, apiPort: 20001 });
});
test('a live install keeps its name', async () => {
const { server } = await joinServer();
await servers.setServerConfig(server.id, { TRUST_PROXY: 'loopback' });
await jobs.newInstall({ customerId: 'cust-1', serverId: server.id, shortName: 'hope', domain: 'events.hope.co.za' }, admin, NOW);
await expect(jobs.newInstall({ customerId: 'cust-1', serverId: server.id, shortName: 'hope', domain: 'events.other.co.za' }, admin, NOW)).rejects.toMatchObject({ code: 'SHORT_NAME_TAKEN' });
});
});