diff --git a/packages/buzz/openorange-buzz/plugin.js b/packages/buzz/openorange-buzz/plugin.js index 725316f..3b5108b 100644 --- a/packages/buzz/openorange-buzz/plugin.js +++ b/packages/buzz/openorange-buzz/plugin.js @@ -253,11 +253,17 @@ function createBridge(spawn, target) { for (const waiting of pending.values()) waiting.reject(ended); pending.clear(); }); - await request("initialize", { - protocolVersion: 1, - clientCapabilities: {}, - clientInfo: { name: "buzz", title: "Buzz", version: "1" }, - }); + try { + await request("initialize", { + protocolVersion: 1, + clientCapabilities: {}, + clientInfo: { name: "buzz", title: "Buzz", version: "1" }, + }); + } catch (error) { + // An oo that can't start is of no use, and the next mention starts another: end this one. + void process.kill().catch(() => undefined); + throw error; + } return self; } diff --git a/tests/test_buzz_plugin.mjs b/tests/test_buzz_plugin.mjs index a520980..eda6193 100644 --- a/tests/test_buzz_plugin.mjs +++ b/tests/test_buzz_plugin.mjs @@ -122,6 +122,8 @@ function run(program, env) { type, replies, restored: () => restored, + /** How many of the processes the plugin started are still running. */ + running: () => children.filter(({ child }) => child.exitCode === null && child.signalCode === null).length, /** The plugin turned off: its cleanup runs, then Buzz ends the processes it started. */ stop: () => (stopped ??= (async () => { @@ -281,3 +283,12 @@ test("when oo is not signed in, the owner is told to run `oo login`", async (t) }, ]); }); + +test("an oo that fails as it starts is ended, so later mentions leave none running", async (t) => { + const refused = { method: "initialize", message: "Not signed in to a Sunport (401)" }; + const buzz = computer(t, { env: { ACP_STUB_REFUSE: JSON.stringify(refused) } }).start(); + await assert.rejects(buzz.type.run(mention("@Clem hello", "root-1").delivery)); + await assert.rejects(buzz.type.run(mention("@Clem again", "root-1").delivery)); + for (let waited = 0; buzz.running() && waited < 50; waited++) await new Promise((resolve) => setTimeout(resolve, 100)); + assert.equal(buzz.running(), 0); +});