50 lines
1.5 KiB
TypeScript
50 lines
1.5 KiB
TypeScript
import { describe, expect, it } from 'bun:test';
|
|
import { __pdfValidationInternals } from '@/lib/server/taxonomy/pdf-validation';
|
|
|
|
describe('pdf metric validation internals', () => {
|
|
it('parses fenced json payloads and rejects invalid payloads', () => {
|
|
const parsed = __pdfValidationInternals.parseValidationPayload([
|
|
'```json',
|
|
'{"revenue":{"value":1000,"pages":[3]},"cash":{"value":200,"pages":["4"]}}',
|
|
'```'
|
|
].join('\n'));
|
|
|
|
expect(parsed).not.toBeNull();
|
|
expect(parsed?.revenue?.value).toBe(1000);
|
|
expect(parsed?.cash?.pages).toEqual(['4']);
|
|
expect(__pdfValidationInternals.parseValidationPayload('not-json')).toBeNull();
|
|
});
|
|
|
|
it('compares taxonomy vs llm values with fixed tolerance rules', () => {
|
|
expect(__pdfValidationInternals.diffStatus(1000, 1004)).toEqual({
|
|
status: 'matched',
|
|
absoluteDiff: 4,
|
|
relativeDiff: 0.004
|
|
});
|
|
|
|
expect(__pdfValidationInternals.diffStatus(1000, 1007)).toEqual({
|
|
status: 'mismatch',
|
|
absoluteDiff: 7,
|
|
relativeDiff: 0.007
|
|
});
|
|
|
|
expect(__pdfValidationInternals.diffStatus(0.5, 1.2)).toEqual({
|
|
status: 'matched',
|
|
absoluteDiff: 0.7,
|
|
relativeDiff: 0.7
|
|
});
|
|
|
|
expect(__pdfValidationInternals.diffStatus(null, 1)).toEqual({
|
|
status: 'mismatch',
|
|
absoluteDiff: null,
|
|
relativeDiff: null
|
|
});
|
|
|
|
expect(__pdfValidationInternals.diffStatus(null, null)).toEqual({
|
|
status: 'not_run',
|
|
absoluteDiff: null,
|
|
relativeDiff: null
|
|
});
|
|
});
|
|
});
|