Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions server/indexer/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,30 @@ export function classifyEvent(topics: string[]): EventType {
/**
* Parse event data into a structured record.
*/
/** Event payload schema versions this parser can decode. */
export const SUPPORTED_EVENT_SCHEMA_VERSIONS: ReadonlySet<number> = new Set([1]);

export class UnsupportedSchemaError extends Error {
constructor(public readonly schemaVersion: unknown) {
super(`Unsupported event schemaVersion ${String(schemaVersion)}; refusing to index (update parser before deploying this contract)`);
this.name = 'UnsupportedSchemaError';
}
}

/**
* Version gate (#757): an event that declares a schemaVersion this parser does
* not support halts indexing instead of silently dropping fields. Events without
* a declared version keep the legacy decode path.
*/
export function assertSupportedSchema(data: any): void {
if (data && typeof data === 'object' && data.schemaVersion !== undefined
&& !SUPPORTED_EVENT_SCHEMA_VERSIONS.has(Number(data.schemaVersion))) {
throw new UnsupportedSchemaError(data.schemaVersion);
}
}

export function parseEvent(topics: string[], data: any): ParsedEvent {
assertSupportedSchema(data);
const eventType = classifyEvent(topics);

const parsed: ParsedEvent = {
Expand Down
10 changes: 8 additions & 2 deletions tests/e2e/layout.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,12 @@ for (const route of ROUTES) {
document.documentElement.dataset.layoutSnapshot = 'true'
})

// Live map tiles and canvas pins re-raster on every capture, so they are masked,
// and CSS animations (mdpulse/mddash) are frozen for a deterministic layout diff.
await page.addStyleTag({
content: '*,*::before,*::after{animation-play-state:paused!important;transition:none!important}',
})

if (route.freezeCss) {
await page.addStyleTag({ content: route.freezeCss })
// Give the injected style one frame to repaint before capturing.
Expand All @@ -188,8 +194,8 @@ for (const route of ROUTES) {
await expect(page).toHaveScreenshot(`layout-${route.name}.png`, {
animations: 'disabled',
caret: 'hide',
// Video frames are the only pixel source that cannot be replayed.
mask: [page.locator('video')],
// Video frames and live map canvases cannot be replayed deterministically.
mask: [page.locator('video'), page.locator('canvas, .mapboxgl-map')],
maxDiffPixelRatio: 0.05,
})
})
Expand Down