T-87: M1.1l — Security-type classifier: eodSymbols.Type → securityTypeByIsin for the security-master loader (no new dependencies)
This commit is contained in:
parent
a368e8a47a
commit
b2a1f5ce80
3 changed files with 102 additions and 36 deletions
|
|
@ -1439,6 +1439,57 @@ describe('security-master source-symbol-readers', () => {
|
|||
expect(JSON.stringify(candidate)).toBe(baselineJson);
|
||||
expect([...candidate.securityTypeByIsin.entries()]).toEqual(baselineTypeEntries);
|
||||
}
|
||||
|
||||
// Reversed-input determinism fixture: duplicate rows sharing (sourceId, isin) with distinct
|
||||
// object/array malformed `Type` values normalize to a single `null` missing-type sentinel so
|
||||
// `securityTypeRecords` order is cursor-order independent.
|
||||
const malformedDocs = [
|
||||
{
|
||||
eodSearchCode: 'MALF.US',
|
||||
Code: 'MALF',
|
||||
Exchange: 'NASDAQ',
|
||||
Country: 'USA',
|
||||
Currency: 'USD',
|
||||
Isin: 'US0378331005',
|
||||
Name: 'Malformed Type Co',
|
||||
Type: { kind: 'A', nested: 1 } as unknown as string,
|
||||
},
|
||||
{
|
||||
eodSearchCode: 'MALF.US',
|
||||
Code: 'MALF',
|
||||
Exchange: 'NASDAQ',
|
||||
Country: 'USA',
|
||||
Currency: 'USD',
|
||||
Isin: 'US0378331005',
|
||||
Name: 'Malformed Type Co',
|
||||
Type: { kind: 'B', nested: 2 } as unknown as string,
|
||||
},
|
||||
{
|
||||
eodSearchCode: 'MALF.US',
|
||||
Code: 'MALF',
|
||||
Exchange: 'NASDAQ',
|
||||
Country: 'USA',
|
||||
Currency: 'USD',
|
||||
Isin: 'US0378331005',
|
||||
Name: 'Malformed Type Co',
|
||||
Type: ['ETF'] as unknown as string,
|
||||
},
|
||||
];
|
||||
const forwardMalformed = await readSecurityMasterSources(
|
||||
new FakeSourceSymbolReader({ eodSymbols: malformedDocs }),
|
||||
{ exchangeLookup }
|
||||
);
|
||||
const reversedMalformed = await readSecurityMasterSources(
|
||||
new FakeSourceSymbolReader({ eodSymbols: [...malformedDocs].reverse() }),
|
||||
{ exchangeLookup }
|
||||
);
|
||||
expect(JSON.stringify(reversedMalformed)).toBe(JSON.stringify(forwardMalformed));
|
||||
expect(forwardMalformed.securityTypeRecords).toEqual([
|
||||
{ isin: 'US0378331005', rawType: null, sourceId: 'MALF.US' },
|
||||
{ isin: 'US0378331005', rawType: null, sourceId: 'MALF.US' },
|
||||
{ isin: 'US0378331005', rawType: null, sourceId: 'MALF.US' },
|
||||
]);
|
||||
expect(forwardMalformed.securityTypeStats.missingType).toBe(3);
|
||||
});
|
||||
|
||||
test('security-type wiring & Stage A integration: maps typed EOD docs (including lowercase type and CUSIP-derived ISIN), keeps non-string Type docs, and reports conflicts/unknowns', async () => {
|
||||
|
|
@ -1569,6 +1620,7 @@ describe('security-master source-symbol-readers', () => {
|
|||
isinsConflicting: 1,
|
||||
conflictsTruncated: 0,
|
||||
});
|
||||
expect(sources.securityTypeLoaderStats).toEqual(sources.securityTypeStats);
|
||||
|
||||
// Feed reader output directly into Stage A and verify every typed non-conflicting EOD instrument
|
||||
// resolves to an ISIN present in securityTypeByIsin (zero missing_security_type skips in persistSecurityMaster).
|
||||
|
|
@ -1694,12 +1746,12 @@ describe('security-master source-symbol-readers', () => {
|
|||
'DUP.TO:duplicate_source_id',
|
||||
]);
|
||||
|
||||
// Loader-facing map contains ONLY the Stage A-accepted member's type ('common'), with zero conflicts.
|
||||
// Loader-facing map, conflicts, and loader stats reflect ONLY Stage A-accepted EOD members.
|
||||
expect([...sources.securityTypeByIsin.entries()]).toEqual([['US0378331005', 'common']]);
|
||||
expect(sources.securityTypeConflicts).toEqual([]);
|
||||
expect(sources.securityTypeByIsin.has('US30303M1027')).toBe(false);
|
||||
expect(sources.securityTypeByIsin.has('CA7800871021')).toBe(false);
|
||||
expect(sources.securityTypeStats).toEqual({
|
||||
expect(sources.securityTypeLoaderStats).toEqual({
|
||||
recordsIn: 1,
|
||||
classified: 1,
|
||||
missingIsin: 0,
|
||||
|
|
@ -1711,6 +1763,21 @@ describe('security-master source-symbol-readers', () => {
|
|||
conflictsTruncated: 0,
|
||||
});
|
||||
|
||||
// Returned vocabulary diagnostics (`securityTypeStats` & `unknownSecurityTypes`) cover ALL 5
|
||||
// emitted EOD rows directly, including quarantined rows like `Structured Note`.
|
||||
expect(sources.securityTypeStats).toEqual({
|
||||
recordsIn: 5,
|
||||
classified: 4,
|
||||
missingIsin: 0,
|
||||
missingType: 0,
|
||||
unknownType: 1,
|
||||
distinctClassifiedIsins: 2,
|
||||
isinsMapped: 1,
|
||||
isinsConflicting: 1,
|
||||
conflictsTruncated: 0,
|
||||
});
|
||||
expect(sources.unknownSecurityTypes).toEqual([{ rawType: 'Structured Note', count: 1 }]);
|
||||
|
||||
// Helper produces the identical loader-facing map when called explicitly after Stage A.
|
||||
const explicitStageAMap = buildSecurityTypeByIsinForStageA(
|
||||
sources.securityTypeRecords,
|
||||
|
|
@ -1719,11 +1786,13 @@ describe('security-master source-symbol-readers', () => {
|
|||
expect([...explicitStageAMap.securityTypeByIsin.entries()]).toEqual([
|
||||
...sources.securityTypeByIsin.entries(),
|
||||
]);
|
||||
expect(explicitStageAMap.stats).toEqual(sources.securityTypeLoaderStats);
|
||||
|
||||
// All 5 emitted EOD rows remain available in `securityTypeRecords` for raw vocabulary diagnostics.
|
||||
// All 5 emitted EOD rows also remain available in `securityTypeRecords` and reconcile with returned diagnostics.
|
||||
expect(sources.securityTypeRecords.length).toBe(5);
|
||||
const rawDiagnostics = buildSecurityTypeByIsin(sources.securityTypeRecords);
|
||||
expect(rawDiagnostics.unknownRawTypes).toEqual([{ rawType: 'Structured Note', count: 1 }]);
|
||||
expect(rawDiagnostics.stats).toEqual(sources.securityTypeStats);
|
||||
expect(rawDiagnostics.unknownRawTypes).toEqual(sources.unknownSecurityTypes);
|
||||
});
|
||||
|
||||
test('local benchmark: >= 368k synthetic docs (300k eod + 50k qm + 18k ib) sustain >= 25,000 docs/s', async () => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue