From f3600bb5494fad86a3255bcb386aca4ceb2dc1e8 Mon Sep 17 00:00:00 2001 From: Asti1982 <65121113+Asti1982@users.noreply.github.com> Date: Tue, 12 May 2026 23:13:04 +0200 Subject: [PATCH] fix: keep bounty verifier star errors shaped --- tools/bounty-bot-pro/tests/test_verifier.py | 93 +++++++++++++++++++++ tools/bounty-bot-pro/verifier.py | 7 +- 2 files changed, 99 insertions(+), 1 deletion(-) diff --git a/tools/bounty-bot-pro/tests/test_verifier.py b/tools/bounty-bot-pro/tests/test_verifier.py index e69de29bb..080ccea15 100644 --- a/tools/bounty-bot-pro/tests/test_verifier.py +++ b/tools/bounty-bot-pro/tests/test_verifier.py @@ -0,0 +1,93 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: MIT + +import importlib.util +import sys +import types +from pathlib import Path + + +def load_verifier_module(): + module_path = Path(__file__).resolve().parents[1] / "verifier.py" + + github_module = types.ModuleType("github") + + class StubGithub: + def __init__(self, token): + self.token = token + + class StubGithubException(Exception): + pass + + github_module.Github = StubGithub + github_module.GithubException = StubGithubException + + google_module = types.ModuleType("google") + google_module.__path__ = [] + generativeai_module = types.ModuleType("google.generativeai") + generativeai_module.configure = lambda **kwargs: None + generativeai_module.GenerativeModel = lambda name: object() + google_module.generativeai = generativeai_module + + dotenv_module = types.ModuleType("dotenv") + dotenv_module.load_dotenv = lambda: None + + stubs = { + "github": github_module, + "google": google_module, + "google.generativeai": generativeai_module, + "dotenv": dotenv_module, + } + originals = {name: sys.modules.get(name) for name in stubs} + sys.modules.update(stubs) + + try: + spec = importlib.util.spec_from_file_location( + "bounty_bot_pro_verifier_test_subject", module_path + ) + module = importlib.util.module_from_spec(spec) + spec.loader.exec_module(module) + return module + finally: + for name, original in originals.items(): + if original is None: + sys.modules.pop(name, None) + else: + sys.modules[name] = original + + +verifier = load_verifier_module() + + +def test_verify_stars_error_keeps_report_shape(): + class FailingGitHub: + def get_user(self, username): + raise verifier.GithubException("rate limit") + + subject = verifier.BountyVerifier.__new__(verifier.BountyVerifier) + subject.gh = FailingGitHub() + + result = subject.verify_stars("alice") + + assert result["count"] == 0 + assert result["is_star_king"] is False + assert result["repos"] == [] + assert "rate limit" in result["error"] + + +def test_generate_report_uses_verified_reward_inputs_without_network(): + subject = verifier.BountyVerifier.__new__(verifier.BountyVerifier) + subject.verify_stars = lambda username: { + "count": 2, + "is_star_king": True, + "repos": ["Scottcjn/Rustchain", "Scottcjn/bottube"], + } + subject.verify_following = lambda username: True + subject.verify_wallet = lambda wallet: {"exists": True, "balance": 12.5} + + report = subject.generate_report("alice", "alice-wallet") + + assert "@alice" in report + assert "alice-wallet" in report + assert "12.5 RTC" in report + assert "**28.0 RTC**" in report diff --git a/tools/bounty-bot-pro/verifier.py b/tools/bounty-bot-pro/verifier.py index 1b0dbdb3d..154b3dbf1 100644 --- a/tools/bounty-bot-pro/verifier.py +++ b/tools/bounty-bot-pro/verifier.py @@ -43,7 +43,12 @@ def verify_stars(self, username: str) -> Dict[str, Any]: "repos": scott_stars[:10] # Sample } except GithubException as e: - return {"error": str(e), "count": 0} + return { + "error": str(e), + "count": 0, + "is_star_king": False, + "repos": [], + } def verify_following(self, username: str) -> bool: """Check if user follows Scottcjn."""