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
c9ab13d5a3
commit
a75385992b
1 changed files with 43 additions and 3 deletions
|
|
@ -2,9 +2,10 @@
|
|||
* QA differential tests for the curate-etl TSV exporter (T-116).
|
||||
*
|
||||
* - The streaming PostgreSQL exporter (`exportCurateInputs`) and the pure core
|
||||
* (`formatProviderMappingTsv`, `formatListingCurrenciesTsv`, `buildDelistingExportRows` +
|
||||
* `formatDelistingsTsv`) must produce byte-identical TSVs and identical skip stats on the same
|
||||
* seeded random security master, for every chunk size (including exact chunk-boundary sizes).
|
||||
* (`formatProviderMappingTsv`, `formatListingCurrenciesTsv`, `formatListingVenuesTsv`,
|
||||
* `buildDelistingExportRows` + `formatDelistingsTsv`) must produce byte-identical TSVs and
|
||||
* identical skip stats on the same seeded random security master, for every chunk size
|
||||
* (including exact chunk-boundary sizes).
|
||||
* - Every emitted `delistings.tsv` row must resolve under the exact Rust `curate-corporate-actions`
|
||||
* lookup rules (`cursor.resolve(delist_date) == from_listing_id` for terminal rows,
|
||||
* `resolve_for_listing_on_or_before` + successor `resolve(effective_date)` for OTC rows) against the
|
||||
|
|
@ -20,7 +21,9 @@ import {
|
|||
exportCurateInputs,
|
||||
formatDelistingsTsv,
|
||||
formatListingCurrenciesTsv,
|
||||
formatListingVenuesTsv,
|
||||
formatProviderMappingTsv,
|
||||
resolveListingVenueForMic,
|
||||
type ContinuityExportSourceRow,
|
||||
type ListingDelistingSourceRow,
|
||||
type ProviderMappingExportRow,
|
||||
|
|
@ -68,6 +71,7 @@ function ymdToDay(ymd: string): number {
|
|||
interface DbListing {
|
||||
listing_id: number;
|
||||
currency: string;
|
||||
mic: string;
|
||||
listed_to: string | null;
|
||||
delist_reason: string | null;
|
||||
terminal_return: string | null;
|
||||
|
|
@ -150,6 +154,12 @@ function buildRandomDataset(seed: number, listingCount: number): Dataset {
|
|||
}
|
||||
|
||||
// Listings are generated in chronological "start" order so reuse can find free tickers.
|
||||
const usMics = ['XNYS', 'XNAS', 'ARCX', 'XASE', 'BATS', 'IEXG', 'OTCM'] as const;
|
||||
const caMics = ['XTSE', 'NEOE', 'XTSX', 'XCNQ'] as const;
|
||||
const micForListing = (listingId: number, currency: string): string => {
|
||||
const pool = currency === 'CAD' ? caMics : usMics;
|
||||
return pool[listingId % pool.length] as string;
|
||||
};
|
||||
const otcSuccessorIds = new Set<number>();
|
||||
for (let i = 0; i < ids.length; i++) {
|
||||
const listingId = ids[i] as number;
|
||||
|
|
@ -159,11 +169,13 @@ function buildRandomDataset(seed: number, listingCount: number): Dataset {
|
|||
const startDay = Math.floor(rng() * 3000);
|
||||
const roll = rng();
|
||||
const currency = pick(['USD', 'USD', 'CAD']);
|
||||
const mic = micForListing(listingId, currency);
|
||||
|
||||
if (roll < 0.35) {
|
||||
listings.push({
|
||||
listing_id: listingId,
|
||||
currency,
|
||||
mic,
|
||||
listed_to: null,
|
||||
delist_reason: 'active',
|
||||
terminal_return: null,
|
||||
|
|
@ -183,6 +195,7 @@ function buildRandomDataset(seed: number, listingCount: number): Dataset {
|
|||
listings.push({
|
||||
listing_id: listingId,
|
||||
currency,
|
||||
mic,
|
||||
listed_to: dayToYmd(endDay),
|
||||
delist_reason: 'moved_to_otc',
|
||||
terminal_return: null,
|
||||
|
|
@ -203,6 +216,7 @@ function buildRandomDataset(seed: number, listingCount: number): Dataset {
|
|||
listings.push({
|
||||
listing_id: successorId,
|
||||
currency,
|
||||
mic: micForListing(successorId, currency),
|
||||
listed_to: successorCancelled ? dayToYmd(successorEnd) : null,
|
||||
delist_reason: successorCancelled ? 'bankruptcy_cancelled' : 'active',
|
||||
terminal_return: successorCancelled ? '-1.000000' : null,
|
||||
|
|
@ -230,6 +244,7 @@ function buildRandomDataset(seed: number, listingCount: number): Dataset {
|
|||
listings.push({
|
||||
listing_id: listingId,
|
||||
currency,
|
||||
mic,
|
||||
listed_to: missingDate ? null : dayToYmd(endDay),
|
||||
delist_reason: pick(['unknown_involuntary', 'bankruptcy_cancelled', 'merger_cash']),
|
||||
terminal_return: terminalReturn,
|
||||
|
|
@ -248,6 +263,7 @@ function buildRandomDataset(seed: number, listingCount: number): Dataset {
|
|||
listings.push({
|
||||
listing_id: listingId,
|
||||
currency,
|
||||
mic,
|
||||
listed_to: dayToYmd(endDay),
|
||||
delist_reason: rng() < 0.5 ? null : 'unknown',
|
||||
terminal_return: null,
|
||||
|
|
@ -454,6 +470,7 @@ async function runExport(data: Dataset, chunkSize: number) {
|
|||
recordedSql,
|
||||
providerMapping: await read(CURATE_INPUT_FILES.providerMapping),
|
||||
listingCurrencies: await read(CURATE_INPUT_FILES.listingCurrencies),
|
||||
listingVenues: await read(CURATE_INPUT_FILES.listingVenues),
|
||||
delistings: await read(CURATE_INPUT_FILES.delistings),
|
||||
};
|
||||
}
|
||||
|
|
@ -472,6 +489,15 @@ describe('exportCurateInputs streaming vs pure core parity (seeded random securi
|
|||
rng
|
||||
)
|
||||
);
|
||||
const expectedListingVenues = formatListingVenuesTsv(
|
||||
shuffle(
|
||||
data.listings.map(l => ({
|
||||
listingId: l.listing_id,
|
||||
venue: resolveListingVenueForMic(l.mic),
|
||||
})),
|
||||
rng
|
||||
)
|
||||
);
|
||||
const built = buildDelistingExportRows(
|
||||
shuffle(pure.delistingListings, rng),
|
||||
shuffle(pure.continuities, rng),
|
||||
|
|
@ -493,6 +519,7 @@ describe('exportCurateInputs streaming vs pure core parity (seeded random securi
|
|||
const out = await runExport(data, Math.min(chunkSize, 5000));
|
||||
expect(out.providerMapping).toBe(expectedProviderMapping);
|
||||
expect(out.listingCurrencies).toBe(expectedListingCurrencies);
|
||||
expect(out.listingVenues).toBe(expectedListingVenues);
|
||||
expect(out.delistings).toBe(expectedDelistings);
|
||||
|
||||
const s = out.result.delistings.stats;
|
||||
|
|
@ -513,9 +540,12 @@ describe('exportCurateInputs streaming vs pure core parity (seeded random securi
|
|||
expect(out.result.providerMapping.rowsIn).toBe(mappingRows);
|
||||
expect(out.result.providerMapping.rowsOut).toBe(mappingRows);
|
||||
expect(out.result.listingCurrencies.rowsOut).toBe(listingRows);
|
||||
expect(out.result.listingVenues.rowsIn).toBe(listingRows);
|
||||
expect(out.result.listingVenues.rowsOut).toBe(listingRows);
|
||||
expect(out.result.totalBytesWritten).toBe(
|
||||
Buffer.byteLength(out.providerMapping) +
|
||||
Buffer.byteLength(out.listingCurrencies) +
|
||||
Buffer.byteLength(out.listingVenues) +
|
||||
Buffer.byteLength(out.delistings)
|
||||
);
|
||||
|
||||
|
|
@ -599,6 +629,7 @@ describe('exportCurateInputs streaming vs pure core parity (seeded random securi
|
|||
{
|
||||
listing_id: 1,
|
||||
currency: 'USD',
|
||||
mic: 'XNYS',
|
||||
listed_to: '2023-01-03',
|
||||
delist_reason: 'x',
|
||||
terminal_return: '0.000000',
|
||||
|
|
@ -606,6 +637,7 @@ describe('exportCurateInputs streaming vs pure core parity (seeded random securi
|
|||
{
|
||||
listing_id: 2,
|
||||
currency: 'USD',
|
||||
mic: 'XNAS',
|
||||
listed_to: '2023-01-03',
|
||||
delist_reason: 'x',
|
||||
terminal_return: '-0.000000',
|
||||
|
|
@ -613,6 +645,7 @@ describe('exportCurateInputs streaming vs pure core parity (seeded random securi
|
|||
{
|
||||
listing_id: 3,
|
||||
currency: 'USD',
|
||||
mic: 'ARCX',
|
||||
listed_to: '2023-01-03',
|
||||
delist_reason: 'x',
|
||||
terminal_return: '-0.000001',
|
||||
|
|
@ -620,6 +653,7 @@ describe('exportCurateInputs streaming vs pure core parity (seeded random securi
|
|||
{
|
||||
listing_id: 4,
|
||||
currency: 'USD',
|
||||
mic: 'XASE',
|
||||
listed_to: '2023-01-03',
|
||||
delist_reason: 'x',
|
||||
terminal_return: '-1.000000',
|
||||
|
|
@ -627,6 +661,7 @@ describe('exportCurateInputs streaming vs pure core parity (seeded random securi
|
|||
{
|
||||
listing_id: 5,
|
||||
currency: 'USD',
|
||||
mic: 'OTCM',
|
||||
listed_to: '2023-01-03',
|
||||
delist_reason: 'x',
|
||||
terminal_return: '-0.300000',
|
||||
|
|
@ -665,6 +700,7 @@ describe('exportCurateInputs streaming vs pure core parity (seeded random securi
|
|||
{
|
||||
listing_id: 10,
|
||||
currency: 'USD',
|
||||
mic: 'XNYS',
|
||||
listed_to: '2023-03-10',
|
||||
delist_reason: 'moved_to_otc',
|
||||
terminal_return: null,
|
||||
|
|
@ -672,6 +708,7 @@ describe('exportCurateInputs streaming vs pure core parity (seeded random securi
|
|||
{
|
||||
listing_id: 11,
|
||||
currency: 'USD',
|
||||
mic: 'OTCM',
|
||||
listed_to: null,
|
||||
delist_reason: 'active',
|
||||
terminal_return: null,
|
||||
|
|
@ -679,6 +716,7 @@ describe('exportCurateInputs streaming vs pure core parity (seeded random securi
|
|||
{
|
||||
listing_id: 20,
|
||||
currency: 'CAD',
|
||||
mic: 'XTSX',
|
||||
listed_to: '2023-03-10',
|
||||
delist_reason: 'moved_to_otc',
|
||||
terminal_return: null,
|
||||
|
|
@ -686,6 +724,7 @@ describe('exportCurateInputs streaming vs pure core parity (seeded random securi
|
|||
{
|
||||
listing_id: 21,
|
||||
currency: 'CAD',
|
||||
mic: 'XCNQ',
|
||||
listed_to: null,
|
||||
delist_reason: 'active',
|
||||
terminal_return: null,
|
||||
|
|
@ -730,6 +769,7 @@ describe('exportCurateInputs streaming vs pure core parity (seeded random securi
|
|||
|
||||
// Assert
|
||||
expect(out.listingCurrencies).toBe('10\tUSD\n11\tUSD\n20\tCAD\n21\tCAD\n');
|
||||
expect(out.listingVenues).toBe('10\tus_tsx\n11\tus_tsx\n20\ttsxv_cse\n21\ttsxv_cse\n');
|
||||
expect(out.providerMapping).toBe(
|
||||
'qm\tA\t2000-01-03\t2023-03-10\t10\nqm\tAQ\t2023-03-28\t\t11\nqm\tB\t2000-01-03\t2023-03-10\t20\nqm\tBQ\t2023-03-28\t\t21\n'
|
||||
);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue