Skip to content

Conversation

@ddmoney420
Copy link

Summary

Implements the process.initgroups(user, extraGroup) function for Node.js compatibility.

  • Takes a username string as the first argument
  • Takes an extra group (number or group name string) as the second argument
  • Validates the user exists before calling initgroups
  • Throws appropriate errors for invalid arguments:
    • ERR_INVALID_ARG_TYPE if user is not a string
    • ERR_UNKNOWN_CREDENTIAL if user doesn't exist
    • ERR_UNKNOWN_CREDENTIAL if group doesn't exist (when passed as string)
  • Only available on non-Windows platforms (consistent with Node.js behavior)

Closes #23891

Test Plan

  • Added tests verifying:
    • process.initgroups is a function
    • Throws with invalid user type (number instead of string)
    • Throws with unknown user
    • Is undefined on Windows

AI Disclosure

This PR was written primarily by Claude Code.

🤖 Generated with Claude Code

Implements the `process.initgroups(user, extraGroup)` function for
Node.js compatibility. This function sets the supplementary group IDs
for the calling process using the POSIX `initgroups` system call.

- Takes a username string and an extra group (number or string)
- Validates the user exists before calling initgroups
- Throws appropriate errors for invalid arguments
- Only available on non-Windows platforms

Closes oven-sh#23891

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 29, 2026

Walkthrough

Implementation of the process.initgroups function for POSIX systems, including hostname and group ID validation with corresponding test coverage for both POSIX and Windows platforms.

Changes

Cohort / File(s) Summary
Process.initgroups implementation
src/bun.js/bindings/BunProcess.cpp
Added host function Process_functioninitgroups with username validation, user lookup via getpwnam_r, gid resolution, and system call to initgroups. Registered in public API with arity 2.
Process.initgroups tests
test/js/node/process/process.test.js
Added tests validating process.initgroups exists on POSIX platforms with checks for invalid input types and unknown users. Updated Windows tests to assert initgroups is undefined.
🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'feat(node:process): implement process.initgroups' clearly and specifically describes the main change: implementing the process.initgroups function for Node.js compatibility.
Description check ✅ Passed The PR description is comprehensive, covering the summary, implementation details, error handling, platform availability, test plan, and includes required sections about what the PR does and verification approach.
Linked Issues check ✅ Passed The PR successfully implements process.initgroups with all requirements from issue #23891: the function is now available on POSIX platforms, accepts username and extra group arguments, validates inputs correctly, and throws appropriate errors.
Out of Scope Changes check ✅ Passed All changes are directly related to implementing process.initgroups: one implementation file adds the host function, and the test file adds appropriate test coverage for the new functionality.

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


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

// Get user argument (first argument) - must be a string username
auto user = callFrame->argument(0);
if (!user.isString()) {
return Bun::ERR::INVALID_ARG_TYPE(scope, globalObject, "user"_s, "string"_s, user);
Copy link
Contributor

Choose a reason for hiding this comment

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

Node.js compatibility issue: According to Node.js documentation, process.initgroups(user, extraGroup) accepts both string | number for the user parameter (numeric UID).

The current implementation only accepts strings. Node.js handles numeric UIDs by looking up the username via getpwuid_r() before calling initgroups().

For reference, the extraGroup parameter already uses maybe_gid_by_name() to handle both types. A similar approach would provide full compatibility.

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.

node:process.initgroups is not yet implemented

1 participant