Clear M1 milestone bugs (T-37, T-39, T-41, T-42, T-44, T-45, T-46, T-48, T-49, T-51, T-52)

This commit is contained in:
Boki 2026-11-27 16:11:57 -05:00
parent 199f7beecd
commit 9e259ca43b
18 changed files with 255 additions and 34 deletions

View file

@ -13,8 +13,11 @@ export type BoardLotPolicy = 'us_100' | 'tsx_tiered' | 'fx';
export type ClassificationMethod = 'explicit_rule' | 'operating_mic';
export const MAX_EXCHANGE_SOURCE_CODE_LENGTH = 32;
export type UnresolvedExchangeReason =
| 'empty_code'
| 'source_code_too_long'
| 'multi_valued_operating_mic'
| 'invalid_operating_mic_format'
| 'unknown_operating_mic'
@ -347,6 +350,20 @@ export function classifySourceExchanges(
continue;
}
if (normalizedCode.length > MAX_EXCHANGE_SOURCE_CODE_LENGTH) {
unresolved.push({
source: record.source,
sourceCode: normalizedCode,
rawCode,
name: normalizeOptionalString(record.name),
country: normalizeOptionalString(record.country),
operatingMic: normalizeOptionalString(record.operatingMic),
currency: normalizeOptionalString(record.currency),
reason: 'source_code_too_long',
});
continue;
}
const key = makeRuleKey(record.source, normalizedCode);
const existing = grouped.get(key);
if (existing) {

View file

@ -1,6 +1,7 @@
import {
compareAscii,
compareUnresolvedExchangeRecords,
MAX_EXCHANGE_SOURCE_CODE_LENGTH,
type ExchangeClassificationResult,
type ExchangeSeedRow,
type ExchangeSourceMapRow,
@ -22,11 +23,63 @@ export function escapeSqlLiteral(value: string | null | undefined): string {
return `'${value.replaceAll("'", "''")}'`;
}
export function generateExchangeSeedSql(input: GenerateExchangeSeedSqlInput): string {
const exchanges = [...(input.exchanges ?? [])].sort((a, b) => compareAscii(a.mic, b.mic));
const mappings = [...input.mappings].sort(
function deduplicateExchanges(rows: readonly ExchangeSeedRow[]): ExchangeSeedRow[] {
const byMic = new Map<string, ExchangeSeedRow>();
for (const row of rows) {
const existing = byMic.get(row.mic);
if (!existing) {
byMic.set(row.mic, row);
continue;
}
if (
existing.operatingMic !== row.operatingMic ||
existing.name !== row.name ||
existing.countryIso !== row.countryIso ||
existing.currency !== row.currency ||
existing.timezone !== row.timezone ||
existing.calendarCode !== row.calendarCode ||
existing.boardLotPolicy !== row.boardLotPolicy
) {
throw new Error(`Conflicting duplicate exchange row for mic "${row.mic}"`);
}
}
return Array.from(byMic.values()).sort((a, b) => compareAscii(a.mic, b.mic));
}
function deduplicateMappings(rows: readonly ExchangeSourceMapRow[]): ExchangeSourceMapRow[] {
const byKey = new Map<string, ExchangeSourceMapRow>();
for (const row of rows) {
if (row.sourceCode.length === 0 || row.sourceCode.length > MAX_EXCHANGE_SOURCE_CODE_LENGTH) {
throw new Error(
`Invalid sourceCode "${row.sourceCode}" for source "${row.source}": length must be between 1 and ${MAX_EXCHANGE_SOURCE_CODE_LENGTH} characters`
);
}
const key = `${row.source}\u0000${row.sourceCode}`;
const existing = byKey.get(key);
if (!existing) {
byKey.set(key, row);
continue;
}
if (
existing.role !== row.role ||
existing.mic !== row.mic ||
existing.countryIso !== row.countryIso ||
existing.method !== row.method ||
(existing.reviewedBy ?? null) !== (row.reviewedBy ?? null)
) {
throw new Error(
`Conflicting duplicate exchange_source_map row for (${row.source}, "${row.sourceCode}")`
);
}
}
return Array.from(byKey.values()).sort(
(a, b) => compareAscii(a.source, b.source) || compareAscii(a.sourceCode, b.sourceCode)
);
}
export function generateExchangeSeedSql(input: GenerateExchangeSeedSqlInput): string {
const exchanges = deduplicateExchanges(input.exchanges ?? []);
const mappings = deduplicateMappings(input.mappings);
const sections: string[] = [
[