diff --git a/electron/plugins/contributionService.cjs b/electron/plugins/contributionService.cjs index 9c8ab6046..686377e09 100644 --- a/electron/plugins/contributionService.cjs +++ b/electron/plugins/contributionService.cjs @@ -351,7 +351,7 @@ class PluginContributionService { command: commandId, ...(args === undefined ? {} : { args }), invocation: freezeJson({ source: invocation.source ?? "host", context: invocation.context ?? {} }), - }, contribution.interactive ? { timeoutMs: InteractiveCommandLimits.const.timeoutMs, expectedIdentity: identity } : undefined); + }, { expectedIdentity: identity, ...(contribution.interactive ? { timeoutMs: InteractiveCommandLimits.const.timeoutMs } : {}) }); failed = false; return result; } finally { diff --git a/electron/plugins/contributionService.test.cjs b/electron/plugins/contributionService.test.cjs index b38468e69..189bd733a 100644 --- a/electron/plugins/contributionService.test.cjs +++ b/electron/plugins/contributionService.test.cjs @@ -117,7 +117,8 @@ test("only explicitly declared interactive commands receive the fixed budget and }); await service.executeCommand(`${pluginManifest.id}.hello`); await service.executeCommand(`${pluginManifest.id}.interactive`); - assert.equal(optionsSeen[0], undefined, "ordinary commands retain the existing router deadline"); + assert.equal(Object.hasOwn(optionsSeen[0], "timeoutMs"), false, "ordinary commands retain the existing router deadline"); + assert.equal(optionsSeen[0].expectedIdentity.runtimeId, runtimeId); assert.equal(optionsSeen[1].timeoutMs, 180_000); assert.equal(optionsSeen[1].expectedIdentity.runtimeId, runtimeId); assert.deepEqual(finished, [runtimeId, runtimeId]); diff --git a/electron/plugins/runtimeSupervisor.test.cjs b/electron/plugins/runtimeSupervisor.test.cjs index 05bdbb2e9..a605b3f9b 100644 --- a/electron/plugins/runtimeSupervisor.test.cjs +++ b/electron/plugins/runtimeSupervisor.test.cjs @@ -12,6 +12,7 @@ const { createPluginPaths } = require("./paths.cjs"); const { RPC_ERRORS } = require("./rpcRouter.cjs"); const { RuntimeSupervisor } = require("./runtimeSupervisor.cjs"); const { createContainmentError } = require("./utilityPluginRuntime.cjs"); +const { PluginContributionService } = require("./contributionService.cjs"); function pluginManifest(overrides = {}) { return { @@ -66,6 +67,31 @@ function createFixture(context, runtimeFactory, supervisorOptions = {}) { return { database, manifest, runtimeOptions, supervisor }; } +test("ordinary command activation A cannot dispatch on replacement runtime B", async (t) => { + let executed = 0, activation; + const fixture = createFixture(t, () => ({ async start(config) { return { pluginId: config.pluginId, pluginVersion: config.pluginVersion, + apiVersion: config.apiVersion, enabledFeatures: config.enabledFeatures }; }, async stop() {}, async request() { executed++; return null; } })); + t.after(() => fixture.supervisor.shutdown()); + const manifest = { ...fixture.manifest, contributes: { commands: [{ id: `${fixture.manifest.id}.ordinary`, title: "Ordinary" }] } }; + const finished = []; + const service = new PluginContributionService({ + database: { listPlugins: () => [{ id: manifest.id, manifest, activeVersion: manifest.version, enabled: true, runtime: {} }] }, + onCommandFinished: (runtimeId) => finished.push(runtimeId), + runtimeSupervisor: { + async start(pluginId) { + activation = await fixture.supervisor.start(pluginId); + await fixture.supervisor.restart(pluginId); + return activation; + }, + request: (...args) => fixture.supervisor.request(...args), + }, + }); + await assert.rejects(service.executeCommand(`${manifest.id}.ordinary`), /no longer matches the authorized activation/); + assert.notEqual(fixture.supervisor.getRuntimeIdentity(manifest.id).runtimeId, activation.runtimeId); + assert.equal(executed, 0, "replacement B receives no stale command"); + assert.deepEqual(finished, [activation.runtimeId]); +}); + test("supervisor prefers the ordinary browser runtime and enforces negotiated identity", async (context) => { const calls = []; const initialEnvironment = { locale: "en", theme: "light", reducedMotion: false, highContrast: false };