Skip to content

fix(cli): validate --repo filter on gitt issues list (#1061) - #1118

Closed
RUNECTZ33 wants to merge 1 commit into
entrius:testfrom
RUNECTZ33:fix/issues-list-repo-filter-validation-test
Closed

fix(cli): validate --repo filter on gitt issues list (#1061)#1118
RUNECTZ33 wants to merge 1 commit into
entrius:testfrom
RUNECTZ33:fix/issues-list-repo-filter-validation-test

Conversation

@RUNECTZ33

Copy link
Copy Markdown

Fixes #1061. Reopened from PR #1113 — that one targeted `main` instead of `test` and was closed (CONTRIBUTING.md says branches should target `test`). This is the same diff, rebased onto current upstream/test (`9b620da`), tests adjusted for the test-branch's network-header-in-JSON-mode behavior.

Problem

`--repo <owner/name>` on `gitt issues list` (added in #910) compares raw user input directly against `repository_full_name`:

```python
issues = [
i for i in issues
if i.get('repository_full_name', '').lower() == repo_filter.lower()
]
```

So:

  • Malformed inputs like `ownerrepo` or `owner//repo` are silently accepted and quietly match nothing (no error feedback).
  • Whitespace-padded valid inputs like `' entrius/gittensor '` fail to match real entries because the comparison string still contains the surrounding spaces.

Fix

Reuse the existing `validate_repository(verify_exists=False)` helper before any contract read. It already:

  • strips whitespace,
  • enforces the `owner/repo` regex,
  • raises `click.BadParameter` with `param_hint='--repo'` on bad input.

Surface that exception through the existing `handle_exception` path so JSON consumers get a structured `bad_parameter` error and human callers exit non-zero — same shape used by `--id` validation a few lines above.

The same validator is already used by mutating commands (`gitt issues register/cancel` in `mutations.py`), so the read-side `--repo` filter now matches the documented contract enforced everywhere else in the CLI.

Tests added

6 new tests in `tests/cli/test_issues_list_json.py`:

  • Malformed filters rejected with structured `bad_parameter` error in JSON mode (parametrized over `ownerrepo`, `owner//repo`, `owner/`, `/repo`, `owner repo`).
  • Malformed filters exit non-zero in human mode.
  • Whitespace-padded valid filter `' owner/repo '` correctly matches contract entries.
  • Mixed-case filter `OWNER/REPO` still matches (preserves existing case-insensitive behavior).
  • Valid non-matching filter returns empty list, not all issues.

Tests use a small `_parse_json_payload(output)` helper that slices from the first `{` so they're robust whether `print_network_header` writes to stdout in JSON mode (current test branch) or not.

All 19 tests in the file pass; `read_issues_from_contract` is asserted not-called for invalid input so we never burn a contract read on bad parameters.

Diff size

  • `gittensor/cli/issue_commands/view.py`: +13 lines (1 import + 11-line validation block)
  • `tests/cli/test_issues_list_json.py`: +95 lines (6 new tests + helper)
  • Total: +108 lines, 0 deletions, 2 files

The `--repo <owner/name>` filter added in entrius#910 compares raw user input
directly against `repository_full_name`, so:

- malformed inputs like `ownerrepo` or `owner//repo` are silently accepted
  and quietly match nothing (no error to the user);
- whitespace-padded valid inputs like `' entrius/gittensor '` fail to
  match real entries because the comparison string still contains the
  surrounding spaces.

Fix by reusing the existing `validate_repository(verify_exists=False)`
helper before any contract read, normalizing `repo_filter` to a clean
`owner/repo` string and surfacing `click.BadParameter` through the
existing `handle_exception` path so JSON consumers get a structured
`bad_parameter` error and human callers exit non-zero.

This is the same validator already used by `gitt issues register/cancel`
mutating commands, so the read-side `--repo` filter now matches the
documented contract enforced everywhere else.

## Tests

- Malformed filters (`ownerrepo`, `owner//repo`, `owner/`, `/repo`,
  `owner repo`) rejected with structured `bad_parameter` error in JSON
  mode and non-zero exit in human mode, before any contract read.
- Whitespace-padded valid filter `'  owner/repo  '` correctly matches
  the contract entry and returns the issue.
- Mixed-case filter `OWNER/REPO` still matches (preserves existing
  case-insensitive behavior).
- Valid non-matching filter returns empty list rather than all issues.

Closes entrius#1061
@xiao-xiao-mao xiao-xiao-mao Bot added the enhancement New feature or request label May 8, 2026
@anderdc

anderdc commented May 8, 2026

Copy link
Copy Markdown
Collaborator

the issue was close as not completed, we are not pursuing it

@anderdc anderdc closed this May 8, 2026
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 issues list --repo silently accepts malformed repo filters and exact-matches untrimmed input

2 participants