fix(generators): keep .env.test.local git-ignored in dotenv generator - #146
Open
detail-app[bot] wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Detail bug report: View on Detail
Closes #130
Bug
The
pu:gem:dotenvgenerator set up dotenv for Rails apps by appending negation rules to.gitignore. It appended!/.env.test.local, which overrode Rails' default/.env*ignore pattern and made the test-secrets file trackable in git. Since the generator also copies.env.test.localand its template instructs users to put "Secrets for testing" there, real secrets could be staged and committed — a security footgun.The bug was an inconsistency: the generator didn't unignore
.env.local(another secrets file, correctly left ignored), but did unignore.env.test.local. It was introduced when.env.test.localwas added to thecopy_filelist and the same!-prefix treatment was applied to it as to the non-secret template files.Fix
Removed
!/.env.test.localfrom thegitignoredirective inlib/generators/pu/gem/dotenv/dotenv_generator.rb:.env.test.localis still copied (so devs have a starter file for test secrets); it is simply no longer un-ignored. Rails' default/.env*continues to ignore both.env.localand.env.test.local, while the non-secret files (.env,.env.template,.env.local.template) remain trackable — matching dotenv's own documented conventions.Testing
Added
test/generators/dotenv_generator_test.rb(21 tests) following the repo's existing generator-test pattern (static source guards, template-content assertions, and behavioralRails::Generators::TestCasetests that run the generator in a temp dir with a realgit init).bundle!is stubbed in a test-only subclass so the suite doesn't shell out tobundle install.standardrblint all pass. The new suite is green under all three appraisals:rails-7,rails-8.0,rails-8.1(21 tests, 66 assertions, 0 failures each).bundle exec appraisal rails-8.1 rake test_generatorsreports "All generator test files passed." including the new file.!/.env.test.localflips 7 tests red (1 static source guard + 6 behavioral guards, including thegit add .env.test.localrefusal test); restoring the fix returns to 0 failures.rails new test_app(which ships/.env*in.gitignore) → add plutonium as a path gem →bundle exec rails g pu:gem:dotenv. The generator emits only threegitignoredirectives (no!/.env.test.local);.gitignoreends with!/.env,!/.env.template,!/.env.local.template.git check-ignore -v .env.test.localreports.gitignore:11:/.env*as the deciding pattern (exit 0 = ignored),git check-ignore .envexits 1 (trackable), andgit add .env.test.localafter writing a real secret is refused: "The following paths are ignored by one of your .gitignore files: .env.test.local".git statusshows only the three non-secret.envfiles as trackable.Automatic Fixes PRs can be configured here.