-
Notifications
You must be signed in to change notification settings - Fork 489
fix: handle undefined steps field for legacy features #199
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: handle undefined steps field for legacy features #199
Conversation
Fix TypeError when toggling 'Enable automated testing' on existing features. Add backward compatibility migration for steps field in use-board-features.ts and defensive checks in testing-tab-content.tsx.
Summary of ChangesHello @AhamSammich, 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 provides a critical fix for a TypeError encountered when interacting with the automated testing functionality for features that predate the introduction of the 'steps' field. By implementing backward compatibility during feature loading and adding robust defensive checks in the UI, the changes ensure a more stable and resilient user experience, preventing crashes and improving the handling of legacy data. 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. 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
|
WalkthroughThis PR fixes a bug where toggling the "Enable automated testing" checkbox crashes the app due to missing Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes
Possibly related PRs
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request effectively addresses a TypeError for legacy features that are missing the steps field. It introduces a migration in use-board-features.ts to ensure steps is always an array when features are loaded, which is a solid approach to fix the root cause. Additionally, defensive checks have been added to testing-tab-content.tsx to make the component more robust. The changes are well-targeted and correct. I've added a couple of minor suggestions to improve consistency and type correctness.
| if (result.success && result.features) { | ||
| const featuresWithIds = result.features.map( | ||
| (f: any, index: number) => ({ | ||
| (f: Feature, index: number) => ({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While I appreciate the move towards stronger types by changing f: any to f: Feature, it introduces a slight logical inconsistency. The Feature type defines steps as a required string[], but the new logic steps: f.steps || [] correctly assumes steps might be missing on legacy feature objects. To be more explicit about this data transformation from a potentially incomplete object to a valid Feature object, it would be more accurate to type f as any or a partial type.
| (f: Feature, index: number) => ({ | |
| (f: any, index: number) => ({ |
| Add manual steps to verify this feature works correctly. | ||
| </p> | ||
| {steps.map((step, index) => ( | ||
| {Array.isArray(steps) && steps.map((step, index) => ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
apps/ui/src/components/views/board-view/shared/testing-tab-content.tsx (1)
8-14: Fix the type definition to reflect runtime handling of undefined steps.The interface declares
steps: string[](line 11) as a non-optional, always-present array. However, the implementation throughout this component guards againstundefined(lines 26, 32, 63), indicating thatstepscan actually be undefined at runtime.This creates a type safety gap:
- TypeScript won't warn callers that passing
undefinedis handled- The declared API contract doesn't match the implementation
- Type checking won't catch potential bugs
Update the interface to accurately reflect the implementation:
interface TestingTabContentProps { skipTests: boolean; onSkipTestsChange: (skipTests: boolean) => void; - steps: string[]; + steps?: string[]; onStepsChange: (steps: string[]) => void; testIdPrefix?: string; }This makes the type system aware of the defensive handling and improves type safety across call sites.
🧹 Nitpick comments (1)
apps/ui/src/components/views/board-view/hooks/use-board-features.ts (1)
2-2: Good TypeScript best practice with type-only import.Using
type Featurefor the import correctly marks it as a type-only import, which helps TypeScript and bundlers optimize the build by ensuring this import is stripped at runtime.
📜 Review details
Configuration used: defaults
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
apps/ui/src/components/views/board-view/hooks/use-board-features.ts(2 hunks)apps/ui/src/components/views/board-view/shared/testing-tab-content.tsx(2 hunks)
🔇 Additional comments (4)
apps/ui/src/components/views/board-view/shared/testing-tab-content.tsx (3)
25-29: Good defensive check for backward compatibility.The guard
steps || []correctly handles legacy features wherestepsmight be undefined, preventing the TypeError mentioned in issue #198.
31-33: Good defensive check when adding new steps.The guard
steps || []ensures that adding a step works even whenstepsis undefined, maintaining consistency with the defensive approach.
63-71: Excellent defense-in-depth with Array.isArray check.Using
Array.isArray(steps) && steps.map(...)is more robust than juststeps?.map(...)because it handles edge cases wherestepsmight be a non-array value (e.g., if corrupted data is loaded). This provides strong runtime safety for the rendering logic.apps/ui/src/components/views/board-view/hooks/use-board-features.ts (1)
62-73: Excellent backward compatibility migration for legacy features.The changes here address the root cause identified in issue #198:
- Line 63: Proper typing (
Featureinstead ofany) improves type safety- Line 71: The
steps: f.steps || []migration ensures legacy features that lack thestepsfield receive an empty array, preventing the TypeError whensteps.map()is called downstreamThis is the primary fix mentioned in the PR objectives and correctly handles the data migration at load time, ensuring all features have a valid
stepsarray before being used by the UI components.
|
the steps was actually removed completely from the application, so I'm thinking maybe some stuff was left around after removing |
|
I will close for now, reopen if this is still an issue on main, thank you for the initial pr |
Fix TypeError when toggling 'Enable automated testing' on existing features. Add backward compatibility migration for steps field in use-board-features.ts and defensive checks in testing-tab-content.tsx.
Fixes #198
Summary by CodeRabbit
Bug Fixes
Refactor
✏️ Tip: You can customize this high-level summary in your review settings.