// tests/hash.test.js const { hashEvent, hashChain, sha256Async } = require('../lib/hash.js'); describe('Hash', () => { test('hashEvent returns consistent hash', () => { const event = { id: 'e1', type: 'tool_use' }; const h1 = hashEvent(event); const h2 = hashEvent(event); expect(h1).toBe(h2); expect(h1.length).toBeGreaterThan(0); }); test('hashEvent returns different hash for different events', () => { const h1 = hashEvent({ id: 'e1', type: 'tool_use' }); const h2 = hashEvent({ id: 'e2', type: 'api_call' }); expect(h1).not.toBe(h2); }); test('hashChain returns empty for empty array', () => { expect(hashChain([])).toBe(''); }); test('hashChain returns hash for events', () => { const chain = hashChain([{ id: 'e1' }, { id: 'e2' }]); expect(chain.length).toBeGreaterThan(0); }); test('hashChain is order-sensitive', () => { const chain1 = hashChain([{ id: 'e1' }, { id: 'e2' }]); const chain2 = hashChain([{ id: 'e2' }, { id: 'e1' }]); expect(chain1).not.toBe(chain2); }); test('sha256Async returns hex string', async () => { const hash = await sha256Async('hello'); expect(hash).toMatch(/^[a-f0-9]{64}$/); }); });