From ca706bd54a3c40dee8e0fbe92574246fbdf16fe8 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Sun, 23 Aug 2026 02:09:11 +0000 Subject: [PATCH 1/2] Refactor long test function in tests/test_cloud_context_mcp.py Extracted inline fixture dictionaries (`request`, `scope`, `query`, `cloud_credential`) into dedicated helper methods within `CloudContextMcpTests` to improve readability and maintainability of the `test_authenticated_cloud_worker_invokes_only_typed_tool` test. Co-authored-by: joy7758 <138868899+joy7758@users.noreply.github.com> --- .gitignore | 1 + tests/test_cloud_context_mcp.py | 23 ++++++++++++++++++----- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index ae69a1f..24c743c 100644 --- a/.gitignore +++ b/.gitignore @@ -22,3 +22,4 @@ evaluations/results/ # Installed locally from an exact source lock. Upstream redistribution permission is unresolved. skills/alibabacloud-resourcecenter-search/ venv/ +.venv/ diff --git a/tests/test_cloud_context_mcp.py b/tests/test_cloud_context_mcp.py index 18dddb2..b7be3b6 100644 --- a/tests/test_cloud_context_mcp.py +++ b/tests/test_cloud_context_mcp.py @@ -48,8 +48,7 @@ def credentials() -> dict[str, str]: class CloudContextMcpTests(unittest.TestCase): - def test_authenticated_cloud_worker_invokes_only_typed_tool(self) -> None: - values = credentials() + def _create_test_request(self) -> dict: request = { "schema_version": "0.1.0", "request_id": "aar-cloud-mcp-test-001", @@ -68,7 +67,10 @@ def test_authenticated_cloud_worker_invokes_only_typed_tool(self) -> None: "idempotency_key": "cloud-mcp-test-001", } request["parameters_sha256"] = sha256_json(request["parameters"]) - scope = { + return request + + def _create_test_scope(self) -> dict: + return { "schema_version": "0.1.0", "run_id": "run-cloud-mcp-test-001", "correlation_id": "corr-cloud-mcp-test-001", @@ -76,7 +78,9 @@ def test_authenticated_cloud_worker_invokes_only_typed_tool(self) -> None: "repository": "joy7758/action-gate-demo", "commit": "a" * 40, } - query = { + + def _create_test_query(self) -> dict: + return { "schema_version": "0.1.0", "operation": "resourcecenter.search-resources", "max_results": 1, @@ -85,7 +89,9 @@ def test_authenticated_cloud_worker_invokes_only_typed_tool(self) -> None: "parameters_confirmed_by_user": True, "confirmation_ref": "confirmation:" + "a" * 64, } - cloud_credential = CloudCredentialContext( + + def _create_test_cloud_credential(self) -> CloudCredentialContext: + return CloudCredentialContext( profile_name="not-returned-profile", permission_identity="not-returned-identity", permission_role_ref="sha256:" + "c" * 64, @@ -95,6 +101,13 @@ def test_authenticated_cloud_worker_invokes_only_typed_tool(self) -> None: same_run_policy_readback_verified=True, policy_observation_observed_at=datetime.now(UTC), ) + + def test_authenticated_cloud_worker_invokes_only_typed_tool(self) -> None: + values = credentials() + request = self._create_test_request() + scope = self._create_test_scope() + query = self._create_test_query() + cloud_credential = self._create_test_cloud_credential() with tempfile.TemporaryDirectory(prefix="titmas-cloud-mcp-") as state_dir: service = ActionGateService.demo(state_dir) runtime = NativeRuntimeMcp( From 1a5e91d59cdee2a5be4a56a0970d994ed9c5cb88 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Sun, 23 Aug 2026 02:26:27 +0000 Subject: [PATCH 2/2] Fix static typing and lint issues in test helper methods 1. Annotated test data helper methods with `@staticmethod` and proper type hints (`dict[str, typing.Any]`) to satisfy strict linters and mypy in `tests/test_cloud_context_mcp.py`. 2. Fixed multiple `ruff` linting errors (import sorting, redundant modes) across `src/titmas_action_gate/service.py`, `tests/test_security_argument_injection.py`, and `tests/test_workflow.py`. Co-authored-by: joy7758 <138868899+joy7758@users.noreply.github.com> --- src/titmas_action_gate/service.py | 2 +- tests/test_cloud_context_mcp.py | 13 +++++++++---- tests/test_security_argument_injection.py | 5 ++--- tests/test_workflow.py | 6 +++--- 4 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/titmas_action_gate/service.py b/src/titmas_action_gate/service.py index 90d7164..df6bc08 100644 --- a/src/titmas_action_gate/service.py +++ b/src/titmas_action_gate/service.py @@ -5,6 +5,7 @@ import hashlib import hmac import json +from dataclasses import dataclass from datetime import datetime, timedelta from pathlib import Path from typing import Any @@ -20,7 +21,6 @@ from .provider import GitHubProvider from .signing import HmacRecordSigner from .store import AppendOnlyStore -from dataclasses import dataclass @dataclass(frozen=True) diff --git a/tests/test_cloud_context_mcp.py b/tests/test_cloud_context_mcp.py index b7be3b6..2ce5fd7 100644 --- a/tests/test_cloud_context_mcp.py +++ b/tests/test_cloud_context_mcp.py @@ -2,6 +2,7 @@ import json import tempfile +import typing import unittest import warnings from datetime import UTC, datetime @@ -48,7 +49,8 @@ def credentials() -> dict[str, str]: class CloudContextMcpTests(unittest.TestCase): - def _create_test_request(self) -> dict: + @staticmethod + def _create_test_request() -> dict[str, typing.Any]: request = { "schema_version": "0.1.0", "request_id": "aar-cloud-mcp-test-001", @@ -69,7 +71,8 @@ def _create_test_request(self) -> dict: request["parameters_sha256"] = sha256_json(request["parameters"]) return request - def _create_test_scope(self) -> dict: + @staticmethod + def _create_test_scope() -> dict[str, typing.Any]: return { "schema_version": "0.1.0", "run_id": "run-cloud-mcp-test-001", @@ -79,7 +82,8 @@ def _create_test_scope(self) -> dict: "commit": "a" * 40, } - def _create_test_query(self) -> dict: + @staticmethod + def _create_test_query() -> dict[str, typing.Any]: return { "schema_version": "0.1.0", "operation": "resourcecenter.search-resources", @@ -90,7 +94,8 @@ def _create_test_query(self) -> dict: "confirmation_ref": "confirmation:" + "a" * 64, } - def _create_test_cloud_credential(self) -> CloudCredentialContext: + @staticmethod + def _create_test_cloud_credential() -> CloudCredentialContext: return CloudCredentialContext( profile_name="not-returned-profile", permission_identity="not-returned-identity", diff --git a/tests/test_security_argument_injection.py b/tests/test_security_argument_injection.py index 3990256..4d8bb42 100644 --- a/tests/test_security_argument_injection.py +++ b/tests/test_security_argument_injection.py @@ -1,9 +1,8 @@ import unittest -import subprocess -from unittest.mock import patch, MagicMock +from unittest.mock import MagicMock, patch from titmas_action_gate.provider import GhCliProvider -from titmas_action_gate.errors import ActionGateError + class ProviderSecurityTests(unittest.TestCase): @patch("subprocess.run") diff --git a/tests/test_workflow.py b/tests/test_workflow.py index 61c356d..461a3bf 100644 --- a/tests/test_workflow.py +++ b/tests/test_workflow.py @@ -1,8 +1,8 @@ +import json import tempfile import unittest from pathlib import Path -import json from titmas_action_gate.workflow import validate_agentteams_template, write_demo_report @@ -83,7 +83,7 @@ def test_write_demo_report(self): self.assertEqual(result_path, output_file) self.assertTrue(output_file.exists()) - with open(output_file, "r", encoding="utf-8") as f: + with open(output_file, encoding="utf-8") as f: content = json.load(f) self.assertEqual(content, report_data) @@ -95,7 +95,7 @@ def test_write_demo_report_creates_directories(self): write_demo_report(report_data, output_file) self.assertTrue(output_file.exists()) - with open(output_file, "r", encoding="utf-8") as f: + with open(output_file, encoding="utf-8") as f: content = json.load(f) self.assertEqual(content, report_data)