Skip to content
Closed
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
60 changes: 33 additions & 27 deletions tests/sdk/agent/test_acp_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import pytest
from acp.exceptions import RequestError as ACPRequestError
from acp.schema import PromptResponse
from pydantic import SecretStr
from pydantic import Field as PydanticField, SecretStr

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Suggestion: The PydanticField alias is functional, but it's worth confirming it's necessary. If another Field is already imported at module scope (e.g. from SQLAlchemy, dataclasses, or an internal SDK module) the alias is the right call — but a brief inline comment explaining the naming conflict would help future readers. If no such conflict exists, the standard name Field would be cleaner.

Suggested change
from pydantic import Field as PydanticField, SecretStr
from pydantic import Field, SecretStr

(Apply only if no other Field is imported at module scope; otherwise keep the alias.)


from openhands.sdk.agent.acp_agent import (
ACPAgent,
Expand Down Expand Up @@ -47,6 +47,7 @@
)
from openhands.sdk.event.conversation_error import ConversationErrorEvent
from openhands.sdk.llm import ImageContent, Message, TextContent
from openhands.sdk.secret import SecretSource
from openhands.sdk.skills import KeywordTrigger, Skill
from openhands.sdk.tool.builtins.finish import FinishAction
from openhands.sdk.utils.cipher import Cipher
Expand Down Expand Up @@ -5812,6 +5813,37 @@ def test_empty_acp_env_does_not_warn(self, tmp_path):
assert not [w for w in caught if "acp_env" in str(w.message)]


# NOTE: These ``SecretSource`` subclasses are intentionally defined at module
# level rather than inside the test methods that use them. ``SecretSource`` is
# a ``DiscriminatedUnionMixin`` that discovers concrete subclasses via
# ``cls.__subclasses__()`` and rejects ``<locals>`` qualnames (see
# ``_get_checked_concrete_subclasses`` in ``openhands/sdk/utils/models.py``).
# When defined inside test methods these classes linger in the process via
# pydantic's schema/instance references and poison deserialization of
# ``ConversationState`` in any test that runs later in the same xdist worker
# (see GH issue #3487). Keeping them at module level gives them stable
# qualnames and avoids the cross-test pollution.
class _FakeLookupSecret(SecretSource):
stored_value: str

def get_value(self) -> str | None:
return self.stored_value


class _CountingLookupSecret(SecretSource):
stored_value: str
calls: list[int] = PydanticField(default_factory=list)

def get_value(self) -> str | None:
self.calls.append(1)
return self.stored_value


class _BrokenSecret(SecretSource):
def get_value(self) -> str | None:
raise OSError("network down")


class TestACPSecretRegistryEnvInjection:
"""Tests for secret injection from the conversation's secret_registry.

Expand Down Expand Up @@ -5914,14 +5946,6 @@ def test_registry_lookup_secret_injected_into_subprocess_env(self, tmp_path):
whose ``get_value()`` fetches over HTTP from the agent-server's
``/api/settings/secrets/{name}`` endpoint.
"""
from openhands.sdk.secret import SecretSource

class _FakeLookupSecret(SecretSource):
stored_value: str

def get_value(self) -> str | None:
return self.stored_value

agent = _make_agent()
env = self._run_start_capturing_env(
agent,
Expand Down Expand Up @@ -5949,18 +5973,6 @@ def test_acp_env_shadow_skips_registry_lookup(self, tmp_path):
a key that ``acp_env`` is about to override wastes a round-trip and
can emit spurious lookup-failure warnings.
"""
from pydantic import Field

from openhands.sdk.secret import SecretSource

class _CountingLookupSecret(SecretSource):
stored_value: str
calls: list[int] = Field(default_factory=list)

def get_value(self) -> str | None:
self.calls.append(1)
return self.stored_value

secret = _CountingLookupSecret(stored_value="from-registry")
agent = _make_agent(acp_env={"GITHUB_TOKEN": "from-acp-env"})
env = self._run_start_capturing_env(
Expand Down Expand Up @@ -6016,12 +6028,6 @@ def test_failing_registry_lookup_swallowed(self, tmp_path):
(network blip, expired token) doesn't take the whole ACP
subprocess down.
"""
from openhands.sdk.secret import SecretSource

class _BrokenSecret(SecretSource):
def get_value(self) -> str | None:
raise OSError("network down")

agent = _make_agent()
env = self._run_start_capturing_env(
agent,
Expand Down
Loading