diff --git a/server/src/__tests__/plugin-routes-authz.test.ts b/server/src/__tests__/plugin-routes-authz.test.ts index 49b08a9efea..5bdcb9f4680 100644 --- a/server/src/__tests__/plugin-routes-authz.test.ts +++ b/server/src/__tests__/plugin-routes-authz.test.ts @@ -1,6 +1,7 @@ import express from "express"; import request from "supertest"; import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; +import { PluginWorkerUnavailableError } from "../services/plugin-worker-unavailable-error.js"; const mockRegistry = vi.hoisted(() => ({ getById: vi.fn(), @@ -1014,6 +1015,26 @@ describe("plugin tool and bridge authz", () => { }); }); + it("reports WORKER_UNAVAILABLE when no worker is registered for the plugin", async () => { + readyPlugin(); + const message = `No worker registered for plugin "${pluginId}"`; + const call = vi.fn().mockRejectedValue( + new PluginWorkerUnavailableError({ pluginId, workerStatus: null, message }), + ); + const { app } = await createApp(boardActor(), {}, { + bridgeDeps: { + workerManager: { call }, + }, + }); + + const res = await request(app) + .post(`/api/plugins/${pluginId}/data/source-objects`) + .send({ companyId: companyA }); + + expect(res.status).toBe(502); + expect(res.body).toMatchObject({ code: "WORKER_UNAVAILABLE", message }); + }); + it("rejects manual job triggers for non-admin board users", async () => { const scheduler = { triggerJob: vi.fn() }; const jobStore = { getJobByIdForPlugin: vi.fn() }; diff --git a/server/src/routes/plugins.ts b/server/src/routes/plugins.ts index 0479f3466c6..488f4eb1560 100644 --- a/server/src/routes/plugins.ts +++ b/server/src/routes/plugins.ts @@ -67,6 +67,7 @@ import type { PluginToolDispatcher } from "../services/plugin-tool-dispatcher.js import { ToolGatewayHttpError, type ToolGatewayService } from "../services/tool-gateway.js"; import type { PluginPerformActionActorContext, ToolRunContext } from "@paperclipai/plugin-sdk"; import { JsonRpcCallError, PLUGIN_RPC_ERROR_CODES } from "@paperclipai/plugin-sdk"; +import { findPluginWorkerUnavailableError } from "../services/plugin-worker-unavailable-error.js"; import { assertAuthenticated, assertBoard, @@ -1374,7 +1375,11 @@ export function pluginRoutes( const message = err instanceof Error ? err.message : String(err); // Worker not running — surface as WORKER_UNAVAILABLE - if (message.includes("not running") || message.includes("not registered")) { + if ( + findPluginWorkerUnavailableError(err) || + message.includes("not running") || + message.includes("not registered") + ) { return { code: "WORKER_UNAVAILABLE", message,