chore(m2): execute host/quant verification, fix live blockers, and record M2 closure evidence (T-215)

This commit is contained in:
Boki 2026-12-06 11:25:07 -05:00
parent 87ae19e5f9
commit a5184bb417
21 changed files with 1370 additions and 74 deletions

View file

@ -21,6 +21,7 @@ import {
type VerifyM2QuantCliDeps,
type VerifyM2QuantDdlOnlyReport,
type VerifyM2QuantReport,
parseVerifyM2QuantArgs,
runVerifyM2QuantCli,
} from '../verify-m2-quant';
@ -1614,5 +1615,48 @@ describe('scripts/verify-m2-quant.ts', () => {
expect(await runVerifyM2QuantCli(nonUtcCutoff.deps)).toBe(1);
assertSingleLineError(nonUtcCutoff.stderr.text());
expect(nonUtcCutoff.stderr.text()).toContain('UTC timestamp ending in');
const badNvdaWindow = createHarness(baseArgs({ '--nvda-from': '2024-06-10' }));
expect(await runVerifyM2QuantCli(badNvdaWindow.deps)).toBe(1);
assertSingleLineError(badNvdaWindow.stderr.text());
expect(badNvdaWindow.stderr.text()).toContain('must straddle ex-date 2024-06-10');
const partialExtra = createHarness(baseArgs({ '--eod-split-label': 'AVGO.US' }));
expect(await runVerifyM2QuantCli(partialExtra.deps)).toBe(1);
assertSingleLineError(partialExtra.stderr.text());
expect(partialExtra.stderr.text()).toContain('Incomplete extra EOD split case flags');
});
test('supports explicit split window overrides and extra EOD split case', () => {
const parsed = parseVerifyM2QuantArgs(
baseArgs({
'--nvda-from': '2024-05-20',
'--nvda-to': '2024-07-02',
'--nexm-from': '2025-06-17',
'--nexm-to': '2025-06-27',
'--eod-split-label': 'AVGO.US',
'--eod-split-listing-id': '10970',
'--eod-split-from': '2024-07-11',
'--eod-split-to': '2024-07-17',
'--eod-split-ex-date': '2024-07-15',
'--eod-split-ratio': '10:1',
}),
{ cwd: '/tmp' }
);
expect(parsed.kind).toBe('run');
if (parsed.kind === 'run') {
expect(parsed.nvdaFromDate).toBe('2024-05-20');
expect(parsed.nvdaToDate).toBe('2024-07-02');
expect(parsed.nexmFromDate).toBe('2025-06-17');
expect(parsed.nexmToDate).toBe('2025-06-27');
expect(parsed.extraSplitCase).toEqual({
label: 'AVGO.US',
listingId: 10970,
fromDate: '2024-07-11',
toDate: '2024-07-17',
exDate: '2024-07-15',
ratio: '10:1',
});
}
});
});

View file

@ -87,13 +87,17 @@ export const REQUIRED_SHARD_PREFIXES = ['bars_1m', 'bars_1m_qm', 'fx_1m'] as con
export type RequiredShardPrefix = (typeof REQUIRED_SHARD_PREFIXES)[number];
export interface SplitBoundaryCaseSpec {
readonly label: 'NVDA.US' | 'NEXM.V';
readonly label: string;
readonly fromDate: string;
readonly toDate: string;
readonly exDate: string;
readonly ratio: string;
}
export interface ExtraSplitBoundaryCase extends SplitBoundaryCaseSpec {
readonly listingId: number;
}
export const M2_SPLIT_BOUNDARY_CASES: readonly SplitBoundaryCaseSpec[] = [
{
label: 'NVDA.US',
@ -134,6 +138,11 @@ export interface ParsedVerifyM2QuantRun {
readonly vaultCutoffTs: number;
readonly nvdaListingId: number;
readonly nexmListingId: number;
readonly nvdaFromDate?: string;
readonly nvdaToDate?: string;
readonly nexmFromDate?: string;
readonly nexmToDate?: string;
readonly extraSplitCase?: ExtraSplitBoundaryCase;
readonly benchListingId: number;
readonly benchFrom: string;
readonly benchTo: string;
@ -323,7 +332,7 @@ export interface SplitBoundarySessionComparison {
}
export interface SplitBoundaryCheckResult {
readonly label: 'NVDA.US' | 'NEXM.V';
readonly label: string;
readonly listingId: number;
readonly fromDate: string;
readonly toDate: string;
@ -439,6 +448,16 @@ export const VERIFY_M2_QUANT_USAGE = [
' --apply-ddl Execute applyM2IntradayDDL before checks (full mode)',
` --warm-runs <pos-int> Number of warm 1y 1m benchmark reads (default: ${DEFAULT_WARM_RUNS})`,
` --wal-settle-timeout-ms <pos-int> WAL settle polling timeout in ms (default: ${DEFAULT_WAL_SETTLE_TIMEOUT_MS})`,
' --nvda-from <YYYY-MM-DD> Optional NVDA.US split window start (< 2024-06-10)',
' --nvda-to <YYYY-MM-DD> Optional NVDA.US split window end (>= 2024-06-10)',
' --nexm-from <YYYY-MM-DD> Optional NEXM.V split window start (< 2025-06-20)',
' --nexm-to <YYYY-MM-DD> Optional NEXM.V split window end (>= 2025-06-20)',
' --eod-split-label <label> Optional extra EOD split check label (e.g. AVGO.US)',
' --eod-split-listing-id <int32> Listing ID for optional extra EOD split check',
' --eod-split-from <YYYY-MM-DD> Window start for optional extra EOD split check',
' --eod-split-to <YYYY-MM-DD> Window end for optional extra EOD split check',
' --eod-split-ex-date <YYYY-MM-DD> Split ex-date for optional extra EOD split check',
' --eod-split-ratio <ratio> Split ratio label (e.g. 10:1) for extra EOD split check',
' --out <path> Optional JSON output file path',
' -h, --help Show this help message',
'',
@ -456,6 +475,16 @@ const VALUE_FLAGS = new Set([
'--vault-cutoff-ts',
'--nvda-listing-id',
'--nexm-listing-id',
'--nvda-from',
'--nvda-to',
'--nexm-from',
'--nexm-to',
'--eod-split-label',
'--eod-split-listing-id',
'--eod-split-from',
'--eod-split-to',
'--eod-split-ex-date',
'--eod-split-ratio',
'--bench-listing-id',
'--bench-from',
'--bench-to',
@ -805,6 +834,82 @@ export function parseVerifyM2QuantArgs(
const warmRuns =
rawWarmRuns !== undefined ? parsePositiveIntFlag('--warm-runs', rawWarmRuns) : DEFAULT_WARM_RUNS;
const parseDateOnlyFlag = (flag: string, raw: string): string => {
const trimmed = validateRawTokenValue(flag, raw);
if (!DATE_ONLY_RE.test(trimmed)) {
throw new VerifyM2QuantError(`Flag '${flag}' must be YYYY-MM-DD (received '${trimmed}').`);
}
const [y, m, d] = trimmed.split('-').map(Number) as [number, number, number];
const dt = new Date(Date.UTC(y, m - 1, d));
if (
dt.getUTCFullYear() !== y ||
dt.getUTCMonth() !== m - 1 ||
dt.getUTCDate() !== d
) {
throw new VerifyM2QuantError(`Flag '${flag}' is not a valid calendar date (received '${trimmed}').`);
}
return trimmed;
};
const nvdaFromRaw = seenValues.get('--nvda-from');
const nvdaToRaw = seenValues.get('--nvda-to');
const nvdaFromDate = nvdaFromRaw !== undefined ? parseDateOnlyFlag('--nvda-from', nvdaFromRaw) : undefined;
const nvdaToDate = nvdaToRaw !== undefined ? parseDateOnlyFlag('--nvda-to', nvdaToRaw) : undefined;
const effNvdaFrom = nvdaFromDate ?? M2_SPLIT_BOUNDARY_CASES[0]!.fromDate;
const effNvdaTo = nvdaToDate ?? M2_SPLIT_BOUNDARY_CASES[0]!.toDate;
if (!(effNvdaFrom < M2_SPLIT_BOUNDARY_CASES[0]!.exDate && effNvdaTo >= M2_SPLIT_BOUNDARY_CASES[0]!.exDate)) {
throw new VerifyM2QuantError(
`NVDA.US split window [${effNvdaFrom}, ${effNvdaTo}] must straddle ex-date ${M2_SPLIT_BOUNDARY_CASES[0]!.exDate}.`
);
}
const nexmFromRaw = seenValues.get('--nexm-from');
const nexmToRaw = seenValues.get('--nexm-to');
const nexmFromDate = nexmFromRaw !== undefined ? parseDateOnlyFlag('--nexm-from', nexmFromRaw) : undefined;
const nexmToDate = nexmToRaw !== undefined ? parseDateOnlyFlag('--nexm-to', nexmToRaw) : undefined;
const effNexmFrom = nexmFromDate ?? M2_SPLIT_BOUNDARY_CASES[1]!.fromDate;
const effNexmTo = nexmToDate ?? M2_SPLIT_BOUNDARY_CASES[1]!.toDate;
if (!(effNexmFrom < M2_SPLIT_BOUNDARY_CASES[1]!.exDate && effNexmTo >= M2_SPLIT_BOUNDARY_CASES[1]!.exDate)) {
throw new VerifyM2QuantError(
`NEXM.V split window [${effNexmFrom}, ${effNexmTo}] must straddle ex-date ${M2_SPLIT_BOUNDARY_CASES[1]!.exDate}.`
);
}
const extraFlags = [
'--eod-split-label',
'--eod-split-listing-id',
'--eod-split-from',
'--eod-split-to',
'--eod-split-ex-date',
'--eod-split-ratio',
] as const;
const providedExtraCount = extraFlags.filter(f => seenValues.has(f)).length;
let extraSplitCase: ExtraSplitBoundaryCase | undefined;
if (providedExtraCount > 0) {
if (providedExtraCount !== extraFlags.length) {
const missingExtra = extraFlags.filter(f => !seenValues.has(f));
throw new VerifyM2QuantError(
`Incomplete extra EOD split case flags; missing: ${missingExtra.join(', ')}.`
);
}
const label = seenValues.get('--eod-split-label')!;
const listingId = parsePositiveIntFlag(
'--eod-split-listing-id',
seenValues.get('--eod-split-listing-id')!,
INT32_MAX
);
const fromDate = parseDateOnlyFlag('--eod-split-from', seenValues.get('--eod-split-from')!);
const toDate = parseDateOnlyFlag('--eod-split-to', seenValues.get('--eod-split-to')!);
const exDate = parseDateOnlyFlag('--eod-split-ex-date', seenValues.get('--eod-split-ex-date')!);
const ratio = seenValues.get('--eod-split-ratio')!;
if (!(fromDate < exDate && toDate >= exDate)) {
throw new VerifyM2QuantError(
`Extra EOD split window [${fromDate}, ${toDate}] must straddle ex-date ${exDate}.`
);
}
extraSplitCase = { label, listingId, fromDate, toDate, exDate, ratio };
}
return {
kind: 'run',
questdb,
@ -813,6 +918,11 @@ export function parseVerifyM2QuantArgs(
vaultCutoffTs,
nvdaListingId,
nexmListingId,
...(nvdaFromDate !== undefined ? { nvdaFromDate } : {}),
...(nvdaToDate !== undefined ? { nvdaToDate } : {}),
...(nexmFromDate !== undefined ? { nexmFromDate } : {}),
...(nexmToDate !== undefined ? { nexmToDate } : {}),
...(extraSplitCase !== undefined ? { extraSplitCase } : {}),
benchListingId,
benchFrom,
benchTo,
@ -2448,15 +2558,42 @@ export async function runVerifyM2QuantCli(deps: VerifyM2QuantCliDeps = {}): Prom
const duckExecutor = await createDuck();
try {
const listingIdByLabel: Record<'NVDA.US' | 'NEXM.V', number> = {
'NVDA.US': parsed.nvdaListingId,
'NEXM.V': parsed.nexmListingId,
};
for (const spec of M2_SPLIT_BOUNDARY_CASES) {
const casesToVerify: { readonly spec: SplitBoundaryCaseSpec; readonly listingId: number }[] =
[
{
spec: {
...M2_SPLIT_BOUNDARY_CASES[0]!,
...(parsed.nvdaFromDate !== undefined ? { fromDate: parsed.nvdaFromDate } : {}),
...(parsed.nvdaToDate !== undefined ? { toDate: parsed.nvdaToDate } : {}),
},
listingId: parsed.nvdaListingId,
},
{
spec: {
...M2_SPLIT_BOUNDARY_CASES[1]!,
...(parsed.nexmFromDate !== undefined ? { fromDate: parsed.nexmFromDate } : {}),
...(parsed.nexmToDate !== undefined ? { toDate: parsed.nexmToDate } : {}),
},
listingId: parsed.nexmListingId,
},
];
if (parsed.extraSplitCase !== undefined) {
casesToVerify.push({
spec: {
label: parsed.extraSplitCase.label,
fromDate: parsed.extraSplitCase.fromDate,
toDate: parsed.extraSplitCase.toDate,
exDate: parsed.extraSplitCase.exDate,
ratio: parsed.extraSplitCase.ratio,
},
listingId: parsed.extraSplitCase.listingId,
});
}
for (const item of casesToVerify) {
splitChecks.push(
await verifySplitBoundaryCase(
spec,
listingIdByLabel[spec.label],
item.spec,
item.listingId,
pgHandle.executor,
duckExecutor,
parsed.curatedRoot