Skip to content

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

Revert "test(cli): cover custom toolkit cache retry"

shams haroon88a106aacc87
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.ts
index 034332d78..3b0dc80bd 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 cacheRefreshSucceeded = false;
+ let cacheRefreshAttempted = false;
if (resolvedProject.projectType === 'CONSUMER') {
const cachedToolkits = yield* getFreshConsumerConnectedToolkitsFromCache({
orgId: resolvedProject.orgId,
@@ -392,15 +392,11 @@ 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))
);
}
@@ -446,7 +442,7 @@ const runToolsSearch = (params: {
toolRouterSessionId: sessionId,
}
: undefined,
- cacheRefreshSucceeded,
+ cacheRefreshAttempted,
};
});
@@ -464,7 +460,7 @@ const runToolsSearch = (params: {
const customToolkitFilters = (toolkitList ?? []).filter(isRemoteCustomToolSlug);
const shouldRetryAfterCustomToolkitMiss =
customToolkitFilters.length > 0 &&
- !firstSearchResult.cacheRefreshSucceeded &&
+ !firstSearchResult.cacheRefreshAttempted &&
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.ts
index c276b922f..90ef84342 100644
--- a/ts/packages/cli/src/services/tool-input-validation.ts
+++ b/ts/packages/cli/src/services/tool-input-validation.ts
@@ -40,28 +40,6 @@ 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(
@@ -176,12 +154,19 @@ export const cacheToolInputDefinition = (params: {
const schemaPath = toolDefinitionPath(path, cacheDir, params.slug);
yield* ensureToolDefinitionsDir(fs, path, cacheDir);
- return yield* writeCachedToolInputDefinition({
- fs,
+ yield* fs.writeFileString(
+ schemaPath,
+ serializeCachedToolDefinition({
+ version: params.version ?? null,
+ inputSchema: params.schema,
+ })
+ );
+
+ return {
schemaPath,
schema: params.schema,
version: params.version ?? null,
- });
+ };
});
export const invalidateToolInputDefinition = (slug: string) =>
@@ -240,12 +225,18 @@ const fetchAndCacheToolInputDefinition = (
yield* ensureToolDefinitionsDir(fs, path, cacheDir);
if (localDefinition) {
- return yield* writeCachedToolInputDefinition({
- fs,
+ yield* fs.writeFileString(
+ schemaPath,
+ serializeCachedToolDefinition({
+ version: localDefinition.version,
+ inputSchema: localDefinition.schema,
+ })
+ );
+ return {
schemaPath,
schema: localDefinition.schema,
version: localDefinition.version,
- });
+ };
}
const [tool, latestVersion] = yield* Effect.all(
@@ -273,7 +264,15 @@ const fetchAndCacheToolInputDefinition = (
resolvedVersion: version,
cachePath: schemaPath,
});
- return yield* writeCachedToolInputDefinition({ fs, schemaPath, schema, version });
+ yield* fs.writeFileString(
+ schemaPath,
+ serializeCachedToolDefinition({
+ version,
+ inputSchema: schema,
+ })
+ );
+
+ return { 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.ts
index be3601f01..5a776ee8c 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,13 +1,10 @@
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';
@@ -101,10 +98,6 @@ 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* () {
@@ -206,81 +199,6 @@ 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 => {