Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

Allow replacing an unreachable VPS SSH alias

koeria657ded6ea46a
diff --git a/server/index.test.ts b/server/index.test.ts
index eb21134836..ed1c28b08a 100644
--- a/server/index.test.ts
+++ b/server/index.test.ts
@@ -11154,6 +11154,30 @@ describe("harness HTTP API", () => {
}
});
+ it.skipIf(process.platform === "win32")("replaces an unreachable VPS SSH alias without requiring the old host", async () => {
+ try {
+ expect((await api("PUT", "/api/config", { vps: { sshAlias: "" } })).status).toBe(200);
+ writeFileSync(fakeSshUnavailable, "");
+ rmSync(fakeSshLog, { force: true });
+
+ const saved = await api("PUT", "/api/config", { vps: { sshAlias: "rockpi4" } });
+ expect(saved.status, JSON.stringify(saved.body)).toBe(200);
+ expect((await api("GET", "/api/config")).body.vps.sshAlias).toBe("rockpi4");
+
+ const replaced = await api("PUT", "/api/config", { vps: { sshAlias: "dietpi" } });
+ expect(replaced.status, JSON.stringify(replaced.body)).toBe(200);
+ expect((await api("GET", "/api/config")).body.vps.sshAlias).toBe("dietpi");
+
+ const cleared = await api("PUT", "/api/config", { vps: { sshAlias: "" } });
+ expect(cleared.status).toBe(503);
+ expect(cleared.body.error).toContain("Keep the current SSH config alias");
+ expect((await api("GET", "/api/config")).body.vps.sshAlias).toBe("dietpi");
+ } finally {
+ rmSync(fakeSshUnavailable, { force: true });
+ expect((await api("PUT", "/api/config", { vps: { sshAlias: "" } })).status).toBe(200);
+ }
+ });
+
it("keeps an active turn alive when only the room timeout changes", async () => {
const created = await api("POST", "/api/bots", {});
const botId = created.body.bot.id;
diff --git a/server/routes/config.ts b/server/routes/config.ts
index 625a26f77f..ac481305ed 100644
--- a/server/routes/config.ts
+++ b/server/routes/config.ts
@@ -283,12 +283,18 @@ export function createConfigRoutes(deps: ConfigRouteDeps): RouteHandler {
managedBoatOwners(),
);
if (!inventory.available) {
- return json(res, 503, {
- error: `${inventory.problem ?? "VPS computer inventory is unavailable"}. Keep the current SSH config alias and retry`,
- });
+ // A host that cannot answer cannot keep the installation on the old alias.
+ // Replacing it is allowed, same as a first save; leftover containers stay on the unreachable host.
+ // Clearing still needs a live inventory so labeled containers are not abandoned silently.
+ if (!nextVpsAlias) {
+ return json(res, 503, {
+ error: `${inventory.problem ?? "VPS computer inventory is unavailable"}. Keep the current SSH config alias and retry`,
+ });
+ }
+ } else {
+ const resourceError = vpsAliasResourceChangeError(inventory.instances.length);
+ if (resourceError) return json(res, 409, { error: resourceError });
}
- const resourceError = vpsAliasResourceChangeError(inventory.instances.length);
- if (resourceError) return json(res, 409, { error: resourceError });
}
let boatRecovery = changingBoatToken ? boatCreateRecoverySnapshot() : [];