Skip to content

refactor(web): move findUserById out of lib/user - #6914

Merged
chrarnoldus merged 2 commits into
mainfrom
refactor/find-user-by-id-module
Sep 29, 2026
Merged

chrarnoldus merged 2 commits into
mainfrom
refactor/find-user-by-id-module

Conversation

@chrarnoldus

Copy link
Copy Markdown
Contributor

Summary

findUserById moves unchanged from lib/user/index.ts to lib/user/find-user-by-id.ts. Request authentication only needs this function, but importing it from lib/user also loaded user creation, account linking and account deletion, with their WorkOS, Impact, MCP gateway, R2 and Discord dependencies.

The importers and the Jest mocks that stubbed findUserById through @/lib/user now point at the new module.

Verification

Tests are left to CI. No manual checks are listed.

Visual Changes

N/A

Reviewer Notes

Split out of #6894, which prepares #6806 (the ai-gateway app and the web-shared package). The move is verbatim; use git show --color-moved to confirm it.

Request authentication only needs findUserById, but importing it from
lib/user also loads user creation, account linking and account deletion,
with their WorkOS, Impact, MCP gateway, R2 and Discord dependencies. The
function moves unchanged to lib/user/find-user-by-id, and importers and
Jest mocks point at the new module.
@kilo-code-bot

kilo-code-bot Bot commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Executive Summary

The follow-up commit re-adds a @/lib/user stub in the balance auth suite, resolving the previously reported import-time failure; no other code changed since the last review.

Files Reviewed (1 file)
  • apps/web/src/app/api/cloud-agent-next/balance/route.auth.test.ts
Previous Review Summary (commit e0cf85c)

Current summary above is authoritative. Previous snapshots are kept for context only.

Previous review (commit e0cf85c)

Status: 1 Issue Found | Recommendation: Address before merge

Executive Summary

The findUserById move is verbatim and every direct importer/mock was updated, but removing the @/lib/user mock in the balance auth test makes the real barrel load and throw at import time via @/lib/stripe-client.

Overview

Severity Count
CRITICAL 1
WARNING 0
SUGGESTION 0
Issue Details (click to expand)

CRITICAL

File Line Issue
apps/web/src/app/api/cloud-agent-next/balance/route.auth.test.ts 20 Replacing the @/lib/user stub causes the real barrel to load through @/lib/user/server; stripe-client throws STRIPE_SECRET_KEY environment variable is not set because @/lib/dotenvx is mocked to return undefined
Files Reviewed (45 files)
  • apps/web/src/app/admin/api/users/[id]/dev/insert-usage-record/route.ts
  • apps/web/src/app/admin/api/users/[id]/kill-balance-cache/route.ts
  • apps/web/src/app/admin/api/users/[id]/referrals/route.ts
  • apps/web/src/app/admin/api/users/gdpr-removal/route.test.ts - 0 issues
  • apps/web/src/app/admin/api/users/gdpr-removal/route.ts
  • apps/web/src/app/admin/users/[id]/heuristic-abuse/page.tsx
  • apps/web/src/app/admin/users/[id]/page.tsx
  • apps/web/src/app/api/auth/native/token/route.test.ts
  • apps/web/src/app/api/auth/native/token/route.ts
  • apps/web/src/app/api/cloud-agent-next/balance/route.auth.test.ts - 1 issue
  • apps/web/src/app/api/dev/consume-credits/route.ts
  • apps/web/src/app/api/internal/bot-session-callback/[botRequestId]/route.test.ts
  • apps/web/src/app/api/internal/bot-session-callback/[botRequestId]/route.ts
  • apps/web/src/app/api/internal/kiloclaw/instance-ready/route.ts
  • apps/web/src/app/api/internal/support/users/gdpr-removal/route.test.ts
  • apps/web/src/app/api/internal/support/users/gdpr-removal/route.ts
  • apps/web/src/app/api/user-deployments/webhook/route.ts
  • apps/web/src/components/dev/actions.ts
  • apps/web/src/lib/ai-gateway/first-usage-events.test.ts
  • apps/web/src/lib/ai-gateway/processUsage.test.ts
  • apps/web/src/lib/autoTopUp.ts
  • apps/web/src/lib/bot.test.ts
  • apps/web/src/lib/bot.ts
  • apps/web/src/lib/code-reviews/action-required.ts
  • apps/web/src/lib/code-reviews/review-memory/llm.ts
  • apps/web/src/lib/discord/auth.ts
  • apps/web/src/lib/observability/rest-routes-auth.test.ts
  • apps/web/src/lib/organizations/organization-billing.ts
  • apps/web/src/lib/organizations/organization-seats.ts
  • apps/web/src/lib/referral.ts
  • apps/web/src/lib/user/deletion-queue/deletion-legacy-backfill.test.ts
  • apps/web/src/lib/user/find-user-by-id.ts
  • apps/web/src/lib/user/gdpr-removal.ts
  • apps/web/src/lib/user/index.test.ts
  • apps/web/src/lib/user/index.ts
  • apps/web/src/lib/user/server.ts
  • apps/web/src/routers/admin-router.ts
  • apps/web/src/routers/admin/user-deletion-queue-router.test.ts
  • apps/web/src/routers/bitbucket-router.test.ts
  • apps/web/src/routers/mcp-gateway-authorizations-router.test.ts
  • apps/web/src/routers/mcp-gateway-router.test.ts
  • apps/web/src/routers/organizations/organization-admin-router.ts
  • apps/web/src/routers/organizations/organization-members-router.ts
  • apps/web/src/routers/test-utils.ts
  • apps/web/src/scripts/d2025-09-01_backfill-referral-code-usages.ts

Fix these issues in Kilo Cloud


Reviewed by deepseek-v4.1-flash · Input: 0 · Output: 0 · Cached: 0

Review guidance: REVIEW.md from base branch main

lib/user/server still imports lib/user, so dropping the stub loaded the
real module, whose Stripe client throws because the test mocks the env
lookup.
@chrarnoldus
chrarnoldus merged commit 67632a9 into main Sep 29, 2026
28 checks passed
@chrarnoldus
chrarnoldus deleted the refactor/find-user-by-id-module branch September 29, 2026 13:48
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.

2 participants