UNPKG

pipe-protocol

Version:

A protocol for large scale Interplanetary Intertool Agent Context

186 lines 6.82 kB
"use strict"; /** * @file Pipe Class Test Suite * @version 1.0.0 * @status STABLE - COMPLETE TEST COVERAGE * @lastModified 2024-02-04 * * Tests for the Pipe class functionality. * * IMPORTANT: * - Maintain complete test coverage * - Test all configuration options * - Test error cases * - Test edge cases * * Test Coverage: * - Configuration handling * - Default configuration * - Custom configuration * - Tool wrapping * - Basic wrapping * - Token limiting * - Schema generation * - Hook system * - Hook execution order * - Hook removal * - IPFS integration * - Storage and retrieval * - Scope settings * - Pinning options */ Object.defineProperty(exports, "__esModule", { value: true }); const vitest_1 = require("vitest"); const pipe_1 = require("../../../pipe"); // 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)('Pipe', () => { (0, vitest_1.describe)('Configuration', () => { (0, vitest_1.it)('should use default configuration when none provided', () => { const pipe = new pipe_1.Pipe(); const tools = pipe.wrap([mockTool]); (0, vitest_1.expect)(tools).toHaveLength(2); // Includes pipe tool (0, vitest_1.expect)(tools[0].name).toBe(mockTool.name); (0, vitest_1.expect)(tools[1].name).toBe('pipe'); // Pipe tool is last }); (0, vitest_1.it)('should accept custom configuration', () => { const pipe = new pipe_1.Pipe({ ipfs: { endpoint: 'http://custom:5001', scope: 'public', pin: false }, defaults: { maxTokens: 500, storeResult: false } }); const tools = pipe.wrap([mockTool]); (0, vitest_1.expect)(tools).toHaveLength(2); // Includes pipe tool (0, vitest_1.expect)(tools[0].name).toBe(mockTool.name); (0, vitest_1.expect)(tools[1].name).toBe('pipe'); // Pipe tool is last }); }); (0, vitest_1.describe)('Hook System', () => { let pipe; const mockBeforeStore = vitest_1.vi.fn(data => data); const mockAfterStore = vitest_1.vi.fn(); (0, vitest_1.beforeEach)(() => { pipe = new pipe_1.Pipe(); pipe.addHooks([ { name: 'beforeStore', type: 'beforeStore', handler: mockBeforeStore }, { name: 'afterStore', type: 'afterStore', handler: mockAfterStore } ]); }); (0, vitest_1.it)('should execute hooks in order', async () => { const tools = pipe.wrap([mockTool]); const result = await tools[0].call({ input: 'test' }); (0, vitest_1.expect)(mockBeforeStore).toHaveBeenCalled(); (0, vitest_1.expect)(mockAfterStore).toHaveBeenCalled(); (0, vitest_1.expect)(result).toHaveProperty('cid'); }); (0, vitest_1.it)('should allow removing hooks', () => { pipe.removeHook('beforeStore'); (0, vitest_1.expect)(pipe['hooks']).toHaveLength(1); (0, vitest_1.expect)(pipe['hooks'][0].name).toBe('afterStore'); }); }); (0, vitest_1.describe)('Tool Wrapping', () => { let pipe; (0, vitest_1.beforeEach)(() => { pipe = new pipe_1.Pipe(); }); (0, vitest_1.it)('should wrap tools with IPFS capabilities', async () => { const tools = pipe.wrap([mockTool]); const result = await tools[0].call({ input: 'test' }); (0, vitest_1.expect)(result).toHaveProperty('cid'); (0, vitest_1.expect)(result).toHaveProperty('schemaCid'); (0, vitest_1.expect)(result).toHaveProperty('metadata'); (0, vitest_1.expect)(result.metadata).toHaveProperty('tool', 'mockTool'); }); (0, vitest_1.it)('should respect token limits', async () => { const pipe = new pipe_1.Pipe({ defaults: { maxTokens: 5 } }); const tools = pipe.wrap([mockTool]); const result = await tools[0].call({ input: 'this is a very long input that should be truncated' }); (0, vitest_1.expect)(result.metadata).toHaveProperty('truncated', true); }); (0, vitest_1.it)('should handle schema generation', async () => { const tools = pipe.wrap([mockTool]); const result = await tools[0].call({ input: 'test', pipeOptions: { generateSchema: true } }); (0, vitest_1.expect)(result).toHaveProperty('schemaCid'); (0, vitest_1.expect)(result.schemaCid).not.toBe('no-schema'); }); }); (0, vitest_1.describe)('IPFS Integration', () => { let pipe; (0, vitest_1.beforeEach)(() => { pipe = new pipe_1.Pipe(); }); (0, vitest_1.it)('should store and retrieve data', async () => { const data = { test: 'data' }; const cid = await pipe.store(data); const retrieved = await pipe.retrieve(cid); (0, vitest_1.expect)(retrieved).toEqual(data); }); (0, vitest_1.it)('should respect scope settings', async () => { const pipe = new pipe_1.Pipe({ defaults: { scope: 'public' } }); const tools = pipe.wrap([mockTool]); const result = await tools[0].call({ input: 'test' }); (0, vitest_1.expect)(result.metadata).toHaveProperty('scope', 'public'); }); (0, vitest_1.it)('should handle pinning options', async () => { const pipe = new pipe_1.Pipe({ defaults: { pin: false } }); const tools = pipe.wrap([mockTool]); const result = await tools[0].call({ input: 'test' }); (0, vitest_1.expect)(result.metadata).toHaveProperty('pinned', false); }); }); }); //# sourceMappingURL=pipe.test.js.map