Files
mcp/tests/error.test.ts
781dbd002f feat: absorb @zap-proto/zap v1.0.1 implementation as @zap-proto/mcp v1.0.0 (#1)
* feat: ZAP JavaScript/TypeScript bindings v0.2.1

JavaScript/TypeScript client library for ZAP (Zero-Copy App Proto).
- Full ZAP protocol support (tools, resources, prompts)
- MCP Gateway bridging
- Post-quantum cryptography (ML-KEM, ML-DSA)
- W3C DID support
- Lux consensus integration

* feat: add documentation site using @hanzo/docs framework

- Next.js 14 docs site in docs/ directory
- Package.json with @hanzo/ui and @hanzo/docs dependencies
- GitHub Actions workflow for deployment to GitHub Pages
- Documentation pages covering:
  - Installation and Quick Start
  - Client API, Gateway, Server
  - TypeScript Types and Configuration
  - Error Handling and Identity/DIDs
  - Browser and Node.js usage guides
  - Code examples and patterns
- Configured basePath '/zap-js' for GitHub Pages
- Uses pnpm and Node 22

* fix: docs build - remove unused @hanzo/docs, upgrade to Next.js 15

- Remove @hanzo/docs and @hanzo/ui dependencies (not actually used)
- Upgrade to Next.js 15 and React 19 for next.config.ts support
- Rename postcss.config.js to postcss.config.cjs for ESM compatibility
- Add pnpm-lock.yaml for reproducible builds

* rebrand: Cap'n Proto → ZAP

Update all documentation to use ZAP branding instead of Cap'n Proto.

* chore: update to Node 22 and latest packages

- Node.js 22 in CI workflow
- fumadocs-core/ui v15
- next v15.1
- react v19
- Consistent workflow across all repos

* fix: revert to fumadocs v14 for compatibility

* fix: update metadata description to use ZAP branding

* chore: rename package to @zap-proto/zap

- Change npm package name from @hanzo/zap to @zap-proto/zap
- Update repository URL to zap-protocol org
- Update homepage to zap-protocol.github.io
- Update keywords and author

* feat: add transport layer and gateway improvements

- Add server transport abstraction
- Add crypto, gateway, and protocol tests
- Update client/server implementations
- Add CI workflow configuration
- Update vitest config with coverage thresholds

* feat: add .zap test schema for native ZAP format testing

* feat: add ZAP-format schema

Convert zap.capnp to proper whitespace-based .zap syntax

* chore: brand-neutral cleanup — remove cross-tenant references

* docs(readme): add canonical link → zap-proto.dev/docs

* docs(readme): also link Native ZAP RPC guide

* test(pqrns): import canonical KAT fixture

* test(pqrns): DID KAT — must match Go reference at zap-proto/rns

* chore: depend on @zap-proto/zap ^1.1.0 (foundation rolled back from premature v2.0.0)

* chore: pin @zap-proto/zap to ^0.1.0 (foundation reset to pre-1.0)

The @zap-proto/zap foundation was reset to v0.1.0 — native ZAP wire
runtime, no Cap'n Proto. Match the pre-1.0 line; no tags until 1.0
works end-to-end across @zap-proto/{zap,web,mcp}.

* chore: depend on @zap-proto/zap ^1.1.0

@zap-proto/zap is published at 1.1.0 (native ZAP wire runtime, back in
the 1.x line). Point the runtime dep at it instead of the pre-publish
^0.1.0. Lockfiles (npm + pnpm) regenerated; 105 tests still pass.

---------

Co-authored-by: Hanzo Dev <[email protected]>
Co-authored-by: z <[email protected]>
2026-06-15 19:46:01 -07:00

166 lines
4.7 KiB
TypeScript

import { describe, it, expect } from 'vitest';
import {
ZapError,
ConnectionError,
TransportError,
ProtocolError,
TimeoutError,
ServerError,
ToolNotFoundError,
ResourceNotFoundError,
InvalidArgumentError,
} from '../src/error.js';
describe('ZapError', () => {
it('should create a ZapError', () => {
const error = new ZapError('Something went wrong');
expect(error.message).toBe('Something went wrong');
expect(error.name).toBe('ZapError');
});
it('should be instanceof Error', () => {
const error = new ZapError('test');
expect(error).toBeInstanceOf(Error);
});
});
describe('ConnectionError', () => {
it('should create a ConnectionError', () => {
const error = new ConnectionError('Failed to connect');
expect(error.message).toBe('Failed to connect');
expect(error.name).toBe('ConnectionError');
});
it('should be instanceof ZapError', () => {
const error = new ConnectionError('test');
expect(error).toBeInstanceOf(ZapError);
});
});
describe('TransportError', () => {
it('should create a TransportError', () => {
const error = new TransportError('Transport failed');
expect(error.message).toBe('Transport failed');
expect(error.name).toBe('TransportError');
});
it('should be instanceof ZapError', () => {
const error = new TransportError('test');
expect(error).toBeInstanceOf(ZapError);
});
});
describe('ProtocolError', () => {
it('should create a ProtocolError', () => {
const error = new ProtocolError('Invalid protocol');
expect(error.message).toBe('Invalid protocol');
expect(error.name).toBe('ProtocolError');
});
it('should be instanceof ZapError', () => {
const error = new ProtocolError('test');
expect(error).toBeInstanceOf(ZapError);
});
});
describe('TimeoutError', () => {
it('should create a TimeoutError', () => {
const error = new TimeoutError('Request timed out');
expect(error.message).toBe('Request timed out');
expect(error.name).toBe('TimeoutError');
});
it('should be instanceof ZapError', () => {
const error = new TimeoutError('test');
expect(error).toBeInstanceOf(ZapError);
});
});
describe('ServerError', () => {
it('should create a ServerError', () => {
const error = new ServerError('Internal server error');
expect(error.message).toBe('Internal server error');
expect(error.name).toBe('ServerError');
});
it('should be instanceof ZapError', () => {
const error = new ServerError('test');
expect(error).toBeInstanceOf(ZapError);
});
});
describe('ToolNotFoundError', () => {
it('should create a ToolNotFoundError', () => {
const error = new ToolNotFoundError('search');
// Message includes tool name
expect(error.message).toContain('search');
expect(error.name).toBe('ToolNotFoundError');
});
it('should be instanceof ZapError', () => {
const error = new ToolNotFoundError('test');
expect(error).toBeInstanceOf(ZapError);
});
});
describe('ResourceNotFoundError', () => {
it('should create a ResourceNotFoundError', () => {
const error = new ResourceNotFoundError('config.json');
// Message includes resource name
expect(error.message).toContain('config.json');
expect(error.name).toBe('ResourceNotFoundError');
});
it('should be instanceof ZapError', () => {
const error = new ResourceNotFoundError('test');
expect(error).toBeInstanceOf(ZapError);
});
});
describe('InvalidArgumentError', () => {
it('should create an InvalidArgumentError', () => {
const error = new InvalidArgumentError('count', 'must be positive');
// Message includes argument name and reason
expect(error.message).toContain('count');
expect(error.message).toContain('must be positive');
expect(error.name).toBe('InvalidArgumentError');
});
it('should be instanceof ZapError', () => {
const error = new InvalidArgumentError('test', 'invalid');
expect(error).toBeInstanceOf(ZapError);
});
});
describe('Error inheritance chain', () => {
it('should catch specific error types', () => {
try {
throw new ConnectionError('test');
} catch (e) {
if (e instanceof ConnectionError) {
expect(true).toBe(true);
} else {
expect.fail('Should catch ConnectionError');
}
}
});
it('should catch ZapError for all error types', () => {
const errors = [
new ConnectionError('test'),
new TransportError('test'),
new ProtocolError('test'),
new TimeoutError('test'),
new ServerError('test'),
new ToolNotFoundError('test'),
new ResourceNotFoundError('test'),
new InvalidArgumentError('test', 'invalid'),
];
for (const error of errors) {
expect(error).toBeInstanceOf(ZapError);
expect(error).toBeInstanceOf(Error);
}
});
});