658 lines
20 KiB
TypeScript
658 lines
20 KiB
TypeScript
import { describe, expect, test } from 'bun:test';
|
|
import type { EventStudyExchangeCalendars } from '../src/event-panel';
|
|
import type {
|
|
BarBatch,
|
|
BarRecord,
|
|
EventKind,
|
|
MarketDataStore,
|
|
Table,
|
|
TableRow,
|
|
} from '../src/market-data-store';
|
|
import {
|
|
type BarsQuery,
|
|
EVENTS_COLUMNS,
|
|
type EventsQuery,
|
|
MarketDataStoreNotImplementedError,
|
|
type UniverseQuery,
|
|
} from '../src/market-data-store-duckdb';
|
|
import {
|
|
type EventStudyExchangeCalendarQuery,
|
|
type EventStudyResultPayload,
|
|
createEventStudyTool,
|
|
createMcpServer,
|
|
} from '../src/mcp/index';
|
|
import type { TrialLedgerExecutor } from '../src/trial-ledger';
|
|
|
|
// QA fixture: deterministic synthetic equity bars & events with explicit
|
|
// half-day closes, intraday Vault cutoffs, exact boundary timestamps, and
|
|
// malformed rows. Models gross daily close-to-close returns, raw adjustment,
|
|
// no fills or transaction costs.
|
|
const AGENT_PRINCIPAL = 'agent:11111111-2222-4333-8444-555555555555';
|
|
|
|
function makeBusinessDates(startDate: string, count: number): string[] {
|
|
const out: string[] = [];
|
|
const current = new Date(`${startDate}T00:00:00.000Z`);
|
|
while (out.length < count) {
|
|
const day = current.getUTCDay();
|
|
if (day !== 0 && day !== 6) {
|
|
out.push(current.toISOString().slice(0, 10));
|
|
}
|
|
current.setUTCDate(current.getUTCDate() + 1);
|
|
}
|
|
return out;
|
|
}
|
|
|
|
function utcMs(date: string, hour: number, minute = 0, second = 0, ms = 0): number {
|
|
const [y, m, d] = date.split('-').map(Number);
|
|
return Date.UTC(y!, m! - 1, d!, hour, minute, second, ms);
|
|
}
|
|
|
|
function createFakeLedger(): {
|
|
executor: TrialLedgerExecutor;
|
|
insertCalls: number;
|
|
rows: Array<{ expression_hash: string; daily_series: number[] }>;
|
|
} {
|
|
const rows: Array<{ expression_hash: string; daily_series: number[] }> = [];
|
|
let nextId = 1;
|
|
const state = {
|
|
rows,
|
|
insertCalls: 0,
|
|
executor: null as unknown as TrialLedgerExecutor,
|
|
};
|
|
|
|
state.executor = {
|
|
async query<Row = Record<string, unknown>>(text: string, params?: readonly unknown[]) {
|
|
const trimmed = text.trimStart();
|
|
if (trimmed.startsWith('INSERT INTO trial_ledger')) {
|
|
state.insertCalls += 1;
|
|
const p = params ?? [];
|
|
const id = nextId++;
|
|
const dailySeries = (p[13] as readonly number[]).map(v => Math.fround(v));
|
|
rows.push({
|
|
expression_hash: p[6] as string,
|
|
daily_series: dailySeries,
|
|
});
|
|
return {
|
|
rows: [
|
|
{
|
|
trial_id: String(id),
|
|
created_at: new Date(Date.UTC(2024, 5, 1, 12, 0, id)),
|
|
} as unknown as Row,
|
|
],
|
|
rowCount: 1,
|
|
};
|
|
}
|
|
if (trimmed.startsWith('SELECT')) {
|
|
const storedRows = rows.map((r, idx) => ({
|
|
trial_id: String(idx + 1),
|
|
created_at: new Date(Date.UTC(2024, 5, 1, 12, 0, idx + 1)),
|
|
principal_id: AGENT_PRINCIPAL,
|
|
campaign_id: null,
|
|
stage: 'event_study',
|
|
universe_market: 'US_EQ',
|
|
horizon_bucket: 'swing_1_10d',
|
|
hypothesis_id: null,
|
|
expression_hash: r.expression_hash,
|
|
sample_start: '2023-01-02',
|
|
sample_end: '2023-02-01',
|
|
n_obs: r.daily_series.length,
|
|
sharpe_unann: 0.5,
|
|
skewness: 0,
|
|
kurtosis: 3,
|
|
daily_series: r.daily_series,
|
|
}));
|
|
return { rows: storedRows as unknown as Row[], rowCount: storedRows.length };
|
|
}
|
|
return { rows: [], rowCount: 0 };
|
|
},
|
|
};
|
|
|
|
return state;
|
|
}
|
|
|
|
function createPassThroughStore(params: {
|
|
bars: readonly BarRecord[];
|
|
eventsTable: Table;
|
|
}): MarketDataStore {
|
|
return {
|
|
bars(_q: BarsQuery): AsyncIterable<BarBatch> {
|
|
return {
|
|
async *[Symbol.asyncIterator]() {
|
|
yield { rows: [...params.bars] };
|
|
},
|
|
};
|
|
},
|
|
async events(_q: EventsQuery): Promise<Table> {
|
|
return params.eventsTable;
|
|
},
|
|
async universe(_q: UniverseQuery): Promise<number[]> {
|
|
return [];
|
|
},
|
|
crossSection() {
|
|
throw new MarketDataStoreNotImplementedError('crossSection');
|
|
},
|
|
fundamentalsAsOf() {
|
|
throw new MarketDataStoreNotImplementedError('fundamentalsAsOf');
|
|
},
|
|
shortsAsOf() {
|
|
throw new MarketDataStoreNotImplementedError('shortsAsOf');
|
|
},
|
|
macroAsOf() {
|
|
throw new MarketDataStoreNotImplementedError('macroAsOf');
|
|
},
|
|
fx() {
|
|
throw new MarketDataStoreNotImplementedError('fx');
|
|
},
|
|
};
|
|
}
|
|
|
|
async function invoke(
|
|
server: ReturnType<typeof createMcpServer>,
|
|
args: Record<string, unknown>
|
|
): Promise<{
|
|
isError?: boolean;
|
|
text: string;
|
|
payload?: EventStudyResultPayload;
|
|
}> {
|
|
const raw = await server.handleMessage(
|
|
JSON.stringify({
|
|
jsonrpc: '2.0',
|
|
id: 1,
|
|
method: 'tools/call',
|
|
params: { name: 'event_study', arguments: args },
|
|
})
|
|
);
|
|
const rpc = JSON.parse(raw!) as {
|
|
result: { content: Array<{ type: string; text: string }>; isError?: boolean };
|
|
};
|
|
const text = rpc.result.content[0]!.text;
|
|
return {
|
|
isError: rpc.result.isError,
|
|
text,
|
|
payload: rpc.result.isError ? undefined : (JSON.parse(text) as EventStudyResultPayload),
|
|
};
|
|
}
|
|
|
|
describe('MCP event_study QA edge cases', () => {
|
|
test('event released after a half-day close anchors to the next trading session, not the half-day', async () => {
|
|
const dates = makeBusinessDates('2023-05-01', 25);
|
|
const vaultCutoffDate = dates[24]!;
|
|
const vaultCutoffTs = utcMs(vaultCutoffDate, 0);
|
|
const listingIds = [101, 102, 103, 104, 105, 106];
|
|
|
|
// Make day index 8 a half-day (closes at 18:00 UTC = 13:00 ET instead of 21:00 UTC).
|
|
// Place 6 events across days 8 and 14, released at 19:00 UTC (after 18:00 UTC half-day close,
|
|
// before 21:00 UTC bar stamp). For half-day (index 8), events must anchor to index 9!
|
|
// Put a +10% jump on index 9 and +20% jump on index 15 (next day after 14, also half-day),
|
|
// and 0% return on index 8 and 14 so AAR at offset 0 proves next-session anchoring.
|
|
const halfDayIndices = new Set([8, 14]);
|
|
const jumpDayReturns = new Map<number, number>([
|
|
[9, 0.1],
|
|
[15, 0.2],
|
|
]);
|
|
|
|
const bars: BarRecord[] = [];
|
|
for (const id of listingIds) {
|
|
let price = 100;
|
|
for (let t = 0; t < 24; t += 1) {
|
|
const ret = jumpDayReturns.get(t) ?? 0;
|
|
price = Number((price * (1 + ret)).toFixed(6));
|
|
const ts = utcMs(dates[t]!, 21); // bars_1d always stamped 16:00 ET (21:00 UTC)
|
|
bars.push({
|
|
listingId: id,
|
|
ts,
|
|
open: price,
|
|
high: price,
|
|
low: price,
|
|
close: price,
|
|
volume: 10_000,
|
|
knownAt: ts,
|
|
});
|
|
}
|
|
}
|
|
|
|
const eventRows: TableRow[] = [];
|
|
for (let i = 0; i < 3; i += 1) {
|
|
// Released at 19:00 UTC on half-day index 8 -> anchors to index 9 (+10%)
|
|
eventRows.push({
|
|
listing_id: listingIds[i]!,
|
|
ts: utcMs(dates[8]!, 19),
|
|
known_at: utcMs(dates[8]!, 19),
|
|
known_at_source: 'exact',
|
|
kind: 'filing' as EventKind,
|
|
subtype: '8-K',
|
|
payload_json: '{}',
|
|
});
|
|
}
|
|
for (let i = 3; i < 6; i += 1) {
|
|
// Released at 19:00 UTC on half-day index 14 -> anchors to index 15 (+20%)
|
|
eventRows.push({
|
|
listing_id: listingIds[i]!,
|
|
ts: utcMs(dates[14]!, 19),
|
|
known_at: utcMs(dates[14]!, 19),
|
|
known_at_source: 'exact',
|
|
kind: 'filing' as EventKind,
|
|
subtype: '8-K',
|
|
payload_json: '{}',
|
|
});
|
|
}
|
|
|
|
const store = createPassThroughStore({
|
|
bars,
|
|
eventsTable: { columns: [...EVENTS_COLUMNS], rows: eventRows },
|
|
});
|
|
const ledger = createFakeLedger();
|
|
|
|
const resolveExchangeCalendars = async (
|
|
q: EventStudyExchangeCalendarQuery
|
|
): Promise<EventStudyExchangeCalendars> => {
|
|
const sessions = dates
|
|
.filter(d => d >= q.fromDate && d <= q.toDate)
|
|
.map((date, _idx) => {
|
|
const globalIdx = dates.indexOf(date);
|
|
const closeHour = halfDayIndices.has(globalIdx) ? 18 : 21;
|
|
return { date, closeTs: utcMs(date, closeHour) };
|
|
});
|
|
const listingCalendarId = new Map<number, string>();
|
|
for (const id of q.listingIds) {
|
|
listingCalendarId.set(id, 'XNYS');
|
|
}
|
|
return {
|
|
calendars: new Map([['XNYS', sessions]]),
|
|
listingCalendarId,
|
|
};
|
|
};
|
|
|
|
const server = createMcpServer({
|
|
name: 'research-mcp',
|
|
version: '1.0.0',
|
|
tools: [
|
|
createEventStudyTool({
|
|
store,
|
|
ledger: ledger.executor,
|
|
vaultContext: { vaultCutoffTs },
|
|
principalId: AGENT_PRINCIPAL,
|
|
resolveExchangeCalendars,
|
|
}),
|
|
],
|
|
});
|
|
|
|
const res = await invoke(server, {
|
|
listingIds,
|
|
from: dates[0]!,
|
|
to: dates[23]!,
|
|
event: { kinds: ['filing'] },
|
|
preDays: 1,
|
|
postDays: 1,
|
|
benchmark: 'none',
|
|
universeMarket: 'US_EQ',
|
|
horizonBucket: 'swing_1_10d',
|
|
});
|
|
|
|
expect(res.isError).toBeUndefined();
|
|
expect(res.payload?.status).toBe('ok');
|
|
if (res.payload?.status !== 'ok') {
|
|
throw new Error('Expected ok');
|
|
}
|
|
|
|
// Offset -1 is the half-day itself (0% return); Offset 0 is the next session (mean of +10% and +20% = +15%).
|
|
const offsetMinus1 = res.payload.study.offsets.find(o => o.offset === -1)!;
|
|
const offset0 = res.payload.study.offsets.find(o => o.offset === 0)!;
|
|
expect(offsetMinus1.aar).toBeCloseTo(0, 8);
|
|
expect(offset0.aar).toBeCloseTo(0.15, 8);
|
|
});
|
|
|
|
test('intraday Vault cutoff excludes rows on the cutoff UTC day and handles start-on-cutoff-day safely', async () => {
|
|
const dates = makeBusinessDates('2023-06-01', 25);
|
|
const cutoffDate = dates[20]!;
|
|
// Intraday Vault cutoff at 12:00 UTC on cutoffDate
|
|
const vaultCutoffTs = utcMs(cutoffDate, 12);
|
|
const listingIds = [201, 202, 203, 204, 205, 206];
|
|
|
|
const bars: BarRecord[] = [];
|
|
for (const id of listingIds) {
|
|
let price = 50;
|
|
for (let t = 0; t < 22; t += 1) {
|
|
price = Number((price * (1 + (t % 3 === 0 ? 0.02 : -0.005))).toFixed(6));
|
|
const ts = t === 20 ? utcMs(dates[t]!, 10) : utcMs(dates[t]!, 21); // Bar on cutoff day at 10:00 UTC (< cutoffTs!)
|
|
bars.push({
|
|
listingId: id,
|
|
ts,
|
|
open: price,
|
|
high: price,
|
|
low: price,
|
|
close: price,
|
|
volume: 5_000,
|
|
knownAt: ts,
|
|
});
|
|
}
|
|
}
|
|
|
|
const baseEvents: TableRow[] = [
|
|
// 6 valid pre-cutoff events across 2 dates
|
|
...listingIds.slice(0, 3).map(id => ({
|
|
listing_id: id,
|
|
ts: utcMs(dates[6]!, 14),
|
|
known_at: utcMs(dates[6]!, 14),
|
|
known_at_source: 'exact',
|
|
kind: 'filing',
|
|
subtype: '8-K',
|
|
payload_json: '{}',
|
|
})),
|
|
...listingIds.slice(3, 6).map(id => ({
|
|
listing_id: id,
|
|
ts: utcMs(dates[12]!, 14),
|
|
known_at: utcMs(dates[12]!, 14),
|
|
known_at_source: 'exact',
|
|
kind: 'filing',
|
|
subtype: '8-K',
|
|
payload_json: '{}',
|
|
})),
|
|
];
|
|
|
|
const intradayCutoffEvents: TableRow[] = [
|
|
// Event on cutoff UTC day BEFORE intraday vaultCutoffTs (10:00 UTC < 12:00 UTC) -> MUST be excluded!
|
|
{
|
|
listing_id: listingIds[0]!,
|
|
ts: utcMs(cutoffDate, 10),
|
|
known_at: utcMs(cutoffDate, 10),
|
|
known_at_source: 'exact',
|
|
kind: 'filing',
|
|
subtype: '8-K',
|
|
payload_json: '{}',
|
|
},
|
|
// Valid ts earlier, but known_at on cutoff UTC day at 09:00 UTC (< 12:00 UTC) -> MUST be excluded!
|
|
{
|
|
listing_id: listingIds[1]!,
|
|
ts: utcMs(dates[10]!, 14),
|
|
known_at: utcMs(cutoffDate, 9),
|
|
known_at_source: 'exact',
|
|
kind: 'filing',
|
|
subtype: '8-K',
|
|
payload_json: '{}',
|
|
},
|
|
// Unrequested valid kind on cutoff day -> MUST NOT inflate vaultExcludedEvents
|
|
{
|
|
listing_id: listingIds[2]!,
|
|
ts: utcMs(cutoffDate, 10),
|
|
known_at: utcMs(cutoffDate, 10),
|
|
known_at_source: 'exact',
|
|
kind: 'ceo_post',
|
|
subtype: null,
|
|
payload_json: '{}',
|
|
},
|
|
];
|
|
|
|
const calendarCalls: EventStudyExchangeCalendarQuery[] = [];
|
|
const resolveExchangeCalendars = async (
|
|
q: EventStudyExchangeCalendarQuery
|
|
): Promise<EventStudyExchangeCalendars> => {
|
|
calendarCalls.push(q);
|
|
const sessions = dates
|
|
.filter(d => d >= q.fromDate && d <= q.toDate)
|
|
.map(date => ({ date, closeTs: utcMs(date, 21) }));
|
|
const listingCalendarId = new Map<number, string>();
|
|
for (const id of q.listingIds) {
|
|
listingCalendarId.set(id, 'XNYS');
|
|
}
|
|
return { calendars: new Map([['XNYS', sessions]]), listingCalendarId };
|
|
};
|
|
|
|
const store = createPassThroughStore({
|
|
bars,
|
|
eventsTable: {
|
|
columns: [...EVENTS_COLUMNS],
|
|
rows: [...baseEvents, ...intradayCutoffEvents],
|
|
},
|
|
});
|
|
const ledger = createFakeLedger();
|
|
const server = createMcpServer({
|
|
name: 'research-mcp',
|
|
version: '1.0.0',
|
|
tools: [
|
|
createEventStudyTool({
|
|
store,
|
|
ledger: ledger.executor,
|
|
vaultContext: { vaultCutoffTs },
|
|
principalId: AGENT_PRINCIPAL,
|
|
resolveExchangeCalendars,
|
|
}),
|
|
],
|
|
});
|
|
|
|
const res = await invoke(server, {
|
|
listingIds,
|
|
from: dates[0]!,
|
|
to: dates[21]!,
|
|
event: { kinds: ['filing'] },
|
|
preDays: 2,
|
|
postDays: 2,
|
|
benchmark: 'none',
|
|
universeMarket: 'US_EQ',
|
|
horizonBucket: 'swing_1_10d',
|
|
});
|
|
|
|
expect(res.payload?.status).toBe('ok');
|
|
expect(res.payload?.vaultExcludedEvents).toBe(2);
|
|
expect(res.payload?.eventCount).toBe(6);
|
|
expect(calendarCalls[0]!.toDate < cutoffDate).toBe(true);
|
|
|
|
// Request starting on the intraday cutoff day before vaultCutoffTs:
|
|
// returns insufficient_data cleanly without calling calendar resolver with inverted dates.
|
|
calendarCalls.length = 0;
|
|
const ledger2 = createFakeLedger();
|
|
const server2 = createMcpServer({
|
|
name: 'research-mcp',
|
|
version: '1.0.0',
|
|
tools: [
|
|
createEventStudyTool({
|
|
store,
|
|
ledger: ledger2.executor,
|
|
vaultContext: { vaultCutoffTs },
|
|
principalId: AGENT_PRINCIPAL,
|
|
resolveExchangeCalendars,
|
|
}),
|
|
],
|
|
});
|
|
|
|
const startOnCutoffRes = await invoke(server2, {
|
|
listingIds,
|
|
from: `${cutoffDate}T01:00:00.000Z`,
|
|
to: `${cutoffDate}T11:00:00.000Z`,
|
|
event: { kinds: ['filing'] },
|
|
preDays: 1,
|
|
postDays: 1,
|
|
universeMarket: 'US_EQ',
|
|
horizonBucket: 'swing_1_10d',
|
|
});
|
|
|
|
expect(startOnCutoffRes.isError).toBeUndefined();
|
|
expect(startOnCutoffRes.payload?.status).toBe('insufficient_data');
|
|
expect(calendarCalls).toHaveLength(0);
|
|
expect(ledger2.insertCalls).toBe(0);
|
|
});
|
|
|
|
test('exact boundary timestamps (fromMs, toMs, asOfMs) and malformed ts rejection', async () => {
|
|
const dates = makeBusinessDates('2023-07-03', 20);
|
|
const vaultCutoffDate = dates[19]!;
|
|
const vaultCutoffTs = utcMs(vaultCutoffDate, 0);
|
|
const listingIds = [301, 302, 303, 304, 305, 306];
|
|
|
|
const bars: BarRecord[] = [];
|
|
for (const id of listingIds) {
|
|
let price = 30;
|
|
for (let t = 0; t < 19; t += 1) {
|
|
price = Number((price * (1 + (t % 2 === 0 ? 0.015 : -0.005))).toFixed(6));
|
|
const ts = utcMs(dates[t]!, 21);
|
|
bars.push({
|
|
listingId: id,
|
|
ts,
|
|
open: price,
|
|
high: price,
|
|
low: price,
|
|
close: price,
|
|
volume: 1_000,
|
|
knownAt: ts,
|
|
});
|
|
}
|
|
}
|
|
|
|
const fromIso = `${dates[2]}T00:00:00.000Z`;
|
|
const toIso = `${dates[15]}T23:59:59.999Z`;
|
|
const asOfIso = `${dates[14]}T21:00:00.000Z`;
|
|
const fromMs = Date.parse(fromIso);
|
|
const toMs = Date.parse(toIso);
|
|
const asOfMs = Date.parse(asOfIso);
|
|
|
|
const rows: TableRow[] = [
|
|
// Exact fromMs -> included
|
|
{
|
|
listing_id: listingIds[0]!,
|
|
ts: fromMs,
|
|
known_at: fromMs,
|
|
known_at_source: 'exact',
|
|
kind: 'filing',
|
|
subtype: '8-K',
|
|
payload_json: '{}',
|
|
},
|
|
// fromMs - 1 -> excluded
|
|
{
|
|
listing_id: listingIds[1]!,
|
|
ts: fromMs - 1,
|
|
known_at: fromMs - 1,
|
|
known_at_source: 'exact',
|
|
kind: 'filing',
|
|
subtype: '8-K',
|
|
payload_json: '{}',
|
|
},
|
|
// Exact asOfMs -> included
|
|
{
|
|
listing_id: listingIds[2]!,
|
|
ts: utcMs(dates[10]!, 14),
|
|
known_at: asOfMs,
|
|
known_at_source: 'exact',
|
|
kind: 'filing',
|
|
subtype: '8-K',
|
|
payload_json: '{}',
|
|
},
|
|
// asOfMs + 1 -> excluded
|
|
{
|
|
listing_id: listingIds[3]!,
|
|
ts: utcMs(dates[10]!, 14),
|
|
known_at: asOfMs + 1,
|
|
known_at_source: 'exact',
|
|
kind: 'filing',
|
|
subtype: '8-K',
|
|
payload_json: '{}',
|
|
},
|
|
// toMs + 1 -> excluded
|
|
{
|
|
listing_id: listingIds[4]!,
|
|
ts: toMs + 1,
|
|
known_at: asOfMs,
|
|
known_at_source: 'exact',
|
|
kind: 'filing',
|
|
subtype: '8-K',
|
|
payload_json: '{}',
|
|
},
|
|
];
|
|
|
|
const resolveExchangeCalendars = async (
|
|
q: EventStudyExchangeCalendarQuery
|
|
): Promise<EventStudyExchangeCalendars> => {
|
|
const sessions = dates
|
|
.filter(d => d >= q.fromDate && d <= q.toDate)
|
|
.map(date => ({ date, closeTs: utcMs(date, 21) }));
|
|
const listingCalendarId = new Map<number, string>();
|
|
for (const id of q.listingIds) {
|
|
listingCalendarId.set(id, 'XNYS');
|
|
}
|
|
return { calendars: new Map([['XNYS', sessions]]), listingCalendarId };
|
|
};
|
|
|
|
const store = createPassThroughStore({
|
|
bars,
|
|
eventsTable: { columns: [...EVENTS_COLUMNS], rows },
|
|
});
|
|
const ledger = createFakeLedger();
|
|
const server = createMcpServer({
|
|
name: 'research-mcp',
|
|
version: '1.0.0',
|
|
tools: [
|
|
createEventStudyTool({
|
|
store,
|
|
ledger: ledger.executor,
|
|
vaultContext: { vaultCutoffTs },
|
|
principalId: AGENT_PRINCIPAL,
|
|
resolveExchangeCalendars,
|
|
}),
|
|
],
|
|
});
|
|
|
|
const res = await invoke(server, {
|
|
listingIds,
|
|
from: fromIso,
|
|
to: toIso,
|
|
asOf: asOfIso,
|
|
event: { kinds: ['filing'] },
|
|
preDays: 1,
|
|
postDays: 1,
|
|
universeMarket: 'US_EQ',
|
|
horizonBucket: 'swing_1_10d',
|
|
});
|
|
|
|
// Only 2 events survived the exact boundaries (fromMs and asOfMs) -> insufficient_data (< 5)
|
|
expect(res.payload?.status).toBe('insufficient_data');
|
|
expect(res.payload?.eventCount).toBe(2);
|
|
expect(ledger.insertCalls).toBe(0);
|
|
|
|
// Malformed `ts` on an otherwise eligible event row must fail with sanitized EventPanelError
|
|
const malformedStore = createPassThroughStore({
|
|
bars,
|
|
eventsTable: {
|
|
columns: [...EVENTS_COLUMNS],
|
|
rows: [
|
|
{
|
|
listing_id: listingIds[0]!,
|
|
ts: 'not-a-timestamp' as unknown as number,
|
|
known_at: fromMs,
|
|
known_at_source: 'exact',
|
|
kind: 'filing',
|
|
subtype: '8-K',
|
|
payload_json: '{}',
|
|
},
|
|
],
|
|
},
|
|
});
|
|
const malformedLedger = createFakeLedger();
|
|
const malformedServer = createMcpServer({
|
|
name: 'research-mcp',
|
|
version: '1.0.0',
|
|
tools: [
|
|
createEventStudyTool({
|
|
store: malformedStore,
|
|
ledger: malformedLedger.executor,
|
|
vaultContext: { vaultCutoffTs },
|
|
principalId: AGENT_PRINCIPAL,
|
|
resolveExchangeCalendars,
|
|
}),
|
|
],
|
|
});
|
|
|
|
const badRes = await invoke(malformedServer, {
|
|
listingIds,
|
|
from: fromIso,
|
|
to: toIso,
|
|
asOf: asOfIso,
|
|
event: { kinds: ['filing'] },
|
|
preDays: 1,
|
|
postDays: 1,
|
|
universeMarket: 'US_EQ',
|
|
horizonBucket: 'swing_1_10d',
|
|
});
|
|
|
|
expect(badRes.isError).toBe(true);
|
|
expect(badRes.text).toBe('EventPanelError: Event table data failed event panel validation.');
|
|
expect(malformedLedger.insertCalls).toBe(0);
|
|
});
|
|
});
|