Integrate crabrl parser into taxonomy hydration
This commit is contained in:
@@ -1,37 +1,43 @@
|
||||
import { beforeEach, describe, expect, it, mock } from 'bun:test';
|
||||
import { beforeEach, describe, expect, it, mock } from "bun:test";
|
||||
|
||||
import type { FinancialStatementKind } from '@/lib/types';
|
||||
import type { TaxonomyHydrationInput, TaxonomyHydrationResult } from '@/lib/server/taxonomy/types';
|
||||
import type { FinancialStatementKind } from "@/lib/types";
|
||||
import type {
|
||||
TaxonomyHydrationInput,
|
||||
TaxonomyHydrationResult,
|
||||
} from "@/lib/server/taxonomy/types";
|
||||
|
||||
function createStatementRecord<T>(factory: () => T): Record<FinancialStatementKind, T> {
|
||||
function createStatementRecord<T>(
|
||||
factory: () => T,
|
||||
): Record<FinancialStatementKind, T> {
|
||||
return {
|
||||
income: factory(),
|
||||
balance: factory(),
|
||||
cash_flow: factory(),
|
||||
equity: factory(),
|
||||
comprehensive_income: factory()
|
||||
comprehensive_income: factory(),
|
||||
};
|
||||
}
|
||||
|
||||
function createHydrationResult(): TaxonomyHydrationResult {
|
||||
return {
|
||||
filing_id: 1,
|
||||
ticker: 'TEST',
|
||||
filing_date: '2025-12-31',
|
||||
filing_type: '10-K',
|
||||
parse_status: 'ready',
|
||||
ticker: "TEST",
|
||||
filing_date: "2025-12-31",
|
||||
filing_type: "10-K",
|
||||
parse_status: "ready",
|
||||
parse_error: null,
|
||||
source: 'xbrl_instance_with_linkbase',
|
||||
parser_engine: 'fiscal-xbrl',
|
||||
parser_version: '0.1.0',
|
||||
taxonomy_regime: 'us-gaap',
|
||||
fiscal_pack: 'core',
|
||||
source: "xbrl_instance_with_linkbase",
|
||||
parser_engine: "fiscal-xbrl",
|
||||
parser_version: "0.1.0",
|
||||
taxonomy_regime: "us-gaap",
|
||||
fiscal_pack: "core",
|
||||
periods: [],
|
||||
faithful_rows: createStatementRecord(() => []),
|
||||
statement_rows: createStatementRecord(() => []),
|
||||
surface_rows: createStatementRecord(() => []),
|
||||
detail_rows: createStatementRecord(() => ({})),
|
||||
kpi_rows: [],
|
||||
computed_definitions: [],
|
||||
contexts: [],
|
||||
derived_metrics: null,
|
||||
validation_result: null,
|
||||
@@ -48,42 +54,44 @@ function createHydrationResult(): TaxonomyHydrationResult {
|
||||
kpi_row_count: 0,
|
||||
unmapped_row_count: 0,
|
||||
material_unmapped_row_count: 0,
|
||||
warnings: ['rust_warning']
|
||||
warnings: ["rust_warning"],
|
||||
},
|
||||
xbrl_validation: {
|
||||
status: 'passed'
|
||||
}
|
||||
status: "passed",
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
const mockHydrateFromSidecar = mock(async () => createHydrationResult());
|
||||
mock.module('@/lib/server/taxonomy/parser-client', () => ({
|
||||
hydrateFilingTaxonomySnapshotFromSidecar: mockHydrateFromSidecar
|
||||
mock.module("@/lib/server/taxonomy/parser-client", () => ({
|
||||
hydrateFilingTaxonomySnapshotFromSidecar: mockHydrateFromSidecar,
|
||||
}));
|
||||
|
||||
describe('taxonomy engine rust path', () => {
|
||||
describe("taxonomy engine rust path", () => {
|
||||
beforeEach(() => {
|
||||
mockHydrateFromSidecar.mockClear();
|
||||
});
|
||||
|
||||
it('returns sidecar output directly from the Rust sidecar', async () => {
|
||||
const { hydrateFilingTaxonomySnapshot } = await import('@/lib/server/taxonomy/engine');
|
||||
it("returns sidecar output directly from the Rust sidecar", async () => {
|
||||
const { hydrateFilingTaxonomySnapshot } =
|
||||
await import("@/lib/server/taxonomy/engine");
|
||||
|
||||
const input: TaxonomyHydrationInput = {
|
||||
filingId: 1,
|
||||
ticker: 'TEST',
|
||||
cik: '0000000001',
|
||||
accessionNumber: '0000000001-25-000001',
|
||||
filingDate: '2025-12-31',
|
||||
filingType: '10-K',
|
||||
filingUrl: 'https://www.sec.gov/Archives/edgar/data/1/000000000125000001/',
|
||||
primaryDocument: 'test-20251231.htm'
|
||||
ticker: "TEST",
|
||||
cik: "0000000001",
|
||||
accessionNumber: "0000000001-25-000001",
|
||||
filingDate: "2025-12-31",
|
||||
filingType: "10-K",
|
||||
filingUrl:
|
||||
"https://www.sec.gov/Archives/edgar/data/1/000000000125000001/",
|
||||
primaryDocument: "test-20251231.htm",
|
||||
};
|
||||
|
||||
const result = await hydrateFilingTaxonomySnapshot(input);
|
||||
|
||||
expect(mockHydrateFromSidecar).toHaveBeenCalledTimes(1);
|
||||
expect(result.parser_engine).toBe('fiscal-xbrl');
|
||||
expect(result.normalization_summary.warnings).toEqual(['rust_warning']);
|
||||
expect(result.parser_engine).toBe("fiscal-xbrl");
|
||||
expect(result.normalization_summary.warnings).toEqual(["rust_warning"]);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user