T-74: M1.1i — Pass 3/4/6 match & conflict report: pure in-memory Markdown + CSV generator and override seed-SQL template (no DB I/O)

This commit is contained in:
Studio 2026-11-27 21:23:56 -05:00
parent 83ec301220
commit 86bf0a68b2
3 changed files with 85 additions and 4 deletions

View file

@ -339,4 +339,84 @@ describe.skipIf(!url)('security master override seed SQL', () => {
).rows;
expect(inserted).toEqual([{ source_id: rawSourceId, listing_id: expectedListingId }]);
});
test('uncommented template candidate with unstorable source_id fails not_null_violation and inserts no row when marker is left in place', async () => {
const f = await createIsolatedFixture();
await seedSingleListing(f.pool);
const overlongSourceId = 'X'.repeat(65);
const report = buildMatchReport({
stageA: {
instruments: [],
unresolved: [],
conflicts: [
{
source: 'eod',
sourceId: overlongSourceId,
conflictKind: 'isin_cusip_mismatch',
detail: { isin: 'US0378331005', cusip: '037833100', country: 'US', derivedIsin: null },
},
],
stats: {
totalInputRecords: 1,
totalInstruments: 0,
bySource: {
ib: { total: 0, tier1Isin: 0, tier2Cusip: 0, unresolved: 0, conflict: 0 },
eod: { total: 1, tier1Isin: 0, tier2Cusip: 0, unresolved: 0, conflict: 1 },
},
},
},
stageB: {
listings: [],
providerMappings: [],
unresolved: [],
conflicts: [],
stats: {
totalListings: 0,
totalProviderMappings: 0,
listingsWithIbConid: 0,
excludedFunds: 0,
bySource: {
eod: { total: 0, matched: 0, unresolved: 0, conflict: 0 },
ib: { total: 0, matched: 0, unresolved: 0, conflict: 0 },
qm: { total: 0, matched: 0, unresolved: 0, conflict: 0 },
ceo: { total: 0, matched: 0, unresolved: 0, conflict: 0 },
},
},
},
});
const templateSql = generateOverrideTemplateSql(report);
const templateLines = templateSql.split('\n');
const insertStartIndex = templateLines.findIndex(
line =>
line ===
'-- INSERT INTO override (source, source_id, valid_from, valid_to, listing_id, reason, created_by)'
);
expect(insertStartIndex).toBeGreaterThan(-1);
const candidateSql = templateLines
.slice(insertStartIndex)
.filter(line => line.startsWith('-- '))
.map(line => line.slice(3))
.join('\n')
.replace("'TODO_ISIN_12'", "'US0378331005'")
.replace("'TODO_MIC'", "'XNAS'")
.replace("'TODO_TICKER'", "'AAPL'");
let caughtError: unknown;
try {
await f.pool.query(candidateSql);
} catch (err) {
caughtError = err;
}
expect(caughtError).toBeDefined();
expect((caughtError as { code?: string }).code).toBe('23502');
const count = (
await f.pool.query<{ count: number }>('SELECT count(*)::int AS count FROM override')
).rows[0]?.count;
expect(count).toBe(0);
});
});