@devries-cameron20 / composio Mirror · read-only
Fork 0

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

Mirrored from https://github.com/Camo67/composio.git

Synced Nov 21, 04:45 UTC

next
ts 69 lines 3.05 KB
Raw
1 import { describe, expect, layer } from '@effect/vitest';
2 import { vi } from 'vitest';
3 import { Cause, Effect } from 'effect';
4 import { commandTelemetryContext } from 'test/__utils__/telemetry-context';
5 import { BackendMismatchWarning } from 'src/services/backend-mismatch-warning';
6 import { CommandLifecycleTelemetry } from 'src/services/command-lifecycle-telemetry';
7 import { PluginHint } from 'src/services/plugin-hint';
8 import { BackgroundUpdateCheck, UpdateNotice } from 'src/services/update-check';
9 import {
10 MockConsole,
11 recordedInvocationCalls,
12 resetInvocationCalls,
13 TestLive,
14 } from 'test/__utils__';
15 import { commandIdentity } from 'test/__utils__/command-identity';
16 import { trackedEvents } from 'test/__utils__/tracked-events';
17
18 // Records instead of dispatching, so a double that reached the real sink would show up below.
19 vi.mock('src/analytics/dispatch', async importOriginal => {
20 const { recordTrackedEvent } = await import('test/__utils__/tracked-events');
21 return {
22 ...(await importOriginal<typeof import('src/analytics/dispatch')>()),
23 trackCliEventEffect: recordTrackedEvent,
24 };
25 });
26
27 describe('TestLive invocation hooks and telemetry sink', () => {
28 layer(TestLive())(it => {
29 it.effect('[Given] every hook and lifecycle event [Then] records each call, in order', () =>
30 Effect.gen(function* () {
31 const invocation = { identity: commandIdentity(['whoami']) };
32 const context = commandTelemetryContext(['whoami'], { path: ['whoami'], input: {} });
33 const cause = Cause.fail(new TypeError('boom'));
34 const shown = {
35 invocationOrigin: 'cli',
36 commandPath: 'whoami',
37 agentHost: 'claude',
38 } as const;
39
40 yield* (yield* BackendMismatchWarning).run(invocation);
41 yield* (yield* UpdateNotice).run(invocation);
42 yield* (yield* PluginHint).run(invocation);
43 yield* (yield* BackgroundUpdateCheck).run(invocation);
44 const telemetry = yield* CommandLifecycleTelemetry;
45 yield* telemetry.invoked(context);
46 yield* telemetry.succeeded(context);
47 yield* telemetry.failed(context, cause);
48 yield* telemetry.pluginHintShown(shown);
49
50 expect(yield* recordedInvocationCalls).toEqual([
51 { service: 'BackendMismatchWarning', invocation },
52 { service: 'UpdateNotice', invocation },
53 { service: 'PluginHint', invocation },
54 { service: 'BackgroundUpdateCheck', invocation },
55 { service: 'CommandLifecycleTelemetry', event: 'invoked', context },
56 { service: 'CommandLifecycleTelemetry', event: 'succeeded', context },
57 { service: 'CommandLifecycleTelemetry', event: 'failed', context, cause },
58 { service: 'CommandLifecycleTelemetry', event: 'pluginHintShown', shown },
59 ]);
60 // The doubles are no-ops: nothing reaches the console or the analytics dispatcher.
61 expect(yield* MockConsole.getLines()).toEqual([]);
62 expect(trackedEvents).toEqual([]);
63
64 yield* resetInvocationCalls;
65 expect(yield* recordedInvocationCalls).toEqual([]);
66 })
67 );
68 });
69 });