← Back to Pull requests

fix(config): keep expanded env files of every forRoot call for set() #2505

Closed
unknown closed this pull request without merging on Nov 26, 2026 08:52 UTC
View on GitHub
unknown unknown commented on Nov 26, 2026 00:23 UTC
Author

PR Checklist


Please check if your PR fulfills the following requirements:

  • The commit message follows our guidelines: https://github.com/nestjs/nest/blob/master/CONTRIBUTING.md

  • Tests for the changes have been added (for bug fixes / features)

  • Docs have been added / updated (for bug fixes / features)
  • PR Type


    What kind of change does this PR introduce?

  • Bugfix

  • Feature

  • Code style update (formatting, local variables)

  • Refactoring (no functional changes, no api changes)

  • Build related changes

  • CI related changes

  • Other... Please describe:
  • What is the current behavior?


    Since #2463, ConfigService#set() re-expands env file variables that reference the key being set (for example URL=http://${HOST}/api follows set('HOST', ...)). The factory of each forRoot() call hands its env file definitions to the shared ConfigService, and every call replaces them.

    So when an app calls ConfigModule.forRoot() more than once (for example an app-level call plus a feature module with its own env file), the module that resolves last wins. If that call has no expandVariables, the expanding call's definitions are dropped:

    @Module({
      imports: [
        ConfigModule.forRoot({ envFilePath: 'a.env', expandVariables: true }), // HOST=localhost, URL=http://${HOST}/api
        ConfigModule.forRoot({ envFilePath: 'b.env' }),
      ],
    })
    class AppModule {}
    
    configService.set('HOST', 'example.com');
    configService.get('URL'); // 'http://localhost/api', expected 'http://example.com/api'
    

    With the imports in the other order it works, so the result depends on module order.

    Issue Number: N/A

    What is the new behavior?

    Each forRoot() call adds its definitions instead of replacing the others. They are merged in call order. When several env files define the same variable, the first call's definition is kept; this is the one loaded into process.env, because forRoot does not overwrite variables that are already set.

    Test: tests/e2e/update-env-expanded.spec.ts covers both import orders. The "after" case fails on master (Received: "http://localhost/api"). Full suite: 145 tests pass.

    Does this PR introduce a breaking change?


  • Yes

  • No
  • Other information

    setExpansionEnv / setPredefinedEnv are still set per call. I left them as they are to keep this change small.

    Diff: 296 lines (+222 / -74) across 3 files Reviewer: kamilmysliwiec Review duration: 508m
    All Vouch review confidence checks passed
    Residual risk 0.27 = Change Risk (0.63) × (1 − Review Confidence (0.57)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.63 · 296 lines diff across 3 files
    0.63
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    56%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.341
    Shallow Review Depth shallow_review_depth
    0.289
    Sensitive Paths sensitive_paths
    0.063
    Real PR Conversation Timeline
    1 comments
    "Review active on #2505"
    general weight: 0.35
    Assignees
    Unassigned
    Labels
    risk: low confidence: 56.8% reviewed sensitive_module
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 63.2% (MEDIUM) · Higher = larger blast radius
    63.2%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 56.8% · Lower = rushed or shallow review
    56.8%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 27.3% · Safe to merge
    27.3%
    Repository