fix(core): apply variable substitution to v2 config loading - #42178
Open
vladislav-miroshnikov wants to merge 1 commit into
Open
fix(core): apply variable substitution to v2 config loading#42178vladislav-miroshnikov wants to merge 1 commit into
vladislav-miroshnikov wants to merge 1 commit into
Conversation
Contributor
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
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.
Issue for this PR
Closes #41973
Type of change
What does this PR do?
The v2 config loading path in
packages/core/src/config.tsreads config files and parses them as JSONC without applying{file:}and{env:}variable substitution. The v1 path inpackages/opencode/src/config/config.tscallsConfigVariable.substitute()on the raw text before parsing. Throughopencode runand the TUI (v1 path),{file:/tmp/demo.key}is resolved and the provider authenticates. Throughopencode serve(v2 path), the literal string{file:/tmp/demo.key}ends up as the API key, causing 401s.This PR adds an Effect-based
substitute()function inpackages/core/src/config/variable.tsthat handles{env:VAR}and{file:path}substitutions, and calls it inloadFile()before JSONC parsing. The implementation mirrors the v1 substitution logic: supports~/expansion, relative paths (relative to the config file), skips substitution inside//line comments, and trims file content.How did you verify your code works?
Added 5 tests to
config.test.tscovering:{file:}with relative paths,{env:}substitution,//comment skipping,{file:}with absolute paths, and{file:}content containing JSON-special characters (quotes, backslashes, newlines). 20/20 tests pass, typecheck clean, prettier clean.Screenshots / recordings
N/A
Checklist