Repository navigation
test(indexer): mixed schema_version fixtures and stop-on-unknown coverage - #43
jdjioe5-cpu wants to merge 1 commit into
Conversation
…rage - Closes Kinlock-Org#34 - Covers Roadmap rows M2-10 and M2-14 - Add forward-compatible v2 handler stubs (lockCreatedV2, releasedV2) registered in HANDLERS - Add synthesized mixed-versions.json fixture covering interleaved v1 and v2 schema events on the same lock (Lock 3) - Verify ingest handles mixed event streams without double counting or state corruption - Prove identical database state when replayed multiple times across varying batch sizes (1, 4, 100) - Add stop-on-unknown coverage verifying schema_version 0 and 99 halt ingest immediately with UnsupportedEventError - Add missing schema_version coverage verifying DecodeError triggers atomic batch rollback - Update ROADMAP.md row statuses and changelog entry
YazarAyobami
left a comment
There was a problem hiding this comment.
Found while reviewing for merge (not a malware finding, but flagging before this merges): lockCreatedV2/releasedV2 in services/indexer/src/handlers/{lock-created,released}.ts are wired into the real production HANDLERS dispatch table in services/indexer/src/handlers/index.ts, registered under schema_version: 2 for LockCreated/Released. There is no actual schema_version: 2 anywhere in kinlock-contracts — these are aliases that just call the v1 handler, invented solely to make this PR's fixture test exercise a "mixed version" scenario.
This is more than unnecessary (AGENTS.md hard rule 10, minimum viable): it's a latent correctness risk. If the contract ever does introduce a genuine v2 event with different fields, the indexer will already "know" version 2 and decode it with the v1 shape instead of correctly stopping on an unknown version — undermining the stop-on-unknown protection (AGENTS.md §8.2) for that real future case.
Suggest testing the version-dispatch mechanism itself (that mixed known-versions in one event stream are each routed to their own handler and none get double-counted) against versions that already exist for a different event type, or via a mock/injected handler map scoped to the test rather than registering a fictional version into the live HANDLERS table. Happy to help rework this if useful.
What and why
Implements test coverage and fixtures for indexer mixed schema_version event streams and stop-on-unknown error behavior per Roadmap rows M2-10 and M2-14 (Closes #34). Proves that the indexer gracefully processes interleaved event versions without double counting, reproduces identical state on replay, and halts with full batch rollback when encountering unknown versions or missing version tags.
Changes
services/indexer/src/handlers/lock-created.ts: ExportedlockCreatedV2forward-compatible handler stub.services/indexer/src/handlers/released.ts: ExportedreleasedV2forward-compatible handler stub.services/indexer/src/handlers/index.ts: RegisteredlockCreatedV2andreleasedV2under version 2 inHANDLERS.services/indexer/test/fixtures/events/mixed-versions.json: Generated 15-event fixture interleaving v1 and v2 events, specifically covering Lock 3 created with v2 and released across v2 and v1 tranches.services/indexer/test/helpers/fixtures.ts: ExportedmixedFixtureandmixedFixtureLocksloader helpers.services/indexer/test/ingest.test.ts: Added suitedescribe("ingest: mixed schema_versions (v1 + v2) and stop-on-unknown (M2-10, M2-14)"):Lock 3markedCompleted).schema_version(0, 99) halts immediately withUnsupportedEventErrorand rolls back without dirty writes.schema_versionhalts immediately withDecodeErrorand rolls back cursor and events.ROADMAP.md: UpdatedM2-10andM2-14toDONE, refreshed Phase 3 (76%) and overall (41%) progress snapshots, and added Section 17 Changelog entry.Hard rules / invariants touched
schema_versionrather than silently skip or discard.chain_eventsintegrity).Tests
Commands executed locally and verified all green:
pnpm test(vitest run):Test Files: 15 passed (15)
Tests: 171 passed (171)
pnpm typecheck(tsc --noEmit): Scope 2 of 3 packages clean (0 errors)pnpm lint(biome check .): Checked 74 files, 0 errorspnpm build(tsc -p tsconfig.json): All packages build cleanDocs / ADR
ROADMAP.md: Updated Section 3 Progress snapshot and Section 17 Changelog; row status updated.Roadmap
M2-10(DONE),M2-14(DONE).Assumptions and open questions
None. No business logic in existing v1 handlers was modified, and zero migrations or core SDK code touched.