feat(worker): enforce global uniqueness and bot name conflict check#123
Merged
feat(worker): enforce global uniqueness and bot name conflict check#123
Conversation
Contributor
Qsnh
commented
Apr 23, 2026
- workerName must not conflict with any platform's bot name (case-insensitive)
- workerName must be globally unique across all workers (case-insensitive)
- applies to both create and update (rename) operations
- existing duplicate workers are preserved (app-level validation only)
- workerName must not conflict with any platform's bot name (case-insensitive) - workerName must be globally unique across all workers (case-insensitive) - applies to both create and update (rename) operations - existing duplicate workers are preserved (app-level validation only) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Add ErrNotFound/ErrValidation sentinel errors to worker domain - Wrap validateWorkerName errors with ErrValidation for proper HTTP status mapping - Fix UpdateWorker to wrap store not-found with ErrNotFound - Fix worker_handler Update to use manager.UpdateWorker (was bypassing bot name conflict check and uniqueness check) - Fix worker_handler Create error response from 500 to use respondWorkerError (400 for validation, 500 for infra) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…e to unreleased Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Trim whitespace in validateWorkerName to prevent " alice " from bypassing dedup check - Add 8 tests covering: duplicate name, case-insensitive dedup, bot name conflict, case-insensitive bot conflict, whitespace trimming, update duplicate, same-name rename (exact and case variant) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…g, and test coverage - Add WorkerStore.UpdateEngine to isolate /engine command from full-row Update bypass - Trim worker name before storage in CreateWorker and UpdateWorker - Fix UpdateWorker case-variant skip that bypassed bot name conflict check - Add TRIM to ExistsByName SQL for consistency with application-layer trimming - Fix double-wrapped ErrNotFound message in UpdateWorker - Add empty name guard in validateWorkerName - Add missing UpdateWorker tests: bot name rename, case-variant bot name rename, no-name-change update Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Extract PlatformsConfig.BotNames() to eliminate duplicated collection loop in app.go and NewManager - Pre-normalize bot names (lowercase+trim) at construction so validateWorkerName does no per-call allocation - Replace bot-name loop with slices.Contains - Fix UpdateWorker to distinguish sql.ErrNoRows from real DB errors instead of blindly returning ErrNotFound Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Add TrimSpace to bot-name comparison in validateWorkerName so the check is self-contained rather than relying on callers pre-trimming - Nil out p.Name when trimmed equals stored name so HasChanges skips a redundant DB write for same-name updates - Replace COUNT(*) with SELECT EXISTS in ExistsByName and drop TRIM() from SQL since names are already stored trimmed at write time Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Extract respondDomainError helper in api/helpers.go, replacing identical respondWorkerError and respondEnvError implementations - Rename Manager.botNames to botNamesLower to make the pre-normalized invariant self-documenting - Remove redundant strings.TrimSpace in validateWorkerName (callers always pre-trim) - Move p.Validate before GetByID in UpdateWorker to reject invalid input before hitting the DB Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…lper respondDomainError in helpers.go is not best practice — each domain's error handling belongs with its own handler. Restore dedicated respondWorkerError and respondEnvError with inline switch statements. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…duplicate error handler code Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.