Repository navigation
test(provider_contract): pin unknown-field rejection on every DTO - #7155
Conversation
Closes #7148. Probe each deny_unknown_fields provider-contract struct at its own JSON object with one extra field so dropping the attribute fails. Co-authored-by: Steven Zimmerman, CPA <EffortlessSteven@users.noreply.github.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configuration
📒 Files selected for processing (1)
🔗 Linked repositories identifiedCodeRabbit considers these linked repositories for cross-repo context during reviews:
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 5 remain after this review. Summary by CodeRabbit
WalkthroughThe wire-format test now checks that eight provider contract structures reject an added ChangesProvider DTO checks
Priority: ⬇️ Low Estimated code review effort: 2 (Simple) | ~10 minutes Change: Other Merge Risk: ⚪ Minimal · up to No merge-blocking issue is identified; merge after the required checks pass. Architecture SummaryArchitecture risk: 🟡 Medium · up to The change affects 1 system. Changed systems: Architecture concerns Review detailsSystems and components
Before / after behavior
Reliability and maintainability
🚥 Pre-merge checks | ✅ 6 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (6 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 Generate unit tests (beta)
I’m a rabbit, testing fields with care, Comment |
There was a problem hiding this comment.
Code Review
This pull request introduces a helper function reject_unknown_field_at_struct_level to test that various DTO structs correctly reject unknown fields during deserialization. It also adds a diagnostic helper fixture and refactors the public_wire_round_trips_and_rejects_unknown_fields test to apply this validation across multiple structs, including receipts, capabilities, snapshots, requests, and diagnostics. There are no review comments, and I have no feedback to provide.
There was a problem hiding this comment.
Confirmed findings
- crates/ripr/src/provider_contract/tests.rs:40 — 'unexpected' is a brittle sentinel. If any DTO grows an 'unexpected' field the helper errors instead of skipping; pin to a high-collision UUID per struct (e.g.
format!("__ripr_unknown__{label}")) so the test fails on collision only when the targeted struct actually has that field, and the message remains descriptive. - Helper hard-codes key 'unexpected' and silently returns Err if a DTO's valid fixture already has that field; no #[ignore] or fail-loud signal means future DTO additions can quietly lose the deny_unknown_fields pin.
Verification questions
- Confirm helper's 'extra field failure' check only matches substring 'unknown field' in the error string; if a nested owner with deny_unknown_fields absorbs the key, the outer call still passes.
- Confirm ripr sensor exited 2 in this packet; given this PR is a ripr test addition, the failure may be on this test or a pre-existing flake. PR body defers local proof to 'follow on this candidate'. Defer to hosted CI but flag for visibility.
- Confirm helper uses
message.contains("unknown field"); the prior test only checked Err vs Ok. New assertion is stricter but still allows any error message containing that substring - a regression that emits e.g. 'unknown fieldunexpected' from a nested owner (not the target DTO) would pass. For request(), the original code just checked Err(.).
Refuted
- Helper could be fooled by a sibling DTO that owns
deny_unknown_fieldsand silently absorb the extraunexpectedfield on the parent object; refuted because:serde_json::to_value(&valid)produces the JSON value for T; the helper mutates that top-level object and feeds it back toserde_json::from_value::<T>, so rejection necessarily comes from T's owndeny_unknown_fields. Confirmed by reading the helper body and theSerialize/DeserializeOwnedbound. - The 'unexpected' key collides with a legitimate DTO field, so the new test silently no-ops on at least one of the 9 DTOs.; refuted because: All 9 DTOs' model.rs field sets (referenced, not in diff) use distinct snake_case names; the helper's contains_key guard would trip if a collision existed and surface it as Err, not silent pass. Currently safe.
- Test round-trip arm is a no-op and could mask a Serialize that doesn't match Deserialize, defeating the stated pin; refuted because: Helper calls serde_json::from_value::(encoded.clone()) before mutating; assert_eq! compares decoded to valid via PartialEq. If a DTO drops PartialEq impl, this won't compile — but all 9 DTOs are claimed structurally equal. Code visibly exercises both directions.
Evidence gaps
- cargo-test is scheduled-late, not yet in receipts. Diff changes test logic in provider_contract; without red/green proof of the new 9-DTO path we cannot confirm the suite passes on this candidate SHA. Resolved once cargo-test receipt lands.
- Cargo-test receipt is scheduled-late; ripr sensor failed exit 2 (also test-related), so the 'focused local proof' cited in PR body is not yet evidenced in this packet.
- Model proof intent was rejected by deterministic validation.
Parked follow-ups
- Helper's
as_object_mut()precondition is asserted via Err return, but the 'unexpected' collision guard returns Err too - so a DTO whose valid fixture already contains a field literally named 'unexpected' becomes un-testable. None of the 9 current DTOs have such a field per the model.rs surface referenced, but the helper silently drops coverage if a future DTO adds one.
EffortlessSteven
left a comment
There was a problem hiding this comment.
review-pr (author self-review, COMMENT)
GitHub cannot request-changes from the PR author. This is a substantive exact-head inspection, not approval.
reviewed_head_sha: 6d0e395147f043a44214de142ad3f4ae36f486c8
integration_basis: origin/main 2dd57018756c6c289da88b7824bb891e19fb5ccc
claim_boundary: test-only pin of deny_unknown_fields on the nine provider-contract DTOs in model.rs; Closes #7148
changed_surfaces_and_semantic_owners_inspected: crates/ripr/src/provider_contract/tests.rs (owner: provider_contract tests); production model.rs/validate.rs unchanged; no MCP/LSP/golden/corpus/xtask overlap
blocking_findings: none on source/oracle for this head
non_blocking_suggestions: corpus unknown-field cases remain optional and were not added; CodeRabbit docstring-coverage 80% is not a repo gate
refuted_or_stale_findings: droid 'unexpected sentinel silently drops coverage' — returning Err from this #[test] fails the test (fail-closed), matching the prior request-only probe's key; collision with a future field named unexpected would fail loudly, not skip. Nested-owner absorption was also refuted in that review: the helper mutates T's own JSON object and deserializes as T.
proof_and_ci_observed: local cargo test -p ripr --lib provider_contract (23 passed); per-struct deny_unknown_fields removal made public_wire_round_trips_and_rejects_unknown_fields fail for all nine DTOs; cargo xtask precommit exit 0. Hosted Ripr Rust Small Result not yet terminal at review time.
proof_or_review_missing: exact-head required check Ripr Rust Small Result (Draft->Ready just fired); advisory droid-review still queued
affected_currentness_dimensions: test stimulus, test oracle, candidate head identity
residual_assumptions_and_non_claims: does not change production serde attributes or validation; does not claim runtime mutation outcomes; optional provider-corpus unknown-field cases omitted
disposition: REVIEW_INCOMPLETE until Ripr Rust Small Result is terminal on this SHA; source/oracle inspection found no blocker
Inspected: complete 1-file diff; nine structs with #[serde(deny_unknown_fields)] in model.rs (descriptor, set, snapshot, subject, request, diagnostic, entry, summary, receipt); helper inserts the extra key at that struct's object so dropping one attribute fails only that case. Positive round-trip plus unknown field substring is a stricter oracle than the old request-only Err(_).
No merge until required hosted proof is current on this head.
There was a problem hiding this comment.
Decision
- Needs reviewer attention before upstream: findings remain.
Confirmed findings
- ripr sensor failed exit 2 in this packet; PR body defers to hosted CI 'Ripr Rust Small Result' as merge authority. Local ripr receipt absent; flag for visibility but not gating per PR scope.
Verification questions
- Confirm substring 'unknown field' check is tighter than prior Err vs Ok and could miss rejection messages that phrase it as 'unknown field
unexpected' vs 'unexpected field'; serde-json phrasing is stable here. - Confirm source-route gap: ripr sensor exited 2 in this packet; helper is a ripr test addition so the failure may be on this test or a pre-existing flake.
- Confirm ripr sensor exit 2 is most likely a self-incident on this PR's test addition; per-struct removal experiment in PR body is the authoritative local proof. Defer to hosted CI.
Refuted
- Nested-owner absorption swallows the 'unexpected' key so the helper silently passes even when T lacks deny_unknown_fields; refuted because: Helper builds Value from serde_json::to_value(&valid) where valid: T, mutates the top-level object's own JSON, and deserializes back as T. The extra key is at T's object level, not inside a nested child's JSON object, so a nested child's deny_unknown_fields cannot absorb it before T sees it.
- Helper silently drops coverage if a DTO already serializes an
unexpectedfield; refuted because: Early-return Err(json_error(...)) makes the #[test] fail loudly rather than skip; per author self-review, future field collision fails the suite.
Parked follow-ups
- 'unexpected' sentinel is brittle if any DTO ever gains a field of that name; helper errors fail-closed (returns Err) which fails the test, not silently skips.
Evidence gaps
- Model proof intent was rejected by deterministic validation.
|
Classifying the follow-up droid review on The remaining “confirmed” item is the advisory packet’s Earlier “silent Err / nested absorb” claims are already refuted in that review and in the author self-review: No source repair. Merge remains gated on |
EffortlessSteven
left a comment
There was a problem hiding this comment.
REVIEW_READY — exact-head review of 6d0e39514 (test-only, gate green, 0 threads).
- Coverage (complete): all 9 DTOs probed (receipt, capability set + descriptor, repository snapshot, subject, request, summary, evidence entry, diagnostic) — matches the 9
deny_unknown_fieldsattributes inmodel.rsone for one. - Mechanism (stronger than the old pin): the helper requires the failure message to contain "unknown field", pinning the deny-attribute mechanism rather than any deserialization failure; the no-preexisting-
unexpected-key assertion prevents vacuous collision; round-trip first guards fixture validity;descriptor/entryextraction carries setup assertions against empty fixtures. - Level-correctness: the extra key goes at each struct's own JSON object with nested children serialized as-is, so each probe pins its own struct's attribute, not a nested owner's.
- Liveness (proven by mutation): commenting out one attribute (
model.rs:155) flips the test to FAIL; restored → green. The failure names the mechanism, not just the test. - Scope: single test file, no production change; zero promotion/demotion surface. The old request-only inline probe is subsumed (request is now one of the 9 helper calls).
Summary
Pin
#[serde(deny_unknown_fields)]on every provider-contract DTO, not just the request.public_wire_round_trips_and_rejects_unknown_fieldsnow deserializes a valid instance of each struct plus one extra field at that struct's JSON object and expects an unknown-field failure.Closes #7148.
Swarm / Source Boundary
This PR targets
EffortlessMetrics/ripr-swarm, the normal development trunk fortrusted same-repo
riprwork. Confirm the change belongs here:dependency, or repo-ops development for
ripr-swarmsurface
Source-of-truth Links
Proposal: n/a
Spec: n/a (test-only pin of existing serde contract)
ADR: n/a
Plan item: n/a
Governing issue or accepted claim: #7148
Acceptance delta (one sentence): Temporarily removing
deny_unknown_fieldsfrom any of the nine provider-contract DTOs makespublic_wire_round_trips_and_rejects_unknown_fieldsfail; restoring it makes the suite pass.Candidate Relationships
Candidate branch (GitHub PR head is authoritative after publication):
cursor/provider-dto-unknown-fields-4aa8Stack parent or prerequisite PR (if any): none
Proposed replacement of PR (if any; not yet accepted): none
Acceptance retained from a replaced candidate (if any): n/a
Accepted winner and losing candidate disposition (when decided): n/a
Scope
Test-only expansion of the existing public-wire unknown-field pin in
crates/ripr/src/provider_contract/tests.rs. Productionmodel.rsand validation logic are unchanged.Scope Classification
This PR is scoped by:
Production delta:
#[serde(deny_unknown_fields)]already exists on all nine DTOs.Evidence/support delta:
reject_unknown_field_at_struct_levelround-trips a valid instance, then inserts"unexpected": trueat that struct's JSON object and requires deserialize failure whose message containsunknown field.Single acceptance criterion:
deny_unknown_fieldsfrom any one of those structs fails the test; restoring it passes.Non-goals:
Support-tier Impact
docs/status/SUPPORT_TIERS.mdClaim/proof notes:
Policy Impact
Ledger or exception notes:
Proof
cargo test -p ripr --lib provider_contract cargo xtask precommitResult, failures, or skipped proof:
cargo test -p ripr --lib provider_contract: 23 passed, 0 failed, includingpublic_wire_round_trips_and_rejects_unknown_fields.deny_unknown_fieldsfrom each of the nine DTOs inmodel.rsmade that exact test fail (exit 101); restoring the attributes left a clean tree and the suite passed again.cargo xtask precommit: exit 0 (fmt, no-panic, file-policy, architecture, public-api, output-contracts, and the rest of the precommit table).6d0e395147f043a44214de142ad3f4ae36f486c8. Hosted required checkRipr Rust Small Resultis the merge authority.Claim Boundary
What may be claimed after this PR? What must not be claimed yet?
deny_unknown_fieldsprovider-contract DTO has a discriminator that fails if that attribute is dropped.Rollback
How can this PR be reverted safely?
Spec-Test-Code Traceability
crates/ripr/src/provider_contract/model.rscrates/ripr/src/provider_contract/tests.rs::public_wire_round_trips_and_rejects_unknown_fieldsStatic Language Check
killed,survived,untested,proven, andadequate.CI Economics
Engineering Check
panic,unwrap,expect,todo, orunimplementedin production code.panic,unwrap,expect,todo, orunimplementedin tests.Gates
Focused local proof named above. Hosted PR CI owns the required merge-gate matrix.
precommitis shift-left, not CI-equivalent completeness.Exact candidate SHA
6d0e395147f043a44214de142ad3f4ae36f486c8oncursor/provider-dto-unknown-fields-4aa8(baseorigin/main2dd57018756c6c289da88b7824bb891e19fb5ccc).