T-40: M1.1c — Pass 1 exchanges: ISO MIC seed, source-code role classifier and reviewable seed-SQL generator
This commit is contained in:
parent
d0d2ebdfc8
commit
dcca90004d
7 changed files with 115 additions and 21 deletions
|
|
@ -5,6 +5,7 @@ import { afterEach, describe, expect, test } from 'bun:test';
|
|||
import { Pool } from 'pg';
|
||||
import { getLogger, setLoggerConfig } from '@stock-bot/logger';
|
||||
import { PostgreSQLClient, runPostgresMigrations } from '@stock-bot/postgres';
|
||||
import { generateExchangeSeedSql } from '../../apps/stock/data-pipeline/src/security-master';
|
||||
|
||||
setLoggerConfig({ logLevel: 'fatal', logConsole: false });
|
||||
const logger = getLogger('security-master-exchange-seed-test');
|
||||
|
|
@ -224,4 +225,68 @@ describe.skipIf(!url)('security master Pass 1 exchange seed migration', () => {
|
|||
|
||||
expect(await countRows()).toEqual(initialCounts);
|
||||
});
|
||||
|
||||
test('reviewed follow-up SQL promotes an existing unreviewed row with reviewed_by and survives baseline re-apply', async () => {
|
||||
const f = await createIsolatedFixture();
|
||||
const baselineSql = readFileSync(exchangeSeedSqlPath, 'utf8');
|
||||
|
||||
const followUpSql = generateExchangeSeedSql({
|
||||
mappings: [
|
||||
{
|
||||
source: 'eod',
|
||||
sourceCode: 'US',
|
||||
role: 'primary_venue',
|
||||
mic: 'XNYS',
|
||||
countryIso: 'US',
|
||||
method: 'explicit_rule',
|
||||
reviewedBy: 'director',
|
||||
},
|
||||
{
|
||||
source: 'qm',
|
||||
sourceCode: 'TSX',
|
||||
role: 'primary_venue',
|
||||
mic: 'XTSE',
|
||||
countryIso: 'CA',
|
||||
method: 'explicit_rule',
|
||||
reviewedBy: 'director',
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
// Apply reviewed follow-up after migration 35 has already run
|
||||
await f.pool.query(followUpSql);
|
||||
|
||||
// Re-apply baseline migration 35; promoted and added reviewed rows must remain intact
|
||||
await f.pool.query(baselineSql);
|
||||
|
||||
const promotedRow = (
|
||||
await f.pool.query(
|
||||
`SELECT role, mic, country_iso, method, reviewed_by
|
||||
FROM exchange_source_map
|
||||
WHERE source = 'eod' AND source_code = 'US'`
|
||||
)
|
||||
).rows[0];
|
||||
expect(promotedRow).toEqual({
|
||||
role: 'primary_venue',
|
||||
mic: 'XNYS',
|
||||
country_iso: 'US',
|
||||
method: 'explicit_rule',
|
||||
reviewed_by: 'director',
|
||||
});
|
||||
|
||||
const addedRow = (
|
||||
await f.pool.query(
|
||||
`SELECT role, mic, country_iso, method, reviewed_by
|
||||
FROM exchange_source_map
|
||||
WHERE source = 'qm' AND source_code = 'TSX'`
|
||||
)
|
||||
).rows[0];
|
||||
expect(addedRow).toEqual({
|
||||
role: 'primary_venue',
|
||||
mic: 'XTSE',
|
||||
country_iso: 'CA',
|
||||
method: 'explicit_rule',
|
||||
reviewed_by: 'director',
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -335,6 +335,31 @@ describe('security master Pass 1 SQL and Markdown generator', () => {
|
|||
expect(mdA).toContain('Pipe \\| Name Line2');
|
||||
});
|
||||
|
||||
test('breaks ties on country and currency for shuffled missing-code records with identical name and MIC', () => {
|
||||
const recordsA: SourceExchangeRecord[] = [
|
||||
{ source: 'qm', code: '', name: 'Unnamed Venue', operatingMic: null, country: 'US', currency: 'USD' },
|
||||
{ source: 'qm', code: '', name: 'Unnamed Venue', operatingMic: null, country: 'US', currency: 'CAD' },
|
||||
{ source: 'qm', code: '', name: 'Unnamed Venue', operatingMic: null, country: 'CA', currency: 'CAD' },
|
||||
];
|
||||
const recordsB: SourceExchangeRecord[] = [recordsA[2]!, recordsA[0]!, recordsA[1]!];
|
||||
|
||||
const resA = classifySourceExchanges(recordsA);
|
||||
const resB = classifySourceExchanges(recordsB);
|
||||
|
||||
expect(resA.unresolved).toEqual(resB.unresolved);
|
||||
expect(resA.unresolved.map(row => [row.country, row.currency])).toEqual([
|
||||
['CA', 'CAD'],
|
||||
['US', 'CAD'],
|
||||
['US', 'USD'],
|
||||
]);
|
||||
|
||||
const mdA = generateUnresolvedExchangesMarkdown(resA);
|
||||
const mdB = generateUnresolvedExchangesMarkdown(resB);
|
||||
expect(mdA).toBe(mdB);
|
||||
expect(mdA.indexOf('| CA | CAD |')).toBeLessThan(mdA.indexOf('| US | CAD |'));
|
||||
expect(mdA.indexOf('| US | CAD |')).toBeLessThan(mdA.indexOf('| US | USD |'));
|
||||
});
|
||||
|
||||
test('escapes single quotes in generated SQL values', () => {
|
||||
const sql = generateExchangeSeedSql({
|
||||
exchanges: [
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue