-
-
Notifications
You must be signed in to change notification settings - Fork 5.4k
fix(js-sandbox): resolve environment variable fallback behavior #5439
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(js-sandbox): resolve environment variable fallback behavior #5439
Conversation
…Value in pre/post-request scripts
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR fixes a bug where environment variables with empty currentValue were not properly falling back to their initialValue in pre/post-request scripts. The fix ensures that when currentValue is empty or unset, the initialValue is used instead.
- Updated environment variable resolution logic to use
initialValueas fallback whencurrentValueis empty - Applied the fix to both direct value retrieval and template string parsing functions
- Ensures consistent behavior across different environment variable access patterns
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
- Merge latest changes alongside conflict resolution. - Add `null` check to fallback conditions in `shared.ts`. - Introduce `SandboxEnvironmentVariable` type to clarify internal vs external types. - Add comprehensive test suite covering fallback behavior across namespaces. - Document type flow from `SandboxValue` (internal) to string (external API).
8985894 to
af1ad0b
Compare
jamesgeorge007
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR, @chhaviG22. I've pushed a few changes to base this on top of the recent architectural changes as part of the scripting revamp efforts, alongside comprehensive test coverage. This will be going live in the upcoming major release.
Closes #5437
This PR addresses the issue where environment variables with empty currentValue don't fall back to their initialValue in pre-request or post-request scripts. It ensures that the correct value is returned as expected.
What's Changed
initialValuewhencurrentValueis empty or unset.initialValueandcurrentValueare not set.SandboxEnvironmentVariableto distinguish between internal sandbox types (which can be arrays/objects/primitives) and the external API boundary (which always uses strings).Notes to Reviewers
Check the fallback behaviour for environment variables with both
initialValueand an emptycurrentValue.Review the changes made in the REST tab to confirm correct functionality for pre/post-request scripts.
The type system changes are purely for clarity - they separate the internal sandbox representation (which can hold complex types for
pmnamespace compatibility) from the external API (which serialises everything to strings). No functional changes to the type system, just better documentation.Let me know if there are any additional edge cases to cover or feedback to address.