feat(config): enforce phase-aware variable substitution scoping#249
Merged
Conversation
Per the devcontainer spec, properties evaluated before container creation (containerEnv) should not have access to containerWorkspaceFolder or containerWorkspaceFolderBasename — those variables only exist after the container is running. This implements two-pass substitution: pre-container fields use a restricted replacer that preserves container-scoped variables as literals, while post-container fields get full variable resolution.
✅ Deploy Preview for devsydev canceled.
|
|
Caution Review failedFailed to post review comments 📝 WalkthroughWalkthroughThis PR implements phase-aware variable substitution for devcontainer configuration. A two-pass substitution mechanism ensures container-scoped variables (containerEnv) are preserved as literals during pre-container field resolution, then fully substituted afterward. Changes include core substitution logic, unit tests, and end-to-end validation. ChangesVariable Substitution Scoping
Sequence DiagramsequenceDiagram
participant Caller as Caller
participant Substitute as Substitute()
participant PreReplace as restrictedReplace
participant FullReplace as fullReplace
participant Merge as Merge Results
Caller->>Substitute: Call Substitute(config, context)
activate Substitute
Substitute->>PreReplace: First pass: preContainerFields with restricted replacer
activate PreReplace
PreReplace-->>Substitute: Returns containerEnv (preserved as literals)
deactivate PreReplace
Substitute->>FullReplace: Second pass: all fields with full replacer
activate FullReplace
FullReplace-->>Substitute: Returns fully substituted config
deactivate FullReplace
Substitute->>Merge: Merge pre-container results back into full results
activate Merge
Merge-->>Substitute: Final config with correct scoping
deactivate Merge
Substitute-->>Caller: Return substituted config
deactivate Substitute
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ 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. Comment |
skevetter
marked this pull request as ready for review
May 6, 2026 17:19
skevetter
enabled auto-merge (squash)
May 6, 2026 17:19
This was referenced May 16, 2026
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.
Summary
Implements two-pass variable substitution per the devcontainer spec (Variables in devcontainer.json):
containerEnv) now only resolve local-scoped variables (devcontainerId,localEnv,localWorkspaceFolder,localWorkspaceFolderBasename). Container-scoped variables (${containerWorkspaceFolder},${containerWorkspaceFolderBasename},${containerEnv:VAR}) are preserved as literals since the container doesn't exist yet at evaluation time.remoteEnv, lifecycle commands, etc.) continue to resolve all variables including container-scoped ones.restrictedReplace()wrapper function that intercepts container-scoped variable resolution while delegating everything else to the full replacer.Summary by CodeRabbit
Release Notes
Bug Fixes
Tests