Skip to content

fix(cli): reject unknown keys in gitt config set to prevent silent typos#813

Open
plind-junior wants to merge 2 commits intoentrius:testfrom
plind-junior:fix/typed-config-set
Open

fix(cli): reject unknown keys in gitt config set to prevent silent typos#813
plind-junior wants to merge 2 commits intoentrius:testfrom
plind-junior:fix/typed-config-set

Conversation

@plind-junior
Copy link
Copy Markdown
Contributor

@plind-junior plind-junior commented Apr 27, 2026

Summary

gitt config set KEY VALUE accepts any string for KEY and writes it to ~/.gittensor/config.json. Downstream commands look up settings by canonical name (config.get('wallet', 'default')), so a typo like wallet_name is silently dropped and the operator unknowingly continues with default values.

This PR whitelists KEY against 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 Click BadParameter error.

$ gitt config set wallet alice          # OK
Set wallet: alice

$ gitt config set wallet_name alice     # rejected
Usage: gitt config set [OPTIONS] {wallet|hotkey|network|contract_address|ws_endpoint} VALUE
Try 'gitt config set --help' for help.

Error: Invalid value for '{wallet|hotkey|...}': 'wallet_name' is not one of 'wallet', 'hotkey', 'network', 'contract_address', 'ws_endpoint'.

Why

Verified read-sites for the five canonical keys:

  • wallet / hotkeycli/miner_commands/check.py, post.py, cli/issue_commands/mutations.py
  • network / ws_endpointcli/issue_commands/helpers.py:resolve_network, cli/miner_commands/helpers.py:_resolve_endpoint
  • contract_address — used as the override for --contract flag

No 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.Choice on the existing positional KEY argument plus a key.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_KEYS is already the source of truth and the upgrade is incremental.

Changes

  • gittensor/cli/main.py (+10 / −3): add CONFIG_KEYS constant; wrap the key arg in click.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 of wallet_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 pass
  • pytest tests/cli/ — 117/117 pass (107 baseline + 10 new), no regressions
  • Manual: gitt config set wallet alice → succeeds; gitt config set wallet_name alice → rejected with helpful error

Notes

Fixes #812

…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.
@xiao-xiao-mao xiao-xiao-mao Bot added the enhancement New feature or request label Apr 27, 2026
@plind-junior
Copy link
Copy Markdown
Contributor Author

@anderdc Fully ready for review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] gitt config set accepts arbitrary keys silently

1 participant