fix(extensions): handle prefix-colliding env vars in _get_env_config#3350
Open
jawwad-ali wants to merge 1 commit into
Open
fix(extensions): handle prefix-colliding env vars in _get_env_config#3350jawwad-ali wants to merge 1 commit into
jawwad-ali wants to merge 1 commit into
Conversation
_get_env_config built the nested dict with 'if part not in current:
current[part] = {}' and an unconditional leaf assignment. Two env vars
that collide on a prefix — e.g. SPECKIT_X_CONNECTION and
SPECKIT_X_CONNECTION_URL — then either crash (scalar processed first:
the walk indexes into a str -> TypeError 'str object does not support
item assignment') or silently clobber the nested dict (scalar processed
last). Via should_execute_hook's blanket except, the crash silently
disables every config-based hook for the extension. Guard the walk and
the leaf assignment with isinstance checks so a colliding scalar yields
to the nested dict; result is order-independent
({'connection': {'url': ...}} either way), matching _merge_configs'
dict-preserving semantics.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.
Description
ConfigManager._get_env_configmapsSPECKIT_{EXT}_{SECTION}_{KEY}env vars into a nested dict:Two env vars can collide on a prefix — e.g.
SPECKIT_JIRA_CONNECTION=xandSPECKIT_JIRA_CONNECTION_URL=y. Behavior then depends onos.environiteration order:CONNECTION_URLdoescurrent = current['connection'](astr) thencurrent['url'] = 'y'→TypeError: 'str' object does not support item assignment;current['connection'] = 'x'overwrites the nested dict → returns{'connection': 'x'}, silently losingconnection.url.Both reproduced on main @
bba473c. Worse: theTypeErrorpropagates throughget_config()/has_value()intoshould_execute_hook's blanketexcept Exception: return False, so a colliding env var silently disables everyconfig.*hook condition for that extension.Fix
Guard the walk (
if not isinstance(current.get(part), dict): current[part] = {}) and the leaf assignment (skip when a nested dict already occupies it). A colliding scalar yields to the more-specific nested var, so the result is order-independent —{'connection': {'url': ...}}either way — matching_merge_configs' dict-preserving semantics.Testing
New
TestConfigManagerEnvPrefixCollision(3 tests, all fail-before / pass-after via source-stash):{'connection': {'url': 'y'}};HookExecutor._evaluate_condition('config.connection.url is set', ...)staysTrueunder colliding env (was silentlyFalse).uvx ruff checkclean.AI Disclosure
Found and fixed with Claude Code (Claude Fable 5) under my direction. AI found the order-dependent crash/clobber and traced it into the swallowed hook exception; I reproduced both modes, verified fail-before/pass-after, and reviewed the diff.