T-211: M2.2v — Export listing_venues.tsv and extend field-shape probe & BSON fixture exporter for M2 collections
This commit is contained in:
parent
e6bc956e49
commit
c9ab13d5a3
12 changed files with 1047 additions and 71 deletions
|
|
@ -1,5 +1,5 @@
|
|||
import { randomUUID } from 'node:crypto';
|
||||
import { mkdtemp, readFile, rm } from 'node:fs/promises';
|
||||
import { mkdtemp, readdir, readFile, rm, writeFile } from 'node:fs/promises';
|
||||
import { tmpdir } from 'node:os';
|
||||
import { join } from 'node:path';
|
||||
import { afterEach, describe, expect, test } from 'bun:test';
|
||||
|
|
@ -7,6 +7,8 @@ import { Pool, type PoolClient } from 'pg';
|
|||
import { getLogger, setLoggerConfig } from '@stock-bot/logger';
|
||||
import { PostgreSQLClient, runPostgresMigrations } from '@stock-bot/postgres';
|
||||
import {
|
||||
CURATE_INPUT_FILES,
|
||||
CurateInputExportError,
|
||||
exportCurateInputs,
|
||||
pinCurateInputSnapshot,
|
||||
type SecurityMasterQueryable,
|
||||
|
|
@ -95,14 +97,21 @@ async function seedFixtureData(pool: Pool) {
|
|||
try {
|
||||
await client.query('BEGIN');
|
||||
|
||||
// Ensure required MICs exist (migration 35 seeds them, ON CONFLICT DO NOTHING keeps idempotent).
|
||||
// Ensure all 11 ISO MICs exist (migration 35 seeds them, ON CONFLICT DO NOTHING keeps idempotent).
|
||||
await client.query(`
|
||||
INSERT INTO exchange (mic, operating_mic, name, country_iso, currency, timezone, calendar_code, board_lot_policy)
|
||||
VALUES
|
||||
('ARCX', 'XNYS', 'NYSE Arca', 'US', 'USD', 'America/New_York', 'XNYS', 'us_100'),
|
||||
('BATS', 'BATS', 'Cboe BZX Exchange', 'US', 'USD', 'America/New_York', 'XNYS', 'us_100'),
|
||||
('IEXG', 'IEXG', 'Investors Exchange', 'US', 'USD', 'America/New_York', 'XNYS', 'us_100'),
|
||||
('NEOE', 'NEOE', 'Cboe Canada (NEO Exchange)', 'CA', 'CAD', 'America/Toronto', 'XTSE', 'tsx_tiered'),
|
||||
('OTCM', 'OTCM', 'OTC Markets', 'US', 'USD', 'America/New_York', 'XNYS', 'us_100'),
|
||||
('XASE', 'XNYS', 'NYSE American', 'US', 'USD', 'America/New_York', 'XNYS', 'us_100'),
|
||||
('XCNQ', 'XCNQ', 'Canadian Securities Exchange', 'CA', 'CAD', 'America/Toronto', 'XTSE', 'tsx_tiered'),
|
||||
('XNAS', 'XNAS', 'NASDAQ', 'US', 'USD', 'America/New_York', 'XNYS', 'us_100'),
|
||||
('XNYS', 'XNYS', 'NYSE', 'US', 'USD', 'America/New_York', 'XNYS', 'us_100'),
|
||||
('XTSE', 'XTSE', 'TSX', 'CA', 'CAD', 'America/Toronto', 'XTSE', 'tsx_tiered'),
|
||||
('OTCM', 'OTCM', 'OTC Markets', 'US', 'USD', 'America/New_York', 'XNYS', 'us_100')
|
||||
('XTSX', 'XTSX', 'TSX Venture Exchange', 'CA', 'CAD', 'America/Toronto', 'XTSE', 'tsx_tiered')
|
||||
ON CONFLICT (mic) DO NOTHING
|
||||
`);
|
||||
|
||||
|
|
@ -132,6 +141,13 @@ async function seedFixtureData(pool: Pool) {
|
|||
const instNoListedTo = await insertInstrument('US0000000035', '000000003', 'No ListedTo Corp', 'common', 'US');
|
||||
const instNoQm = await insertInstrument('US0000000043', '000000004', 'No QM Mapping Corp', 'common', 'US');
|
||||
const instNoSuccQm = await insertInstrument('US0000000050', '000000005', 'No Succ QM Corp', 'common', 'US');
|
||||
const instArcx = await insertInstrument('US0000000068', '000000006', 'Arca ETF Corp', 'etf', 'US');
|
||||
const instXase = await insertInstrument('US0000000076', '000000007', 'American Corp', 'common', 'US');
|
||||
const instBats = await insertInstrument('US0000000084', '000000008', 'BZX ETF Corp', 'etf', 'US');
|
||||
const instIexg = await insertInstrument('US0000000092', '000000009', 'IEX Corp', 'common', 'US');
|
||||
const instNeoe = await insertInstrument('CA0000000109', '000000010', 'NEO Corp', 'common', 'CA');
|
||||
const instXtsx = await insertInstrument('CA0000000117', '000000011', 'Venture Mining Corp', 'common', 'CA');
|
||||
const instXcnq = await insertInstrument('CA0000000125', '000000012', 'CSE Junior Corp', 'common', 'CA');
|
||||
|
||||
const insertListing = async (params: {
|
||||
instrumentId: number;
|
||||
|
|
@ -284,6 +300,76 @@ async function seedFixtureData(pool: Pool) {
|
|||
delistReason: null,
|
||||
terminalReturn: null,
|
||||
});
|
||||
const arcxId = await insertListing({
|
||||
instrumentId: instArcx,
|
||||
mic: 'ARCX',
|
||||
tickerRoot: 'ARCA',
|
||||
currency: 'USD',
|
||||
listedFrom: '2020-01-02',
|
||||
listedTo: null,
|
||||
delistReason: 'active',
|
||||
terminalReturn: null,
|
||||
});
|
||||
const xaseId = await insertListing({
|
||||
instrumentId: instXase,
|
||||
mic: 'XASE',
|
||||
tickerRoot: 'AMEX',
|
||||
currency: 'USD',
|
||||
listedFrom: '2020-01-02',
|
||||
listedTo: null,
|
||||
delistReason: 'active',
|
||||
terminalReturn: null,
|
||||
});
|
||||
const batsId = await insertListing({
|
||||
instrumentId: instBats,
|
||||
mic: 'BATS',
|
||||
tickerRoot: 'CBOE',
|
||||
currency: 'USD',
|
||||
listedFrom: '2020-01-02',
|
||||
listedTo: null,
|
||||
delistReason: 'active',
|
||||
terminalReturn: null,
|
||||
});
|
||||
const iexgId = await insertListing({
|
||||
instrumentId: instIexg,
|
||||
mic: 'IEXG',
|
||||
tickerRoot: 'IEXX',
|
||||
currency: 'USD',
|
||||
listedFrom: '2020-01-02',
|
||||
listedTo: null,
|
||||
delistReason: 'active',
|
||||
terminalReturn: null,
|
||||
});
|
||||
const neoeId = await insertListing({
|
||||
instrumentId: instNeoe,
|
||||
mic: 'NEOE',
|
||||
tickerRoot: 'NEOC',
|
||||
currency: 'CAD',
|
||||
listedFrom: '2020-01-02',
|
||||
listedTo: null,
|
||||
delistReason: 'active',
|
||||
terminalReturn: null,
|
||||
});
|
||||
const xtsxId = await insertListing({
|
||||
instrumentId: instXtsx,
|
||||
mic: 'XTSX',
|
||||
tickerRoot: 'VMIN',
|
||||
currency: 'CAD',
|
||||
listedFrom: '2020-01-02',
|
||||
listedTo: null,
|
||||
delistReason: 'active',
|
||||
terminalReturn: null,
|
||||
});
|
||||
const xcnqId = await insertListing({
|
||||
instrumentId: instXcnq,
|
||||
mic: 'XCNQ',
|
||||
tickerRoot: 'CSEJ',
|
||||
currency: 'CAD',
|
||||
listedFrom: '2020-01-02',
|
||||
listedTo: null,
|
||||
delistReason: 'active',
|
||||
terminalReturn: null,
|
||||
});
|
||||
|
||||
const insertMapping = async (
|
||||
source: string,
|
||||
|
|
@ -351,6 +437,13 @@ async function seedFixtureData(pool: Pool) {
|
|||
noQmId,
|
||||
noSuccQmFromId,
|
||||
noSuccQmToId,
|
||||
arcxId,
|
||||
xaseId,
|
||||
batsId,
|
||||
iexgId,
|
||||
neoeId,
|
||||
xtsxId,
|
||||
xcnqId,
|
||||
};
|
||||
} catch (error) {
|
||||
await client.query('ROLLBACK').catch(() => {});
|
||||
|
|
@ -402,6 +495,7 @@ describe('exportCurateInputs PostgreSQL integration (isolated stock_bot_safety_*
|
|||
expect(pinned5000.generationId).toBe(res5000.generationId);
|
||||
expect(pinned5000.providerMapping).toBe(res5000.providerMapping.path);
|
||||
expect(pinned5000.listingCurrencies).toBe(res5000.listingCurrencies.path);
|
||||
expect(pinned5000.listingVenues).toBe(res5000.listingVenues.path);
|
||||
expect(pinned5000.delistings).toBe(res5000.delistings.path);
|
||||
|
||||
// Verify chunkSize=1 actually paginated across multiple queries.
|
||||
|
|
@ -410,10 +504,12 @@ describe('exportCurateInputs PostgreSQL integration (isolated stock_bot_safety_*
|
|||
// Byte-identical outputs between chunkSize=1 and chunkSize=5000.
|
||||
const pm5000 = await readFile(res5000.providerMapping.path, 'utf8');
|
||||
const lc5000 = await readFile(res5000.listingCurrencies.path, 'utf8');
|
||||
const lv5000 = await readFile(res5000.listingVenues.path, 'utf8');
|
||||
const dl5000 = await readFile(res5000.delistings.path, 'utf8');
|
||||
|
||||
expect(await readFile(res1.providerMapping.path, 'utf8')).toBe(pm5000);
|
||||
expect(await readFile(res1.listingCurrencies.path, 'utf8')).toBe(lc5000);
|
||||
expect(await readFile(res1.listingVenues.path, 'utf8')).toBe(lv5000);
|
||||
expect(await readFile(res1.delistings.path, 'utf8')).toBe(dl5000);
|
||||
|
||||
// Assert exact provider_mapping.tsv content (COLLATE "C" ASCII order).
|
||||
|
|
@ -456,10 +552,60 @@ describe('exportCurateInputs PostgreSQL integration (isolated stock_bot_safety_*
|
|||
`${ids.noQmId}\tUSD`,
|
||||
`${ids.noSuccQmFromId}\tUSD`,
|
||||
`${ids.noSuccQmToId}\tUSD`,
|
||||
`${ids.arcxId}\tUSD`,
|
||||
`${ids.xaseId}\tUSD`,
|
||||
`${ids.batsId}\tUSD`,
|
||||
`${ids.iexgId}\tUSD`,
|
||||
`${ids.neoeId}\tCAD`,
|
||||
`${ids.xtsxId}\tCAD`,
|
||||
`${ids.xcnqId}\tCAD`,
|
||||
'',
|
||||
].join('\n')
|
||||
);
|
||||
|
||||
// Assert exact listing_venues.tsv content covering all 11 ISO MICs (us_tsx vs tsxv_cse).
|
||||
expect(lv5000).toBe(
|
||||
[
|
||||
`${ids.aaplId}\tus_tsx`,
|
||||
`${ids.shopId}\tus_tsx`,
|
||||
`${ids.fbOldId}\tus_tsx`,
|
||||
`${ids.fbNewId}\tus_tsx`,
|
||||
`${ids.sivbId}\tus_tsx`,
|
||||
`${ids.sivbReuseId}\tus_tsx`,
|
||||
`${ids.sivbqId}\tus_tsx`,
|
||||
`${ids.del30Id}\tus_tsx`,
|
||||
`${ids.noListedToId}\tus_tsx`,
|
||||
`${ids.noQmId}\tus_tsx`,
|
||||
`${ids.noSuccQmFromId}\tus_tsx`,
|
||||
`${ids.noSuccQmToId}\tus_tsx`,
|
||||
`${ids.arcxId}\tus_tsx`,
|
||||
`${ids.xaseId}\tus_tsx`,
|
||||
`${ids.batsId}\tus_tsx`,
|
||||
`${ids.iexgId}\tus_tsx`,
|
||||
`${ids.neoeId}\tus_tsx`,
|
||||
`${ids.xtsxId}\ttsxv_cse`,
|
||||
`${ids.xcnqId}\ttsxv_cse`,
|
||||
'',
|
||||
].join('\n')
|
||||
);
|
||||
|
||||
// Verify strict load_listing_venues_tsv compliance (headerless 2-col LF TSV, ascending positive i32).
|
||||
expect(lv5000.includes('\r')).toBe(false);
|
||||
expect(lv5000.endsWith('\n')).toBe(true);
|
||||
const lvLines = lv5000.slice(0, -1).split('\n');
|
||||
expect(lvLines).toHaveLength(19);
|
||||
let prevListingId = 0;
|
||||
for (const line of lvLines) {
|
||||
const cols = line.split('\t');
|
||||
expect(cols).toHaveLength(2);
|
||||
expect(cols[0]).toMatch(/^[1-9]\d*$/);
|
||||
const id = Number(cols[0]);
|
||||
expect(id).toBeGreaterThan(prevListingId);
|
||||
expect(id).toBeLessThanOrEqual(2_147_483_647);
|
||||
expect(cols[1] === 'us_tsx' || cols[1] === 'tsxv_cse').toBe(true);
|
||||
prevListingId = id;
|
||||
}
|
||||
|
||||
// Assert exact delistings.tsv content.
|
||||
expect(dl5000).toBe(
|
||||
[
|
||||
|
|
@ -473,13 +619,13 @@ describe('exportCurateInputs PostgreSQL integration (isolated stock_bot_safety_*
|
|||
// Assert exact stats reconciliation.
|
||||
const stats = res5000.delistings.stats;
|
||||
expect(stats).toEqual({
|
||||
rowsIn: 12,
|
||||
rowsIn: 19,
|
||||
rowsOut: 3,
|
||||
otcTransfersOut: 1,
|
||||
terminalDelistingsOut: 2,
|
||||
skippedTotal: 9,
|
||||
skippedTotal: 16,
|
||||
skipped: {
|
||||
active: 4, // AAPL, SHOP, FB new, SIVB reuse
|
||||
active: 11, // AAPL, SHOP, FB new, SIVB reuse + 7 MIC-coverage active listings
|
||||
noOutcome: 2, // FB old, NOSUQ
|
||||
missingListedTo: 1, // NLDT
|
||||
missingOutgoingQmMapping: 1, // NOQM
|
||||
|
|
@ -489,5 +635,80 @@ describe('exportCurateInputs PostgreSQL integration (isolated stock_bot_safety_*
|
|||
});
|
||||
expect(stats.rowsIn).toBe(stats.rowsOut + stats.skippedTotal);
|
||||
expect(res1.delistings.stats).toEqual(stats);
|
||||
expect(res5000.listingVenues.rowsIn).toBe(19);
|
||||
expect(res5000.listingVenues.rowsOut).toBe(19);
|
||||
expect(res1.listingVenues.bytesWritten).toBe(res5000.listingVenues.bytesWritten);
|
||||
});
|
||||
|
||||
test('fails closed with UNKNOWN_LISTING_MIC on an unmapped exchange MIC (XLON) and leaves existing outDir files intact', async () => {
|
||||
const { pool } = await createIsolatedFixture();
|
||||
const client = await pool.connect();
|
||||
let xlonListingId = 0;
|
||||
try {
|
||||
await client.query('BEGIN');
|
||||
await client.query(`
|
||||
INSERT INTO exchange (mic, operating_mic, name, country_iso, currency, timezone, calendar_code, board_lot_policy)
|
||||
VALUES ('XLON', 'XLON', 'London Stock Exchange', 'GB', 'GBP', 'Europe/London', 'XLON', 'us_100')
|
||||
ON CONFLICT (mic) DO NOTHING
|
||||
`);
|
||||
const instRes = await client.query<{ instrument_id: number }>(
|
||||
`INSERT INTO instrument (primary_isin, primary_cusip, canonical_name, security_type, issuer_country)
|
||||
VALUES ('GB0000000011', 'G00000001', 'London Test PLC', 'common', 'GB')
|
||||
RETURNING instrument_id`
|
||||
);
|
||||
const listRes = await client.query<{ listing_id: number }>(
|
||||
`INSERT INTO listing (
|
||||
instrument_id, mic, ticker_root, class_suffix, currency,
|
||||
listed_from, listed_to, delist_reason, terminal_return
|
||||
)
|
||||
VALUES ($1, 'XLON', 'LSE', '', 'GBP', '2020-01-02'::date, NULL, 'active', NULL)
|
||||
RETURNING listing_id`,
|
||||
[instRes.rows[0]!.instrument_id]
|
||||
);
|
||||
xlonListingId = listRes.rows[0]!.listing_id;
|
||||
await client.query('COMMIT');
|
||||
} catch (error) {
|
||||
await client.query('ROLLBACK').catch(() => {});
|
||||
throw error;
|
||||
} finally {
|
||||
client.release();
|
||||
}
|
||||
|
||||
const outDir = await makeTempDir('curate-inputs-pg-unknown-mic-');
|
||||
const origPm = 'eod\tORIG.US\t2020-01-01\t\t1\n';
|
||||
const origLc = '1\tUSD\n';
|
||||
const origLv = '1\tus_tsx\n';
|
||||
const origDl = 'ORIG\t2023-01-01\t1\t\t-0.3\n';
|
||||
await writeFile(join(outDir, CURATE_INPUT_FILES.providerMapping), origPm, 'utf8');
|
||||
await writeFile(join(outDir, CURATE_INPUT_FILES.listingCurrencies), origLc, 'utf8');
|
||||
await writeFile(join(outDir, CURATE_INPUT_FILES.listingVenues), origLv, 'utf8');
|
||||
await writeFile(join(outDir, CURATE_INPUT_FILES.delistings), origDl, 'utf8');
|
||||
|
||||
let caught: unknown;
|
||||
try {
|
||||
await withRecordingClient(pool, async queryable => {
|
||||
await exportCurateInputs(queryable, { outDir });
|
||||
});
|
||||
} catch (error) {
|
||||
caught = error;
|
||||
}
|
||||
|
||||
expect(caught).toBeInstanceOf(CurateInputExportError);
|
||||
const err = caught as CurateInputExportError;
|
||||
expect(err.code).toBe('UNKNOWN_LISTING_MIC');
|
||||
expect(err.table).toBe('listing');
|
||||
expect(err.key).toBe(`listing_id=${xlonListingId}`);
|
||||
expect(err.message).toContain('XLON');
|
||||
|
||||
expect(await readFile(join(outDir, CURATE_INPUT_FILES.providerMapping), 'utf8')).toBe(origPm);
|
||||
expect(await readFile(join(outDir, CURATE_INPUT_FILES.listingCurrencies), 'utf8')).toBe(origLc);
|
||||
expect(await readFile(join(outDir, CURATE_INPUT_FILES.listingVenues), 'utf8')).toBe(origLv);
|
||||
expect(await readFile(join(outDir, CURATE_INPUT_FILES.delistings), 'utf8')).toBe(origDl);
|
||||
expect((await readdir(outDir)).sort()).toEqual([
|
||||
CURATE_INPUT_FILES.delistings,
|
||||
CURATE_INPUT_FILES.listingCurrencies,
|
||||
CURATE_INPUT_FILES.listingVenues,
|
||||
CURATE_INPUT_FILES.providerMapping,
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -19,16 +19,22 @@ import {
|
|||
formatDelistingsTsv,
|
||||
formatExportCurateInputsSummary,
|
||||
formatListingCurrenciesTsv,
|
||||
formatListingVenuesTsv,
|
||||
formatPlainDecimal,
|
||||
formatProviderMappingTsv,
|
||||
ISO_EXCHANGE_SEEDS,
|
||||
LISTING_STATUTORY_LAG_VENUES,
|
||||
LISTING_VENUE_BY_MIC,
|
||||
parseExportCurateInputsArgs,
|
||||
pinCurateInputSnapshot,
|
||||
resolveListingVenueForMic,
|
||||
runExportCurateInputs,
|
||||
runExportCurateInputsCli,
|
||||
type ContinuityExportSourceRow,
|
||||
type DelistingExportRow,
|
||||
type ListingCurrencyExportRow,
|
||||
type ListingDelistingSourceRow,
|
||||
type ListingVenueExportRow,
|
||||
type ProviderMappingExportRow,
|
||||
type SecurityMasterQueryable,
|
||||
type SecurityMasterQueryResult,
|
||||
|
|
@ -93,6 +99,7 @@ async function expectExportErrorAsync(
|
|||
interface InMemorySecurityMasterData {
|
||||
readonly listings: readonly {
|
||||
readonly listing_id: number;
|
||||
readonly mic: string | null;
|
||||
readonly currency: string | null;
|
||||
readonly listed_to: string | null;
|
||||
readonly delist_reason: string | null;
|
||||
|
|
@ -579,6 +586,135 @@ describe('formatListingCurrenciesTsv', () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe('resolveListingVenueForMic and formatListingVenuesTsv', () => {
|
||||
test('maps all 11 ISO_EXCHANGE_SEEDS MICs to us_tsx or tsxv_cse with 100% coverage', () => {
|
||||
const usTsxMics = ['XTSE', 'XNYS', 'XNAS', 'ARCX', 'XASE', 'BATS', 'NEOE', 'OTCM', 'IEXG'];
|
||||
const tsxvCseMics = ['XTSX', 'XCNQ'];
|
||||
|
||||
for (const mic of usTsxMics) {
|
||||
expect(resolveListingVenueForMic(mic)).toBe('us_tsx');
|
||||
}
|
||||
for (const mic of tsxvCseMics) {
|
||||
expect(resolveListingVenueForMic(mic)).toBe('tsxv_cse');
|
||||
}
|
||||
|
||||
const seededMics = ISO_EXCHANGE_SEEDS.map(s => s.mic).sort(compareAscii);
|
||||
const mappedMics = Object.keys(LISTING_VENUE_BY_MIC).sort(compareAscii);
|
||||
expect(mappedMics).toEqual(seededMics);
|
||||
expect(seededMics).toHaveLength(11);
|
||||
for (const seed of ISO_EXCHANGE_SEEDS) {
|
||||
expect(LISTING_STATUTORY_LAG_VENUES).toContain(resolveListingVenueForMic(seed.mic));
|
||||
}
|
||||
});
|
||||
|
||||
test('resolveListingVenueForMic fails closed on unknown, blank, whitespace-padded, control-char, and prototype-key MICs', () => {
|
||||
for (const unknownMic of ['XLON', 'xtse', ' XTSE ', 'XTSX ', '__proto__', 'toString', 'constructor']) {
|
||||
expectExportError(
|
||||
() => resolveListingVenueForMic(unknownMic, 'listing', 'listing_id=42'),
|
||||
'UNKNOWN_LISTING_MIC',
|
||||
'listing',
|
||||
'listing_id=42'
|
||||
);
|
||||
}
|
||||
|
||||
for (const blankMic of ['', ' ', null, undefined]) {
|
||||
expectExportError(
|
||||
() => resolveListingVenueForMic(blankMic, 'listing', 'listing_id=42'),
|
||||
'BLANK_FIELD',
|
||||
'listing',
|
||||
'listing_id=42'
|
||||
);
|
||||
}
|
||||
|
||||
for (const controlMic of ['XT\tSE', 'XT\nSE', 'XT\rSE']) {
|
||||
expectExportError(
|
||||
() => resolveListingVenueForMic(controlMic, 'listing', 'listing_id=42'),
|
||||
'FORBIDDEN_CONTROL_CHAR',
|
||||
'listing',
|
||||
'listing_id=42'
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
test('formatListingVenuesTsv sorts by ascending listing_id, handles empty input, and satisfies load_listing_venues_tsv rules', () => {
|
||||
expect(formatListingVenuesTsv([])).toBe('');
|
||||
|
||||
const rows: ListingVenueExportRow[] = [
|
||||
{ listingId: 10, venue: 'tsxv_cse' },
|
||||
{ listingId: 2, venue: 'us_tsx' },
|
||||
{ listingId: 5, venue: 'tsxv_cse' },
|
||||
{ listingId: 2_147_483_647, venue: 'us_tsx' },
|
||||
];
|
||||
const expected = '2\tus_tsx\n5\ttsxv_cse\n10\ttsxv_cse\n2147483647\tus_tsx\n';
|
||||
const actual = formatListingVenuesTsv(rows);
|
||||
expect(actual).toBe(expected);
|
||||
expect(formatListingVenuesTsv([...rows].reverse())).toBe(expected);
|
||||
|
||||
// Cross-language load_listing_venues_tsv format verification
|
||||
expect(actual.includes('\r')).toBe(false);
|
||||
expect(actual.endsWith('\n')).toBe(true);
|
||||
const lines = actual.slice(0, -1).split('\n');
|
||||
expect(lines).toHaveLength(rows.length);
|
||||
let prevId = 0;
|
||||
for (const line of lines) {
|
||||
const cols = line.split('\t');
|
||||
expect(cols).toHaveLength(2);
|
||||
expect(cols[0]).toMatch(/^[1-9]\d*$/);
|
||||
const id = Number(cols[0]);
|
||||
expect(id).toBeGreaterThan(prevId);
|
||||
expect(id).toBeLessThanOrEqual(2_147_483_647);
|
||||
expect(cols[1] === 'us_tsx' || cols[1] === 'tsxv_cse').toBe(true);
|
||||
prevId = id;
|
||||
}
|
||||
});
|
||||
|
||||
test('formatListingVenuesTsv fails closed on invalid listing_id, invalid venue, control chars, and duplicate listing_id', () => {
|
||||
for (const badId of [0, -3, 2_147_483_648]) {
|
||||
expectExportError(
|
||||
() => formatListingVenuesTsv([{ listingId: badId, venue: 'us_tsx' }]),
|
||||
'INVALID_LISTING_ID',
|
||||
'listing',
|
||||
'row#0'
|
||||
);
|
||||
}
|
||||
|
||||
for (const badVenue of ['', 'NYSE', 'US_TSX', ' us_tsx ', null, undefined]) {
|
||||
expectExportError(
|
||||
() =>
|
||||
formatListingVenuesTsv([
|
||||
{ listingId: 1, venue: badVenue as unknown as ListingVenueExportRow['venue'] },
|
||||
]),
|
||||
'INVALID_LISTING_VENUE',
|
||||
'listing',
|
||||
'listing_id=1'
|
||||
);
|
||||
}
|
||||
|
||||
for (const ctrlVenue of ['us_tsx\t', 'us_tsx\n', 'tsxv_cse\r']) {
|
||||
expectExportError(
|
||||
() =>
|
||||
formatListingVenuesTsv([
|
||||
{ listingId: 1, venue: ctrlVenue as unknown as ListingVenueExportRow['venue'] },
|
||||
]),
|
||||
'FORBIDDEN_CONTROL_CHAR',
|
||||
'listing',
|
||||
'listing_id=1'
|
||||
);
|
||||
}
|
||||
|
||||
expectExportError(
|
||||
() =>
|
||||
formatListingVenuesTsv([
|
||||
{ listingId: 7, venue: 'us_tsx' },
|
||||
{ listingId: 7, venue: 'tsxv_cse' },
|
||||
]),
|
||||
'DUPLICATE_LISTING_VENUE',
|
||||
'listing',
|
||||
'listing_id=7'
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('buildDelistingExportRows and formatDelistingsTsv', () => {
|
||||
test('handles OTC transfer + successor terminal delisting (SIVB -> SIVBQ -> -1), -0.3 Shumway, active/null skips, and stats conservation', () => {
|
||||
const listings: ListingDelistingSourceRow[] = [
|
||||
|
|
@ -760,18 +896,21 @@ describe('exportCurateInputs atomic publish and streaming', () => {
|
|||
const outDir = await makeTempDir('curate-inputs-atomic-');
|
||||
const pmPath = join(outDir, CURATE_INPUT_FILES.providerMapping);
|
||||
const lcPath = join(outDir, CURATE_INPUT_FILES.listingCurrencies);
|
||||
const lvPath = join(outDir, CURATE_INPUT_FILES.listingVenues);
|
||||
const dlPath = join(outDir, CURATE_INPUT_FILES.delistings);
|
||||
|
||||
const origPm = 'eod\tORIG.US\t2020-01-01\t\t1\n';
|
||||
const origLc = '1\tUSD\n';
|
||||
const origLv = '1\tus_tsx\n';
|
||||
const origDl = 'ORIG\t2023-01-01\t1\t\t-0.3\n';
|
||||
await writeFile(pmPath, origPm, 'utf8');
|
||||
await writeFile(lcPath, origLc, 'utf8');
|
||||
await writeFile(lvPath, origLv, 'utf8');
|
||||
await writeFile(dlPath, origDl, 'utf8');
|
||||
|
||||
const baseData: InMemorySecurityMasterData = {
|
||||
listings: [
|
||||
{ listing_id: 1, currency: 'USD', listed_to: null, delist_reason: 'active', terminal_return: null },
|
||||
{ listing_id: 1, mic: 'XNAS', currency: 'USD', listed_to: null, delist_reason: 'active', terminal_return: null },
|
||||
],
|
||||
continuities: [],
|
||||
providerMappings: [
|
||||
|
|
@ -782,11 +921,13 @@ describe('exportCurateInputs atomic publish and streaming', () => {
|
|||
const assertIntact = async () => {
|
||||
expect(await readFile(pmPath, 'utf8')).toBe(origPm);
|
||||
expect(await readFile(lcPath, 'utf8')).toBe(origLc);
|
||||
expect(await readFile(lvPath, 'utf8')).toBe(origLv);
|
||||
expect(await readFile(dlPath, 'utf8')).toBe(origDl);
|
||||
const entries = (await readdir(outDir)).sort();
|
||||
expect(entries).toEqual([
|
||||
CURATE_INPUT_FILES.delistings,
|
||||
CURATE_INPUT_FILES.listingCurrencies,
|
||||
CURATE_INPUT_FILES.listingVenues,
|
||||
CURATE_INPUT_FILES.providerMapping,
|
||||
]);
|
||||
};
|
||||
|
|
@ -798,7 +939,7 @@ describe('exportCurateInputs atomic publish and streaming', () => {
|
|||
);
|
||||
await assertIntact();
|
||||
|
||||
// 2. Mid-validation failure (tab inside source_id)
|
||||
// 2a. Mid-validation failure (tab inside source_id)
|
||||
const badDataClient = createInMemoryQueryable({
|
||||
...baseData,
|
||||
providerMappings: [
|
||||
|
|
@ -813,6 +954,21 @@ describe('exportCurateInputs atomic publish and streaming', () => {
|
|||
);
|
||||
await assertIntact();
|
||||
|
||||
// 2b. Mid-validation failure (unmapped listing MIC)
|
||||
const badMicClient = createInMemoryQueryable({
|
||||
...baseData,
|
||||
listings: [
|
||||
{ listing_id: 1, mic: 'XLON', currency: 'USD', listed_to: null, delist_reason: 'active', terminal_return: null },
|
||||
],
|
||||
});
|
||||
await expectExportErrorAsync(
|
||||
() => exportCurateInputs(badMicClient, { outDir }),
|
||||
'UNKNOWN_LISTING_MIC',
|
||||
'listing',
|
||||
'listing_id=1'
|
||||
);
|
||||
await assertIntact();
|
||||
|
||||
// 3. Mid-rename failure on the 2nd top-level target symlink replacement (after staging->gen + 1st backup/link + 2nd backup)
|
||||
let renameCalls = 0;
|
||||
const goodClient = createInMemoryQueryable(baseData);
|
||||
|
|
@ -832,7 +988,7 @@ describe('exportCurateInputs atomic publish and streaming', () => {
|
|||
).rejects.toThrow('Simulated EIO on 2nd target publish rename');
|
||||
await assertIntact();
|
||||
|
||||
// 4. Failure at the atomic `current` commit rename restores all 3 pre-existing files cleanly
|
||||
// 4. Failure at the atomic `current` commit rename restores all 4 pre-existing files cleanly
|
||||
const commitFailClient = createInMemoryQueryable(baseData);
|
||||
await expect(
|
||||
exportCurateInputs(commitFailClient, {
|
||||
|
|
@ -854,15 +1010,17 @@ describe('exportCurateInputs atomic publish and streaming', () => {
|
|||
const outDir = await makeTempDir('curate-inputs-post-commit-cleanup-');
|
||||
const pmPath = join(outDir, CURATE_INPUT_FILES.providerMapping);
|
||||
const lcPath = join(outDir, CURATE_INPUT_FILES.listingCurrencies);
|
||||
const lvPath = join(outDir, CURATE_INPUT_FILES.listingVenues);
|
||||
const dlPath = join(outDir, CURATE_INPUT_FILES.delistings);
|
||||
|
||||
await writeFile(pmPath, 'eod\tOLD.US\t2020-01-01\t\t1\n', 'utf8');
|
||||
await writeFile(lcPath, '1\tUSD\n', 'utf8');
|
||||
await writeFile(lvPath, '1\tus_tsx\n', 'utf8');
|
||||
await writeFile(dlPath, 'OLD\t2023-01-01\t1\t\t-0.3\n', 'utf8');
|
||||
|
||||
const newData: InMemorySecurityMasterData = {
|
||||
listings: [
|
||||
{ listing_id: 2, currency: 'CAD', listed_to: null, delist_reason: 'active', terminal_return: null },
|
||||
{ listing_id: 2, mic: 'XTSX', currency: 'CAD', listed_to: null, delist_reason: 'active', terminal_return: null },
|
||||
],
|
||||
continuities: [],
|
||||
providerMappings: [
|
||||
|
|
@ -886,13 +1044,14 @@ describe('exportCurateInputs atomic publish and streaming', () => {
|
|||
},
|
||||
});
|
||||
|
||||
// All three live paths reflect the new committed snapshot (no partial rollback).
|
||||
// All four live paths reflect the new committed snapshot (no partial rollback).
|
||||
expect(await readFile(pmPath, 'utf8')).toBe('eod\tNEW.TO\t2022-01-01\t\t2\n');
|
||||
expect(await readFile(lcPath, 'utf8')).toBe('2\tCAD\n');
|
||||
expect(await readFile(lvPath, 'utf8')).toBe('2\ttsxv_cse\n');
|
||||
expect(await readFile(dlPath, 'utf8')).toBe('');
|
||||
|
||||
// Backup #1 and #3 were deleted; #2 failed and is reported in cleanupWarnings.
|
||||
expect(backupUnlinkCalls).toBe(3);
|
||||
// Backups #1, #3, #4 were deleted; #2 failed and is reported in cleanupWarnings.
|
||||
expect(backupUnlinkCalls).toBe(4);
|
||||
expect(result.cleanupWarnings).toHaveLength(1);
|
||||
expect(result.cleanupWarnings[0]).toContain('Simulated EIO deleting 2nd backup');
|
||||
expect(result.cleanupWarnings[0]).toContain('.bak');
|
||||
|
|
@ -903,18 +1062,21 @@ describe('exportCurateInputs atomic publish and streaming', () => {
|
|||
const outDir = await makeTempDir('curate-inputs-restore-fail-');
|
||||
const pmPath = join(outDir, CURATE_INPUT_FILES.providerMapping);
|
||||
const lcPath = join(outDir, CURATE_INPUT_FILES.listingCurrencies);
|
||||
const lvPath = join(outDir, CURATE_INPUT_FILES.listingVenues);
|
||||
const dlPath = join(outDir, CURATE_INPUT_FILES.delistings);
|
||||
|
||||
const origPm = 'eod\tORIG.US\t2020-01-01\t\t1\n';
|
||||
const origLc = '1\tUSD\n';
|
||||
const origLv = '1\tus_tsx\n';
|
||||
const origDl = 'ORIG\t2023-01-01\t1\t\t-0.3\n';
|
||||
await writeFile(pmPath, origPm, 'utf8');
|
||||
await writeFile(lcPath, origLc, 'utf8');
|
||||
await writeFile(lvPath, origLv, 'utf8');
|
||||
await writeFile(dlPath, origDl, 'utf8');
|
||||
|
||||
const newData: InMemorySecurityMasterData = {
|
||||
listings: [
|
||||
{ listing_id: 2, currency: 'CAD', listed_to: null, delist_reason: 'active', terminal_return: null },
|
||||
{ listing_id: 2, mic: 'XTSE', currency: 'CAD', listed_to: null, delist_reason: 'active', terminal_return: null },
|
||||
],
|
||||
continuities: [],
|
||||
providerMappings: [
|
||||
|
|
@ -928,7 +1090,7 @@ describe('exportCurateInputs atomic publish and streaming', () => {
|
|||
outDir,
|
||||
fs: {
|
||||
rename: async (oldPath, newPath) => {
|
||||
// Fail at the atomic commit point to trigger rollback of all 3 backups.
|
||||
// Fail at the atomic commit point to trigger rollback of all 4 backups.
|
||||
if (String(newPath) === join(outDir, 'current')) {
|
||||
throw new Error('Simulated commit EIO');
|
||||
}
|
||||
|
|
@ -953,8 +1115,9 @@ describe('exportCurateInputs atomic publish and streaming', () => {
|
|||
expect(err.message).toContain('Simulated restore EIO');
|
||||
expect(err.message).toContain('.bak');
|
||||
|
||||
// The other two targets were restored intact.
|
||||
// The other three targets were restored intact.
|
||||
expect(await readFile(lcPath, 'utf8')).toBe(origLc);
|
||||
expect(await readFile(lvPath, 'utf8')).toBe(origLv);
|
||||
expect(await readFile(dlPath, 'utf8')).toBe(origDl);
|
||||
|
||||
// The unrestored provider_mapping backup MUST still exist on disk with original bytes!
|
||||
|
|
@ -972,7 +1135,7 @@ describe('exportCurateInputs atomic publish and streaming', () => {
|
|||
// Generation 1: only SIVB active (no SIVBQ successor yet).
|
||||
const gen1Data: InMemorySecurityMasterData = {
|
||||
listings: [
|
||||
{ listing_id: 4, currency: 'USD', listed_to: null, delist_reason: 'active', terminal_return: null },
|
||||
{ listing_id: 4, mic: 'XNAS', currency: 'USD', listed_to: null, delist_reason: 'active', terminal_return: null },
|
||||
],
|
||||
continuities: [],
|
||||
providerMappings: [
|
||||
|
|
@ -983,8 +1146,8 @@ describe('exportCurateInputs atomic publish and streaming', () => {
|
|||
// Generation 2: SIVB -> SIVBQ OTC transfer added to both provider_mapping and delistings.
|
||||
const gen2Data: InMemorySecurityMasterData = {
|
||||
listings: [
|
||||
{ listing_id: 4, currency: 'USD', listed_to: '2023-03-10', delist_reason: 'moved_to_otc', terminal_return: null },
|
||||
{ listing_id: 6, currency: 'USD', listed_to: null, delist_reason: 'active', terminal_return: null },
|
||||
{ listing_id: 4, mic: 'XNAS', currency: 'USD', listed_to: '2023-03-10', delist_reason: 'moved_to_otc', terminal_return: null },
|
||||
{ listing_id: 6, mic: 'OTCM', currency: 'USD', listed_to: null, delist_reason: 'active', terminal_return: null },
|
||||
],
|
||||
continuities: [
|
||||
{ from_listing_id: 4, to_listing_id: 6, effective_date: '2023-03-28', kind: 'otc_delist_transfer' },
|
||||
|
|
@ -1007,10 +1170,12 @@ describe('exportCurateInputs atomic publish and streaming', () => {
|
|||
const res2 = await exportCurateInputs(createInMemoryQueryable(gen2Data), { outDir });
|
||||
expect(res2.generationId).not.toBe(res1.generationId);
|
||||
|
||||
// Consumer 1 finishes reading listing_currencies.tsv and delistings.tsv from its pinned generation 1.
|
||||
// Consumer 1 finishes reading listing_currencies.tsv, listing_venues.tsv, and delistings.tsv from its pinned generation 1.
|
||||
const consumer1Lc = await readFile(pinned1.listingCurrencies, 'utf8');
|
||||
const consumer1Lv = await readFile(pinned1.listingVenues, 'utf8');
|
||||
const consumer1Dl = await readFile(pinned1.delistings, 'utf8');
|
||||
expect(consumer1Lc).toBe('4\tUSD\n');
|
||||
expect(consumer1Lv).toBe('4\tus_tsx\n');
|
||||
expect(consumer1Dl).toBe(''); // Consistent with gen1 (no SIVBQ transfer referencing missing SIVBQ!)
|
||||
|
||||
// Consumer 2 pins after Generation 2 committed and sees the full Generation 2 snapshot.
|
||||
|
|
@ -1020,6 +1185,7 @@ describe('exportCurateInputs atomic publish and streaming', () => {
|
|||
'qm\tSIVB\t1988-01-04\t2023-03-10\t4\nqm\tSIVBQ\t2023-03-28\t\t6\n'
|
||||
);
|
||||
expect(await readFile(pinned2.listingCurrencies, 'utf8')).toBe('4\tUSD\n6\tUSD\n');
|
||||
expect(await readFile(pinned2.listingVenues, 'utf8')).toBe('4\tus_tsx\n6\tus_tsx\n');
|
||||
expect(await readFile(pinned2.delistings, 'utf8')).toBe('SIVB\t2023-03-28\t4\tSIVBQ\t\n');
|
||||
});
|
||||
|
||||
|
|
@ -1028,7 +1194,7 @@ describe('exportCurateInputs atomic publish and streaming', () => {
|
|||
|
||||
const snapA: InMemorySecurityMasterData = {
|
||||
listings: [
|
||||
{ listing_id: 10, currency: 'USD', listed_to: '2023-06-15', delist_reason: 'unknown_involuntary', terminal_return: '-0.3' },
|
||||
{ listing_id: 10, mic: 'XNAS', currency: 'USD', listed_to: '2023-06-15', delist_reason: 'unknown_involuntary', terminal_return: '-0.3' },
|
||||
],
|
||||
continuities: [],
|
||||
providerMappings: [
|
||||
|
|
@ -1037,7 +1203,7 @@ describe('exportCurateInputs atomic publish and streaming', () => {
|
|||
};
|
||||
const snapB: InMemorySecurityMasterData = {
|
||||
listings: [
|
||||
{ listing_id: 20, currency: 'CAD', listed_to: '2024-01-15', delist_reason: 'bankruptcy_cancelled', terminal_return: '-1' },
|
||||
{ listing_id: 20, mic: 'XTSX', currency: 'CAD', listed_to: '2024-01-15', delist_reason: 'bankruptcy_cancelled', terminal_return: '-1' },
|
||||
],
|
||||
continuities: [],
|
||||
providerMappings: [
|
||||
|
|
@ -1053,17 +1219,20 @@ describe('exportCurateInputs atomic publish and streaming', () => {
|
|||
const pinned = await pinCurateInputSnapshot(outDir);
|
||||
const pm = await readFile(pinned.providerMapping, 'utf8');
|
||||
const lc = await readFile(pinned.listingCurrencies, 'utf8');
|
||||
const lv = await readFile(pinned.listingVenues, 'utf8');
|
||||
const dl = await readFile(pinned.delistings, 'utf8');
|
||||
|
||||
const isAllA =
|
||||
pinned.generationId === resA.generationId &&
|
||||
pm === 'qm\tSNAP_A\t2020-01-01\t2023-06-15\t10\n' &&
|
||||
lc === '10\tUSD\n' &&
|
||||
lv === '10\tus_tsx\n' &&
|
||||
dl === 'SNAP_A\t2023-06-15\t10\t\t-0.3\n';
|
||||
const isAllB =
|
||||
pinned.generationId === resB.generationId &&
|
||||
pm === 'qm\tSNAP_B\t2021-01-01\t2024-01-15\t20\n' &&
|
||||
lc === '20\tCAD\n' &&
|
||||
lv === '20\ttsxv_cse\n' &&
|
||||
dl === 'SNAP_B\t2024-01-15\t20\t\t-1\n';
|
||||
|
||||
expect(isAllA || isAllB).toBe(true);
|
||||
|
|
@ -1072,7 +1241,7 @@ describe('exportCurateInputs atomic publish and streaming', () => {
|
|||
test('concurrent fresh-dir exports serialize publish/rollback so a failed export never deletes a committed export top-level links', async () => {
|
||||
const snapA: InMemorySecurityMasterData = {
|
||||
listings: [
|
||||
{ listing_id: 10, currency: 'USD', listed_to: '2023-06-15', delist_reason: 'unknown_involuntary', terminal_return: '-0.3' },
|
||||
{ listing_id: 10, mic: 'XNAS', currency: 'USD', listed_to: '2023-06-15', delist_reason: 'unknown_involuntary', terminal_return: '-0.3' },
|
||||
],
|
||||
continuities: [],
|
||||
providerMappings: [
|
||||
|
|
@ -1081,7 +1250,7 @@ describe('exportCurateInputs atomic publish and streaming', () => {
|
|||
};
|
||||
const snapB: InMemorySecurityMasterData = {
|
||||
listings: [
|
||||
{ listing_id: 20, currency: 'CAD', listed_to: '2024-01-15', delist_reason: 'bankruptcy_cancelled', terminal_return: '-1' },
|
||||
{ listing_id: 20, mic: 'XTSX', currency: 'CAD', listed_to: '2024-01-15', delist_reason: 'bankruptcy_cancelled', terminal_return: '-1' },
|
||||
],
|
||||
continuities: [],
|
||||
providerMappings: [
|
||||
|
|
@ -1145,10 +1314,14 @@ describe('exportCurateInputs atomic publish and streaming', () => {
|
|||
expect(await readFile(join(outDir, CURATE_INPUT_FILES.listingCurrencies), 'utf8')).toBe(
|
||||
'20\tCAD\n'
|
||||
);
|
||||
expect(await readFile(join(outDir, CURATE_INPUT_FILES.listingVenues), 'utf8')).toBe(
|
||||
'20\ttsxv_cse\n'
|
||||
);
|
||||
expect(await readFile(join(outDir, CURATE_INPUT_FILES.delistings), 'utf8')).toBe(
|
||||
'SNAP_B\t2024-01-15\t20\t\t-1\n'
|
||||
);
|
||||
const pinned = await pinCurateInputSnapshot(outDir);
|
||||
expect(await readFile(pinned.listingVenues, 'utf8')).toBe('20\ttsxv_cse\n');
|
||||
expect(await readFile(pinned.delistings, 'utf8')).toBe('SNAP_B\t2024-01-15\t20\t\t-1\n');
|
||||
const entries = await readdir(outDir);
|
||||
expect(entries.some(e => e.includes('.tmp') || e.includes('.bak') || e === CURATE_INPUT_PUBLISH_LOCK)).toBe(false);
|
||||
|
|
@ -1215,10 +1388,14 @@ describe('exportCurateInputs atomic publish and streaming', () => {
|
|||
expect(await readFile(join(outDir, CURATE_INPUT_FILES.listingCurrencies), 'utf8')).toBe(
|
||||
'20\tCAD\n'
|
||||
);
|
||||
expect(await readFile(join(outDir, CURATE_INPUT_FILES.listingVenues), 'utf8')).toBe(
|
||||
'20\ttsxv_cse\n'
|
||||
);
|
||||
expect(await readFile(join(outDir, CURATE_INPUT_FILES.delistings), 'utf8')).toBe(
|
||||
'SNAP_B\t2024-01-15\t20\t\t-1\n'
|
||||
);
|
||||
const pinned = await pinCurateInputSnapshot(outDir);
|
||||
expect(await readFile(pinned.listingVenues, 'utf8')).toBe('20\ttsxv_cse\n');
|
||||
expect(await readFile(pinned.providerMapping, 'utf8')).toBe(
|
||||
'qm\tSNAP_B\t2021-01-01\t2024-01-15\t20\n'
|
||||
);
|
||||
|
|
@ -1258,6 +1435,7 @@ describe('exportCurateInputs atomic publish and streaming', () => {
|
|||
listings: [
|
||||
{
|
||||
listing_id: 1,
|
||||
mic: 'XNAS',
|
||||
currency: 'USD',
|
||||
listed_to: null,
|
||||
delist_reason: 'active',
|
||||
|
|
@ -1373,10 +1551,18 @@ describe('golden fixtures cross-language parity', () => {
|
|||
);
|
||||
|
||||
// Also verify streaming exportCurateInputs produces identical bytes with chunkSize=2.
|
||||
const goldenMics = ['XNAS', 'XNAS', 'XNYS', 'XNAS', 'XNAS', 'OTCM', 'XNYS', 'XTSE'] as const;
|
||||
const expectedLv = formatListingVenuesTsv(
|
||||
dataset.listings.map((l, idx) => ({
|
||||
listingId: l.listingId,
|
||||
venue: resolveListingVenueForMic(goldenMics[idx]!),
|
||||
}))
|
||||
);
|
||||
const outDir = await makeTempDir('curate-inputs-golden-');
|
||||
const queryable = createInMemoryQueryable({
|
||||
listings: dataset.delistingListings.map((l, idx) => ({
|
||||
listing_id: l.listingId,
|
||||
mic: goldenMics[idx]!,
|
||||
currency: dataset.listings[idx]!.currency,
|
||||
listed_to: l.listedTo,
|
||||
delist_reason: l.delistReason,
|
||||
|
|
@ -1400,8 +1586,15 @@ describe('golden fixtures cross-language parity', () => {
|
|||
const result = await exportCurateInputs(queryable, { outDir, chunkSize: 2 });
|
||||
expect(await readFile(result.providerMapping.path, 'utf8')).toBe(expectedPm);
|
||||
expect(await readFile(result.listingCurrencies.path, 'utf8')).toBe(expectedLc);
|
||||
expect(await readFile(result.listingVenues.path, 'utf8')).toBe(expectedLv);
|
||||
expect(await readFile(result.delistings.path, 'utf8')).toBe(expectedDl);
|
||||
expect(result.delistings.stats).toEqual(builtDelistings.stats);
|
||||
expect(result.totalBytesWritten).toBe(
|
||||
result.providerMapping.bytesWritten +
|
||||
result.listingCurrencies.bytesWritten +
|
||||
result.listingVenues.bytesWritten +
|
||||
result.delistings.bytesWritten
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
|
|
@ -1483,7 +1676,7 @@ describe('CLI args, safety guard, and runner', () => {
|
|||
|
||||
const queryable = createInMemoryQueryable({
|
||||
listings: [
|
||||
{ listing_id: 1, currency: 'USD', listed_to: null, delist_reason: 'active', terminal_return: null },
|
||||
{ listing_id: 1, mic: 'XNAS', currency: 'USD', listed_to: null, delist_reason: 'active', terminal_return: null },
|
||||
],
|
||||
continuities: [],
|
||||
providerMappings: [
|
||||
|
|
@ -1514,6 +1707,7 @@ describe('CLI args, safety guard, and runner', () => {
|
|||
expect(output.summary).toBe(formatExportCurateInputsSummary(output.result));
|
||||
expect(stdoutText).toContain('provider_mapping.tsv: rows_in=1 rows_out=1');
|
||||
expect(stdoutText).toContain('listing_currencies.tsv: rows_in=1 rows_out=1');
|
||||
expect(stdoutText).toContain('listing_venues.tsv: rows_in=1 rows_out=1');
|
||||
expect(stdoutText).toContain('delistings.tsv: rows_in=1 rows_out=0');
|
||||
});
|
||||
|
||||
|
|
@ -1563,7 +1757,7 @@ describe('CLI args, safety guard, and runner', () => {
|
|||
|
||||
const queryable = createInMemoryQueryable({
|
||||
listings: [
|
||||
{ listing_id: 1, currency: 'USD', listed_to: null, delist_reason: 'active', terminal_return: null },
|
||||
{ listing_id: 1, mic: 'XNAS', currency: 'USD', listed_to: null, delist_reason: 'active', terminal_return: null },
|
||||
],
|
||||
continuities: [],
|
||||
providerMappings: [
|
||||
|
|
@ -1586,6 +1780,9 @@ describe('CLI args, safety guard, and runner', () => {
|
|||
expect(await readFile(join(outDir, CURATE_INPUT_FILES.providerMapping), 'utf8')).toBe(
|
||||
'qm\tAAPL\t2020-01-01\t\t1\n'
|
||||
);
|
||||
expect(await readFile(join(outDir, CURATE_INPUT_FILES.listingVenues), 'utf8')).toBe(
|
||||
'1\tus_tsx\n'
|
||||
);
|
||||
|
||||
// Still rejects dev -> QA PostgreSQL even with STOCK_BOT_ALLOW_DEV_ON_QA_DB=true!
|
||||
resetStockConfig();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue