From 0b3a111cb60999ca0b06bf36073230af8f9b3b7b Mon Sep 17 00:00:00 2001 From: Studio Date: Sat, 28 Nov 2026 06:00:23 -0500 Subject: [PATCH] =?UTF-8?q?T-88:=20M1.1m=20=E2=80=94=20Security-master=20r?= =?UTF-8?q?un=20composer:=20readers=20output=20+=20bar=20spans=20=E2=86=92?= =?UTF-8?q?=20Stage=20A=20=E2=86=92=20Stage=20B=20=E2=86=92=20Pass=206=20?= =?UTF-8?q?=E2=86=92=20Pass=204=20=E2=86=92=20match=20report=20+=20persist?= =?UTF-8?q?=20input=20(pure,=20in-memory,=20no=20new=20dependencies)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../data-pipeline/src/security-master/run.ts | 8 ++ test/unit/security-master-run.test.ts | 132 ++++++++++++++++++ 2 files changed, 140 insertions(+) diff --git a/apps/stock/data-pipeline/src/security-master/run.ts b/apps/stock/data-pipeline/src/security-master/run.ts index 1b1c8e87..182ca474 100644 --- a/apps/stock/data-pipeline/src/security-master/run.ts +++ b/apps/stock/data-pipeline/src/security-master/run.ts @@ -897,15 +897,23 @@ function applyEndToEndStageACoverage( if (rec === undefined || consumeStageBCount(rec.source, rec.sourceId)) { continue; } + const excluded = + rec.source === 'eod' && isExcludedByDesignRole(eodRoleBySourceId.get(rec.sourceId)); const d = deltaBySource[rec.source]; d.total += 1; d.conflict += 1; + if (excluded) { + d.excludedByDesign += 1; + } const country = lookupSourceCountryValue(sourceCountries, rec.source, rec.sourceId); if (country !== null) { const cAcc = getOrCreateCountry(country); cAcc.total += 1; cAcc.conflict += 1; + if (excluded) { + cAcc.excludedByDesign += 1; + } } } diff --git a/test/unit/security-master-run.test.ts b/test/unit/security-master-run.test.ts index 19fc9b74..ff6ebfd0 100644 --- a/test/unit/security-master-run.test.ts +++ b/test/unit/security-master-run.test.ts @@ -986,6 +986,138 @@ describe('composeSecurityMasterRun', () => { expect(dupResult.report.meetsExitThresholds.equitiesResolved95).toBe(false); }); + test('applies venue eligibility exclusions to Stage A conflicts in source and country coverage while keeping the conflict', () => { + const stageARecords: StageASourceRecord[] = []; + const eodListings: StageBEodListingInput[] = []; + const barSpans: BarSpan[] = []; + const securityTypeByIsin = new Map(); + + // 95 resolved eligible EOD equities + for (let i = 0; i < 95; i++) { + const base8 = `C${String(i).padStart(7, '0')}`; + let sum = 0; + for (let pos = 0; pos < 8; pos++) { + const ch = base8.charCodeAt(pos); + let v = ch >= 65 ? ch - 55 : ch - 48; + if (pos % 2 === 1) { + v *= 2; + } + sum += Math.floor(v / 10) + (v % 10); + } + const cusip = `${base8}${(10 - (sum % 10)) % 10}`; + const isin = cusipToIsin(cusip, 'US')!; + const ticker = `G${String(i).padStart(3, '0')}`; + const sourceId = `${ticker}.US`; + stageARecords.push({ + source: 'eod', + sourceId, + isin, + cusip, + country: 'US', + currency: 'USD', + name: `Good Equity ${i}`, + }); + eodListings.push({ + sourceId, + ticker, + mic: 'XNAS', + role: 'primary_venue', + currency: 'USD', + span: null, + }); + barSpans.push({ + source: 'eod', + sourceId, + firstBarDate: '2020-01-02', + lastBarDate: '2025-11-28', + barCount: 1500, + }); + securityTypeByIsin.set(isin, 'common'); + } + + // 5 unresolved eligible EOD equities -> exactly 95 / 100 = 95.00% + for (let i = 0; i < 5; i++) { + const ticker = `U${String(i).padStart(3, '0')}`; + const sourceId = `${ticker}.US`; + stageARecords.push({ + source: 'eod', + sourceId, + isin: null, + cusip: null, + country: 'US', + currency: 'USD', + name: `Unresolved Equity ${i}`, + }); + eodListings.push({ + sourceId, + ticker, + mic: 'XNAS', + role: 'primary_venue', + currency: 'USD', + span: null, + }); + } + + // 1 additional EOD record from a US composite venue with disagreeing valid ISIN & CUSIP + stageARecords.push({ + source: 'eod', + sourceId: 'COMP.US', + isin: 'US0378331005', + cusip: '594918104', + country: 'US', + currency: 'USD', + name: 'Composite Conflict Corp', + }); + eodListings.push({ + sourceId: 'COMP.US', + ticker: 'COMP', + mic: null, + role: 'composite', + currency: 'USD', + span: null, + }); + + const sources = makeSourcesResult({ + stageARecords, + eodListings, + ibContracts: [], + tickerSources: [], + securityTypeByIsin, + }); + + const result = composeSecurityMasterRun({ sources, barSpans }, { asOfDate: '2025-11-28' }); + + // Conflict is preserved in Stage A, report, CSV, and persist input + expect(result.stageA.conflicts.length).toBe(1); + expect(result.stageA.conflicts[0]?.sourceId).toBe('COMP.US'); + expect(result.report.conflicts.length).toBe(1); + expect(result.report.conflicts[0]?.sourceId).toBe('COMP.US'); + expect(result.persistInput.stageA.conflicts.length).toBe(1); + expect(result.conflictsCsv).toContain('COMP.US'); + + // Excluded composite conflict does not inflate eligibleTotal beyond 100 + const eodRow = result.report.resolutionBySource.find(r => r.source === 'eod'); + expect(eodRow?.total).toBe(101); + expect(eodRow?.matched).toBe(95); + expect(eodRow?.unresolved).toBe(5); + expect(eodRow?.conflict).toBe(1); + expect(eodRow?.excludedByDesign).toBe(1); + expect(eodRow?.eligibleTotal).toBe(100); + expect(eodRow?.eligibleResolvedPct).toBeCloseTo(0.95, 10); + + const usRow = result.report.resolutionByCountry.find(r => r.country === 'US'); + expect(usRow?.total).toBe(101); + expect(usRow?.matched).toBe(95); + expect(usRow?.unresolved).toBe(5); + expect(usRow?.conflict).toBe(1); + expect(usRow?.excludedByDesign).toBe(1); + expect(usRow?.eligibleTotal).toBe(100); + expect(usRow?.eligibleResolvedPct).toBeCloseTo(0.95, 10); + + expect(result.report.meetsExitThresholds.equitiesResolved95).toBe(true); + expect(result.reportMarkdown).toContain('| Equities Resolved (Eligible) | PASS | >= 95.00% |'); + }); + test('restricts Pass 4 sample closes to Stage B mapping validity windows on reused tickers', () => { const sources = makeSourcesResult({ stageARecords: [