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 80 lines 2.84 KB
Raw
1 import { afterEach, describe, expect, layer, vi } from '@effect/vitest';
2 import { ConfigProvider, Effect } from 'effect';
3 import { logToolDebug, makePerfDebugLogger } from 'src/services/runtime-debug-logger';
4 import {
5 cliDebugFlagsLayer,
6 NO_CLI_DEBUG_FLAG_OVERRIDES,
7 type CliDebugFlagOverrides,
8 } from 'src/services/runtime-flags';
9 import { MockConsole, TestLive } from 'test/__utils__';
10
11 const configuredDebugFlags = ConfigProvider.fromEnvRecord({
12 COMPOSIO_PERF_DEBUG: '1',
13 COMPOSIO_TOOL_DEBUG: '1',
14 });
15
16 const withDebugFlags = (overrides: Partial<CliDebugFlagOverrides>) =>
17 Effect.provide(cliDebugFlagsLayer({ ...NO_CLI_DEBUG_FLAG_OVERRIDES, ...overrides }));
18
19 describe('runtime debug logger', () => {
20 afterEach(() => {
21 vi.restoreAllMocks();
22 });
23
24 layer(TestLive())(it => {
25 it.effect('writes tool diagnostics as the existing JSON line format', () =>
26 Effect.gen(function* () {
27 yield* logToolDebug('resolved', { slug: 'GITHUB_GET_REPO' });
28
29 expect(yield* MockConsole.getLines()).toContain(
30 '[tool-debug] {"label":"resolved","slug":"GITHUB_GET_REPO"}'
31 );
32 }).pipe(withDebugFlags({ toolDebug: true }))
33 );
34
35 it.effect('writes performance diagnostics with elapsed time', () =>
36 Effect.gen(function* () {
37 vi.spyOn(Date, 'now').mockReturnValue(125);
38 const logPerfDebug = makePerfDebugLogger(100);
39
40 yield* logPerfDebug('started', { slug: 'GITHUB_GET_REPO' });
41
42 expect(yield* MockConsole.getLines()).toContain(
43 '[perf] {"phase":"event","label":"started","elapsedMs":25,"slug":"GITHUB_GET_REPO"}'
44 );
45 }).pipe(withDebugFlags({ perfDebug: true }))
46 );
47
48 it.effect('writes diagnostics enabled through app config', () =>
49 Effect.gen(function* () {
50 vi.spyOn(Date, 'now').mockReturnValue(125);
51
52 yield* logToolDebug('configured-tool');
53 yield* makePerfDebugLogger(100)('configured-perf');
54
55 const lines = yield* MockConsole.getLines();
56 expect(lines).toContain('[tool-debug] {"label":"configured-tool"}');
57 expect(lines).toContain(
58 '[perf] {"phase":"event","label":"configured-perf","elapsedMs":25}'
59 );
60 }).pipe(
61 withDebugFlags({}),
62 Effect.provideService(ConfigProvider.ConfigProvider, configuredDebugFlags)
63 )
64 );
65
66 it.effect('lets explicit false flags override enabled app config', () =>
67 Effect.gen(function* () {
68 const existingLineCount = (yield* MockConsole.getLines()).length;
69
70 yield* logToolDebug('configured-tool');
71 yield* makePerfDebugLogger(100)('configured-perf');
72
73 expect((yield* MockConsole.getLines()).slice(existingLineCount)).toEqual([]);
74 }).pipe(
75 withDebugFlags({ perfDebug: false, toolDebug: false }),
76 Effect.provideService(ConfigProvider.ConfigProvider, configuredDebugFlags)
77 )
78 );
79 });
80 });