T-88: M1.1m — Security-master run composer: readers output + bar spans → Stage A → Stage B → Pass 6 → Pass 4 → match report + persist input (pure, in-memory, no new dependencies)

This commit is contained in:
Studio 2026-11-28 06:00:23 -05:00
parent bd8ddab1a2
commit 0b3a111cb6
2 changed files with 140 additions and 0 deletions

View file

@ -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;
}
}
}

View file

@ -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<string, SecurityType>();
// 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: [