T-211: M2.2v — Export listing_venues.tsv and extend field-shape probe & BSON fixture exporter for M2 collections

This commit is contained in:
Studio 2026-12-04 14:33:13 -05:00
parent 12da9aa899
commit ba20f9a2e5
8 changed files with 345 additions and 63 deletions

View file

@ -1,5 +1,16 @@
import { afterEach, describe, expect, test } from 'bun:test';
import { mkdtemp, open, readdir, readFile, rename, rm, unlink, writeFile } from 'node:fs/promises';
import {
mkdir,
mkdtemp,
open,
readdir,
readFile,
rename,
rm,
symlink,
unlink,
writeFile,
} from 'node:fs/promises';
import { tmpdir } from 'node:os';
import { join, resolve } from 'node:path';
import {
@ -10,7 +21,9 @@ import {
import {
assertExportCurateInputsSafety,
buildDelistingExportRows,
CURATE_INPUT_CURRENT_LINK,
CURATE_INPUT_FILES,
CURATE_INPUT_GENERATIONS_DIR,
CURATE_INPUT_PUBLISH_LOCK,
CurateInputExportError,
DEFAULT_EXPORT_CHUNK_SIZE,
@ -1521,6 +1534,63 @@ describe('exportCurateInputs atomic publish and streaming', () => {
'chunkSize'
);
});
test('pinCurateInputSnapshot fails closed with INCOMPLETE_SNAPSHOT on legacy M1 three-file generation and succeeds after refresh', async () => {
const outDir = await makeTempDir('curate-inputs-legacy-m1-');
const legacyGenId = 'gen-m1-legacy';
const legacyGenDir = join(outDir, CURATE_INPUT_GENERATIONS_DIR, legacyGenId);
await mkdir(legacyGenDir, { recursive: true });
await writeFile(join(legacyGenDir, CURATE_INPUT_FILES.providerMapping), 'qm\tAAPL\t2020-01-01\t\t1\n', 'utf8');
await writeFile(join(legacyGenDir, CURATE_INPUT_FILES.listingCurrencies), '1\tUSD\n', 'utf8');
await writeFile(join(legacyGenDir, CURATE_INPUT_FILES.delistings), '', 'utf8');
await symlink(
join(CURATE_INPUT_GENERATIONS_DIR, legacyGenId),
join(outDir, CURATE_INPUT_CURRENT_LINK)
);
let caught: unknown;
try {
await pinCurateInputSnapshot(outDir);
} catch (error) {
caught = error;
}
expect(caught).toBeInstanceOf(CurateInputExportError);
const err = caught as CurateInputExportError;
expect(err.code).toBe('INCOMPLETE_SNAPSHOT');
expect(err.table).toBe('publish');
expect(err.key).toBe(legacyGenId);
expect(err.field).toBe(CURATE_INPUT_FILES.listingVenues);
expect(err.message).toContain('listing_venues.tsv');
expect(err.message).toContain('refresh the export');
// Refreshing the export publishes a complete 4-file generation that pins cleanly.
const refreshedClient = createInMemoryQueryable({
listings: [
{
listing_id: 1,
mic: 'XNAS',
currency: 'USD',
listed_to: null,
delist_reason: 'active',
terminal_return: null,
},
],
continuities: [],
providerMappings: [
{
source: 'qm',
source_id: 'AAPL',
valid_from: '2020-01-01',
valid_to: null,
listing_id: 1,
},
],
});
await exportCurateInputs(refreshedClient, { outDir });
const pinned = await pinCurateInputSnapshot(outDir);
expect(await readFile(pinned.listingVenues, 'utf8')).toBe('1\tus_tsx\n');
expect(await readFile(pinned.providerMapping, 'utf8')).toBe('qm\tAAPL\t2020-01-01\t\t1\n');
});
});
describe('golden fixtures cross-language parity', () => {