Files
fil/e2e/node/tests/batch.test.ts
Henrik Jess Nielsen b4c07d3693
All checks were successful
Deploy fil (kreuzberg) / deploy (push) Successful in 49s
Nomad changes
2026-06-01 23:40:55 +02:00

63 lines
4.2 KiB
TypeScript
Generated

// This file is auto-generated by alef — DO NOT EDIT.
// alef:hash:4e15143f4af1ae8bafbdb1506ef057da924484c66a19483966333558ad437e75
// To regenerate: alef generate
// To verify freshness: alef verify --exit-code
// Issues & docs: https://github.com/kreuzberg-dev/alef
import { describe, expect, it } from 'vitest';import { extractFile, batchExtractBytesSync, batchExtractBytes, batchExtractFiles, batchExtractFilesSync, BatchBytesItem, BatchFileItem, type ExtractionConfig } from '@kreuzberg/node';
function _alefE2eText(value: unknown): string {
return value == null ? "" : String(value);
}
function _alefE2eItemTexts(item: unknown): string[] {
if (item == null || typeof item !== "object") {
return [_alefE2eText(item)];
}
const record = item as Record<string, unknown>;
const itemsText = Array.isArray(record.items) ? record.items.map(_alefE2eText).join(" ") : "";
return [_alefE2eText(item), _alefE2eText(record.kind), _alefE2eText(record.name), _alefE2eText(record.source), _alefE2eText(record.alias), _alefE2eText(record.text), _alefE2eText(record.signature), itemsText];
}
function _alefE2eFormatMetadataDisplay(fm: unknown): string {
if (fm == null) return "";
if (typeof fm !== "object") return String(fm);
const record = fm as Record<string, unknown>;
const formatType = record.format_type;
// FormatMetadata is a tagged union: { format_type: 'image', image: { format: 'PNG', ... }, ... }
// Extract the display string based on the variant type
if (formatType === "image" && typeof record.image === "object") {
const imageData = record.image as Record<string, unknown>;
if (typeof imageData.format === "string") return imageData.format;
}
// Fallback: return format_type variant name
if (typeof record.format_type === "string") return record.format_type;
return "";
}
describe('batch', () => { it('batch_bytes_invalid_mime: batch_extract_bytes_sync invalid MIME', () => { batchExtractBytesSync([{ content: new Uint8Array([72, 101, 108, 108, 111]), mimeType: "application/x-nonexistent" }], undefined);
}, 30000);
it('batch_extract_bytes_happy: batch_extract_bytes: happy path with mixed inputs', async () => { const result = await batchExtractBytes([{ content: new Uint8Array([72, 101, 108, 108, 111, 44, 32, 119, 111, 114, 108, 100, 33]), mimeType: "text/plain" }, { content: new Uint8Array([60, 104, 116, 109, 108, 62, 60, 98, 111, 100, 121, 62, 84, 101, 115, 116, 60, 47, 98, 111, 100, 121, 62, 60, 47, 104, 116, 109, 108, 62]), mimeType: "text/html" }], undefined); expect(result.length).toBeGreaterThanOrEqual(1);
}, 30000);
it('batch_extract_bytes_mixed_format: batch_extract_bytes: handles unsupported MIME gracefully', async () => { await batchExtractBytes([{ content: new Uint8Array([80, 68, 70, 32, 112, 108, 97, 99, 101, 104, 111, 108, 100, 101, 114]), mimeType: "application/x-unknown" }], undefined);
}, 30000);
it('batch_extract_bytes_sync_empty_list: batch_extract_bytes_sync: empty batch', () => { const result = batchExtractBytesSync([], undefined); expect(result.length).toBe(0);
}, 30000);
it('batch_extract_bytes_sync_invalid_mime: batch_extract_bytes_sync: unsupported MIME', () => { batchExtractBytesSync([{ content: new Uint8Array([100, 97, 116, 97]), mimeType: "application/x-unknown" }], undefined);
}, 30000);
it('batch_file_async_basic: Extract text from multiple files asynchronously', async () => { await batchExtractFiles([{ path: "pdf/fake_memo.pdf" }, { path: "text/fake_text.txt" }], undefined);
}, 30000);
it('batch_file_async_not_found: batch_extract_file async nonexistent', async () => { await batchExtractFiles([{ path: "/nonexistent/a.pdf" }], undefined);
}, 30000);
it('batch_file_not_found: batch_extract_file_sync nonexistent', () => { batchExtractFilesSync([{ path: "/nonexistent/a.pdf" }, { path: "/nonexistent/b.txt" }], undefined);
}, 30000);
it('batch_file_partial: batch_extract_file_sync mixed', () => { batchExtractFilesSync([{ path: "text/plain.txt" }, { path: "/nonexistent/missing.pdf" }], undefined);
}, 30000);
it('batch_file_sync_basic: Extract text from multiple files synchronously', () => { batchExtractFilesSync([{ path: "pdf/fake_memo.pdf" }, { path: "text/fake_text.txt" }], undefined);
}, 30000);
});