Loading AGEI...
How to run and write tests for the CIAF-LCM system
cd ui # Install dependencies (if not already done) npm install # Run all tests npm test # Run tests in watch mode (recommended for development) npm test:watch # Run tests with coverage report npm test:coverage
ui/lib/api/__tests__/ ├── canonicalization.test.ts # Hashing and canonicalization ├── signatures.test.ts # Digital signatures └── integration.test.ts # Full workflows
Canonicalization & Signature Tests
Canonicalization Tests
Signature Tests
End-to-end workflow testing
Receipt Creation and Verification
Vault Object Sealing
Lineage Chains
Audit Pack Assembly
npm test
Output:
PASS lib/api/__tests__/canonicalization.test.ts
Canonicalization
✓ should produce deterministic output (3 ms)
✓ should sort object keys (2 ms)
✓ should handle nested objects (1 ms)
✓ should preserve array order (1 ms)
✓ should handle Unicode characters (2 ms)
PASS lib/api/__tests__/signatures.test.ts
Digital Signatures
✓ should generate Ed25519 key pair (45 ms)
✓ should sign and verify payload (12 ms)
✓ should detect tampering (8 ms)
Test Suites: 3 passed, 3 total
Tests: 24 passed, 24 total
Snapshots: 0 total
Time: 2.456 sAutomatically re-run tests on file changes
npm test:watch
npm test:coverage
Output:
---------------------------|---------|----------|---------|---------| File | % Stmts | % Branch | % Funcs | % Lines | ---------------------------|---------|----------|---------|---------| All files | 94.23 | 91.67 | 96.15 | 94.12 | canonicalization.ts | 96.77 | 93.75 | 100.00 | 96.67 | signatures.ts | 92.31 | 90.00 | 93.33 | 92.00 | ---------------------------|---------|----------|---------|---------|
Test structure and best practices
import { describe, it, expect } from '@jest/globals'
import { canonicalizePayload, hashPayload, verifyHash } from '../canonicalization'
describe('Canonicalization', () => {
it('should produce deterministic output', () => {
const payload = { z: 1, a: 2, m: 3 }
const canonical1 = canonicalizePayload(payload)
const canonical2 = canonicalizePayload(payload)
expect(canonical1).toBe(canonical2)
expect(canonical1).toBe('{"a":2,"m":3,"z":1}')
})
it('should generate consistent hashes', () => {
const payload = { model: 'gpt-4', version: '1.0' }
const hash1 = hashPayload(payload)
const hash2 = hashPayload(payload)
expect(hash1).toBe(hash2)
expect(hash1).toMatch(/^[a-f0-9]{64}$/) // SHA-256 hex
})
it('should verify hashes correctly', () => {
const payload = { accuracy: 0.97 }
const hash = hashPayload(payload)
expect(verifyHash(payload, hash)).toBe(true)
expect(verifyHash({ accuracy: 0.96 }, hash)).toBe(false)
})
})