@devries-cameron20 / composio Mirror · read-only / commits / f366f346e
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, 09:45 UTC

fix(cli): validate tool input before sending the execute call (#4729)

This PR: - fixes `composio execute` running a tool while reporting a validation failure: client-side validation ran in a background fiber and was raced against the API call with `Effect.raceFirst`, and losing the race never cancelled the HTTP request - replaces the race with a gate: `validateToolInputBeforeExecute` fetches the cached or remote schema, validates, and only then calls `executor.execute`, as `--parallel` already does - removes `validationGuardFromFiber`, `spawnBackgroundValidationGuard`, `initializeValidationState`, and the now-unused `refreshToolInputDefinitionIfVersionChanged` - keeps the cached schema on disk after a validation failure, since the error message points the user at that path (it was deleted before) - keeps a schema that cannot be loaded from blocking the call; the server still validates - makes `--dry-run` validate against a refreshed schema when the cached one is stale - adds regression tests asserting the executor is never invoked on invalid input (cache miss and cache hit), via a new `onExecute` hook on the mock executor - fixes the "stale cached schema" test, which only passed because the mock executor won the race; it now mocks a newer latest version so the cache is actually refreshed ## Context On a schema cache hit, the tool call now waits for the latest-version check before it is sent. That lookup is memoized and shared with the executor's own schema lookup, so no request is added. Verified with `pnpm typecheck` and `pnpm --filter @composio/cli test` (1444 passed, 1 skipped). The two new tests fail on `next` without the fix.

Alberto Schiabel committed Oct 7, 2026 at 15:01 UTC f366f346ef10813fb68ee14ce53c546367b7e8cb
6 files changed +228 -216
ts/packages/cli/CHANGELOG.md
+7
@@ -4,6 +4,13 @@
4
5 ### Patch Changes
6
7 +- `composio execute` now validates the arguments before it sends the tool
8 + call, so a call that fails local validation is never run. Validation used to
9 + race the request, and the tool could execute while the CLI reported a
10 + validation failure. The cached schema named in the validation error is now
11 + kept on disk instead of being deleted. A schema the CLI cannot compile no
12 + longer blocks the call; the server still validates it.
13 +
14 - Generate help from the command definitions, including every supported flag and
15 nested command. Remove help levels and the nonexistent `files` help topic.
16 Install agent skills with `composio setup skill <claude|codex|openclaw>`
ts/packages/cli/src/commands/tools/commands/tools.execute.cmd.ts
+32 -175
@@ -1,16 +1,14 @@
1 import { Argument, Command, Flag } from 'effect/unstable/cli';
2 import util from 'node:util';
3 -import { Cause, Context, Data, Effect, Exit, Fiber, Option, Result } from 'effect';
3 +import { Data, Effect, Context, Option, Result } from 'effect';
4 import { redact } from 'src/ui/redact';
5 import { parseJsonRecord, isPlainRecord } from 'src/utils/parse-json';
6 import { toolkitFromToolSlug } from 'src/effects/toolkit-from-tool-slug';
7 import { requireAuth } from 'src/effects/require-auth';
8 import { resolveOptionalTextInput } from 'src/effects/resolve-optional-text-input';
9 import {
10 - getCachedToolInputDefinition,
10 getOrFetchToolInputDefinition,
11 invalidateToolInputDefinition,
13 - refreshToolInputDefinitionIfVersionChanged,
12 ToolInputValidationError,
13 validateToolInputArguments,
14 validateToolInputArgumentsWithDefinition,
@@ -723,144 +721,26 @@ const handleExecutionError = (
721 return { error: mapped.message, slug: slugValue };
722 });
723
726 -type CachedValidationDecision =
727 - { readonly status: 'valid' | 'stale' } | { readonly status: 'fail'; readonly error: unknown };
728 -
729 -type ValidationState = {
730 - readonly cacheHit: boolean;
731 - readonly validationGuard: Effect.Effect<never, unknown>;
732 - readonly awaitCachedValidationDecision: Effect.Effect<CachedValidationDecision, never> | null;
733 -};
734 -
735 -type CachedDefinition = {
736 - readonly schemaPath: string;
737 - readonly schema: Record<string, unknown>;
738 - readonly version: string | null;
739 -} | null;
740 -
741 -const validationGuardFromFiber = (validationFiber: Fiber.Fiber<unknown, unknown>) =>
742 - Fiber.await(validationFiber).pipe(
743 - Effect.flatMap(
744 - Exit.match({
745 - onFailure: cause => {
746 - const fail = Cause.findFail(cause);
747 - if (Result.isSuccess(fail) && fail.success.error instanceof ToolInputValidationError) {
748 - return Effect.failCause(cause);
749 - }
750 - return Effect.never;
751 - },
752 - onSuccess: () => Effect.never,
753 - })
754 - )
755 - );
756 -
757 -const spawnBackgroundValidationGuard = (params: {
758 - readonly slug: string;
759 - readonly args: Record<string, unknown>;
760 - readonly resolvedProject: {
761 - readonly orgId: string;
762 - readonly projectId: string;
763 - };
764 -}) =>
765 - Effect.gen(function* () {
766 - yield* perfDebugLog('execute.validation.background_spawn', { slug: params.slug });
767 - const validationFiber = yield* validateToolInputArguments(params.slug, params.args, {
768 - orgId: params.resolvedProject.orgId,
769 - projectId: params.resolvedProject.projectId,
770 - }).pipe(Effect.forkDetach);
771 - yield* perfDebugLog('execute.validation.background_spawned', { slug: params.slug });
772 - return validationGuardFromFiber(validationFiber);
773 - });
774 -
775 -const initializeValidationState = (params: {
724 +// Gates the tool call: the request is only sent once the arguments pass. A
725 +// schema that cannot be loaded does not block the call, the server validates too.
726 +const validateToolInputBeforeExecute = (params: {
727 readonly slug: string;
728 readonly args: Record<string, unknown>;
778 - readonly cachedDefinition: CachedDefinition;
729 readonly resolvedProject: {
730 readonly orgId: string;
731 readonly projectId: string;
732 };
733 }) =>
784 - Effect.gen(function* () {
785 - if (!params.cachedDefinition) {
786 - yield* perfDebugLog('execute.validation.cache_miss', { slug: params.slug });
787 - return {
788 - cacheHit: false,
789 - validationGuard: Effect.never,
790 - awaitCachedValidationDecision: null,
791 - } satisfies ValidationState;
792 - }
793 - const cachedDefinition = params.cachedDefinition;
794 -
795 - yield* perfDebugLog('execute.validation.cache_hit', {
796 - slug: params.slug,
797 - cachedVersion: cachedDefinition.version,
798 - });
799 - const versionCheckFiber = yield* refreshToolInputDefinitionIfVersionChanged(
800 - params.slug,
801 - cachedDefinition.version,
802 - {
803 - orgId: params.resolvedProject.orgId,
804 - projectId: params.resolvedProject.projectId,
805 - }
806 - ).pipe(
807 - Effect.tap(result =>
808 - perfDebugLog('execute.validation.version_check_done', {
809 - slug: params.slug,
810 - cachedVersion: cachedDefinition.version,
811 - latestVersion: result.latestVersion,
812 - isStale: result.isStale,
813 - })
814 - ),
815 - Effect.option,
816 - Effect.forkDetach
817 - );
818 - const cachedValidationDecisionFiber = yield* Effect.gen(function* () {
819 - yield* perfDebugLog('execute.validation.cached_start', { slug: params.slug });
820 - const validationDecision = yield* validateToolInputArgumentsWithDefinition(
821 - params.slug,
822 - params.args,
823 - cachedDefinition
824 - ).pipe(
825 - Effect.match({
826 - onFailure: error => ({ status: 'fail', error }) satisfies CachedValidationDecision,
827 - onSuccess: () => ({ status: 'valid' }) satisfies CachedValidationDecision,
828 - })
829 - );
830 - yield* perfDebugLog('execute.validation.cached_end', {
831 - slug: params.slug,
832 - successful: validationDecision.status === 'valid',
833 - });
834 - if (validationDecision.status === 'valid') {
835 - return validationDecision;
836 - }
837 -
838 - const freshnessResult = yield* Fiber.join(versionCheckFiber);
839 - const isStale = Option.isSome(freshnessResult) && freshnessResult.value.isStale;
840 - yield* perfDebugLog('execute.validation.cached_failed', {
841 - slug: params.slug,
842 - cacheStillCurrent: !isStale,
843 - });
844 - return isStale
845 - ? ({ status: 'stale' } satisfies CachedValidationDecision)
846 - : validationDecision;
847 - }).pipe(Effect.forkDetach);
848 - const awaitCachedValidationDecision = Fiber.join(cachedValidationDecisionFiber);
849 -
850 - return {
851 - cacheHit: true,
852 - awaitCachedValidationDecision,
853 - validationGuard: awaitCachedValidationDecision.pipe(
854 - Effect.flatMap(decision => {
855 - if (decision.status === 'fail') {
856 - return Effect.fail(decision.error);
857 - }
858 -
859 - return Effect.never;
860 - })
861 - ),
862 - } satisfies ValidationState;
863 - });
734 + validateToolInputArguments(params.slug, params.args, {
735 + orgId: params.resolvedProject.orgId,
736 + projectId: params.resolvedProject.projectId,
737 + }).pipe(
738 + Effect.asVoid,
739 + Effect.catchIf(
740 + error => !(error instanceof ToolInputValidationError),
741 + () => perfDebugLog('execute.validation.schema_unavailable', { slug: params.slug })
742 + )
743 + );
744
745 type DryRunSummary = {
746 readonly successful: true;
@@ -1235,38 +1115,13 @@ const runExecuteWithSpinner = (params: {
1115 }) =>
1116 Effect.gen(function* () {
1117 const verificationDisabled = params.skipChecks || params.skipToolParamsCheck;
1238 - const cachedDefinition = verificationDisabled
1239 - ? null
1240 - : yield* getCachedToolInputDefinition(params.slug);
1241 - const validationState: ValidationState = verificationDisabled
1242 - ? ({
1243 - cacheHit: false,
1244 - validationGuard: Effect.never,
1245 - awaitCachedValidationDecision: null,
1246 - } satisfies ValidationState)
1247 - : yield* initializeValidationState({
1248 - slug: params.slug,
1249 - args: params.args,
1250 - cachedDefinition,
1251 - resolvedProject: params.resolvedProject,
1252 - });
1118
1119 yield* params.ui.useMakeSpinner(`Executing tool "${params.slug}"...`, spinner =>
1120 Effect.gen(function* () {
1256 - let validationGuard = validationState.validationGuard;
1257 - if (!verificationDisabled && !validationState.cacheHit) {
1258 - validationGuard = yield* spawnBackgroundValidationGuard({
1259 - slug: params.slug,
1260 - args: params.args,
1261 - resolvedProject: params.resolvedProject,
1262 - });
1263 - }
1264 -
1121 if (params.dryRun) {
1122 const definition = verificationDisabled
1123 ? null
1268 - : (cachedDefinition ??
1269 - (yield* getOrFetchToolInputDefinition(params.slug, {
1124 + : yield* getOrFetchToolInputDefinition(params.slug, {
1125 orgId: params.resolvedProject.orgId,
1126 projectId: params.resolvedProject.projectId,
1127 }).pipe(
@@ -1281,7 +1136,7 @@ const runExecuteWithSpinner = (params: {
1136 projectScope: toolkitProjectScope(params.resolvedProject),
1137 })
1138 )
1284 - )));
1139 + );
1140 if (definition) {
1141 yield* validateToolInputArgumentsWithDefinition(
1142 params.slug,
@@ -1330,8 +1185,15 @@ const runExecuteWithSpinner = (params: {
1185 }
1186
1187 yield* perfDebugLog('execute.tool_call.start', { slug: params.slug });
1333 - const result = yield* params.executor.execute(params.slug, params.executeParams).pipe(
1334 - Effect.raceFirst(validationGuard),
1188 + const validateArgs = verificationDisabled
1189 + ? Effect.void
1190 + : validateToolInputBeforeExecute({
1191 + slug: params.slug,
1192 + args: params.args,
1193 + resolvedProject: params.resolvedProject,
1194 + });
1195 + const result = yield* validateArgs.pipe(
1196 + Effect.andThen(params.executor.execute(params.slug, params.executeParams)),
1197 Effect.matchEffect({
1198 onFailure: error =>
1199 Effect.gen(function* () {
@@ -1340,9 +1202,13 @@ const runExecuteWithSpinner = (params: {
1202 slug: params.slug,
1203 successful: false,
1204 });
1343 - yield* invalidateToolInputDefinition(params.slug).pipe(
1344 - Effect.catch(() => Effect.void)
1345 - );
1205 + // The validation error points the user at the cached schema, so
1206 + // it has to stay on disk.
1207 + if (!(error instanceof ToolInputValidationError)) {
1208 + yield* invalidateToolInputDefinition(params.slug).pipe(
1209 + Effect.catch(() => Effect.void)
1210 + );
1211 + }
1212 yield* spinner.error();
1213 const summary = yield* handleExecutionError(params.ui, error, {
1214 toolSlug: params.slug,
@@ -1383,15 +1249,6 @@ const runExecuteWithSpinner = (params: {
1249 }),
1250 })
1251 );
1386 - if (validationState.awaitCachedValidationDecision) {
1387 - const decision = yield* validationState.awaitCachedValidationDecision;
1388 - if (decision.status === 'fail') {
1389 - yield* perfDebugLog('execute.validation.post_success_failure_ignored', {
1390 - slug: params.slug,
1391 - });
1392 - }
1393 - }
1394 -
1252 if (!result.successful) {
1253 yield* invalidateToolInputDefinition(params.slug).pipe(Effect.catch(() => Effect.void));
1254 const logId = result.logId
ts/packages/cli/src/services/tool-input-validation.ts
+17 -17
@@ -185,7 +185,7 @@ export const invalidateToolInputDefinition = (slug: string) =>
185 });
186
187 // One `get_latest_version` round trip per tool per process. `composio execute`
188 -// asks twice on every call: the background version check forked from the
188 +// asks twice on every call: the validation that gates the tool call in the
189 // command, and `getOrFetchToolInputDefinition` on the executor's file-upload
190 // path. Both want the same answer within the same second.
191 const fetchLatestToolVersionOnce = memoizeInProcess({
@@ -332,15 +332,6 @@ const refreshAndFetchToolInputDefinitionIfVersionChanged = (
332 return { isStale, latestVersion, definition, skipped: false as const };
333 });
334
335 -export const refreshToolInputDefinitionIfVersionChanged = (
336 - slug: string,
337 - cachedVersion: string | null,
338 - params?: { readonly orgId?: string; readonly projectId?: string }
339 -) =>
340 - refreshAndFetchToolInputDefinitionIfVersionChanged(slug, cachedVersion, params).pipe(
341 - Effect.map(({ isStale, latestVersion, skipped }) => ({ isStale, latestVersion, skipped }))
342 - );
343 -
335 export class ToolInputValidationError extends Data.TaggedError('ToolInputValidationError')<{
336 readonly toolSlug: string;
337 readonly schemaPath: string;
@@ -356,6 +347,21 @@ export class ToolInputValidationError extends Data.TaggedError('ToolInputValidat
347 }
348 }
349
350 +// The schema itself is unusable, which says nothing about the arguments. Kept
351 +// apart from `ToolInputValidationError` so it never blocks a tool call.
352 +export class ToolInputSchemaCompileError extends Data.TaggedError('ToolInputSchemaCompileError')<{
353 + readonly toolSlug: string;
354 + readonly schemaPath: string;
355 + readonly cause?: unknown;
356 +}> {
357 + override get message(): string {
358 + return [
359 + `Could not compile the cached JSON schema for ${this.toolSlug} into a validator.`,
360 + `Schema: ${this.schemaPath}`,
361 + ].join('\n');
362 + }
363 +}
364 +
365 const getObjectSchemaProperties = (schema: Record<string, unknown>): ReadonlyArray<string> => {
366 const objectSchema = decodeObjectSchemaWithProperties(schema);
367 return Option.isSome(objectSchema) ? Object.keys(objectSchema.value.properties) : [];
@@ -476,13 +482,7 @@ export const validateToolInputArgumentsWithDefinition = (
482
483 const inputSchema = yield* Effect.try({
484 try: () => compileToolInputSchema(normalizedSchema, allowedKeys),
479 - catch: error =>
480 - new ToolInputValidationError({
481 - toolSlug: slug,
482 - schemaPath,
483 - issues: ['Could not compile the cached JSON schema into a validator.'],
484 - cause: error,
485 - }),
485 + catch: error => new ToolInputSchemaCompileError({ toolSlug: slug, schemaPath, cause: error }),
486 });
487
488 yield* Schema.decodeUnknownEffect(inputSchema, { errors: 'all' })(args).pipe(
ts/packages/cli/test/__utils__/services/test-layer.ts
+18 -14
@@ -263,6 +263,8 @@ export interface TestLiveInput {
263 toolsExecutor?: {
264 failWith?: unknown;
265 respondWith?: ToolExecuteResponse;
266 + /** Called each time the mock executor actually runs a tool call. */
267 + onExecute?: (slug: string) => void;
268 };
269
270 /**
@@ -1503,20 +1505,22 @@ export const TestLayer = (input?: TestLiveInput) =>
1505 ? Layer.succeed(
1506 ToolsExecutor,
1507 ToolsExecutor.of({
1506 - execute: (slug, params) => {
1507 - if (input.toolsExecutor!.failWith) {
1508 - return Effect.fail(input.toolsExecutor!.failWith);
1509 - }
1510 - if (input.toolsExecutor!.respondWith) {
1511 - return Effect.succeed(input.toolsExecutor!.respondWith);
1512 - }
1513 - return Effect.succeed({
1514 - data: { slug, params },
1515 - error: null,
1516 - successful: true,
1517 - logId: 'log_test',
1518 - });
1519 - },
1508 + execute: (slug, params) =>
1509 + Effect.suspend(() => {
1510 + input.toolsExecutor!.onExecute?.(slug);
1511 + if (input.toolsExecutor!.failWith) {
1512 + return Effect.fail(input.toolsExecutor!.failWith);
1513 + }
1514 + if (input.toolsExecutor!.respondWith) {
1515 + return Effect.succeed(input.toolsExecutor!.respondWith);
1516 + }
1517 + return Effect.succeed({
1518 + data: { slug, params },
1519 + error: null,
1520 + successful: true,
1521 + logId: 'log_test',
1522 + });
1523 + }),
1524 })
1525 )
1526 : Layer.provide(
ts/packages/cli/test/src/commands/tools/tools.execute.cmd.test.ts
+140 -2
@@ -1251,6 +1251,9 @@ describe('CLI: composio execute', () => {
1251 }),
1252 'utf8'
1253 );
1254 + vi.spyOn(composioClients, 'getLatestToolVersion').mockImplementation(({ toolSlug }) =>
1255 + Effect.succeed({ tool_slug: toolSlug, version: '20260115_00' })
1256 + );
1257
1258 yield* cli([
1259 'execute',
@@ -1268,12 +1271,12 @@ describe('CLI: composio execute', () => {
1271 version: string | null;
1272 inputSchema: Record<string, unknown>;
1273 };
1271 - expect(['20260101_00', '20260115_00']).toContain(refreshed.version);
1274 + expect(refreshed.version).toBe('20260115_00');
1275 expect(refreshed.inputSchema.type).toBe('object');
1276 const propertyKeys = Object.keys(
1277 (refreshed.inputSchema.properties ?? {}) as Record<string, unknown>
1278 );
1276 - expect(propertyKeys.some(key => key === 'recipient_email' || key === 'to')).toBe(true);
1279 + expect(propertyKeys).toContain('recipient_email');
1280 })
1281 );
1282 }
@@ -1353,6 +1356,141 @@ describe('CLI: composio execute', () => {
1356 );
1357 });
1358
1359 + const executedToolSlugs: Array<string> = [];
1360 +
1361 + layer(
1362 + TestLive({
1363 + baseConfigProvider: testConfigProvider,
1364 + fixture: 'global-test-user-id',
1365 + stdin: { isTTY: true, data: '' },
1366 + toolkitsData: {
1367 + tools: [
1368 + {
1369 + name: 'Send Email',
1370 + slug: 'GMAIL_SEND_EMAIL',
1371 + description: 'Send an email',
1372 + tags: ['email'],
1373 + available_versions: ['20260101_00'],
1374 + input_parameters: {
1375 + type: 'object',
1376 + required: ['recipient_email'],
1377 + properties: {
1378 + recipient_email: { type: 'string', description: 'Recipient email' },
1379 + },
1380 + },
1381 + output_parameters: { type: 'object', properties: {} },
1382 + },
1383 + ],
1384 + } satisfies TestLiveInput['toolkitsData'],
1385 + toolsExecutor: {
1386 + onExecute: slug => {
1387 + executedToolSlugs.push(slug);
1388 + },
1389 + },
1390 + })
1391 + )('[Given] invalid tool input [Then] validation gates the tool call and keeps the schema', it => {
1392 + // The schema lookup answers after the mock executor would have finished,
1393 + // so a tool call that does not wait for validation always gets through.
1394 + const slowSchemaLookup = () =>
1395 + vi
1396 + .spyOn(composioClients, 'getLatestToolVersion')
1397 + .mockImplementation(({ toolSlug }) =>
1398 + Effect.promise(() => new Promise<void>(resolve => setTimeout(resolve, 25))).pipe(
1399 + Effect.as({ tool_slug: toolSlug, version: '20260101_00' })
1400 + )
1401 + );
1402 +
1403 + const executeWithInvalidInput = cli([
1404 + 'execute',
1405 + 'GMAIL_SEND_EMAIL',
1406 + '--skip-connection-check',
1407 + '-d',
1408 + '{"recipient":42}',
1409 + ]).pipe(
1410 + Effect.flip,
1411 + Effect.map(error => (error instanceof Error ? error.message : String(error)))
1412 + );
1413 +
1414 + it.effect('never sends the tool call on a schema cache miss', () =>
1415 + Effect.gen(function* () {
1416 + slowSchemaLookup();
1417 + executedToolSlugs.length = 0;
1418 +
1419 + const failure = yield* executeWithInvalidInput;
1420 +
1421 + expect(failure).toContain('Input validation failed for GMAIL_SEND_EMAIL');
1422 + expect(executedToolSlugs).toEqual([]);
1423 + const cacheDir = yield* setupCacheDir;
1424 + const schemaPath = `${cacheDir}/tool_definitions/GMAIL_SEND_EMAIL.json`;
1425 + expect(failure).toContain(schemaPath);
1426 + expect(fs.existsSync(schemaPath)).toBe(true);
1427 + })
1428 + );
1429 +
1430 + it.effect('never sends the tool call on a schema cache hit', () =>
1431 + Effect.gen(function* () {
1432 + yield* getOrFetchToolInputDefinition('GMAIL_SEND_EMAIL');
1433 + clearInProcessMemos();
1434 + slowSchemaLookup();
1435 + executedToolSlugs.length = 0;
1436 +
1437 + const failure = yield* executeWithInvalidInput;
1438 +
1439 + expect(failure).toContain('Input validation failed for GMAIL_SEND_EMAIL');
1440 + expect(executedToolSlugs).toEqual([]);
1441 + const cacheDir = yield* setupCacheDir;
1442 + const schemaPath = `${cacheDir}/tool_definitions/GMAIL_SEND_EMAIL.json`;
1443 + expect(failure).toContain(schemaPath);
1444 + expect(fs.existsSync(schemaPath)).toBe(true);
1445 + })
1446 + );
1447 +
1448 + it.effect('sends the tool call when the cached schema cannot be compiled', () =>
1449 + Effect.gen(function* () {
1450 + const cacheDir = yield* setupCacheDir;
1451 + fs.mkdirSync(`${cacheDir}/tool_definitions`, { recursive: true });
1452 + fs.writeFileSync(
1453 + `${cacheDir}/tool_definitions/GMAIL_SEND_EMAIL.json`,
1454 + JSON.stringify({
1455 + version: '20260101_00',
1456 + inputSchema: {
1457 + type: 'object',
1458 + properties: { recipient_email: { type: 'string' } },
1459 + // Not a JavaScript regular expression, so the validator cannot be built.
1460 + patternProperties: { '(?i)^x-': { type: 'string' } },
1461 + },
1462 + }),
1463 + 'utf8'
1464 + );
1465 + clearInProcessMemos();
1466 + slowSchemaLookup();
1467 + executedToolSlugs.length = 0;
1468 +
1469 + yield* cli([
1470 + 'execute',
1471 + 'GMAIL_SEND_EMAIL',
1472 + '--skip-connection-check',
1473 + '-d',
1474 + '{"recipient_email":"karan"}',
1475 + ]);
1476 +
1477 + expect(executedToolSlugs).toEqual(['GMAIL_SEND_EMAIL']);
1478 +
1479 + const dryRunFailure = yield* cli([
1480 + 'execute',
1481 + 'GMAIL_SEND_EMAIL',
1482 + '--dry-run',
1483 + '-d',
1484 + '{"recipient_email":"karan"}',
1485 + ]).pipe(
1486 + Effect.flip,
1487 + Effect.map(error => (error instanceof Error ? error.message : String(error)))
1488 + );
1489 + expect(dryRunFailure).toContain('Could not compile the cached JSON schema');
1490 + })
1491 + );
1492 + });
1493 +
1494 layer(
1495 TestLive({
1496 baseConfigProvider: largeOutputConfigProvider,
ts/packages/cli/test/src/services/tool-input-validation.test.ts
+14 -8
@@ -7,6 +7,7 @@ import { ConfigProvider, Effect, Layer } from 'effect';
7 import * as tempy from 'tempy';
8 import {
9 getCachedToolInputDefinition,
10 + ToolInputSchemaCompileError,
11 ToolInputValidationError,
12 validateToolInputArgumentsWithDefinition,
13 } from 'src/services/tool-input-validation';
@@ -27,6 +28,11 @@ const definition = {
28 },
29 } as const;
30
31 +// Every schema here compiles, so only the argument failure is of interest.
32 +const flipValidationError = <A, R>(
33 + effect: Effect.Effect<A, ToolInputValidationError | ToolInputSchemaCompileError, R>
34 +) => effect.pipe(Effect.catchTag('ToolInputSchemaCompileError', Effect.die), Effect.flip);
35 +
36 describe('tool input validation', () => {
37 it.effect('validates tool input through Effect Schema', () =>
38 Effect.gen(function* () {
@@ -46,7 +52,7 @@ describe('tool input validation', () => {
52 'GMAIL_SEND_EMAIL',
53 { recipent_email: 'karan@composio.dev' },
54 definition
49 - ).pipe(Effect.flip);
55 + ).pipe(flipValidationError);
56
57 expect(error).toBeInstanceOf(ToolInputValidationError);
58 expect(error.issues).toContain(
@@ -61,12 +67,12 @@ describe('tool input validation', () => {
67 'GMAIL_SEND_EMAIL',
68 { recipient: 'karan@composio.dev' },
69 definition
64 - ).pipe(Effect.flip);
70 + ).pipe(flipValidationError);
71 const unrelatedError = yield* validateToolInputArgumentsWithDefinition(
72 'GMAIL_SEND_EMAIL',
73 { account: 'karan@composio.dev' },
74 definition
69 - ).pipe(Effect.flip);
75 + ).pipe(flipValidationError);
76
77 expect(prefixError.issues).toContain(
78 '<root>: Unknown key "recipient". Use "recipient_email" instead. Allowed top-level keys: recipient_email, subject, body'
@@ -85,7 +91,7 @@ describe('tool input validation', () => {
91 'GMAIL_SEND_EMAIL',
92 { recpnt_email: 'karan@composio.dev' },
93 definition
88 - ).pipe(Effect.flip);
94 + ).pipe(flipValidationError);
95 const containmentError = yield* validateToolInputArgumentsWithDefinition(
96 'TEST_TOOL',
97 { to: true },
@@ -97,7 +103,7 @@ describe('tool input validation', () => {
103 properties: { auto_reply: { type: 'boolean' } },
104 },
105 }
100 - ).pipe(Effect.flip);
106 + ).pipe(flipValidationError);
107
108 expect(longTypoError.issues).toContain(
109 '<root>: Unknown key "recpnt_email". Use "recipient_email" instead. Allowed top-level keys: recipient_email, subject, body'
@@ -143,7 +149,7 @@ describe('tool input validation', () => {
149 'GMAIL_SEND_EMAIL',
150 { recipient_email: 42 },
151 definition
146 - ).pipe(Effect.flip);
152 + ).pipe(flipValidationError);
153
154 expect(error.issues.some(issue => issue.startsWith('recipient_email:'))).toBe(true);
155 })
@@ -155,7 +161,7 @@ describe('tool input validation', () => {
161 'GMAIL_SEND_EMAIL',
162 { recipient_email: 42, subject: false, recipent_email: 'karan@composio.dev' },
163 definition
158 - ).pipe(Effect.flip);
164 + ).pipe(flipValidationError);
165
166 expect(error.issues.some(issue => issue.startsWith('recipient_email:'))).toBe(true);
167 expect(error.issues.some(issue => issue.startsWith('subject:'))).toBe(true);
@@ -195,7 +201,7 @@ describe('free-form object tool inputs', () => {
201 'GMAIL_SEND_EMAIL',
202 { recipient_email: 'karan@composio.dev', nope: 1 },
203 definition
198 - ).pipe(Effect.flip);
204 + ).pipe(flipValidationError);
205
206 expect(error).toBeInstanceOf(ToolInputValidationError);
207 })