Skip to content

CHEF-34003: Support ~/.chef/ruby/<version>/gems for Habitat gem persistence#343

Open
sanghinitin wants to merge 3 commits into
mainfrom
CHEF-34003-gem-install-hab
Open

CHEF-34003: Support ~/.chef/ruby/<version>/gems for Habitat gem persistence#343
sanghinitin wants to merge 3 commits into
mainfrom
CHEF-34003-gem-install-hab

Conversation

@sanghinitin

@sanghinitin sanghinitin commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

Summary

  • What changed: Modified the chef gem command to use ~/.chef/ruby/<ruby_version>/gems as the default GEM_HOME when running inside a Habitat-based Workstation environment. This ensures user-installed gems persist across Workstation package upgrades (previously lost when /hab/pkgs/... path changed on each upgrade).
  • Why: Gems installed via chef gem install were being lost on every Workstation upgrade because the Habitat package path changes. This aligns Habitat behavior with the existing omnibus approach that already uses Gem.user_dir.
  • Plan: CHEF-34003 — Gem extension support for Workstation 26
  • Files/paths touched:
    • lib/chef-cli/command/gem.rb — Added setup_gem_environment for Habitat detection
    • lib/chef-cli/helpers.rb — Added habitat_user_gem_dir, updated habitat_env
    • habitat/plan.sh — Updated wrapper script for runtime GEM_HOME/GEM_PATH resolution; added bundle config unset with
    • habitat/plan.ps1 — Added CHEF_GEM_HOME_ENABLED runtime env marker
    • binstub_patch.rb — Prepends user gem dir to GEM_PATH in all binstubs
    • spec/unit/command/gem_spec.rb — New spec (15 examples)
    • spec/unit/helpers_spec.rb — Updated habitat env tests

Evidence

  • Tests:
    bundle exec rspec spec/unit/command/gem_spec.rb spec/unit/helpers_spec.rb
    20 examples, 0 failures
    
  • Coverage: 88.73% line coverage (126/142 lines)
  • Style: bundle exec cookstyle lib/chef-cli/command/gem.rb spec/unit/command/gem_spec.rb → 0 offenses

Risk & Rollback

  • Risk: Low — changes are gated by habitat_install? check; non-Habitat installs are completely unaffected
  • Rollback: git revert 49d250a8 or remove the setup_gem_environment call in gem.rb

Review Focus

  • Verify the habitat_user_gem_dir path convention (~/.chef/ruby/<version>/gems) aligns with team expectations
  • Confirm plan.sh wrapper correctly resolves Ruby ABI version at runtime
  • Ensure binstub_patch.rb change does not break appbundler-generated binstubs in omnibus installs (gated by unless ENV["APPBUNDLER_ALLOW_RVM"])
  • Verification steps:
    bundle exec rspec spec/unit/command/gem_spec.rb spec/unit/helpers_spec.rb
    bundle exec cookstyle lib/chef-cli/command/gem.rb spec/unit/command/gem_spec.rb

Test Cases Run With Evidence

Test Result
Non-Habitat: GemForwarder forwards params without modifying GEM_HOME PASS
Habitat: GemForwarder sets GEM_HOME to ~/.chef/ruby//gems PASS
Habitat: GEM_PATH includes both user dir and vendor dir PASS
Habitat: Creates gem directory if missing PASS
Habitat: Skips mkdir if directory exists PASS
Habitat: All gem subcommands (install/list/uninstall/source/search/update) forwarded PASS
Habitat: Gem.clear_paths called after env setup PASS
SystemExitException: exits with correct code PASS
habitat_user_gem_dir: returns version-specific path PASS
helpers habitat_env: GEM_HOME set to user gem dir PASS
helpers habitat_env: GEM_PATH includes user dir + vendor PASS

Signed-off-by: nitin sanghi <nsanghi@progress.com>
@sanghinitin sanghinitin requested review from a team as code owners June 15, 2026 10:57
@sanghinitin sanghinitin added Type: Enhancement Adds new functionality. ai-assisted and removed Type: Enhancement Adds new functionality. labels Jun 15, 2026
@github-actions

Copy link
Copy Markdown

Simplecov Report

Covered Threshold
98.51% 90%

@sanghinitin sanghinitin force-pushed the CHEF-34003-gem-install-hab branch 2 times, most recently from 3c0c9e1 to bf99b54 Compare June 15, 2026 12:15
…stence

Modify the chef gem command to use ~/.chef/ruby/<ruby_version>/gems as the
default GEM_HOME when running inside a Habitat-based Workstation environment.
This ensures all user-installed gems persist across Workstation package upgrades.

Changes:
- GemForwarder sets GEM_HOME/GEM_PATH to user gem dir in Habitat mode
- habitat_user_gem_dir helper returns version-specific path
- habitat_env updated to include user gem dir in PATH/GEM_PATH
- plan.sh wrapper resolves Ruby ABI version at runtime
- plan.ps1 sets CHEF_GEM_HOME_ENABLED for Ruby-level handling
- binstub_patch.rb includes user gem dir in GEM_PATH
- plan.sh adds bundle config unset with to avoid build conflicts

Signed-off-by: nitin sanghi <nsanghi@progress.com>
@sanghinitin sanghinitin force-pushed the CHEF-34003-gem-install-hab branch from bf99b54 to 2123f42 Compare June 16, 2026 09:48
Signed-off-by: nitin sanghi <nsanghi@progress.com>
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.

1 participant