Skip to content

feat(worker): enforce global uniqueness and bot name conflict check#123

Merged
Qsnh merged 10 commits intomainfrom
feat/worker-name-validation
Apr 23, 2026
Merged

feat(worker): enforce global uniqueness and bot name conflict check#123
Qsnh merged 10 commits intomainfrom
feat/worker-name-validation

Conversation

@Qsnh
Copy link
Copy Markdown
Contributor

@Qsnh 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)

Qsnh and others added 10 commits April 22, 2026 20:06
- 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>
@Qsnh Qsnh merged commit 6c6a237 into main Apr 23, 2026
@Qsnh Qsnh deleted the feat/worker-name-validation branch April 23, 2026 04:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant