WIP main worktree changes before merge

This commit is contained in:
2026-03-13 00:20:22 -04:00
parent 58bf80189d
commit e5141238fb
25 changed files with 940 additions and 208 deletions

View File

@@ -1586,6 +1586,99 @@ describe('financial taxonomy internals', () => {
expect(merged[0]?.provenanceType).toBe('taxonomy');
});
it('builds faithful rows when persisted statement rows are missing sourceFactIds', () => {
const malformedSnapshot = {
...createSnapshot({
filingId: 19,
filingType: '10-K',
filingDate: '2026-02-20',
statement: 'income',
periods: [
{ id: '2025-fy', periodStart: '2025-01-01', periodEnd: '2025-12-31', periodLabel: '2025 FY' }
]
}),
statement_rows: {
income: [{
...createRow({
key: 'revenue',
label: 'Revenue',
statement: 'income',
values: { '2025-fy': 123_000_000 }
}),
sourceFactIds: undefined
} as unknown as TaxonomyStatementRow],
balance: [],
cash_flow: [],
equity: [],
comprehensive_income: []
}
} satisfies FilingTaxonomySnapshotRecord;
const rows = __financialTaxonomyInternals.buildRows(
[malformedSnapshot],
'income',
new Set(['2025-fy'])
);
expect(rows).toHaveLength(1);
expect(rows[0]?.key).toBe('revenue');
expect(rows[0]?.sourceFactIds).toEqual([]);
});
it('aggregates persisted surface rows when legacy snapshots are missing source arrays', () => {
const snapshot = {
...createSnapshot({
filingId: 20,
filingType: '10-K',
filingDate: '2026-02-21',
statement: 'income',
periods: [
{ id: '2025-fy', periodStart: '2025-01-01', periodEnd: '2025-12-31', periodLabel: '2025 FY' }
]
}),
surface_rows: {
income: [{
key: 'revenue',
label: 'Revenue',
category: 'revenue',
templateSection: 'statement',
order: 10,
unit: 'currency',
values: { '2025-fy': 123_000_000 },
sourceConcepts: undefined,
sourceRowKeys: undefined,
sourceFactIds: undefined,
formulaKey: null,
hasDimensions: false,
resolvedSourceRowKeys: {},
statement: 'income',
detailCount: 0,
resolutionMethod: 'direct',
confidence: 'high',
warningCodes: []
} as unknown as FilingTaxonomySnapshotRecord['surface_rows']['income'][number]],
balance: [],
cash_flow: [],
equity: [],
comprehensive_income: []
}
} satisfies FilingTaxonomySnapshotRecord;
const rows = __financialTaxonomyInternals.aggregateSurfaceRows({
snapshots: [snapshot],
statement: 'income',
selectedPeriodIds: new Set(['2025-fy'])
});
expect(rows).toHaveLength(1);
expect(rows[0]).toMatchObject({
key: 'revenue',
sourceConcepts: [],
sourceRowKeys: [],
sourceFactIds: []
});
});
it('builds normalization metadata from snapshot fiscal pack and counts', () => {
const snapshot = {
...createSnapshot({
@@ -1610,11 +1703,81 @@ describe('financial taxonomy internals', () => {
} satisfies FilingTaxonomySnapshotRecord;
expect(__financialTaxonomyInternals.buildNormalizationMetadata([snapshot])).toEqual({
parserEngine: 'fiscal-xbrl',
regime: 'us-gaap',
fiscalPack: 'bank_lender',
parserVersion: '0.1.0',
surfaceRowCount: 5,
detailRowCount: 3,
kpiRowCount: 2,
unmappedRowCount: 4,
materialUnmappedRowCount: 1
materialUnmappedRowCount: 1,
warnings: []
});
});
it('aggregates normalization counts and warning codes across snapshots while using the latest parser identity', () => {
const olderSnapshot = {
...createSnapshot({
filingId: 17,
filingType: '10-K',
filingDate: '2025-02-13',
statement: 'income',
periods: [
{ id: '2024-fy', periodStart: '2024-01-01', periodEnd: '2024-12-31', periodLabel: '2024 FY' }
]
}),
parser_engine: 'fiscal-xbrl',
parser_version: '0.9.0',
fiscal_pack: 'core',
normalization_summary: {
surfaceRowCount: 4,
detailRowCount: 2,
kpiRowCount: 1,
unmappedRowCount: 3,
materialUnmappedRowCount: 1,
warnings: ['balance_residual_detected', 'income_sparse_mapping']
}
} satisfies FilingTaxonomySnapshotRecord;
const latestSnapshot = {
...createSnapshot({
filingId: 18,
filingType: '10-Q',
filingDate: '2026-02-13',
statement: 'income',
periods: [
{ id: '2025-q4', periodStart: '2025-10-01', periodEnd: '2025-12-31', periodLabel: '2025 Q4' }
]
}),
parser_engine: 'fiscal-xbrl',
parser_version: '1.1.0',
fiscal_pack: 'bank_lender',
normalization_summary: {
surfaceRowCount: 6,
detailRowCount: 5,
kpiRowCount: 4,
unmappedRowCount: 2,
materialUnmappedRowCount: 0,
warnings: ['income_sparse_mapping', 'unmapped_cash_flow_bridge']
}
} satisfies FilingTaxonomySnapshotRecord;
expect(__financialTaxonomyInternals.buildNormalizationMetadata([olderSnapshot, latestSnapshot])).toEqual({
parserEngine: 'fiscal-xbrl',
regime: 'us-gaap',
fiscalPack: 'bank_lender',
parserVersion: '1.1.0',
surfaceRowCount: 10,
detailRowCount: 7,
kpiRowCount: 5,
unmappedRowCount: 5,
materialUnmappedRowCount: 1,
warnings: [
'balance_residual_detected',
'income_sparse_mapping',
'unmapped_cash_flow_bridge'
]
});
});