Normalize env value parsing for config loading#209
Normalize env value parsing for config loading#209shuofengzhang wants to merge 5 commits intostickerdaniel:mainfrom
Conversation
|
Addressed both review points in this PR:
Validation run:
|
|
Good call — I removed the redundant transformation in the LOG_LEVEL path. Changes:
Validation:
|
|
Added the missing symmetric falsy coverage:
Validation:
|
cde6d4b to
c486d8c
Compare
c486d8c to
3619a31
Compare
Greptile SummaryThis PR improves robustness of environment variable parsing by introducing a Key changes:
Confidence Score: 5/5
Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[os.environ.get] --> B{Value present?}
B -- No --> Z[Keep default]
B -- Yes --> C["_normalize_env: strip + lower"]
C --> D{Which env var?}
D -- HEADLESS --> E{In FALSY_VALUES?}
E -- Yes --> F[headless = False]
E -- No --> G{In TRUTHY_VALUES?}
G -- Yes --> H[headless = True]
G -- No --> Z
D -- TRANSPORT --> I[transport_explicitly_set = True]
I --> J{Normalized value?}
J -- stdio --> K[transport = stdio]
J -- streamable-http --> L[transport = streamable-http]
J -- other --> M[raise ConfigurationError]
D -- LOG_LEVEL --> N["Inline: strip + upper"]
N --> O{In DEBUG/INFO/WARNING/ERROR?}
O -- Yes --> P[log_level = value]
O -- No --> Z
Last reviewed commit: 3619a31 |
What changed
strip().lower()before parsing.HEADLESSparsing more tolerant by supporting mixed case / surrounding whitespace andon/offaliases.TRANSPORTparsing tolerant to mixed case / surrounding whitespace while preserving validation for unsupported values.HEADLESS=" TrUe "HEADLESS="off"TRANSPORT=" StReAmAbLe-HtTp "Why
Testing
scripts/clone_and_test.sh stickerdaniel/linkedin-mcp-serversource .venv/bin/activate && pytest tests/test_config.py -qsource .venv/bin/activate && pytest -qGreptile Summary
This PR improves the robustness of environment variable parsing in the config loader by introducing a
_normalize_env()helper (strip().lower()) and applying it to theHEADLESSandTRANSPORTkeys. It also adds"on"/"off"as boolean aliases. The changes are fully backward-compatible — all previously accepted values still work because the old mixed-case variants ("True","False","Yes","No") are handled naturally by the lowercasing step. TheLOG_LEVELpath correctly opts out of_normalize_env()and instead uses.strip().upper()directly, which avoids the redundant lower→upper round-trip.HEADLESS(both truthy and falsy), theon/offaliases, a normalisedLOG_LEVEL, and bothTRANSPORTvalues (stdioandstreamable-http) with whitespace and mixed case.onalias,stdiotransport normalisation, whitespace falsyHEADLESS) are addressed.TRANSPORTvalues retain the original, un-normalised value for clear user feedback — a nice touch.Confidence Score: 5/5
Important Files Changed
_normalize_env()helper and applies it to HEADLESS and TRANSPORT parsing; LOG_LEVEL correctly uses.strip().upper()directly. Backward-compatible changes with no logic regressions found.on/offaliases), LOG_LEVEL, and both TRANSPORT values (stdioandstreamable-http). All previously flagged gaps are now covered.Flowchart
%%{init: {'theme': 'neutral'}}%% flowchart TD A[os.environ.get] --> B{Value present?} B -- No --> Z[Use default] B -- Yes --> C[_normalize_env: strip + lower] C --> D{Which key?} D -- HEADLESS --> E{in FALSY_VALUES?} E -- Yes --> F[headless = False] E -- No --> G{in TRUTHY_VALUES?} G -- Yes --> H[headless = True] G -- No --> Z D -- TRANSPORT --> I{== 'stdio'?} I -- Yes --> J[transport = 'stdio'] I -- No --> K{== 'streamable-http'?} K -- Yes --> L[transport = 'streamable-http'] K -- No --> M[raise ConfigurationError] D -- LOG_LEVEL --> N[strip + upper only] N --> O{in DEBUG/INFO/WARNING/ERROR?} O -- Yes --> P[log_level = value] O -- No --> ZComments Outside Diff (1)
tests/test_config.py, line 100-105 (link)No normalization test for
LOG_LEVELThe
load_from_envfunction now routesLOG_LEVELthrough_normalize_env()before calling.upper(), which means whitespace-padded values likeLOG_LEVEL=" debug "orLOG_LEVEL=" WARNING "would silently work. However, there is no test exercising this normalization path forLOG_LEVEL, unlike the explicit whitespace/case tests added forHEADLESSandTRANSPORT.Consider adding a test such as:
Prompt To Fix With AI
Last reviewed commit: c486d8c