Files
puaros/packages/ipuaro/tests/unit/shared/utils/hash.test.ts
imfozilbek 130a8c4f24 feat(ipuaro): implement v0.1.0 foundation
- Project setup with tsup, vitest, ESM support
- Domain entities: Session, Project
- Value objects: FileData, FileAST, FileMeta, ChatMessage, ToolCall, ToolResult, UndoEntry
- Service interfaces: IStorage, ILLMClient, ITool, IIndexer, IToolRegistry
- Shared: Config (zod), IpuaroError, utils (hash, tokens), Result type
- CLI with placeholder commands (start, init, index)
- 91 unit tests with 100% coverage
- Fix package scope @puaros -> @samiyev in CLAUDE.md
2025-11-29 23:08:38 +05:00

57 lines
1.5 KiB
TypeScript

import { describe, it, expect } from "vitest"
import { md5, hashLines, shortHash } from "../../../../src/shared/utils/hash.js"
describe("hash utils", () => {
describe("md5", () => {
it("should return consistent hash for same input", () => {
const hash1 = md5("hello")
const hash2 = md5("hello")
expect(hash1).toBe(hash2)
})
it("should return different hash for different input", () => {
const hash1 = md5("hello")
const hash2 = md5("world")
expect(hash1).not.toBe(hash2)
})
it("should return 32 character hex string", () => {
const hash = md5("test")
expect(hash).toHaveLength(32)
expect(hash).toMatch(/^[a-f0-9]+$/)
})
})
describe("hashLines", () => {
it("should hash joined lines", () => {
const lines = ["line1", "line2", "line3"]
const hash = hashLines(lines)
expect(hash).toBe(md5("line1\nline2\nline3"))
})
it("should handle empty array", () => {
const hash = hashLines([])
expect(hash).toBe(md5(""))
})
})
describe("shortHash", () => {
it("should return truncated hash", () => {
const hash = shortHash("test")
expect(hash).toHaveLength(8)
})
it("should accept custom length", () => {
const hash = shortHash("test", 12)
expect(hash).toHaveLength(12)
})
})
})