Skip to content

feat: improve ControlPlane seeding#2562

Merged
wilsonrivera merged 1 commit intomainfrom
wilson/eng-9038-improve-controlplane-seed
Feb 26, 2026
Merged

feat: improve ControlPlane seeding#2562
wilsonrivera merged 1 commit intomainfrom
wilson/eng-9038-improve-controlplane-seed

Conversation

@wilsonrivera
Copy link
Copy Markdown
Contributor

@wilsonrivera wilsonrivera commented Feb 26, 2026

Summary by CodeRabbit

  • New Features

    • Added automated organization and group initialization during the seeding workflow
  • Bug Fixes

    • Seed script now properly handles and reuses existing users instead of failing
    • Integrated organization existence validation to prevent duplicate setup attempts
    • Enhanced logging output for improved visibility and troubleshooting during seeding operations

Checklist

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Feb 26, 2026

Walkthrough

This change modifies the seed script to handle existing users and organizations differently. Instead of exiting when a user exists, it now reuses the existing user ID. It adds organization existence validation via group queries and introduces a variable to hold the Keycloak user ID across conditional branches.

Changes

Cohort / File(s) Summary
Seed script refactoring
controlplane/src/bin/seed.ts
Added dotenv configuration loading, changed existing user handling from early exit to reuse pattern, added organization existence check via group queries, introduced keycloakUserID variable for cross-branch state management, repositioned logging messages, and adjusted final output to avoid duplication.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat: improve ControlPlane seeding' is related to the main changes but lacks specificity about what improvements were made to the seeding process.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@StarpTech StarpTech left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@controlplane/src/bin/seed.ts`:
- Around line 80-84: The code assigns keycloakUserID with a non-null assertion
users[0].id! which is unsafe; update the logic in seed.ts where keycloakUserID
is set (look for the users array handling and the users[0].id reference) to
defensively check that users[0] exists and that users[0].id is defined before
assigning to keycloakUserID — if the id is missing, log a clear error (including
the user email/context) and abort/throw so downstream code doesn't run with an
undefined id. Ensure all places that use keycloakUserID (the variable and any
subsequent calls) rely on this validated assignment.
- Around line 96-106: Rename the unclear variable o to existingGroups and stop
using the unreliable search+exact pattern with
keycloakClient.client.groups.find; instead call
keycloakClient.client.groups.find({ realm }) to load groups and then filter the
returned array for an exact name match against user.organization.slug
restricting to root groups (e.g., by checking that the group is a top-level/root
group via parentId being absent or the path depth used in migrate-groups.ts),
then use the filtered existingGroups.length to decide whether to exit. Ensure
you update the identifier from o to existingGroups and follow the same
root-group filtering logic used in migrate-groups.ts when comparing group.name
to user.organization.slug.

ℹ️ Review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 48a1613 and 14cdbf6.

📒 Files selected for processing (1)
  • controlplane/src/bin/seed.ts

Comment thread controlplane/src/bin/seed.ts
Comment thread controlplane/src/bin/seed.ts
@wilsonrivera wilsonrivera merged commit 59c3b86 into main Feb 26, 2026
10 checks passed
@wilsonrivera wilsonrivera deleted the wilson/eng-9038-improve-controlplane-seed branch February 26, 2026 16:58
@codecov
Copy link
Copy Markdown

codecov Bot commented Feb 26, 2026

Codecov Report

❌ Patch coverage is 0% with 19 lines in your changes missing coverage. Please review.
✅ Project coverage is 63.59%. Comparing base (48a1613) to head (14cdbf6).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
controlplane/src/bin/seed.ts 0.00% 19 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##             main    #2562       +/-   ##
===========================================
+ Coverage   43.84%   63.59%   +19.75%     
===========================================
  Files        1034      298      -736     
  Lines      144938    41917   -103021     
  Branches     9274     4439     -4835     
===========================================
- Hits        63542    26657    -36885     
+ Misses      79700    15238    -64462     
+ Partials     1696       22     -1674     
Files with missing lines Coverage Δ
controlplane/src/bin/seed.ts 0.00% <0.00%> (ø)

... and 737 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants