Repository navigation
RHIDP-18071: extend environment variable parsing behaviour #2969
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
Open
Jdubrick
wants to merge
4
commits into
lightspeed-core:main
Choose a base branch
from
Jdubrick:codex/uierfe-9-env-reference-parity
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
7b43ebb
UIERFE-9: add environment reference normalization helpers
Jdubrick 96f4bcc
UIERFE-9: add focused environment reference process tests
Jdubrick 46c7840
UIERFE-9: support short environment references in configuration paths
Jdubrick 015e44f
UIERFE-9: document both environment reference syntaxes
Jdubrick File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| """Normalize environment references and resolve them using OGX semantics.""" | ||
|
|
||
| import re | ||
| from typing import Any, Final | ||
|
|
||
| from ogx.core.stack import replace_env_vars | ||
|
|
||
| # Match ${VAR} and ${env.VAR}, optionally with :=default or :+value. | ||
| # Names use OGX's uppercase/digit/underscore grammar; operands end at the first }. | ||
| _ENV_REFERENCE_PATTERN: Final[re.Pattern[str]] = re.compile( | ||
| r"\$\{(?:env\.)?[A-Z0-9_]+(?::[=+][^}]*)?\}" | ||
| ) | ||
|
|
||
|
|
||
| def canonicalize_reference(match: re.Match[str]) -> str: | ||
| """Preserve OGX references and prefix short references with env. | ||
|
|
||
| Parameters: | ||
| match: A supported reference found by the normalizer's regex. | ||
|
|
||
| Returns: | ||
| The reference in canonical ${env.VAR} syntax, without resolving it. | ||
|
|
||
| """ | ||
| # group(0) is the complete matched reference, including ${ and }. | ||
| reference = match.group(0) | ||
| if reference.startswith("${env."): | ||
| return reference | ||
| return reference.replace("${", "${env.", 1) | ||
|
|
||
|
|
||
| def normalize_env_references(config: Any) -> Any: | ||
| """Convert supported ${VAR} references to ${env.VAR} without resolving them. | ||
|
|
||
| Recursively visit dictionary values and list elements, rebuilding each | ||
| container and normalizing its strings. Keys and existing OGX references are | ||
| unchanged. Variable names and operators follow OGX's resolver grammar. | ||
|
|
||
| Parameters: | ||
| config: A configuration value, including nested containers and scalars. | ||
|
|
||
| Returns: | ||
| The configuration with supported short references canonicalized. | ||
|
|
||
| """ | ||
| if isinstance(config, str): | ||
| # sub calls the canonicalizer for each match, preserving surrounding text. | ||
| # For ${HOST}:${PORT}, each reference gets its own canonical replacement. | ||
| return _ENV_REFERENCE_PATTERN.sub(canonicalize_reference, config) | ||
| if isinstance(config, dict): | ||
| return {key: normalize_env_references(value) for key, value in config.items()} | ||
| if isinstance(config, list): | ||
| return [normalize_env_references(value) for value in config] | ||
| return config | ||
|
|
||
|
|
||
| def resolve_env_references(config: Any) -> Any: | ||
| """Normalize environment references, then delegate their resolution to OGX. | ||
|
|
||
| Parameters: | ||
| config: A configuration value, including nested containers and scalars. | ||
|
|
||
| Returns: | ||
| The recursively resolved configuration. OGX may convert substituted | ||
| strings to numbers, booleans, or None; other scalar values pass through. | ||
|
|
||
| """ | ||
| normalized_config = normalize_env_references(config) | ||
| return replace_env_vars(normalized_config) |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| """Fixtures shared by the unit and integration test suites.""" | ||
|
|
||
| import pytest | ||
|
|
||
|
|
||
| @pytest.fixture( | ||
| name="reference_prefix", params=["", "env."], ids=["short", "canonical"] | ||
| ) | ||
| def reference_prefix_fixture(request: pytest.FixtureRequest) -> str: | ||
| """Exercise both environment-reference spellings.""" | ||
| return str(request.param) |
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
Oops, something went wrong.
Oops, something went wrong.
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.
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.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Resolve the BYOK
vector_db_idbefore the comparison too.The comment says new entries have resolved values. That premise is wrong in both callers:
synthesize_configuration(Line 1453) andgenerate_configuration(Line 1688) normalize their raw input but do not resolve it.brag["vector_db_id"]therefore reaches Line 333 as${env.STORE_ID}.existing_store_idsholds resolved values.Trigger: an operator writes
vector_db_id: ${STORE_ID}(either spelling), and an existingregistered_resources.vector_storesentry refers to the same store.Result: the membership check never matches, and a duplicate vector store registration is appended. If the existing entry is a literal ID, the result is the same.
Resolve both sides for the comparison. Keep the raw reference in the emitted entry.
🐛 Proposed fix
🤖 Prompt for AI Agents