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