Files
Neon-Desk/lib/server/company-overview-synthesis.test.ts

86 lines
3.1 KiB
TypeScript

import { describe, expect, it, mock } from 'bun:test';
import { __companyOverviewSynthesisInternals, synthesizeCompanyOverview } from './company-overview-synthesis';
describe('company overview synthesis', () => {
it('parses strict json AI responses', () => {
const parsed = __companyOverviewSynthesisInternals.parseAiJson(JSON.stringify({
bull: ['Demand remains durable'],
bear: ['Valuation is demanding'],
weeklySummary: 'The week centered on enterprise demand and new disclosures.',
weeklyHighlights: ['8-K signaled a new contract']
}));
expect(parsed.bull).toEqual(['Demand remains durable']);
expect(parsed.bear).toEqual(['Valuation is demanding']);
expect(parsed.weeklyHighlights).toEqual(['8-K signaled a new contract']);
});
it('falls back to memo-backed bullets when AI is unavailable', async () => {
const result = await synthesizeCompanyOverview({
ticker: 'MSFT',
companyName: 'Microsoft Corp',
description: 'Microsoft builds software and cloud infrastructure.',
memo: {
id: 1,
user_id: 'u1',
organization_id: null,
ticker: 'MSFT',
rating: 'buy',
conviction: 'high',
time_horizon_months: 24,
packet_title: null,
packet_subtitle: null,
thesis_markdown: 'Azure demand remains durable.',
variant_view_markdown: '',
catalysts_markdown: 'Copilot monetization can expand ARPU.',
risks_markdown: 'Competition may compress pricing.',
disconfirming_evidence_markdown: 'Enterprise optimization could slow seat growth.',
next_actions_markdown: '',
created_at: '2026-03-01T00:00:00.000Z',
updated_at: '2026-03-10T00:00:00.000Z'
},
latestFilingSummary: null,
recentAiReports: [],
recentDevelopments: []
}, {
aiConfigured: false
});
expect(result.bullBear.source).toBe('memo_fallback');
expect(result.bullBear.bull[0]).toContain('Azure demand');
expect(result.bullBear.bear[0]).toContain('Competition');
expect(result.weeklySnapshot?.source).toBe('heuristic');
});
it('uses AI output when available', async () => {
const runAnalysis = mock(async () => ({
provider: 'zhipu' as const,
model: 'glm-5',
text: JSON.stringify({
bull: ['Demand remains durable'],
bear: ['Spending could normalize'],
weeklySummary: 'The week was defined by a new contract disclosure.',
weeklyHighlights: ['8-K disclosed a new enterprise customer']
})
}));
const result = await synthesizeCompanyOverview({
ticker: 'MSFT',
companyName: 'Microsoft Corp',
description: 'Microsoft builds software and cloud infrastructure.',
memo: null,
latestFilingSummary: null,
recentAiReports: [],
recentDevelopments: []
}, {
aiConfigured: true,
runAnalysis
});
expect(runAnalysis).toHaveBeenCalledTimes(1);
expect(result.bullBear.source).toBe('ai_synthesized');
expect(result.bullBear.bull).toEqual(['Demand remains durable']);
expect(result.weeklySnapshot?.source).toBe('ai_synthesized');
});
});