Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions packages/buzz/openorange-buzz/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
11 changes: 11 additions & 0 deletions tests/test_buzz_plugin.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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);
});