diff --git a/skills/productivity/google-workspace/scripts/google_api.py b/skills/productivity/google-workspace/scripts/google_api.py index 5a9d0839f6..3276e54e20 100644 --- a/skills/productivity/google-workspace/scripts/google_api.py +++ b/skills/productivity/google-workspace/scripts/google_api.py @@ -275,7 +275,7 @@ def build_service(api, version): # ========================================================================= -def gmail_search(args): +def gmail_search(args: argparse.Namespace) -> None: if _gws_binary(): results = _run_gws( ["gmail", "users", "messages", "list"], diff --git a/tests/skills/test_google_workspace_api.py b/tests/skills/test_google_workspace_api.py index e7d6aaedb6..51329e3a91 100644 --- a/tests/skills/test_google_workspace_api.py +++ b/tests/skills/test_google_workspace_api.py @@ -197,26 +197,16 @@ def test_api_get_credentials_refresh_persists_authorized_user_type(api_module, m assert saved["type"] == "authorized_user" -def test_gmail_search_empty_result_prints_json_array(api_module, capsys): - """Regression for #131711: an empty Gmail search through the Python - fallback printed "No messages found." instead of the JSON array the gws - backend emits, breaking consumers that parse search output as JSON.""" - - class EmptyGmail: - def users(self): - return self - - def messages(self): - return self - - def list(self, **_kwargs): - return self - - def execute(self): - return {"resultSizeEstimate": 0} - - api_module._gws_binary = lambda: None - api_module.build_service = lambda *_args, **_kwargs: EmptyGmail() +def test_gmail_search_empty_result_prints_json_array( + api_module: types.ModuleType, + monkeypatch: pytest.MonkeyPatch, + capsys: pytest.CaptureFixture[str], +) -> None: + """Python-fallback empty search prints [] like the gws path (#131711).""" + service = MagicMock() + service.users().messages().list().execute.return_value = {"resultSizeEstimate": 0} + monkeypatch.setattr(api_module, "_gws_binary", lambda: None) + monkeypatch.setattr(api_module, "build_service", lambda *_args: service) api_module.gmail_search(api_module.argparse.Namespace(query="is:unread", max=10))