Skip to content

Standardize --json behavior#1152

Merged
anderdc merged 2 commits into
entrius:testfrom
seroperson:json-unify
May 12, 2026
Merged

Standardize --json behavior#1152
anderdc merged 2 commits into
entrius:testfrom
seroperson:json-unify

Conversation

@seroperson
Copy link
Copy Markdown
Contributor

Closes #1151

Summary

Three CLI surface differences collapsed into one:

  1. gitt miner {post,check,score} shipped --json-output; every other command uses --json. Renamed everything to the --json.
  2. The miner commands emitted {"success": false, "error": "<string>"}; issue commands emit {"success": false, "error": {"type": ..., "message": ...}}. Unified everything on the nested shape.
  3. Click's own parse errors (Invalid value for '--id', No such option, Missing option) printed plain text to stderr regardless of --json. Sometimes we throw such exceptions by ourselves. Added JsonAwareAliasGroup at the root so parse errors surface as the canonical JSON envelope when --json is in argv. Without --json the default Click rendering is preserved.

Centralized the envelope helpers in a new gittensor/cli/json_output.py (emit_json, emit_error_json, wants_json_output, click_error_type). Issue commands, miner commands, and the root group now import from one source.

Before / After

Before:

$ gitt issues list --json --id abc

Error: Invalid value for '--id': 'abc' is not a valid integer.

After (standardized json error handling behavior across the whole codebase):

$ gitt issues list --json --id abc

{"success": false, "error": {"type": "bad_parameter", "message": "Invalid value for '--id': 'abc' is not a valid integer."}}

Testing

  • test_click_parse_errors_stay_human_without_json_flag - asserts plain-text rendering is preserved when --json is absent
  • test_click_parse_errors_emit_canonical_json - asserts that Click's own arg-parsing errors emit the canonical {success: false, error: {type, message}} envelope when --json is in argv.

Other existing tests were updated according to the new behavior.

@xiao-xiao-mao xiao-xiao-mao Bot added the refactor Code restructuring without behavior change label May 11, 2026
@anderdc anderdc mentioned this pull request May 12, 2026
10 tasks
@anderdc anderdc merged commit 5f340cb into entrius:test May 12, 2026
3 checks passed
anderdc pushed a commit that referenced this pull request May 12, 2026
Picks up:
- #1066 (cache fallback on DAS issue-discovery fetch failure)
- #1152 (standardized --json behavior across CLI)

Resolutions:
- forward.py: drop the legacy `mirror_repos` filter; pass evaluation_cache
  through to run_issue_discovery, which now handles the empty-repos case
  itself.
- issue_discovery/scan.py: keep our renamed run_issue_discovery /
  _score_miner_issues identifiers; pick up the
  _restore_issue_discovery_from_cache call on MirrorRequestError from #1066.
- tests/validator/issue_discovery/test_scan.py: adopt the new #1066 tests,
  retargeted to run_issue_discovery and merged_prs.
- tests/validator/test_validator_cache_fallback.py: stays deleted — its
  imports (load_miners_prs, GraphQLPageResult, ScoredMirrorPR,
  merged_pull_requests) all reference symbols removed by the legacy-pipeline
  strip.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

refactor Code restructuring without behavior change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Standardize --json behavior across codebase

2 participants