diff --git a/changelog/fixed/tap-dancing-interceptors.md b/changelog/fixed/tap-dancing-interceptors.md new file mode 100644 index 000000000..8bb0d3861 --- /dev/null +++ b/changelog/fixed/tap-dancing-interceptors.md @@ -0,0 +1 @@ +Preserve and append Activity and Nexus client interceptors when SimplePlugin merges client or worker client configuration. diff --git a/packages/plugin/package.json b/packages/plugin/package.json index c55e1c0cc..4f73c876a 100644 --- a/packages/plugin/package.json +++ b/packages/plugin/package.json @@ -13,12 +13,19 @@ "author": "Temporal Technologies Inc. ", "license": "MIT", "scripts": { - "build": "tsc --build" + "build": "tsc --build", + "test": "tsx ../../scripts/ava-ci.ts ./lib/__tests__/test-*.js" + }, + "ava": { + "timeout": "60s", + "concurrency": 1, + "workerThreads": false }, "devDependencies": { "@temporalio/client": "workspace:*", "@temporalio/common": "workspace:*", "@temporalio/worker": "workspace:*", + "ava": "^5.3.1", "nexus-rpc": "^0.0.3" }, "bugs": { @@ -38,6 +45,8 @@ }, "files": [ "src", - "lib" + "lib", + "!src/__tests__", + "!lib/__tests__" ] } diff --git a/packages/plugin/src/__tests__/test-client-interceptors.ts b/packages/plugin/src/__tests__/test-client-interceptors.ts new file mode 100644 index 000000000..c55a64b3e --- /dev/null +++ b/packages/plugin/src/__tests__/test-client-interceptors.ts @@ -0,0 +1,37 @@ +import test from 'ava'; +import type { ClientInterceptors } from '@temporalio/client'; +import { SimplePlugin } from '../plugin'; + +test('SimplePlugin appends Activity and Nexus client interceptors', (t) => { + const existingActivity = {}; + const existingNexus = {}; + const pluginActivity = {}; + const pluginNexus = {}; + const plugin = new SimplePlugin({ + name: 'interceptor-merge', + clientInterceptors: { activity: [pluginActivity], nexus: [pluginNexus] }, + }); + const actual = plugin.configureClient({ + interceptors: { activity: [existingActivity], nexus: [existingNexus] }, + }).interceptors; + + t.is(actual?.activity?.length, 2); + t.is(actual?.activity?.[0], existingActivity); + t.is(actual?.activity?.[1], pluginActivity); + t.is(actual?.nexus?.length, 2); + t.is(actual?.nexus?.[0], existingNexus); + t.is(actual?.nexus?.[1], pluginNexus); +}); + +test('SimplePlugin clientInterceptors overrides default behavior', (t) => { + const original: ClientInterceptors = { activity: [{}], nexus: [{}] }; + const replacement: ClientInterceptors = { activity: [{}], nexus: [{}] }; + const plugin = new SimplePlugin({ + name: 'custom-merge', + clientInterceptors: (current) => { + t.is(current, original); + return replacement; + }, + }); + t.is(plugin.configureClient({ interceptors: original }).interceptors, replacement); +}); diff --git a/packages/plugin/src/plugin.ts b/packages/plugin/src/plugin.ts index 929b0bc1c..9c7ac0b9f 100644 --- a/packages/plugin/src/plugin.ts +++ b/packages/plugin/src/plugin.ts @@ -269,6 +269,8 @@ function resolveClientInterceptors( modernWorkflowInterceptors(parameter?.workflow) ), schedule: tryConcat(existing?.schedule, parameter?.schedule), + activity: tryConcat(existing?.activity, parameter?.activity), + nexus: tryConcat(existing?.nexus, parameter?.nexus), })); } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 640f84dfb..a167882ec 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -697,6 +697,9 @@ importers: '@temporalio/worker': specifier: workspace:* version: link:../worker + ava: + specifier: ^5.3.1 + version: 5.3.1 nexus-rpc: specifier: ^0.0.3 version: 0.0.3