From c2c85f9c40081ad58b48454a0867cd6bfc0458a0 Mon Sep 17 00:00:00 2001 From: Michael Xu Date: Thu, 1 Oct 2026 04:38:53 -0500 Subject: [PATCH] style(agentex): apply ruff fixes and formatting so make lint passes `make lint` checks the scope the repo's ruff config defines (agentex/, migrations excluded), the same files the pre-commit hooks check. On main that reports three auto-fixable lint errors (two unsorted import blocks and an aliased asyncio.TimeoutError) and thirteen unformatted files, mostly tests. Apply `ruff check --fix` and `ruff format` with the locked ruff (0.13.2). No behaviour change. --- agentex/src/api/routes/checkpoints.py | 8 ++++---- .../repositories/checkpoint_repository.py | 4 +--- .../src/domain/services/agent_acp_service.py | 6 +++++- ...est_acp_type_backwards_compatibility_api.py | 6 +++--- .../checkpoints/test_checkpoint_repository.py | 7 ++++++- .../integration/api/health/test_health_api.py | 6 +++--- .../tests/integration/test_redis_stream_ttl.py | 6 +++--- agentex/tests/integration/test_task_stream.py | 2 +- agentex/tests/unit/api/test_states_schema.py | 1 + agentex/tests/unit/api/test_webhook_trigger.py | 9 +++++++-- .../unit/repositories/test_agent_repository.py | 6 +++--- .../test_agent_task_tracker_repository.py | 6 +++--- .../unit/temporal/test_healthcheck_workflow.py | 6 +++--- ...cp_type_backwards_compatibility_use_case.py | 12 ++++++------ .../use_cases/test_agents_api_keys_use_case.py | 4 +--- .../use_cases/test_slack_gateway_use_case.py | 18 +++++++++--------- 16 files changed, 59 insertions(+), 48 deletions(-) diff --git a/agentex/src/api/routes/checkpoints.py b/agentex/src/api/routes/checkpoints.py index 8c1d7090..69b64f33 100644 --- a/agentex/src/api/routes/checkpoints.py +++ b/agentex/src/api/routes/checkpoints.py @@ -2,6 +2,10 @@ from fastapi import APIRouter, Response +from src.api.schemas.authorization_types import ( + AgentexResourceType, + AuthorizedOperationType, +) from src.api.schemas.checkpoints import ( BlobResponse, CheckpointListItem, @@ -14,10 +18,6 @@ PutWritesRequest, WriteResponse, ) -from src.api.schemas.authorization_types import ( - AgentexResourceType, - AuthorizedOperationType, -) from src.domain.use_cases.checkpoints_use_case import DCheckpointsUseCase from src.utils.authorization_shortcuts import DAuthorizedBodyId from src.utils.logging import make_logger diff --git a/agentex/src/domain/repositories/checkpoint_repository.py b/agentex/src/domain/repositories/checkpoint_repository.py index b320517d..567fd15d 100644 --- a/agentex/src/domain/repositories/checkpoint_repository.py +++ b/agentex/src/domain/repositories/checkpoint_repository.py @@ -248,9 +248,7 @@ async def list_checkpoints( self.async_ro_session_maker() as session, async_sql_exception_handler(), ): - query = select(CheckpointORM).where( - CheckpointORM.thread_id == thread_id - ) + query = select(CheckpointORM).where(CheckpointORM.thread_id == thread_id) if checkpoint_ns is not None: query = query.where(CheckpointORM.checkpoint_ns == checkpoint_ns) diff --git a/agentex/src/domain/services/agent_acp_service.py b/agentex/src/domain/services/agent_acp_service.py index eb7a45f9..c2bcb5db 100644 --- a/agentex/src/domain/services/agent_acp_service.py +++ b/agentex/src/domain/services/agent_acp_service.py @@ -308,7 +308,11 @@ async def get_headers( # message, streaming and cancel (which call get_headers(agent) with no # request_headers) would drop traceparent and the downstream agent would # start a detached trace. The inbound headers are on self._request. - inbound_headers = dict(self._request.headers) if getattr(self, "_request", None) is not None else {} + inbound_headers = ( + dict(self._request.headers) + if getattr(self, "_request", None) is not None + else {} + ) trace_context_headers = extract_trace_context_headers(inbound_headers) delegation_headers = self.get_delegation_headers(agent) auth_headers = await self.get_agent_auth_headers(agent) diff --git a/agentex/tests/integration/api/agents/test_acp_type_backwards_compatibility_api.py b/agentex/tests/integration/api/agents/test_acp_type_backwards_compatibility_api.py index 38e744e6..15da2d34 100644 --- a/agentex/tests/integration/api/agents/test_acp_type_backwards_compatibility_api.py +++ b/agentex/tests/integration/api/agents/test_acp_type_backwards_compatibility_api.py @@ -70,9 +70,9 @@ async def test_retrieve_agentic_agent_preserves_type(self, isolated_client): get_response = await isolated_client.get(f"/agents/{agent_id}") assert get_response.status_code == 200 agent_data = get_response.json() - assert ( - agent_data["acp_type"] == "agentic" - ), "API should return 'agentic' for legacy agents, not convert to 'async'" + assert agent_data["acp_type"] == "agentic", ( + "API should return 'agentic' for legacy agents, not convert to 'async'" + ) # Retrieve by name get_by_name_response = await isolated_client.get( diff --git a/agentex/tests/integration/api/checkpoints/test_checkpoint_repository.py b/agentex/tests/integration/api/checkpoints/test_checkpoint_repository.py index 062e8c86..4a4fdddd 100644 --- a/agentex/tests/integration/api/checkpoints/test_checkpoint_repository.py +++ b/agentex/tests/integration/api/checkpoints/test_checkpoint_repository.py @@ -640,7 +640,12 @@ async def test_null_blob_stored_correctly(self, isolated_repositories): repo = isolated_repositories["checkpoint_repository"] blobs = [ - {"channel": "empty_channel", "version": "v1", "type": "empty", "blob": None}, + { + "channel": "empty_channel", + "version": "v1", + "type": "empty", + "blob": None, + }, ] checkpoint = { "id": "cp-1", diff --git a/agentex/tests/integration/api/health/test_health_api.py b/agentex/tests/integration/api/health/test_health_api.py index db6a3c61..5359d0d6 100644 --- a/agentex/tests/integration/api/health/test_health_api.py +++ b/agentex/tests/integration/api/health/test_health_api.py @@ -23,9 +23,9 @@ async def test_health_endpoint_variations(self, isolated_client): for endpoint in health_endpoints: response = await isolated_client.get(endpoint) - assert ( - response.status_code == 200 - ), f"Health endpoint {endpoint} should return 200" + assert response.status_code == 200, ( + f"Health endpoint {endpoint} should return 200" + ) @pytest.mark.asyncio async def test_health_endpoint_http_methods(self, isolated_client): diff --git a/agentex/tests/integration/test_redis_stream_ttl.py b/agentex/tests/integration/test_redis_stream_ttl.py index 959a63db..747a8bdf 100644 --- a/agentex/tests/integration/test_redis_stream_ttl.py +++ b/agentex/tests/integration/test_redis_stream_ttl.py @@ -19,9 +19,9 @@ async def test_send_data_sets_ttl_on_stream_key(self, isolated_repositories): # while still catching a regression where EXPIRE isn't called. assert ttl > 0, f"Expected positive TTL, got {ttl}" assert ttl <= 3600, f"Expected TTL <= 3600, got {ttl}" - assert ( - ttl >= 3480 - ), f"Expected TTL >= 3480 (within 120s of configured), got {ttl}" + assert ttl >= 3480, ( + f"Expected TTL >= 3480 (within 120s of configured), got {ttl}" + ) # Cleanup await repo.redis.delete(topic) diff --git a/agentex/tests/integration/test_task_stream.py b/agentex/tests/integration/test_task_stream.py index 918b0916..fca6b45b 100644 --- a/agentex/tests/integration/test_task_stream.py +++ b/agentex/tests/integration/test_task_stream.py @@ -595,7 +595,7 @@ async def test_event_xadded_after_connected_is_delivered( for _ in range(10): try: evt = await asyncio.wait_for(gen.__anext__(), timeout=4) - except (TimeoutError, asyncio.TimeoutError): + except TimeoutError: break # stream went silent — sentinel was dropped if evt.startswith("data: ") and sentinel in evt: received = True diff --git a/agentex/tests/unit/api/test_states_schema.py b/agentex/tests/unit/api/test_states_schema.py index 3237632a..d7eb2b60 100644 --- a/agentex/tests/unit/api/test_states_schema.py +++ b/agentex/tests/unit/api/test_states_schema.py @@ -1,6 +1,7 @@ import pytest from src.api.schemas.states import UpdateStateRequest + @pytest.mark.unit def test_update_state_request_ignores_legacy_parent_identifiers(): request = UpdateStateRequest.model_validate( diff --git a/agentex/tests/unit/api/test_webhook_trigger.py b/agentex/tests/unit/api/test_webhook_trigger.py index ab8fbc22..a03f11f9 100644 --- a/agentex/tests/unit/api/test_webhook_trigger.py +++ b/agentex/tests/unit/api/test_webhook_trigger.py @@ -95,7 +95,9 @@ async def test_forward_path_reserved_chars_are_url_encoded(self, monkeypatch): name="o/r", forward_path="github-pr/cfg-9?mode=review#frag ment", ) - resp, _ = await self._call(monkeypatch, req, base_env="https://sgp.example.com/") + resp, _ = await self._call( + monkeypatch, req, base_env="https://sgp.example.com/" + ) assert ( resp.webhook_path @@ -154,7 +156,10 @@ async def test_slack_without_secret_rejected(self, monkeypatch): # Slack signs with the app's existing Signing Secret — we can't generate one, # so omitting it must 400 rather than store a random value that never matches. req = CreateWebhookTriggerRequest( - agent_name="a", source=AgentAPIKeyType.SLACK, name="my-app", forward_path="slack" + agent_name="a", + source=AgentAPIKeyType.SLACK, + name="my-app", + forward_path="slack", ) with pytest.raises(HTTPException) as exc: await self._call(monkeypatch, req) diff --git a/agentex/tests/unit/repositories/test_agent_repository.py b/agentex/tests/unit/repositories/test_agent_repository.py index 79f3f0f4..c3c5cc43 100644 --- a/agentex/tests/unit/repositories/test_agent_repository.py +++ b/agentex/tests/unit/repositories/test_agent_repository.py @@ -175,9 +175,9 @@ async def test_agent_repository_crud_operations(postgres_url, isolated_test_sche # Should be empty after rollback agent_list = await repository2.list() - assert ( - len(agent_list) == 0 - ), f"Expected 0 agents after rollback, got {len(agent_list)}" + assert len(agent_list) == 0, ( + f"Expected 0 agents after rollback, got {len(agent_list)}" + ) print("✅ TRANSACTION ROLLBACK verification successful") finally: diff --git a/agentex/tests/unit/repositories/test_agent_task_tracker_repository.py b/agentex/tests/unit/repositories/test_agent_task_tracker_repository.py index 001d0c2b..8b75be9a 100644 --- a/agentex/tests/unit/repositories/test_agent_task_tracker_repository.py +++ b/agentex/tests/unit/repositories/test_agent_task_tracker_repository.py @@ -89,9 +89,9 @@ async def test_agent_task_tracker_repository_crud_operations(postgres_url): # The task creation should have automatically created an AgentTaskTracker # Let's find it and test our operations all_trackers = await tracker_repo.list() - assert ( - len(all_trackers) >= 1 - ), "Task creation should have created an AgentTaskTracker" + assert len(all_trackers) >= 1, ( + "Task creation should have created an AgentTaskTracker" + ) # Find our tracker our_tracker = None diff --git a/agentex/tests/unit/temporal/test_healthcheck_workflow.py b/agentex/tests/unit/temporal/test_healthcheck_workflow.py index 07aaab31..11c4fb53 100644 --- a/agentex/tests/unit/temporal/test_healthcheck_workflow.py +++ b/agentex/tests/unit/temporal/test_healthcheck_workflow.py @@ -126,8 +126,8 @@ async def sleep(_): await workflow_instance.run({"agent_id": "agent-1", "acp_url": "http://agent"}) - assert status_updates == [ - ["agent-1", "Unhealthy"] - ], "the fifth consecutive failed probe must mark the agent unhealthy" + assert status_updates == [["agent-1", "Unhealthy"]], ( + "the fifth consecutive failed probe must mark the agent unhealthy" + ) assert probe_count == 5, "the workflow must wait for five failed probes" continue_as_new.assert_not_called() diff --git a/agentex/tests/unit/use_cases/test_acp_type_backwards_compatibility_use_case.py b/agentex/tests/unit/use_cases/test_acp_type_backwards_compatibility_use_case.py index 78c24ac6..94874114 100644 --- a/agentex/tests/unit/use_cases/test_acp_type_backwards_compatibility_use_case.py +++ b/agentex/tests/unit/use_cases/test_acp_type_backwards_compatibility_use_case.py @@ -36,9 +36,9 @@ async def test_both_agentic_and_async_have_same_allowed_methods(self): agentic_methods = set(ACP_TYPE_TO_ALLOWED_RPC_METHODS[ACPType.AGENTIC]) async_methods = set(ACP_TYPE_TO_ALLOWED_RPC_METHODS[ACPType.ASYNC]) - assert ( - agentic_methods == async_methods - ), "AGENTIC and ASYNC should have identical allowed RPC methods" + assert agentic_methods == async_methods, ( + "AGENTIC and ASYNC should have identical allowed RPC methods" + ) # Verify they include the expected methods expected_methods = { @@ -362,6 +362,6 @@ async def test_agentic_and_async_agents_both_use_not_sync_logic(self): # Both AGENTIC and ASYNC should pass the same conditional checks agentic_is_not_sync = agentic_agent.acp_type != ACPType.SYNC async_is_not_sync = async_agent.acp_type != ACPType.SYNC - assert ( - agentic_is_not_sync == async_is_not_sync - ), "AGENTIC and ASYNC should have identical behavior in != SYNC checks" + assert agentic_is_not_sync == async_is_not_sync, ( + "AGENTIC and ASYNC should have identical behavior in != SYNC checks" + ) diff --git a/agentex/tests/unit/use_cases/test_agents_api_keys_use_case.py b/agentex/tests/unit/use_cases/test_agents_api_keys_use_case.py index 4bee562a..801a90f8 100644 --- a/agentex/tests/unit/use_cases/test_agents_api_keys_use_case.py +++ b/agentex/tests/unit/use_cases/test_agents_api_keys_use_case.py @@ -268,9 +268,7 @@ def test_returns_none_for_empty_credentials(self): assert extract_agent_key_from_authorization("AgentKey ") is None def test_strips_surrounding_whitespace(self): - assert ( - extract_agent_key_from_authorization(" AgentKey abc123 ") == "abc123" - ) + assert extract_agent_key_from_authorization(" AgentKey abc123 ") == "abc123" @pytest.mark.asyncio diff --git a/agentex/tests/unit/use_cases/test_slack_gateway_use_case.py b/agentex/tests/unit/use_cases/test_slack_gateway_use_case.py index 913bebdc..e14bef35 100644 --- a/agentex/tests/unit/use_cases/test_slack_gateway_use_case.py +++ b/agentex/tests/unit/use_cases/test_slack_gateway_use_case.py @@ -1766,9 +1766,9 @@ async def test_the_link_is_never_broadcast(self, monkeypatch): for method, payload in (c.args for c in api.await_args_list): if method == "chat.postMessage": - assert ( - payload["channel"] == "D_DM" - ), f"the nonce was posted to {payload['channel']}, not the DM" + assert payload["channel"] == "D_DM", ( + f"the nonce was posted to {payload['channel']}, not the DM" + ) # Nothing that lands in channel history mentions it. broadcast = [ p @@ -2812,9 +2812,9 @@ def test_duplicate_names_resolve_the_same_way_for_every_worker(): other = {"id": "x", "name": "something-else", "created_at": "2020-01-01T00:00:00"} for order in ([older, newer, other], [newer, other, older], [other, newer, older]): - assert ( - sg._canonical_named(order, "slack-agentex-bot") == "b-older" - ), "list order must not change the answer" + assert sg._canonical_named(order, "slack-agentex-bot") == "b-older", ( + "list order must not change the answer" + ) assert sg._canonical_named([older, newer], "absent") is None @@ -3047,9 +3047,9 @@ async def test_cooldown_is_released_when_nothing_could_be_delivered(monkeypatch) await uc._notify_config_forbidden(_inbound(team_id="T", user="U1")) - assert deleted == [ - "slack:config_forbidden:T:U1" - ], "nothing was delivered, so the next turn must be allowed to retry" + assert deleted == ["slack:config_forbidden:T:U1"], ( + "nothing was delivered, so the next turn must be allowed to retry" + ) @pytest.mark.asyncio