fix(cli): reject unknown keys in gitt config set to prevent silent typos#813
Open
plind-junior wants to merge 2 commits intoentrius:testfrom
Open
fix(cli): reject unknown keys in gitt config set to prevent silent typos#813plind-junior wants to merge 2 commits intoentrius:testfrom
gitt config set to prevent silent typos#813plind-junior wants to merge 2 commits intoentrius:testfrom
Conversation
…typos
Whitelist KEY against the five settings that downstream commands actually
read (wallet, hotkey, network, contract_address, ws_endpoint) via
`click.Choice(case_sensitive=False)`. Mistyped keys like `wallet_name`
now fail loudly at the CLI rather than persisting a dead entry that
`config.get('wallet', 'default')` silently ignores.
Contributor
Author
|
@anderdc Fully ready for review |
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.
Summary
gitt config set KEY VALUEaccepts any string forKEYand writes it to~/.gittensor/config.json. Downstream commands look up settings by canonical name (config.get('wallet', 'default')), so a typo likewallet_nameis silently dropped and the operator unknowingly continues with default values.This PR whitelists
KEYagainst the five settings that downstream commands actually read:wallet,hotkey,network,contract_address,ws_endpoint. Anything else is rejected at the CLI layer with a ClickBadParametererror.Why
Verified read-sites for the five canonical keys:
wallet/hotkey—cli/miner_commands/check.py,post.py,cli/issue_commands/mutations.pynetwork/ws_endpoint—cli/issue_commands/helpers.py:resolve_network,cli/miner_commands/helpers.py:_resolve_endpointcontract_address— used as the override for--contractflagNo reader consumes a key outside this list. Restricting writes to the same set is a safe, targeted fix.
Approach
Minimal-surface change: a single
click.Choiceon the existing positionalKEYargument plus akey.lower()normalisation. The positional form (gitt config set wallet alice) is preserved — no breaking change for valid usages, no shell scripts to migrate. Only typo'd keys now fail.If maintainers later want full btcli-style typed options (
--wallet,--hotkey, …),CONFIG_KEYSis already the source of truth and the upgrade is incremental.Changes
gittensor/cli/main.py(+10 / −3): addCONFIG_KEYSconstant; wrap thekeyarg inclick.Choice(CONFIG_KEYS, case_sensitive=False); lowercase normalise; clarify docstring.tests/cli/test_config_set.py(new, +98): 10 tests covering valid keys (parametrised over all five), rejection ofwallet_name, no-clobber-on-rejection guarantee, mixed-case normalisation, and the update-vs-set message branch.Test plan
pytest tests/cli/test_config_set.py -v— 10/10 passpytest tests/cli/— 117/117 pass (107 baseline + 10 new), no regressionsgitt config set wallet alice→ succeeds;gitt config set wallet_name alice→ rejected with helpful errorNotes
gitt config get <key>subcommand #803 (config get, closed) or feat(cli): addgitt config unset <key>subcommand #804 (config unset, open). Both keep their own positional forms; if desired, they can adopt the sameChoicepattern in a follow-up.Fixes #812