fix(request-filters): preserve advanced mode when rebinding#1264
Conversation
📝 WalkthroughWalkthrough补全了 updateRequestFilterAction 在绑定字段校验时传入的规则模式与操作集参数,并新增可控的 getRequestFilterById mock 与两条测试,覆盖允许更新 providerIds 的成功场景与基于更新后规则模式的失败校验场景。 变更绑定更新校验补全
🎯 2 (Simple) | ⏱️ ~8 分钟 🚥 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 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 |
There was a problem hiding this comment.
Code Review
This pull request updates the updateRequestFilterAction to include ruleMode and operations from the existing filter during validation, and adds corresponding unit tests. A review comment points out that if ruleMode or operations are being updated in the same request, using the existing values directly will use stale data and cause validation failures. The reviewer suggests using the updated values from the payload if they are provided.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| ruleMode: existing!.ruleMode, | ||
| operations: existing!.operations, |
There was a problem hiding this comment.
When updating a request filter, if both the binding-related fields (such as providerIds, groupTags, or bindingType) and the rule mode/operations are updated in the same request, using existing!.ruleMode and existing!.operations directly in validatePayload will use the stale (pre-update) values.
This can cause validation to fail or run against the wrong mode (e.g., validating an advanced filter as a simple one, leading to errors like '目标字段不能为空'). We should use the updated values from updates if they are provided.
| ruleMode: existing!.ruleMode, | |
| operations: existing!.operations, | |
| ruleMode: updates.ruleMode ?? existing!.ruleMode, | |
| operations: updates.operations !== undefined ? updates.operations : existing!.operations, |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 279e968e15
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| ruleMode: existing!.ruleMode, | ||
| operations: existing!.operations, |
There was a problem hiding this comment.
Validate binding updates against the effective rule mode
When a single update both changes bindings and switches an existing advanced filter back to simple, this still validates with existing!.ruleMode/existing!.operations. For an advanced filter whose target is intentionally empty, a PATCH such as { ruleMode: "simple", providerIds: [...] } passes validation because validatePayload skips simple-mode target checks, then persists a simple filter with an empty target. Use the effective updates.ruleMode ?? existing!.ruleMode (and corresponding operations) here so mixed mode/binding updates are validated in the state that will actually be saved.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Code Review Summary
No significant issues identified in this PR. The fix correctly preserves ruleMode and operations from the existing record when calling validatePayload during binding-only updates, preventing advanced filters with empty targets from being incorrectly rejected as simple-mode filters. The regression test directly covers the reported bug scenario.
PR Size: XS
- Lines changed: 33 (32 additions, 1 deletion)
- Files changed: 2
Review Coverage
- Logic and correctness - Clean. The
existing\!non-null assertion at lines 375-376 is safe becauseneedsExisting(line 296) includes binding-related fields, guaranteeing the null check at line 310 has already passed. - Security (OWASP Top 10) - Clean. No new attack surface introduced.
- Error handling - Clean. Follows existing patterns with proper error propagation.
- Type safety - Clean.
ruleModeandoperationstypes match thevalidatePayloadsignature. - Documentation accuracy - Clean. No comment drift.
- Test coverage - Adequate. Regression test covers the exact bug scenario (advanced filter + empty target + provider binding update).
- Code clarity - Good. Minimal, targeted fix.
Automated review by Claude AI
279e968 to
9a78331
Compare
Summary
Preserve the existing
ruleModeandoperationswhen validating provider/group binding-only updates, preventing advanced-mode filters with an emptytargetfrom being incorrectly rejected.Problem
This is a regression from #912 (advanced mode operations). When updating only binding fields (
providerIds,groupTags) on an advanced-mode filter, the binding-validation path atsrc/actions/request-filters.ts:368constructs avalidatePayloadcall that omitsruleModeandoperations. WithoutruleMode, the validator defaults to"simple"mode, which enforces a non-emptytarget— but advanced-mode filters legitimately have emptytargetfields since they useoperationsinstead. This makes binding-only updates on advanced filters fail with "目标字段不能为空".Solution
Forward the existing filter's
ruleModeandoperationsinto thevalidatePayloadcall so the validator correctly recognizes advanced-mode filters and skips the empty-target check.Follow-up to #912 — the advanced-mode validation path for binding-only updates was missed in the original implementation.
Changes
Core Fix
src/actions/request-filters.ts— Passexisting.ruleModeandexisting.operationstovalidatePayloadin the binding-update validation blockTests
tests/unit/actions/request-filters-cache-reload.test.ts— Regression test: updating provider bindings on an advanced final filter with an emptytargetsucceeds and calls the repository correctlyTesting
bun run test tests/unit/actions/request-filters-cache-reload.test.tsbunx biome check src/actions/request-filters.ts tests/unit/actions/request-filters-cache-reload.test.tsDescription enhanced by Claude AI
Greptile Summary
This PR fixes a regression introduced in #912 where binding-only updates (
providerIds,groupTags) on advanced-mode filters incorrectly failed with "目标字段不能为空". The root cause was the binding-validation call insideupdateRequestFilterActionomittingruleModeandoperations, causingvalidatePayloadto default to simple mode and enforce a non-emptytargetcheck that advanced filters legitimately bypass.src/actions/request-filters.ts):effectiveRuleModeandeffectiveOperationsare now computed and forwarded tovalidatePayloadin the binding-update validation block, so the validator correctly recognises advanced-mode filters and skips the empty-target check.tests/unit/actions/request-filters-cache-reload.test.ts): Two new tests cover the primary fix (binding update on advanced filter with emptytargetsucceeds) and the boundary case (transitioning to simple mode without a target still fails correctly).Confidence Score: 5/5
Safe to merge — the change is narrow, well-targeted, and covered by regression tests; no existing behaviour outside the advanced-mode binding path is affected.
The fix touches only two new lines in a single conditional block, correctly mirrors how every other effective-value computation in that block already works, and is guarded by two new tests covering both the happy path and the failure boundary.
No files require special attention beyond the noted pre-existing gap in the binding validation's target handling.
Important Files Changed
Flowchart
%%{init: {'theme': 'neutral'}}%% flowchart TD A[updateRequestFilterAction called] --> B{binding fields in updates?} B -- No --> G[other validation / DB write] B -- Yes --> C[compute effectiveBindingType\neffectiveProviderIds\neffectiveGroupTags] C --> D["compute effectiveRuleMode\n(updates.ruleMode ?? existing.ruleMode)\n[NEW]"] D --> E["compute effectiveOperations\n(updates.operations ?? existing.operations)\n[NEW]"] E --> F["validatePayload(name, scope, action,\ntarget, bindingType, providerIds, groupTags,\nruleMode, operations)"] F -- ruleMode=advanced --> H[validateOperations → skip empty-target check] F -- ruleMode=simple --> I{target empty?} I -- Yes --> J[return error] I -- No --> K[check binding constraints] H --> K K --> GPrompt To Fix All With AI
Reviews (2): Last reviewed commit: "fix(request-filters): preserve advanced ..." | Re-trigger Greptile