UNPKG

pipe-protocol

Version:

A protocol for large scale Interplanetary Intertool Agent Context

115 lines 4.62 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const pipe_js_1 = require("../src/pipe.js"); async function testReplication() { console.log('Starting replication test...\n'); const config = { ipfs: { endpoint: 'https://ipfs.infura.io:5001', offline: false } }; const pipe = new pipe_js_1.PipeProtocol(config); try { // Test 1: Publish a record to private scope console.log('Test 1: Publishing a record to private scope...'); const privateRecord = { type: 'data', content: { message: 'Private data' }, scope: 'private', accessPolicy: { hiddenFromLLM: false }, encryption: { enabled: false }, pinned: true }; const publishedPrivate = await pipe.publishRecord(privateRecord); console.log('Published private record:', { cid: publishedPrivate.cid, scope: publishedPrivate.scope }); // Test 2: Replicate to public scope console.log('\nTest 2: Replicating to public scope...'); if (publishedPrivate.cid) { await pipe.replicate(publishedPrivate.cid, 'private', 'public'); console.log('Record replicated to public scope'); } // Test 3: Verify record is accessible in both scopes console.log('\nTest 3: Verifying record accessibility...'); if (publishedPrivate.cid) { const privateAccess = await pipe.fetchRecord(publishedPrivate.cid, 'private'); const publicAccess = await pipe.fetchRecord(publishedPrivate.cid, 'public'); console.log('Record accessibility:', { privateScope: Boolean(privateAccess), publicScope: Boolean(publicAccess) }); } // Test 4: Test machine scope console.log('\nTest 4: Testing machine scope...'); const machineRecord = { type: 'data', content: { message: 'Machine-specific data' }, scope: 'machine', accessPolicy: { hiddenFromLLM: false }, encryption: { enabled: false }, pinned: true }; const publishedMachine = await pipe.publishRecord(machineRecord); console.log('Published machine record:', { cid: publishedMachine.cid, scope: publishedMachine.scope }); // Test 5: Test user scope console.log('\nTest 5: Testing user scope...'); const userRecord = { type: 'data', content: { message: 'User-specific data' }, scope: 'user', accessPolicy: { hiddenFromLLM: false }, encryption: { enabled: false }, pinned: true }; const publishedUser = await pipe.publishRecord(userRecord); console.log('Published user record:', { cid: publishedUser.cid, scope: publishedUser.scope }); // Test 6: Verify pinning across scopes console.log('\nTest 6: Verifying pinning across scopes...'); const privatePins = await pipe.getPinnedCids('private'); const publicPins = await pipe.getPinnedCids('public'); const machinePins = await pipe.getPinnedCids('machine'); const userPins = await pipe.getPinnedCids('user'); console.log('Pinned CIDs by scope:', { private: privatePins.length, public: publicPins.length, machine: machinePins.length, user: userPins.length }); // Test 7: Test scope isolation console.log('\nTest 7: Testing scope isolation...'); if (publishedMachine.cid && publishedUser.cid) { try { await pipe.fetchRecord(publishedMachine.cid, 'user'); console.log('Warning: Machine record accessible from user scope'); } catch (error) { console.log('Expected: Machine record not accessible from user scope'); } try { await pipe.fetchRecord(publishedUser.cid, 'machine'); console.log('Warning: User record accessible from machine scope'); } catch (error) { console.log('Expected: User record not accessible from machine scope'); } } } catch (error) { console.error('Error during tests:', error); process.exit(1); } finally { await pipe.stop(); } } testReplication().catch(console.error); //# sourceMappingURL=test-replication.js.map