Testing Strategy
Relevant source files
The following files were used as context for generating this wiki page:
e-zer0 employs a comprehensive testing strategy focused on verifying secure bridges between AI agents and email providers. The strategy prioritizes the verification of PII redaction, prompt injection protection, audit logging, and correct Model Context Protocol (MCP) tool behavior. Tests run using mocked services to avoid requiring live Cloudflare credentials or connected mailboxes during the verification process.
Sources: CONTRIBUTING.md:28-30, AGENTS.md:73-77
Core Framework and Execution
The project uses Vitest as the primary testing framework. Test files reside alongside the source files they verify (e.g., src/lib/crypto.test.ts). Developers execute the full quality gate, which includes formatting, linting, and testing, via a unified command.
| Task | Command | Description |
|---|---|---|
| Quality Gate | npm run check | Runs Prettier, TypeScript type-checking, and Vitest. |
| Test Execution | npm run test | Runs the Vitest suite once. |
| Watch Mode | npm run test:watch | Runs Vitest in interactive watch mode. |
Sources: CLAUDE.md:7-14, AGENTS.md:79-84, package.json:15-18
Test Categories and Logic
1. Security and Sanitization Verification
Tests verify that the sanitizer.ts logic correctly identifies and redacts Personal Identifiable Information (PII) and detects malicious prompt injections.
- PII Redaction: Verifies detection of credit cards, CVV codes, SSNs, API keys (AWS, OpenAI, GitHub), and private keys.
- Injection Detection: Scans for patterns like "ignore previous instructions", "you are now" role manipulation, and data exfiltration URLs.
- Risk Scoring: Ensures the system calculates appropriate risk scores and adds safety warnings for high-risk content.
Sources: src/lib/sanitizer.test.ts:24-150, AGENTS.md:65-68
2. MCP Server and Tool Verification
Tests ensure the MCP server correctly advertises tool metadata and enforces security constraints.
- Annotation Checks: Verifies that every tool correctly reports its
readOnlyHintanddestructiveHintstatus. - Grant Enforcement: Confirms that the server rejects requests if an agent lacks specific mailbox or calendar permissions.
- Audit Verification: Ensures every tool execution (success or failure) triggers a call to
logAudit.
Sources: src/mcp/server.test.ts:10-53, AGENTS.md:95-99
3. Provider API Mocking
Integration tests for Google and Microsoft services use mocked global fetch responses to simulate API behavior, including pagination and error states.
4. Cryptographic Integrity
Tests for src/lib/crypto.ts verify the implementation of AES-256-GCM encryption and PBKDF2 password hashing using the Web Crypto API.
- Round-trip Verification: Ensures plaintext can be encrypted and successfully decrypted with the same key.
- Collision Resistance: Verifies that unique salts and tokens are generated for every call.
- Error Handling: Confirms that decryption fails when provided with incorrect keys or malformed hex strings.
Sources: src/lib/crypto.test.ts:85-132, AGENTS.md:53-55
Data Flow Verification
The testing strategy validates the flow of data from raw provider responses through the sanitization layer before reaching the MCP client.
Transport and Network Testing
The strategy includes verifying the Hono application's routing and MCP transport layer.
- SSE Validation: Ensures that Server-Sent Events (SSE) endpoints only accept POST requests and correctly reject GET probes.
- Stream Management: Verifies that cancelling a response stream results in correct logging (
mcp_response_stream_cancelled) without reporting a failure to the user. - Health Checks: Confirms that the
/healthendpoint operates independently of database or authentication state.
Sources: src/routes/mcp-transport.test.ts:13-75
Summary
e-zer0's testing strategy ensures a "Security First" approach by mandating mocked environments for all provider integrations and rigorous validation of redaction logic. By running npm run check, developers verify that every change maintains the integrity of the audit trail, cryptographic protections, and MCP tool schemas.
Sources: AGENTS.md:60-63, CONTRIBUTING.md:31-35