{"_id":"@aimf/testing","_rev":"2-cce247fbbbee9e60baba1f15a6977000","name":"@aimf/testing","dist-tags":{"latest":"0.1.1"},"versions":{"0.1.0":{"name":"@aimf/testing","version":"0.1.0","_id":"@aimf/testing@0.1.0","maintainers":[{"name":"vetriselvans","email":"vetriselvans029@gmail.com"}],"dist":{"shasum":"6565b060b3443fd50b737e502f4f3cf9308275ff","tarball":"https://registry.npmjs.org/@aimf/testing/-/testing-0.1.0.tgz","fileCount":78,"integrity":"sha512-q9z2jOIJy3XLDMNcehd7EnjQIqY3IFlMa8mLbr/P7P/aihi/i4f7YcJkVtWEnC1nEZDZzG2Xps1m19BJVZ/NKA==","signatures":[{"sig":"MEQCIFXqUPIh0HvdhoWFsn+d0WUjplTYRuh6MAWXJrHSpS7TAiAPcBL2ZJ5wgowEi3qTHzxXyPk/v8cJEtfzchFbNpm3Qg==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":234248},"main":"dist/index.js","type":"module","_from":"file:aimf-testing-0.1.0.tgz","types":"dist/index.d.ts","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js"}},"scripts":{"lint":"eslint src/","test":"vitest run","build":"tsc","test:watch":"vitest","test:coverage":"vitest run --coverage","test:integration":"vitest run --config vitest.integration.config.ts","test:integration:watch":"vitest --config vitest.integration.config.ts"},"_npmUser":{"name":"vetriselvans","email":"vetriselvans029@gmail.com"},"_resolved":"C:\\Users\\I9159~1.LAP\\AppData\\Local\\Temp\\1637636817880d430ab3bb152433b8f3\\aimf-testing-0.1.0.tgz","_integrity":"sha512-q9z2jOIJy3XLDMNcehd7EnjQIqY3IFlMa8mLbr/P7P/aihi/i4f7YcJkVtWEnC1nEZDZzG2Xps1m19BJVZ/NKA==","_npmVersion":"10.9.0","description":"Testing utilities for the AI-MCP Framework (AIMF).","directories":{},"_nodeVersion":"22.12.0","dependencies":{"@aimf/shared":"0.1.0","@aimf/ncp-core":"0.1.0"},"_hasShrinkwrap":false,"devDependencies":{"vitest":"^1.0.0","typescript":"^5.0.0","@vitest/coverage-v8":"^1.0.0"},"peerDependencies":{"vitest":"^1.0.0"},"_npmOperationalInternal":{"tmp":"tmp/testing_0.1.0_1765129039368_0.9606846646642939","host":"s3://npm-registry-packages-npm-production"}},"0.1.1":{"name":"@aimf/testing","version":"0.1.1","type":"module","main":"dist/index.js","types":"dist/index.d.ts","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js"}},"dependencies":{"@aimf/shared":"0.1.1","@aimf/ncp-core":"0.1.1"},"devDependencies":{"typescript":"^5.0.0","vitest":"^1.0.0","@vitest/coverage-v8":"^1.0.0"},"peerDependencies":{"vitest":"^1.0.0"},"scripts":{"build":"tsc","test":"vitest run","test:watch":"vitest","test:coverage":"vitest run --coverage","test:integration":"vitest run --config vitest.integration.config.ts","test:integration:watch":"vitest --config vitest.integration.config.ts","lint":"eslint src/"},"_id":"@aimf/testing@0.1.1","description":"Testing utilities for the AI-MCP Framework (AIMF).","_integrity":"sha512-ouPwFAzjMO2CMaoGTrjTO/hdG5xDXJSwfVQo5aJFEjJvj0A0C3N8Y1xJnmGjzXQicTR4Px655EW0rMjaocbtCw==","_resolved":"C:\\Users\\I9159~1.LAP\\AppData\\Local\\Temp\\987c2b0f68d1782e758131fa9b4d1252\\aimf-testing-0.1.1.tgz","_from":"file:aimf-testing-0.1.1.tgz","_nodeVersion":"22.12.0","_npmVersion":"10.9.0","dist":{"integrity":"sha512-ouPwFAzjMO2CMaoGTrjTO/hdG5xDXJSwfVQo5aJFEjJvj0A0C3N8Y1xJnmGjzXQicTR4Px655EW0rMjaocbtCw==","shasum":"cc68fc74442cba9b5c37f5f1d0b702ed55ece944","tarball":"https://registry.npmjs.org/@aimf/testing/-/testing-0.1.1.tgz","fileCount":78,"unpackedSize":234248,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQDqkXNfs3zestPSJBpP5CMAOTmgT16E4ekHmzxZGizDSAIgZcRbMTQkNs3iyt92YQQVZT1MXYnkuAcv4205AbQwPcg="}]},"_npmUser":{"name":"vetriselvans","email":"vetriselvans029@gmail.com"},"directories":{},"maintainers":[{"name":"vetriselvans","email":"vetriselvans029@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/testing_0.1.1_1765130897952_0.2818500459005544"},"_hasShrinkwrap":false}},"time":{"created":"2025-12-07T17:37:19.309Z","modified":"2025-12-07T18:08:18.391Z","0.1.0":"2025-12-07T17:37:19.517Z","0.1.1":"2025-12-07T18:08:18.100Z"},"description":"Testing utilities for the AI-MCP Framework (AIMF).","maintainers":[{"name":"vetriselvans","email":"vetriselvans029@gmail.com"}],"readme":"# @aimf/testing\r\n\r\nTesting utilities for the AI-MCP Framework (AIMF).\r\n\r\n## Installation\r\n\r\n```bash\r\npnpm add -D @aimf/testing vitest\r\n```\r\n\r\n## Features\r\n\r\n### Custom Matchers\r\n\r\nAIMF-specific Vitest matchers for asserting neural data:\r\n\r\n```typescript\r\nimport { expect } from \"@aimf/testing\";\r\n\r\n// Validate NCP messages\r\nexpect(message).toBeValidNcpMessage();\r\n\r\n// Check for neural hash\r\nexpect(data).toHaveNeuralHash();\r\n\r\n// Check for verified data (has hash + embedding)\r\nexpect(data).toBeVerifiedData();\r\n\r\n// Match against NCP schema\r\nexpect(data).toMatchNcpSchema(schema);\r\n```\r\n\r\n### Mock Factories\r\n\r\n#### NCP Mocks\r\n\r\n```typescript\r\nimport {\r\n  createMockNcpClient,\r\n  createMockNcpServer,\r\n  createMockNcpRequest,\r\n  createMockNcpTransport,\r\n} from \"@aimf/testing\";\r\n\r\n// Mock NCP client\r\nconst client = createMockNcpClient();\r\nawait client.callTool(\"my-tool\", { input: \"test\" });\r\n\r\n// Mock NCP server\r\nconst server = createMockNcpServer();\r\nserver.registerTool(\"my-tool\", \"description\", async (input) => ({ result: \"ok\" }));\r\n\r\n// Mock NCP request\r\nconst request = createMockNcpRequest(\"method/name\", { param: \"value\" });\r\n```\r\n\r\n#### Storage Mocks\r\n\r\n```typescript\r\nimport {\r\n  createMockNeuralStorage,\r\n  createMockEmbeddingProvider,\r\n  createMockVectorDB,\r\n} from \"@aimf/testing\";\r\n\r\n// Mock neural storage\r\nconst storage = createMockNeuralStorage();\r\nconst id = await storage.store({ data: \"test\" });\r\nconst result = await storage.retrieve(id);\r\n\r\n// Mock embedding provider\r\nconst embedder = createMockEmbeddingProvider();\r\nconst embedding = await embedder.embed(\"text\");\r\n\r\n// Mock vector database\r\nconst db = createMockVectorDB();\r\nawait db.createCollection(\"my-collection\", 1536);\r\nawait db.upsert(\"my-collection\", \"id\", embedding, { payload: \"data\" });\r\n```\r\n\r\n### Test Fixtures\r\n\r\nPre-built fixtures for common test data:\r\n\r\n```typescript\r\nimport {\r\n  createUserFixture,\r\n  createDataFixture,\r\n  createToolFixture,\r\n  createManifestFixture,\r\n  createNcpRequestFixture,\r\n} from \"@aimf/testing\";\r\n\r\n// Create test data\r\nconst user = createUserFixture({ name: \"Test User\" });\r\nconst data = createDataFixture();\r\nconst tool = createToolFixture({ name: \"my-tool\" });\r\nconst manifest = createManifestFixture();\r\nconst request = createNcpRequestFixture(\"test/method\");\r\n```\r\n\r\n### Test Utilities\r\n\r\nHelpful utilities for async testing:\r\n\r\n```typescript\r\nimport {\r\n  wait,\r\n  waitFor,\r\n  createDeferred,\r\n  captureError,\r\n  mockFetch,\r\n  createAsyncSpy,\r\n  createMockEventEmitter,\r\n} from \"@aimf/testing\";\r\n\r\n// Wait for a duration\r\nawait wait(100);\r\n\r\n// Wait for a condition\r\nawait waitFor(() => someCondition, { timeout: 5000 });\r\n\r\n// Create a deferred promise\r\nconst deferred = createDeferred<string>();\r\ndeferred.resolve(\"value\");\r\nconst result = await deferred.promise;\r\n\r\n// Capture errors from async functions\r\nconst error = await captureError(async () => {\r\n  throw new Error(\"test\");\r\n});\r\n\r\n// Mock fetch globally\r\nmockFetch(new Map([[\"https://api.example.com\", { data: \"response\" }]]));\r\n\r\n// Create async spy with call tracking\r\nconst spy = createAsyncSpy(async (x: number) => x * 2);\r\nawait spy(5);\r\nexpect(spy.calls).toEqual([[5]]);\r\n```\r\n\r\n## Setup\r\n\r\nThe package includes a global setup file that:\r\n\r\n1. Extends `expect` with custom matchers\r\n2. Stubs global `fetch`\r\n3. Clears mocks between tests\r\n4. Restores mocks after tests\r\n\r\nTo use in your vitest config:\r\n\r\n```typescript\r\n// vitest.config.ts\r\nimport { defineConfig } from \"vitest/config\";\r\n\r\nexport default defineConfig({\r\n  test: {\r\n    setupFiles: [\"@aimf/testing/dist/setup.js\"],\r\n  },\r\n});\r\n```\r\n\r\nOr use the root workspace config:\r\n\r\n```typescript\r\n// vitest.config.ts\r\nimport { defineConfig } from \"vitest/config\";\r\n\r\nexport default defineConfig({\r\n  test: {\r\n    setupFiles: [\"./packages/testing/src/setup.ts\"],\r\n  },\r\n});\r\n```\r\n\r\n## API Reference\r\n\r\n### Matchers\r\n\r\n| Matcher | Description |\r\n|---------|-------------|\r\n| `toBeVerifiedData()` | Checks for `hash` and `embedding` properties |\r\n| `toBeValidNcpMessage()` | Validates JSON-RPC 2.0 message structure |\r\n| `toHaveNeuralHash()` | Checks for 64-character hex `neuralHash` property |\r\n| `toMatchNcpSchema(schema)` | Validates object against JSON schema |\r\n\r\n### NCP Mocks\r\n\r\n| Function | Description |\r\n|----------|-------------|\r\n| `createMockNcpClient()` | Mock NCP client with all methods |\r\n| `createMockNcpServer()` | Mock NCP server with tool/resource registration |\r\n| `createMockNcpTransport()` | Mock transport layer |\r\n| `createMockNcpRequest(method, params?)` | Create mock request |\r\n| `createMockNcpResponse(id, result)` | Create mock response |\r\n| `createMockNcpError(id, code, message)` | Create mock error response |\r\n\r\n### Storage Mocks\r\n\r\n| Function | Description |\r\n|----------|-------------|\r\n| `createMockNeuralStorage()` | Full neural storage mock |\r\n| `createMockEmbeddingProvider()` | Mock embedding generation |\r\n| `createMockVectorDB()` | Mock vector database |\r\n| `createMockHashProvider()` | Mock hash calculation |\r\n\r\n### Fixtures\r\n\r\n| Function | Description |\r\n|----------|-------------|\r\n| `createUserFixture(overrides?)` | User data fixture |\r\n| `createDataFixture(overrides?)` | Neural data fixture |\r\n| `createToolFixture(overrides?)` | Tool definition fixture |\r\n| `createResourceFixture(overrides?)` | Resource definition fixture |\r\n| `createPromptFixture(overrides?)` | Prompt definition fixture |\r\n| `createManifestFixture(overrides?)` | Neural manifest fixture |\r\n| `createNcpRequestFixture(method, params?)` | NCP request fixture |\r\n| `createNcpResponseFixture(id, result)` | NCP response fixture |\r\n\r\n### Utilities\r\n\r\n| Function | Description |\r\n|----------|-------------|\r\n| `wait(ms)` | Wait for specified milliseconds |\r\n| `waitFor(condition, options?)` | Wait for condition to be true |\r\n| `createDeferred<T>()` | Create a deferred promise |\r\n| `captureError(fn)` | Capture error from async function |\r\n| `mockFetch(responses)` | Mock global fetch |\r\n| `createMockFetchResponse(data, options?)` | Create mock Response object |\r\n| `createAsyncSpy(impl?)` | Create spy with call tracking |\r\n| `createMockEventEmitter()` | Create mock event emitter |\r\n| `retryWithBackoff(fn, options?)` | Retry with exponential backoff |\r\n\r\n## Integration Testing\r\n\r\nThe testing package provides comprehensive integration testing utilities for testing with real services.\r\n\r\n### Running Integration Tests\r\n\r\n```bash\r\n# Run integration tests (requires Docker)\r\npnpm test:integration\r\n\r\n# Watch mode\r\npnpm test:integration:watch\r\n```\r\n\r\n### Container Management\r\n\r\nAutomatically manage Docker containers for testing:\r\n\r\n```typescript\r\nimport { TestContainerManager } from \"@aimf/testing\";\r\n\r\n// Get container manager instance\r\nconst containers = TestContainerManager.getInstance();\r\n\r\n// Start all containers (Qdrant, Redis)\r\nawait containers.startAll();\r\n\r\n// Get container info\r\nconst qdrant = containers.getContainer(\"qdrant\");\r\nconsole.log(qdrant?.url); // http://localhost:6333\r\n\r\n// Stop all containers\r\nawait containers.stopAll();\r\n```\r\n\r\n### Integration Test Context\r\n\r\nManage shared test resources:\r\n\r\n```typescript\r\nimport {\r\n  IntegrationTestContext,\r\n  createIntegrationContext,\r\n  useIntegrationTest,\r\n} from \"@aimf/testing\";\r\n\r\n// Using the hook pattern\r\ndescribe(\"My Integration Tests\", () => {\r\n  const { getContext } = useIntegrationTest();\r\n\r\n  it(\"should use shared context\", async () => {\r\n    const ctx = getContext();\r\n    await ctx.getDatabase(\"qdrant\").seed([/* data */]);\r\n  });\r\n});\r\n\r\n// Manual setup\r\nconst context = createIntegrationContext({\r\n  qdrantUrl: \"http://localhost:6333\",\r\n  redisUrl: \"redis://localhost:6379\",\r\n});\r\nawait context.setup();\r\n// ... run tests\r\nawait context.teardown();\r\n```\r\n\r\n### NCP Integration Helpers\r\n\r\nTest NCP clients and servers with real HTTP connections:\r\n\r\n```typescript\r\nimport {\r\n  createTestNcpServer,\r\n  createTestNcpClient,\r\n  createNcpTestScenario,\r\n} from \"@aimf/testing\";\r\n\r\n// Create a test server\r\nconst server = await createTestNcpServer(3999);\r\n\r\n// Register tools\r\nserver.registerTool(\"echo\", async (args) => ({ echoed: args }));\r\nserver.registerResource(\"aimf://config\", async () => ({ version: \"1.0\" }));\r\n\r\n// Start the server\r\nawait server.start();\r\n\r\n// Create a client\r\nconst client = await createTestNcpClient(server.url);\r\n\r\n// Make calls\r\nconst result = await client.callTool(\"echo\", { message: \"hello\" });\r\n\r\n// Build test scenarios\r\nconst scenario = createNcpTestScenario(\"multi-step\")\r\n  .callTool(\"echo\", { step: 1 })\r\n  .assertResult((r) => r.echoed?.step === 1)\r\n  .wait(100)\r\n  .callTool(\"echo\", { step: 2 });\r\n\r\nawait scenario.run(client);\r\n\r\n// Cleanup\r\nawait client.close();\r\nawait server.stop();\r\n```\r\n\r\n### Vector Database Helpers\r\n\r\nTest vector database operations:\r\n\r\n```typescript\r\nimport {\r\n  createVectorDBClient,\r\n  createMockVectorDBClient,\r\n  createTestVectors,\r\n  seedVectorDB,\r\n  cosineSimilarity,\r\n} from \"@aimf/testing\";\r\n\r\n// Create real client (falls back to mock if unavailable)\r\nconst client = createVectorDBClient({\r\n  url: \"http://localhost:6333\",\r\n  fallbackToMock: true,\r\n});\r\nawait client.connect();\r\n\r\n// Create collection\r\nawait client.createCollection(\"test_collection\", 128);\r\n\r\n// Generate test vectors\r\nconst vectors = createTestVectors(100, 128);\r\nawait seedVectorDB(client, \"test_collection\", vectors);\r\n\r\n// Search\r\nconst results = await client.search(\r\n  \"test_collection\",\r\n  vectors[0].vector,\r\n  5\r\n);\r\n\r\n// Calculate similarity\r\nconst similarity = cosineSimilarity(vectors[0].vector, vectors[1].vector);\r\n\r\n// Cleanup\r\nawait client.deleteCollection(\"test_collection\");\r\nawait client.disconnect();\r\n```\r\n\r\n### Integration Test Configuration\r\n\r\nConfigure integration tests in `vitest.integration.config.ts`:\r\n\r\n```typescript\r\nimport { defineConfig } from \"vitest/config\";\r\n\r\nexport default defineConfig({\r\n  test: {\r\n    globals: true,\r\n    include: [\"src/integration/**/*.test.ts\"],\r\n    globalSetup: \"./src/integration/global-setup.ts\",\r\n    globalTeardown: \"./src/integration/global-teardown.ts\",\r\n    testTimeout: 30000,\r\n    hookTimeout: 60000,\r\n  },\r\n});\r\n```\r\n\r\n## License\r\n\r\nMIT\r\n","readmeFilename":"README.md"}