Make the MiniLcm validation wrapper validate writes by construction#2363
Make the MiniLcm validation wrapper validate writes by construction#2363myieye wants to merge 4 commits into
Conversation
The shared MiniLcm test bases now wrap their Api in the same validation/normalization stack production uses, so the tests hit the API the way the app actually does instead of more loosely. Reuses the production AddMiniLcmValidators wiring so new validators flow into tests automatically. One test that deliberately stores an empty value now talks to the raw BaseApi (it checks storage round-tripping, not a real user call, and validation correctly rejects empty values). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
📝 WalkthroughWalkthrough
ChangesValidation Wrapper Restructure
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related issues
Possibly related PRs
Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 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 |
|
The latest updates on your projects. Learn more about Argos notifications ↗︎
|
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@backend/FwLite/MiniLcm/Validators/MiniLcmApiValidationWrapper.cs`:
- Around line 106-109: The UpdatePublication method passes the api parameter
directly to _api.UpdatePublication instead of using the null-coalescing operator
pattern used by other Update methods in this class. Change the method call from
_api.UpdatePublication(before, after, api) to _api.UpdatePublication(before,
after, api ?? this) to ensure that when api is null, the request routes through
this validation wrapper instead of bypassing it.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: bddf2441-0e42-4cff-9d00-c12eb7305e7e
📒 Files selected for processing (1)
backend/FwLite/MiniLcm/Validators/MiniLcmApiValidationWrapper.cs
| public Task<Publication> UpdatePublication(Publication before, Publication after, IMiniLcmApi? api = null) | ||
| { | ||
| return _api.UpdatePublication(before, after, api); | ||
| } |
There was a problem hiding this comment.
Inconsistent api parameter: should be api ?? this.
All other Update*(..., before, after, api) overloads pass api ?? this to ensure callbacks from the inner API route through this validation wrapper. This method passes api directly, which could skip validation for related operations if api is null.
Proposed fix
public Task<Publication> UpdatePublication(Publication before, Publication after, IMiniLcmApi? api = null)
{
- return _api.UpdatePublication(before, after, api);
+ return _api.UpdatePublication(before, after, api ?? this);
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| public Task<Publication> UpdatePublication(Publication before, Publication after, IMiniLcmApi? api = null) | |
| { | |
| return _api.UpdatePublication(before, after, api); | |
| } | |
| public Task<Publication> UpdatePublication(Publication before, Publication after, IMiniLcmApi? api = null) | |
| { | |
| return _api.UpdatePublication(before, after, api ?? this); | |
| } |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@backend/FwLite/MiniLcm/Validators/MiniLcmApiValidationWrapper.cs` around
lines 106 - 109, The UpdatePublication method passes the api parameter directly
to _api.UpdatePublication instead of using the null-coalescing operator pattern
used by other Update methods in this class. Change the method call from
_api.UpdatePublication(before, after, api) to _api.UpdatePublication(before,
after, api ?? this) to ensure that when api is null, the request routes through
this validation wrapper instead of bypassing it.
…apper The validation wrapper auto-forwarded the whole IMiniLcmApi via BeaKona, so any write method without a matching hand-written override silently forwarded unvalidated. That is how CreateEntry drifted out of validation: its override took (Entry) while the interface member is (Entry, CreateEntryOptions?), so the generated 2-arg forwarder bypassed it entirely (#2362). Re-target BeaKona at IMiniLcmReadApi only (like the write-normalization wrapper) and hand-write every write method, so a new/renamed write becomes a compile error instead of a silent unvalidated forward. Behavior is unchanged: the same methods validate as before, and the sync-write surface (CreateEntry, CreatePublication, CreateMorphType and all JsonPatch updates) deliberately stays pass-through because sync/import writes empty FLEx MultiStrings the validators would reject. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The validator classes have unit tests, but nothing tested the seam where they meet the API - which is exactly where #2362 hid (a dead CreateEntry override). These pin the two things that matter at that seam: methods we expect to validate actually do, and the ones that deliberately don't (CreateEntry, CreatePublication, CreateMorphType) keep passing through, so a future "fix" that breaks sync of empty FLEx values goes red. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
7e413ca to
256b8c6
Compare
…updates UpdatePublication(before, after) forwarded `api` directly while every other before/after update passes `api ?? this`, so nested callbacks bypassed the wrapper. No behavior change today (Publication writes pass through anyway), but it matches the established pattern and avoids a latent gap if Publication validation is added. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
Want to talk about this |
Fixes #2362. Companion to the open decision in #2359.
The validation wrapper let BeaKona auto-forward the whole
IMiniLcmApi, so any write without a hand-written override forwarded straight through unvalidated. That's howCreateEntryquietly stopped validating — its override wasCreateEntry(Entry)but the interface had grown aCreateEntryOptions?parameter, so callers bound to the generated 2-arg forwarder and skipped it.This does what the write-normalization wrapper already does: BeaKona forwards only the read interface, and every write is hand-written — so a new or renamed write won't compile until someone decides how it validates, instead of silently slipping through. Plus wrapper tests that exercise the seam through
IMiniLcmApi(reusing #2360'sTestMiniLcmWrappers).This PR preserves current behavior — same methods validate, same ones pass through.
CreateEntry,CreatePublication,CreateMorphTypeand the JsonPatch updates stay pass-through on purpose: sync/import wraps the API here and writes empty FLEx MultiStrings the validators reject, so validating would break import. Whether we should change that (actually validate user-facing creates) is tracked separately in #2359.Stacked on #2360, so the diff includes its commits until that merges.
🤖 Generated with Claude Code