Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
TypeScript agentic-aiagentsaiai-agentsaiagentsdeveloper-toolsfunction-callinggpt-4javascriptjsllmllmopsmcppythonremote-mcp-serverssetypescript
test(cli): cover custom toolkit cache retry
shams haroond4b96d9c83cb
diff --git a/ts/packages/cli/src/commands/tools/commands/tools.search.cmd.ts b/ts/packages/cli/src/commands/tools/commands/tools.search.cmd.tsindex 3b0dc80bd..034332d78 100644--- a/ts/packages/cli/src/commands/tools/commands/tools.search.cmd.ts+++ b/ts/packages/cli/src/commands/tools/commands/tools.search.cmd.ts@@ -376,7 +376,7 @@ const runToolsSearch = (params: {orgId: resolvedProject.orgId,projectId: resolvedProject.projectId,});- let cacheRefreshAttempted = false;+ let cacheRefreshSucceeded = false;if (resolvedProject.projectType === 'CONSUMER') {const cachedToolkits = yield* getFreshConsumerConnectedToolkitsFromCache({orgId: resolvedProject.orgId,@@ -392,11 +392,15 @@ const runToolsSearch = (params: {forceRefresh || Option.isNone(cachedToolkits) || requestedCustomToolkitMissing;if (shouldRefresh) {- cacheRefreshAttempted = true;yield* refreshConsumerConnectedToolkitsCache({orgId: resolvedProject.orgId,consumerUserId: resolvedUserId.value,}).pipe(+ Effect.tap(() =>+ Effect.sync(() => {+ cacheRefreshSucceeded = true;+ })+ ),Effect.catchAll(() => invalidateConsumerConnectedToolkitsCache().pipe(Effect.ignore)));}@@ -442,7 +446,7 @@ const runToolsSearch = (params: {toolRouterSessionId: sessionId,}: undefined,- cacheRefreshAttempted,+ cacheRefreshSucceeded,};});@@ -460,7 +464,7 @@ const runToolsSearch = (params: {const customToolkitFilters = (toolkitList ?? []).filter(isRemoteCustomToolSlug);const shouldRetryAfterCustomToolkitMiss =customToolkitFilters.length > 0 &&- !firstSearchResult.cacheRefreshAttempted &&+ !firstSearchResult.cacheRefreshSucceeded &&customToolkitFilters.some(toolkit => !searchResponseIncludesToolkit(firstSearchResult.searchResponse, toolkit));diff --git a/ts/packages/cli/src/services/tool-input-validation.ts b/ts/packages/cli/src/services/tool-input-validation.tsindex 90ef84342..c276b922f 100644--- a/ts/packages/cli/src/services/tool-input-validation.ts+++ b/ts/packages/cli/src/services/tool-input-validation.ts@@ -40,6 +40,28 @@ const toolDefinitionPath = (path: Path.Path, cacheDir: string, slug: string) =>const ensureToolDefinitionsDir = (fs: FileSystem.FileSystem, path: Path.Path, cacheDir: string) =>fs.makeDirectory(path.join(cacheDir, TOOL_DEFINITIONS_DIR), { recursive: true });+const writeCachedToolInputDefinition = (params: {+ readonly fs: FileSystem.FileSystem;+ readonly schemaPath: string;+ readonly schema: Record<string, unknown>;+ readonly version: string | null;+}) =>+ Effect.gen(function* () {+ yield* params.fs.writeFileString(+ params.schemaPath,+ serializeCachedToolDefinition({+ version: params.version,+ inputSchema: params.schema,+ })+ );++ return {+ schemaPath: params.schemaPath,+ schema: params.schema,+ version: params.version,+ };+ });+const parseSchemaFile = (raw: string, schemaPath: string) =>decodeJsonObject(raw).pipe(Effect.mapError(@@ -154,19 +176,12 @@ export const cacheToolInputDefinition = (params: {const schemaPath = toolDefinitionPath(path, cacheDir, params.slug);yield* ensureToolDefinitionsDir(fs, path, cacheDir);- yield* fs.writeFileString(- schemaPath,- serializeCachedToolDefinition({- version: params.version ?? null,- inputSchema: params.schema,- })- );-- return {+ return yield* writeCachedToolInputDefinition({+ fs,schemaPath,schema: params.schema,version: params.version ?? null,- };+ });});export const invalidateToolInputDefinition = (slug: string) =>@@ -225,18 +240,12 @@ const fetchAndCacheToolInputDefinition = (yield* ensureToolDefinitionsDir(fs, path, cacheDir);if (localDefinition) {- yield* fs.writeFileString(- schemaPath,- serializeCachedToolDefinition({- version: localDefinition.version,- inputSchema: localDefinition.schema,- })- );- return {+ return yield* writeCachedToolInputDefinition({+ fs,schemaPath,schema: localDefinition.schema,version: localDefinition.version,- };+ });}const [tool, latestVersion] = yield* Effect.all(@@ -264,15 +273,7 @@ const fetchAndCacheToolInputDefinition = (resolvedVersion: version,cachePath: schemaPath,});- yield* fs.writeFileString(- schemaPath,- serializeCachedToolDefinition({- version,- inputSchema: schema,- })- );-- return { schemaPath, schema, version };+ return yield* writeCachedToolInputDefinition({ fs, schemaPath, schema, version });});export const getOrFetchToolInputDefinition = (diff --git a/ts/packages/cli/test/src/commands/tools/tools.search.cmd.test.ts b/ts/packages/cli/test/src/commands/tools/tools.search.cmd.test.tsindex 5a776ee8c..be3601f01 100644--- a/ts/packages/cli/test/src/commands/tools/tools.search.cmd.test.ts+++ b/ts/packages/cli/test/src/commands/tools/tools.search.cmd.test.ts@@ -1,10 +1,13 @@import { describe, expect, layer } from '@effect/vitest';-import { ConfigProvider, Effect } from 'effect';import type {SessionCreateParams,SessionSearchParams,+ SessionSearchResponse,} from '@composio/client/resources/tool-router';+import { ConfigProvider, Effect, Option } from 'effect';+import { afterEach, vi } from 'vitest';import { extendConfigProvider } from 'src/services/config';+import * as consumerShortTermCache from 'src/services/consumer-short-term-cache';import { cli, TestLive, MockConsole } from 'test/__utils__';import type { TestLiveInput } from 'test/__utils__/services/test-layer';import type { Tools } from 'src/models/tools';@@ -98,6 +101,10 @@ const extractFirstJsonObject = (output: string): Record<string, unknown> | null};describe('CLI: composio search', () => {+ afterEach(() => {+ vi.restoreAllMocks();+ });+layer(TestLive(testLiveOptions))('[Given] a blank query [Then] typed validation fails', it => {it.scoped('returns the structured missing-query error', () =>Effect.gen(function* () {@@ -199,6 +206,81 @@ describe('CLI: composio search', () => {});+ layer(TestLive(testLiveOptions))(+ '[Given] a fresh cache and a custom toolkit miss [Then] search refreshes and retries once',+ it => {+ it.scoped('refreshes only after the requested custom toolkit is absent', () =>+ Effect.gen(function* () {+ const customSlug = 'CUSTOM_DEEPWIKI_READ_WIKI_CONTENTS';+ let searchCalls = 0;+ const refreshSpy = vi+ .spyOn(consumerShortTermCache, 'refreshConsumerConnectedToolkitsCache')+ .mockReturnValue(Effect.void);+ vi.spyOn(consumerShortTermCache, 'getFreshConsumerConnectedToolkitsFromCache').mockReturnValue(+ Effect.succeed(Option.some(['CUSTOM_DEEPWIKI']))+ );++ const live = TestLive({+ ...testLiveOptions,+ toolRouter: {+ search: async (_sessionId, params) => {+ searchCalls += 1;+ const found = searchCalls === 2;+ const toolSchemas: SessionSearchResponse['tool_schemas'] = found+ ? {+ [customSlug]: {+ tool_slug: customSlug,+ toolkit: 'CUSTOM_DEEPWIKI',+ description: 'Read wiki contents',+ hasFullSchema: true,+ input_schema: { type: 'object', properties: {} },+ output_schema: { type: 'object', properties: {} },+ },+ }+ : {};+ return {+ success: true,+ error: null,+ results: [+ {+ index: 1,+ use_case: params.queries[0]?.use_case ?? '',+ primary_tool_slugs: found ? [customSlug] : [],+ related_tool_slugs: [],+ toolkits: found ? ['CUSTOM_DEEPWIKI'] : [],+ },+ ],+ tool_schemas: toolSchemas,+ toolkit_connection_statuses: [],+ next_steps_guidance: [],+ session: {+ id: 'trs_test_session',+ generate_id: false,+ instructions: 'Reuse this session id for follow-up calls.',+ },+ time_info: {+ current_time_utc: '2026-01-01T00:00:00.000Z',+ current_time_utc_epoch_seconds: 1767225600,+ message: 'UTC time',+ },+ };+ },+ },+ });++ yield* cli(['search', 'read wiki contents', '--toolkits', 'CUSTOM_DEEPWIKI']).pipe(+ Effect.provide(live)+ );++ expect(searchCalls).toBe(2);+ expect(refreshSpy).toHaveBeenCalledOnce();+ const output = (yield* MockConsole.getLines({ stripAnsi: true })).join('\n');+ expect(output).toContain(customSlug);+ })+ );+ }+ );+layer(TestLive(testLiveOptions))('[Given] multiple queries [Then] the CLI returns a batched JSON response',it => {