-
-
Notifications
You must be signed in to change notification settings - Fork 251
fix(api): generateSlug infinite loop causing Auth and Feedback Controller test failures #1162
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
Conversation
…Controller due to generateSlug infinite loop keyshade-xyz#1158
…niqueness - Add randomization to slug suffix to reduce collision probability - Improve retry and collision handling logic in generateUniqueSlug - Ensure robust error handling and logging
- Cast model to string for safe Prisma index access - Fixes TypeScript error: 'Type symbol cannot be used as an index type' - Prepares slug-generator for reliable slug creation and test suite - Related to keyshade-xyz#1158
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Explore these optional code suggestions:
|
||||||||||||||
|
@johnny603, please resolve all open reviews! |
|
@johnny603, please resolve all open reviews; otherwise this PR will be closed after Sun Sep 28 2025 08:00:11 GMT+0000 (Coordinated Universal Time)! |
| * Prints several possible slugs to the console. | ||
| * Not used in production; for review/testing only. | ||
| */ | ||
| static demoSlugCombinations(name: string) { |
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.
By this, I meant could you drop some screenshots/console debugs where I could see the function in action? Please remove this added code
- Added comprehensive console debugging to generateUniqueSlug function - Created standalone demo scripts showing algorithm in action - Added debug controller for API-based testing - Demonstrates: base slug creation, existing slug analysis, collision handling, retry logic - FOR REVIEW ONLY - will be reverted after maintainer review
…to generate a slug in SlugGenerator
|
I think I see the issue The infinite loop was caused by the introduction of random suffixes (e.g., my-workspace-1-abc1) which broke the collision detection mechanism that expected the simple name-numeric_part format (e.g., my-workspace-1). Here is what I did: Removed Random Suffixes: Fixed Numeric Part Parsing: Improved Cache Consistency: Enhanced Sequential Logic: Testing Scenario Fix: The algorithm now properly handles the scenario you mentioned: CREATE "My Workspace" → my-workspace-0 ✅ Impact: |
debug-enhanced-demo.js
Outdated
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.
remove these extra files too
## [2.43.0-stage.3](v2.43.0-stage.2...v2.43.0-stage.3) (2025-10-28) ### 🐛 Bug Fixes * **api:** generateSlug infinite loop causing Auth and Feedback Controller test failures ([#1162](#1162)) ([7183ee5](7183ee5))
|
🎉 This PR is included in version 2.43.0-stage.3 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |



User description
Description
This PR fixes the infinite loop issue in the generateSlug function that was causing Auth Controller and Feedback Controller tests to fail during the beforeEach setup phase. The issue manifested as excessive iterations (>10 times) when generating workspace slugs for test users, blocking development workflow and CI/CD pipeline.
Resolved:
Dependencies
No new dependencies added.
Future Improvements
Consider implementing slug caching mechanism for better performance in high-load scenarios.
Add comprehensive monitoring dashboard for slug generation metrics.
Evaluate database indexing optimization for slug uniqueness checks.
Mentions
none
Relevant Screenshots
no screenshots as this is backend/testing scoped
Developer's checklist
My PR follows the style guidelines of this project
I have performed a self-check on my work
If changes are made in the code:
Documentation Update
PR Type
Bug Fix
Description
Fix infinite loop in generateSlug function causing test timeouts
Enhance slug generation algorithm with better randomization
Implement proper test isolation and database cleanup
Add performance optimizations for test environments
Enable Auth Controller and Feedback Controller tests to pass consistently
Improve overall test suite execution time and reliability
PR Type
Bug fix
Description
Fix infinite loop in
generateSlugfunction causing test failuresAdd randomization to slug suffix for better uniqueness
Improve Prisma model type casting for safe index access
Enhance error handling and collision detection logic
Diagram Walkthrough
File Walkthrough
slug-generator.service.ts
Enhance slug generation with randomization and type safetyapps/api/src/common/slug-generator.service.ts
Math.random()for uniquenessmodeltomodel as stringMAX_ITERATIONSconstant