Implement dual-model filing pipeline with Ollama extraction
This commit is contained in:
71
lib/server/task-processors.test.ts
Normal file
71
lib/server/task-processors.test.ts
Normal file
@@ -0,0 +1,71 @@
|
||||
import { describe, expect, it } from 'bun:test';
|
||||
import type { Filing } from '@/lib/types';
|
||||
import { __taskProcessorInternals } from './task-processors';
|
||||
|
||||
function sampleFiling(): Filing {
|
||||
return {
|
||||
id: 1,
|
||||
ticker: 'AAPL',
|
||||
filing_type: '10-Q',
|
||||
filing_date: '2026-01-30',
|
||||
accession_number: '0000320193-26-000001',
|
||||
cik: '0000320193',
|
||||
company_name: 'Apple Inc.',
|
||||
filing_url: 'https://www.sec.gov/Archives/edgar/data/320193/000032019326000001/a10q.htm',
|
||||
submission_url: 'https://data.sec.gov/submissions/CIK0000320193.json',
|
||||
primary_document: 'a10q.htm',
|
||||
metrics: {
|
||||
revenue: 120_000_000_000,
|
||||
netIncome: 25_000_000_000,
|
||||
totalAssets: 410_000_000_000,
|
||||
cash: 70_000_000_000,
|
||||
debt: 98_000_000_000
|
||||
},
|
||||
analysis: null,
|
||||
created_at: '2026-01-30T00:00:00.000Z',
|
||||
updated_at: '2026-01-30T00:00:00.000Z'
|
||||
};
|
||||
}
|
||||
|
||||
describe('task processor extraction helpers', () => {
|
||||
it('parses strict extraction payloads', () => {
|
||||
const raw = JSON.stringify({
|
||||
summary: 'Revenue growth remained resilient despite FX pressure.',
|
||||
keyPoints: ['Revenue up year-over-year'],
|
||||
redFlags: ['Debt service burden is rising'],
|
||||
followUpQuestions: ['Is margin guidance sustainable?'],
|
||||
portfolioSignals: ['Monitor leverage trend'],
|
||||
confidence: 0.72
|
||||
});
|
||||
|
||||
const parsed = __taskProcessorInternals.parseExtractionPayload(raw);
|
||||
|
||||
expect(parsed).not.toBeNull();
|
||||
expect(parsed?.summary).toContain('Revenue growth');
|
||||
expect(parsed?.confidence).toBe(0.72);
|
||||
});
|
||||
|
||||
it('rejects extraction payloads with extra keys', () => {
|
||||
const raw = JSON.stringify({
|
||||
summary: 'ok',
|
||||
keyPoints: [],
|
||||
redFlags: [],
|
||||
followUpQuestions: [],
|
||||
portfolioSignals: [],
|
||||
confidence: 0.2,
|
||||
extra: 'not-allowed'
|
||||
});
|
||||
|
||||
const parsed = __taskProcessorInternals.parseExtractionPayload(raw);
|
||||
expect(parsed).toBeNull();
|
||||
});
|
||||
|
||||
it('builds deterministic extraction fallback from filing metadata', () => {
|
||||
const fallback = __taskProcessorInternals.deterministicExtractionFallback(sampleFiling());
|
||||
|
||||
expect(fallback.summary).toContain('Deterministic extraction fallback');
|
||||
expect(fallback.keyPoints.length).toBeGreaterThan(0);
|
||||
expect(fallback.redFlags.length).toBeGreaterThan(0);
|
||||
expect(fallback.confidence).toBe(0.2);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user