🐛 bug: skip non-string state keys during iteration#4048
Conversation
Summary of ChangesHello @gaby, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request resolves an issue where the internal Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
WalkthroughThe changes modify the Keys() and serviceKeys() methods to continue iterating over non-string keys instead of terminating early, ensuring all string keys are collected without premature exit. Comprehensive test coverage validates the new behavior across various scenarios. Changes
Suggested labels
Suggested reviewers
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes
🚥 Pre-merge checks | ✅ 1 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (1 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Important Action Needed: IP Allowlist UpdateIf your organization protects your Git platform with IP whitelisting, please add the new CodeRabbit IP address to your allowlist:
Failure to add the new IP will result in interrupted reviews. 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
The pull request effectively addresses a bug where sync.Map iteration would prematurely stop upon encountering non-string keys in Keys() and serviceKeys() methods. By changing return false to return true when a non-string key is found, the iteration now correctly skips these keys and continues to discover all valid string keys. The added tests in state_test.go adequately cover these new behaviors, including scenarios with mixed-type keys and mixed insertion orders, ensuring the robustness of the fix.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4048 +/- ##
==========================================
- Coverage 91.21% 91.17% -0.04%
==========================================
Files 119 119
Lines 11117 11121 +4
==========================================
Hits 10140 10140
- Misses 620 624 +4
Partials 357 357
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
This PR fixes a bug where iterating over the internal State.dependencies sync.Map would abort prematurely when encountering non-string keys, preventing valid string keys inserted after non-string keys from being discovered.
Changes:
- Modified
Keys()andserviceKeys()methods to continue iteration instead of stopping when non-string keys are encountered - Added comprehensive test coverage for mixed-type entries in the sync.Map, including tests for key insertion order and service discovery with non-string keys
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| state.go | Fixed iteration logic in Keys() and serviceKeys() to skip non-string keys by returning true instead of false |
| state_test.go | Added three new test cases to verify string keys are correctly returned when non-string keys are present in various orders |
Motivation
State.dependenciessync.Mapfrom aborting when encountering non-stringkeys so valid string keys and service entries are always discovered.Description
Keys()to continue iterating (returntrue) when async.Mapkey is not astringinstead of stopping the iteration.serviceKeys()to continue iterating when async.Mapkey is not astringso non-string entries don't interrupt service discovery.TestState_Keys_SkipsNonStringKeys_WithMixedOrderto verify string keys inserted before and after a non-string key are still returned, and extend service-key tests withwith-non-string-keyandwith-non-service-keysscenarios to cover mixed-type entries.