Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(plugins): report a sandboxed plugin without a live worker unhealthy
Yudhi Armyndharis387dd949dbf5
diff --git a/src/core/plugins/plugin-loader-sandbox-routing.spec.ts b/src/core/plugins/plugin-loader-sandbox-routing.spec.tsindex 4a84f07e0..c2a92f1b8 100644--- a/src/core/plugins/plugin-loader-sandbox-routing.spec.ts+++ b/src/core/plugins/plugin-loader-sandbox-routing.spec.ts@@ -208,6 +208,27 @@ describe('PluginLoaderService — sandbox tier routing', () => {);});+ it('reports a sandboxed plugin with no live worker as unhealthy (crashed or disabled)', async () => {+ const loader = makeLoader();+ seed(loader, { builtIn: false, instance: null });+ await loader.enablePlugin('p1');+ jest+ .spyOn((loader as unknown as { logger: { warn: jest.Mock } }).logger, 'warn')+ .mockImplementation(() => undefined);++ loader.capturedOnWorkerExit!(1, false);+ const crashed = await loader.checkPluginHealth('p1');+ expect(crashed.healthy).toBe(false);+ expect(crashed.message).toContain('worker exited unexpectedly');++ pluginOf(loader).status = PluginStatus.DISABLED;+ pluginOf(loader).error = undefined;+ expect(await loader.checkPluginHealth('p1')).toEqual({+ healthy: false,+ message: 'plugin is not running (status disabled)',+ });+ });+it('enables a built-in plugin in-process (no sandbox worker spawned)', async () => {const loader = makeLoader();const onEnable = jest.fn().mockResolvedValue(undefined);diff --git a/src/core/plugins/plugin-sandbox-bridge.ts b/src/core/plugins/plugin-sandbox-bridge.tsindex 8db356221..1f9dc7b3f 100644--- a/src/core/plugins/plugin-sandbox-bridge.ts+++ b/src/core/plugins/plugin-sandbox-bridge.ts@@ -143,7 +143,8 @@ export class PluginSandboxBridge {/*** Run a plugin's healthCheck across both tiers. A sandboxed plugin's healthCheck lives in the worker* (plugin.instance is null), so route to the live worker host (time-bounded); built-ins use the- * in-process instance. Returns the default "healthy" when the plugin implements no health check.+ * in-process instance. A sandboxed plugin with no live worker (crashed, failed to enable, disabled) is+ * unhealthy. Returns the default "healthy" when a built-in implements no health check.*/async checkPluginHealth(pluginId: string): Promise<{ healthy: boolean; message?: string }> {const sandboxHost = this.sandboxHosts.get(pluginId);@@ -158,6 +159,13 @@ export class PluginSandboxBridge {return { healthy: result.healthy, message: result.message ? `${result.message}; ${note}` : note };}const plugin = this.plugins.get(pluginId);+ if (plugin && !plugin.builtIn) {+ const message =+ plugin.status === PluginStatus.ERROR && plugin.error+ ? plugin.error+ : `plugin is not running (status ${plugin.status})`;+ return { healthy: false, message };+ }if (plugin?.instance?.healthCheck) {return plugin.instance.healthCheck();}