Spaces:
Sleeping
Sleeping
Download backend/tests/unit/tabularExtractionTrace.test.ts from bardd/mike-backend: direct link, hf CLI and curl.
- Browser
- Download file 3.43 kB
-
https://huggingface.co/spaces/bardd/mike-backend/resolve/main/backend/tests/unit/tabularExtractionTrace.test.ts
- Command line
-
hf download hf://spaces/bardd/mike-backend/backend/tests/unit/tabularExtractionTrace.test.ts
-
curl -L -o tabularExtractionTrace.test.ts https://huggingface.co/spaces/bardd/mike-backend/resolve/main/backend/tests/unit/tabularExtractionTrace.test.ts
3.43 kB
| import { describe, it } from "node:test"; | |
| import assert from "node:assert"; | |
| import { | |
| buildColumnsSchema, | |
| buildColumnsRequested, | |
| buildDocumentTraceSummary, | |
| buildTraceCellEntry, | |
| truncateForTrace, | |
| } from "../../src/lib/tabularExtractionTrace"; | |
| describe("tabularExtractionTrace", () => { | |
| const sampleCol = { | |
| index: 2, | |
| name: "Price Escalation", | |
| prompt: "Extract the price escalation mechanism from the document.", | |
| format: "short answer", | |
| tags: ["pricing"], | |
| }; | |
| it("truncateForTrace leaves short strings unchanged", () => { | |
| assert.strictEqual(truncateForTrace("hello"), "hello"); | |
| }); | |
| it("truncateForTrace caps long strings", () => { | |
| const long = "x".repeat(2500); | |
| const out = truncateForTrace(long, 2000); | |
| assert.ok(out.endsWith("…[truncated]")); | |
| assert.strictEqual(out.length, 2000 + "…[truncated]".length); | |
| }); | |
| it("buildColumnsSchema maps and truncates column prompts", () => { | |
| const schema = buildColumnsSchema([sampleCol]); | |
| assert.strictEqual(schema.length, 1); | |
| assert.strictEqual(schema[0].index, 2); | |
| assert.strictEqual(schema[0].name, "Price Escalation"); | |
| assert.ok(schema[0].prompt.includes("price escalation")); | |
| assert.strictEqual(schema[0].format, "short answer"); | |
| assert.deepStrictEqual(schema[0].tags, ["pricing"]); | |
| }); | |
| it("buildTraceCellEntry for done cell includes extracted values", () => { | |
| const cell = buildTraceCellEntry(sampleCol, "done", { | |
| summary: "Fixed 3% annual increase", | |
| flag: "green", | |
| reasoning: "Found in section 4.", | |
| }); | |
| assert.strictEqual(cell.status, "done"); | |
| assert.strictEqual(cell.column_index, 2); | |
| assert.strictEqual(cell.column_name, "Price Escalation"); | |
| assert.ok(cell.column_prompt.includes("price escalation")); | |
| assert.strictEqual(cell.extracted?.flag, "green"); | |
| assert.strictEqual(cell.extracted?.summary, "Fixed 3% annual increase"); | |
| assert.strictEqual(cell.error_reason, undefined); | |
| }); | |
| it("buildTraceCellEntry for error cell has null extracted", () => { | |
| const cell = buildTraceCellEntry( | |
| sampleCol, | |
| "error", | |
| null, | |
| "no_output", | |
| ); | |
| assert.strictEqual(cell.status, "error"); | |
| assert.strictEqual(cell.error_reason, "no_output"); | |
| assert.strictEqual(cell.extracted, null); | |
| }); | |
| it("buildDocumentTraceSummary counts done and failed cells", () => { | |
| const done = buildTraceCellEntry(sampleCol, "done", { | |
| summary: "x", | |
| flag: "grey", | |
| reasoning: "", | |
| }); | |
| const failed = buildTraceCellEntry(sampleCol, "error", null, "no_output"); | |
| const summary = buildDocumentTraceSummary({ | |
| documentId: "doc-1", | |
| filename: "contract.pdf", | |
| cells: [done, failed], | |
| llmFinishReason: "length", | |
| }); | |
| assert.strictEqual(summary.cells_done, 1); | |
| assert.strictEqual(summary.cells_failed, 1); | |
| assert.strictEqual(summary.llm_finish_reason, "length"); | |
| }); | |
| it("buildColumnsRequested returns index and name pairs", () => { | |
| assert.deepStrictEqual(buildColumnsRequested([sampleCol]), [ | |
| { index: 2, name: "Price Escalation" }, | |
| ]); | |
| }); | |
| }); | |