Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions gittensor/cli/issue_commands/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
print_network_header,
read_issues_from_contract,
validate_issue_id,
validate_repository,
with_cli_behavior_options,
with_network_contract_options,
)
Expand Down Expand Up @@ -74,6 +75,13 @@ def issues_list(
except click.BadParameter as e:
handle_exception(as_json, str(e), 'bad_parameter')

if repo_filter:
try:
owner, repo_name = validate_repository(repo_filter, verify_exists=False)
except click.BadParameter as e:
handle_exception(as_json, str(e), 'bad_parameter')
repo_filter = f'{owner}/{repo_name}'

contract_addr, ws_endpoint, network_name = _resolve_contract_and_network(
contract,
network,
Expand Down
67 changes: 67 additions & 0 deletions tests/cli/test_issues_list_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@
'target_bounty': 100_000_000_000,
'status': 'Active',
},
{
'id': 2,
'repository_full_name': 'other/repo',
'issue_number': 11,
'bounty_amount': 25_000_000_000,
'target_bounty': 100_000_000_000,
'status': 'Active',
},
]


Expand Down Expand Up @@ -78,3 +86,62 @@ def test_issues_list_rejects_invalid_id_json(cli_root, runner, bad_id):
assert payload['error']['type'] == 'bad_parameter'
assert 'between 1 and 999999' in payload['error']['message']
mock_read.assert_not_called()


def test_issues_list_repo_filter_strips_whitespace_json(cli_root, runner):
"""A valid --repo pasted with whitespace should still match the repository."""
with (
patch(
'gittensor.cli.issue_commands.view._resolve_contract_and_network',
return_value=('5Fakeaddr', 'ws://x', 'test'),
),
patch('gittensor.cli.issue_commands.view.read_issues_from_contract', return_value=FAKE_ISSUES),
):
result = runner.invoke(cli_root, ['issues', 'list', '--json', '--repo', ' owner/repo '], catch_exceptions=False)

assert result.exit_code == 0
payload = json.loads(result.output)
assert payload['success'] is True
assert payload['issue_count'] == 1
assert payload['issues'][0]['repository_full_name'] == 'owner/repo'


def test_issues_list_repo_filter_strips_whitespace_human(cli_root, runner):
"""Human table mode should use the same normalized --repo filter."""
with (
patch(
'gittensor.cli.issue_commands.view._resolve_contract_and_network',
return_value=('5Fakeaddr', 'ws://x', 'test'),
),
patch('gittensor.cli.issue_commands.view.read_issues_from_contract', return_value=FAKE_ISSUES),
):
result = runner.invoke(cli_root, ['issues', 'list', '--repo', ' owner/repo '], catch_exceptions=False)

assert result.exit_code == 0
assert 'owner/repo' in result.output
assert 'other/repo' not in result.output


@pytest.mark.parametrize('bad_repo', ['ownerrepo', 'owner//repo', 'https://github.com/owner/repo'])
def test_issues_list_rejects_invalid_repo_human(cli_root, runner, bad_repo):
"""Malformed --repo values must fail before contract reads."""
with patch('gittensor.cli.issue_commands.view.read_issues_from_contract') as mock_read:
result = runner.invoke(cli_root, ['issues', 'list', '--repo', bad_repo], catch_exceptions=False)

assert result.exit_code != 0
assert 'owner/repo format' in result.output
mock_read.assert_not_called()


@pytest.mark.parametrize('bad_repo', ['ownerrepo', 'owner//repo', 'https://github.com/owner/repo'])
def test_issues_list_rejects_invalid_repo_json(cli_root, runner, bad_repo):
"""JSON mode should report invalid --repo as a structured bad_parameter error."""
with patch('gittensor.cli.issue_commands.view.read_issues_from_contract') as mock_read:
result = runner.invoke(cli_root, ['issues', 'list', '--json', '--repo', bad_repo], catch_exceptions=False)

assert result.exit_code != 0
payload = json.loads(result.output)
assert payload['success'] is False
assert payload['error']['type'] == 'bad_parameter'
assert 'owner/repo format' in payload['error']['message']
mock_read.assert_not_called()