diff --git a/packages/host/src/pairing.ts b/packages/host/src/pairing.ts index ab1ceda5..a1374347 100644 --- a/packages/host/src/pairing.ts +++ b/packages/host/src/pairing.ts @@ -297,9 +297,12 @@ export async function ensurePaired( }, }); + // The host has not started yet, so the new token needs no restart. + const restartRequired = config.restartRequired; config.set("host.id", result.hostId); config.set("host.name", result.name); config.set("host.controller_token", result.token); + config.restartRequired = restartRequired; await config.save(); logger.info(`Host approved as "${result.name}" with id ${result.hostId}`); } diff --git a/test/host/pairing.js b/test/host/pairing.js index bb5e98c6..da52ab74 100644 --- a/test/host/pairing.js +++ b/test/host/pairing.js @@ -252,6 +252,7 @@ describe("host/src/pairing", function() { config = new lib.HostConfig("host", undefined, path.join(directory, "config-host.json")); config.set("host.name", "My Host"); config.set("host.controller_url", stub.url); + config.restartRequired = false; }); afterEach(async function() { await fs.rm(directory, { recursive: true, force: true, maxRetries: 10 }); @@ -279,6 +280,9 @@ describe("host/src/pairing", function() { assert.equal(saved["host.id"], 1234); assert.equal(saved["host.name"], "Approved"); assert.equal(saved["host.controller_token"], "host-token"); + assert.equal(config.restartRequired, false, "pairing flagged a restart"); + config.set("host.controller_token", "other-token"); + assert.equal(config.restartRequired, true, "later change did not flag a restart"); }); it("does nothing when the controller accepts the saved token", async function() { @@ -294,6 +298,7 @@ describe("host/src/pairing", function() { it("asks to join again with the user token when the saved token is not accepted", async function() { config.set("host.controller_token", "revoked-token"); + config.restartRequired = false; stub.handler = ({ url, headers }) => { if (url === "/api/host-pairing/check") { return [401, undefined]; @@ -307,6 +312,7 @@ describe("host/src/pairing", function() { assert.equal(saved["host.id"], 5); assert.equal(saved["host.controller_token"], "new-token"); assert(!JSON.stringify(saved).includes("user-token"), "user token must not be saved"); + assert.equal(config.restartRequired, false, "pairing flagged a restart"); }); it("stops when aborted while checking the saved token", async function() {