Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

next
ts 62 lines 2.54 KB
Raw
1 import { describe, expect, it } from '@effect/vitest';
2 import { Option } from 'effect';
3 import { resolvePusherConstructor } from 'src/services/triggers-realtime';
4
5 /**
6 * Regression tests for issue #3918: `composio listen` crashed with
7 * `TypeError: Object is not a constructor` in compiled release binaries
8 * because pusher-js 8.5.0 exports a namespace object
9 * (`module.exports = { Pusher }`), so the dynamic import's `.default` is not
10 * the constructor.
11 */
12 describe('resolvePusherConstructor', () => {
13 class FakePusher {}
14
15 it('resolves the constructor from `module.default` (Node interop, running from source)', () => {
16 expect(resolvePusherConstructor({ default: FakePusher })).toEqual(Option.some(FakePusher));
17 });
18
19 it('resolves the constructor from `module.default.default` (defensive double-wrapped interop)', () => {
20 expect(resolvePusherConstructor({ default: { default: FakePusher } })).toEqual(
21 Option.some(FakePusher)
22 );
23 });
24
25 it('prefers the nested constructor when both interop levels are callable', () => {
26 const outer = Object.assign(function outer() {}, { default: FakePusher });
27 expect(resolvePusherConstructor({ default: outer })).toEqual(Option.some(FakePusher));
28 });
29
30 it('falls back to the module object itself when it is the constructor', () => {
31 expect(resolvePusherConstructor(FakePusher)).toEqual(Option.some(FakePusher));
32 });
33
34 it('resolves a named `Pusher` export on the default namespace (pusher-js 8.5.0 shape, issue #3918)', () => {
35 expect(
36 resolvePusherConstructor({ default: { Pusher: FakePusher }, Pusher: FakePusher })
37 ).toEqual(Option.some(FakePusher));
38 });
39
40 it('resolves a named `Pusher` export on the module itself', () => {
41 expect(resolvePusherConstructor({ Pusher: FakePusher })).toEqual(Option.some(FakePusher));
42 });
43
44 it('resolves a `default.Pusher` namespace export without a top-level `Pusher` fallback', () => {
45 expect(resolvePusherConstructor({ default: { Pusher: FakePusher } })).toEqual(
46 Option.some(FakePusher)
47 );
48 });
49
50 it('resolves the constructor from the real installed pusher-js module', async () => {
51 const pusherModule = await import('pusher-js');
52 const resolved = resolvePusherConstructor(pusherModule);
53 expect(Option.isSome(resolved)).toBe(true);
54 });
55
56 it('returns none when no interop shape exposes a callable constructor', () => {
57 expect(resolvePusherConstructor({ default: { default: 'not-a-function' } })).toEqual(
58 Option.none()
59 );
60 expect(resolvePusherConstructor(undefined)).toEqual(Option.none());
61 });
62 });