refactor(projectors): single-source decodePayload[T] + DRY completeness guard (WS16b)#438
Conversation
…ss guard WS16b DRY-discipline. The ~90 *FromEvent decoders in internal/projectors/ each hand-rolled the identical decode shape: a (stream_type, event_type) guard returning ErrIgnoredEvent, an empty-payload guard, json.Unmarshal(e.Data, &p), and the canonical "projector: invalid <event> payload: %w" wrap. Collapse the boilerplate into one generic decodePayload[T] helper; per-event field validation stays in the caller. 40 decoders converted (-305 LOC net). TestDecodePayloadHelperUsedByAllProjectors AST-walks the package and fails the build if any *FromEvent hand-rolls json.Unmarshal without routing through the helper, unless it is a recorded exception (empty-payload-valid, multi-stream / runtime-eventType, or non-canonical DB-params shape). The allowlist is guarded against stale entries and a vacuous walk. Decoders that route through a shared per-cluster sub-decoder carry no direct json.Unmarshal and are neither flagged nor allowlisted. ADR 0021 records the single-source-helper + self-discovering-test DRY policy and the decision to defer the noisy `dupl` CI backstop in favor of specific completeness tests. Closes #437
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (22)
📝 WalkthroughWalkthroughIntroduces a generic ChangesDRY projector decode helper + completeness guard
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
WS16b DRY-discipline — projector decode collapse (closes #437)
The ~90
*FromEventdecoders ininternal/projectors/each hand-rolled the identical shape:(stream_type, event_type)guard →ErrIgnoredEvent; empty-payload guard;json.Unmarshal(e.Data, &p); canonical"projector: invalid <event> payload: %w"wrap.What changed
decodePayload[T](newdecode.go) centralizes that boilerplate; per-event field validation stays in the caller. 40 decoders converted, −305 LOC net across 18 files. Error-message forms are byte-identical (the comprehensive projector suite asserts them — all green).TestDecodePayloadHelperUsedByAllProjectors(self-discovering AST guard) fails the build if any*FromEventhand-rollsjson.Unmarshalwithout routing through the helper, unless it's a recorded exception. The allowlist is guarded against stale entries and a vacuous (zero-match) walk. It empirically caught 3 decoders during authoring.json.Unmarshaland are neither flagged nor allowlisted.duplCI backstop in favor of specific completeness tests.Gates
gofmt/go vetclean; fullgo test ./internal/projectors/green (37s, asserts exact error strings); local CodeRabbit: no findings.Part of the security/RBAC hardening work plan (WS16b). The cert/CSR test-fixture row lands separately in sdk + agent.
Summary by CodeRabbit
Documentation
Refactor
Tests