fix(reconcile): reject unknown top-level fields in desired-state documents - #1888
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
📝 WalkthroughSummary by CodeRabbit
Walkthrough
ChangesStrict envelope validation
Estimated code review effort: 2 (Simple) | ~10 minutes Merge Risk: ⚪ Minimal · up to The decoder now rejects unknown or mis-cased top-level fields before reconciliation, preventing typoed documents from being silently accepted. A trivial casing regression test remains a follow-up, but no actionable merge-blocking risk remains. 🚥 Pre-merge checks | ✅ 2✅ Passed checks (2 passed)
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 |
Coverage Report for CI Build 32106205618Coverage increased (+0.01%) to 48.747%Details
Uncovered ChangesNo uncovered changes found. Coverage RegressionsNo coverage regressions found. Coverage Stats
💛 - Coveralls |
|
Review: reject unknown top-level fields (RFC 0001 Rule 3) Verified on this branch: This does what it claims. Verdict: approve with nits. Nits:
|
|
Follow-up on the review nits.
|
|
Re-review (head 3e21c89) Build, tests, and lint are all green on the branch. The multi-document test One nit still open, cosmetic: the error still surfaces the internal Go type name, Verdict: approve with nits. |
3e21c89 to
9ef21ae
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (1)
internal/reconcile/reconcile_test.go (1)
116-125: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick winAdd a case-sensitivity regression test.
The current test rejects
spce, but it does not prove that known keys with different casing, such asKindorSpec, are rejected. Add one case and assert that reconciliation is not dispatched.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 87f33dce-a6d7-4f4d-8719-2566124961a9
📒 Files selected for processing (2)
internal/reconcile/reconcile.gointernal/reconcile/reconcile_test.go
Included review availability: Your plan includes up to 2 reviews per rolling hour; 1 remains after this review.
What
The reconcile document decoder ignored unknown top-level keys. A stray key (a typo of
spec, a misplacedmetadata, a misspelledapiVersionthat silently falls back to v1) was dropped instead of failing the file.This adds
KnownFields(true)to the document decoder, so an unknown top-level key fails the whole file up front, the same way entry decoding already rejects unknown fields. The spec's own content is decoded separately, so only the outerapiVersion/kind/specenvelope is guarded.Why
RFC 0001 Rule 3 ("validate before apply") says the whole file is checked first, including that unknown fields are rejected. The document level did not enforce this, so a typo could pass validation and hide a mistake.
Testing
internal/reconcilepackage passes.Stack
Base of a four-PR stack fixing reconcile-kind findings from the RFC 0001 audit:
fix/reconcile-framework-known-fields(this PR)fix/reconcile-permission-spicedb-grammarfix/reconcile-billingproduct-r2docs/reconcile-platformuser-disabled-out-of-scopeNote on casing
Top-level keys are now case-sensitive.
apiversion:orKIND:fail instead of silently defaulting. That is the intended typo-catch, and export always writes the correct casing, so exported files are unaffected.