proofchain/packages/agent/test/checks-origin.test.ts
caelum0x bac8f9e662 feat: Wave C+D — agent multi-skill verification engine + infra data layer
- agent: 6 auto-collecting registries (parsers/checks/risk/scoring/tools/pipelines);
  15 doc parsers, 12 check packs, 6 risk models, scoring dimensions + reconciler,
  ~15 Claude tools, 8 pipelines (financing/underwriting/dpp/compliance/grading/esg) + routes; 380 tests
- infra: BaseRepository + ~35 typed repositories, 56 composed schema modules,
  storage/queue/notifications/cache/events adapters; 203 tests
- pnpm -r typecheck/build/test all green

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-31 23:48:46 +03:00

68 lines
2.1 KiB
TypeScript

import { describe, expect, it } from 'vitest';
import { ORIGIN_CHECKS } from '../src/checks/origin.js';
import { checkRegistry } from '../src/checks/index.js';
import { sampleProvenance, invoiceDoc } from './helpers.js';
import { makeDoc, runPack, codesOf, cleanInput } from './checks-support.js';
describe('origin cross-check pack', () => {
it('registers its checks', () => {
for (const c of ORIGIN_CHECKS) expect(checkRegistry.has(c.code)).toBe(true);
});
it('is silent when no certificate of origin is present', () => {
expect(runPack(ORIGIN_CHECKS, cleanInput())).toHaveLength(0);
});
it('flags a supplier mismatch between certificate and invoice', () => {
const input = {
provenance: sampleProvenance(),
documents: [
invoiceDoc({ fields: { supplierName: 'Acme' } }),
makeDoc('certificate_of_origin', { supplierName: 'Globex' }),
],
};
expect(codesOf(runPack(ORIGIN_CHECKS, input))).toContain(
'ORIGIN_SUPPLIER_MISMATCH',
);
});
it('flags a certificate that identifies no producer', () => {
const input = {
provenance: sampleProvenance(),
documents: [makeDoc('certificate_of_origin', {})],
};
expect(codesOf(runPack(ORIGIN_CHECKS, input))).toContain(
'ORIGIN_CERT_INCOMPLETE',
);
});
it('flags a certificate dated before the batch', () => {
const input = {
provenance: sampleProvenance(),
documents: [
makeDoc('certificate_of_origin', {
supplierName: 'Acme',
date: '2000-01-01T00:00:00.000Z',
}),
],
};
expect(codesOf(runPack(ORIGIN_CHECKS, input))).toContain(
'ORIGIN_CERT_PREDATES_BATCH',
);
});
it('accepts a consistent certificate', () => {
const input = {
provenance: sampleProvenance(),
documents: [
invoiceDoc({ fields: { supplierName: 'Acme' } }),
makeDoc('certificate_of_origin', {
supplierName: 'Acme',
date: '2024-01-01T00:00:00.000Z',
}),
],
};
expect(runPack(ORIGIN_CHECKS, input)).toHaveLength(0);
});
});