pipe-protocol
Version:
A protocol for large scale Interplanetary Intertool Agent Context
160 lines • 6.38 kB
JavaScript
"use strict";
/**
* @file Tool Wrapping Test Suite
* @version 1.0.0
* @status STABLE - COMPLETE TEST COVERAGE
* @lastModified 2024-02-04
*
* Tests for tool wrapping functionality.
*
* IMPORTANT:
* - Maintain complete test coverage
* - Test all wrapping features
* - Test configuration options
* - Test error cases
*
* Test Coverage:
* - Basic Tool Wrapping
* - Property preservation
* - Functionality maintenance
* - Multiple tool handling
* - IPFS Integration
* - Storage configuration
* - Scope settings
* - Pinning options
*/
Object.defineProperty(exports, "__esModule", { value: true });
const vitest_1 = require("vitest");
const toolWrapping_1 = require("../toolWrapping");
const ipfsClient_1 = require("../../ipfs/ipfsClient");
// Mock IPFS client for testing
const mockIpfsClient = new ipfsClient_1.IPFSClient({
endpoint: 'http://localhost:5001',
timeout: 30000,
scope: 'private',
pin: true
});
// Mock tool for testing
const mockTool = {
name: 'mockTool',
description: 'A mock tool for testing',
parameters: {
type: 'object',
properties: {
input: {
type: 'string',
description: 'Input for the mock tool'
}
},
required: ['input']
},
call: async (args) => {
return { result: `Processed: ${args.input}` };
}
};
(0, vitest_1.describe)('Tool Wrapping', () => {
(0, vitest_1.describe)('Basic Tool Wrapping', () => {
(0, vitest_1.it)('should preserve original tool properties', () => {
const wrappedTool = (0, toolWrapping_1.wrapTool)(mockTool, {
ipfsClient: mockIpfsClient,
storeResult: true,
pin: true,
scope: 'private'
});
(0, vitest_1.expect)(wrappedTool.name).toBe(mockTool.name);
(0, vitest_1.expect)(wrappedTool.description).toContain(mockTool.description);
(0, vitest_1.expect)(wrappedTool.parameters).toEqual(mockTool.parameters);
});
(0, vitest_1.it)('should maintain tool functionality', async () => {
const wrappedTool = (0, toolWrapping_1.wrapTool)(mockTool, {
ipfsClient: mockIpfsClient,
storeResult: true,
pin: true,
scope: 'private'
});
const result = await wrappedTool.call({ input: 'test' });
(0, vitest_1.expect)(result).toHaveProperty('result', 'Processed: test');
(0, vitest_1.expect)(result).toHaveProperty('cid');
(0, vitest_1.expect)(result).toHaveProperty('metadata');
});
(0, vitest_1.it)('should handle multiple tools', () => {
const anotherMockTool = {
name: 'anotherMockTool',
description: 'Another mock tool for testing',
parameters: mockTool.parameters,
call: mockTool.call
};
const wrappedTool1 = (0, toolWrapping_1.wrapTool)(mockTool, {
ipfsClient: mockIpfsClient,
storeResult: true,
pin: true,
scope: 'private'
});
const wrappedTool2 = (0, toolWrapping_1.wrapTool)(anotherMockTool, {
ipfsClient: mockIpfsClient,
storeResult: true,
pin: true,
scope: 'private'
});
(0, vitest_1.expect)(wrappedTool1.name).toBe('mockTool');
(0, vitest_1.expect)(wrappedTool2.name).toBe('anotherMockTool');
});
(0, vitest_1.it)('should enhance tool description with Pipe information', () => {
const wrappedTool = (0, toolWrapping_1.wrapTool)(mockTool, {
ipfsClient: mockIpfsClient,
storeResult: true,
pin: true,
scope: 'private'
});
(0, vitest_1.expect)(wrappedTool.description).toContain('Enhanced by Pipe Protocol');
(0, vitest_1.expect)(wrappedTool.description).toContain('IPFS storage');
(0, vitest_1.expect)(wrappedTool.description).toContain('schema validation');
(0, vitest_1.expect)(wrappedTool.description).toContain('token management');
});
});
(0, vitest_1.describe)('IPFS Integration', () => {
(0, vitest_1.it)('should store results in IPFS when configured', async () => {
const wrappedTool = (0, toolWrapping_1.wrapTool)(mockTool, {
ipfsClient: mockIpfsClient,
storeResult: true,
generateSchema: true,
pin: true,
scope: 'private'
});
const result = await wrappedTool.call({ input: 'test' });
(0, vitest_1.expect)(result).toHaveProperty('cid');
(0, vitest_1.expect)(result).toHaveProperty('schema');
(0, vitest_1.expect)(result).toHaveProperty('schemaCid');
(0, vitest_1.expect)(result.schema).toEqual({
type: 'object',
properties: {
result: { type: 'string' }
},
required: ['result']
});
(0, vitest_1.expect)(result.metadata).toHaveProperty('tool', 'mockTool');
(0, vitest_1.expect)(result.metadata).toHaveProperty('pinned', true);
});
(0, vitest_1.it)('should respect scope settings', async () => {
const wrappedTool = (0, toolWrapping_1.wrapTool)(mockTool, {
ipfsClient: mockIpfsClient,
storeResult: true,
pin: true,
scope: 'public'
});
const result = await wrappedTool.call({ input: 'test' });
(0, vitest_1.expect)(result.metadata).toHaveProperty('scope', 'public');
});
(0, vitest_1.it)('should handle pinning options', async () => {
const wrappedTool = (0, toolWrapping_1.wrapTool)(mockTool, {
ipfsClient: mockIpfsClient,
storeResult: true,
pin: false,
scope: 'private'
});
const result = await wrappedTool.call({ input: 'test' });
(0, vitest_1.expect)(result.metadata).toHaveProperty('pinned', false);
});
});
});
//# sourceMappingURL=toolWrapping.test.js.map