Spaces:
Sleeping
Sleeping
Download backend/src/lib/langsmith.test.ts from bardd/mike-backend: direct link, hf CLI and curl.
- Browser
- Download file 2.46 kB
-
https://huggingface.co/spaces/bardd/mike-backend/resolve/main/backend/src/lib/langsmith.test.ts
- Command line
-
hf download hf://spaces/bardd/mike-backend/backend/src/lib/langsmith.test.ts
-
curl -L -o langsmith.test.ts https://huggingface.co/spaces/bardd/mike-backend/resolve/main/backend/src/lib/langsmith.test.ts
2.46 kB
| // @ts-ignore vitest is not installed locally but provided by npx vitest at test time | |
| import { describe, it, expect } from "vitest"; | |
| import { | |
| sha256, | |
| chunkSurfaceForTrace, | |
| buildDocumentSurfaceTracePayload, | |
| } from "./langsmith"; | |
| describe("LangSmith surface trace helpers", () => { | |
| it("sha256 produces consistent hex hashes", () => { | |
| expect(sha256("hello")).toMatch(/^[a-f0-9]{64}$/); | |
| expect(sha256("hello")).toBe(sha256("hello")); | |
| expect(sha256("hello")).not.toBe(sha256("world")); | |
| }); | |
| it("chunkSurfaceForTrace splits text into ordered chunks", () => { | |
| const text = "a".repeat(40000); | |
| const chunks = chunkSurfaceForTrace(text); | |
| expect(chunks.length).toBeGreaterThan(1); | |
| expect(chunks[0].start).toBe(0); | |
| expect(chunks[chunks.length - 1].end).toBe(text.length); | |
| // Verify continuity | |
| for (let i = 1; i < chunks.length; i++) { | |
| expect(chunks[i].start).toBe(chunks[i - 1].end); | |
| } | |
| }); | |
| it("buildDocumentSurfaceTracePayload includes all required fields", () => { | |
| const text = `[[P_0001 type=paragraph container=body chars=10]]\nHello world.\n[[P_0002 type=paragraph container=body chars=5]]\nTest.`; | |
| const payload = buildDocumentSurfaceTracePayload({ | |
| docLabel: "doc-0", | |
| documentId: "db-id-123", | |
| filename: "Test.docx", | |
| surfaceId: "surf-abc", | |
| text, | |
| }); | |
| expect(payload.doc_id).toBe("doc-0"); | |
| expect(payload.document_id).toBe("db-id-123"); | |
| expect(payload.filename).toBe("Test.docx"); | |
| expect(payload.surface_id).toBe("surf-abc"); | |
| expect(payload.block_count).toBe(2); | |
| expect(payload.char_count).toBe(text.length); | |
| expect(payload.surface_sha256).toBe(sha256(text)); | |
| expect(Array.isArray(payload.surface_chunks)).toBe(true); | |
| expect(payload.chunks_count).toBe((payload.surface_chunks as any[]).length); | |
| }); | |
| it("buildDocumentSurfaceTracePayload counts BMK_ bookmark blocks", () => { | |
| const text = `[[BMK_P_a3x7k type=paragraph container=body chars=10]]\nHello world.\n[[BMK_T_b4m2n type=paragraph container=table_cell chars=5]]\nTest.\n[[P_0003 type=paragraph container=body chars=8]]\nAnother.`; | |
| const payload = buildDocumentSurfaceTracePayload({ | |
| docLabel: "doc-1", | |
| text, | |
| }); | |
| expect(payload.block_count).toBe(3); | |
| }); | |
| }); | |