Skip to content

Commit f4edab9

Browse files
committed
fix(a2a): address review findings for push, tenant and FaaS updates
- Forward initialize() in DefaultingPushNotificationConfigStore so a server with both database_url and push_webhook_url starts instead of raising AttributeError during lifespan startup. - Apply the RemoteVeAgent tenant inside _ensure_resolved, after the ADK client exists, instead of in __init__ where _a2a_client is still None. - Unwrap TenantTransportDecorator before auth-header injection so TIP and bearer credentials are still applied when tenant routing is enabled. - Pass the tenant-aware owner resolver into InMemoryTaskStore so tasks are filtered before pagination, not after. - Seed the placeholder VEADK_A2A_PUBLIC_URL before releasing an updated code bundle, so apps created before the env existed can boot the new template. All five findings are covered by unit tests; the DB+push startup path was also verified against a real AIDAP workspace. Signed-off-by: Codex <codex@openai.com>
1 parent bd5a4ac commit f4edab9

8 files changed

Lines changed: 345 additions & 37 deletions

File tree

‎tests/a2a/test_a2a_server_capabilities.py‎

Lines changed: 195 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -694,6 +694,33 @@ def test_build_stores_with_push_wraps_default_store():
694694
assert isinstance(stores.push_config_store, DefaultingPushNotificationConfigStore)
695695

696696

697+
def test_a2a_stores_initialize_initializes_push_config_store():
698+
import asyncio
699+
700+
from veadk.a2a.stores import A2AStores
701+
702+
class Initializable:
703+
def __init__(self):
704+
self.initialized = False
705+
706+
async def initialize(self):
707+
self.initialized = True
708+
709+
task_store = Initializable()
710+
event_stream = Initializable()
711+
push_store = Initializable()
712+
stores = A2AStores(
713+
task_store=task_store,
714+
event_stream=event_stream,
715+
push_config_store=push_store,
716+
engine=object(),
717+
)
718+
asyncio.run(stores.initialize())
719+
assert task_store.initialized is True
720+
assert event_stream.initialized is True
721+
assert push_store.initialized is True
722+
723+
697724
def test_require_auth_without_oidc_config_raises(make_server):
698725
with pytest.raises(ValueError):
699726
make_server(A2AServerConfig(require_auth=True)).build()
@@ -733,6 +760,60 @@ async def run():
733760
asyncio.run(run())
734761

735762

763+
def test_defaulting_store_forwards_initialize():
764+
import asyncio
765+
766+
from veadk.a2a.push import DefaultingPushNotificationConfigStore
767+
768+
class Inner:
769+
initialized = False
770+
771+
async def initialize(self):
772+
self.initialized = True
773+
774+
inner = Inner()
775+
store = DefaultingPushNotificationConfigStore(inner, "https://default")
776+
asyncio.run(store.initialize())
777+
assert inner.initialized is True
778+
779+
780+
def test_owner_scoped_store_filters_tenant_before_pagination():
781+
import asyncio
782+
783+
from a2a.server.context import ServerCallContext
784+
from a2a.types import ListTasksRequest, Task, TaskState, TaskStatus
785+
786+
resolve = make_owner_resolver("x-a2a-tenant")
787+
store = OwnerScopedInMemoryTaskStore(resolve)
788+
tenant_a = ServerCallContext(user=A2AUser({"sub": "alice"}), tenant="a")
789+
tenant_b = ServerCallContext(user=A2AUser({"sub": "alice"}), tenant="b")
790+
791+
async def run():
792+
for index in range(60):
793+
await store.save(
794+
Task(
795+
id=f"b-{index}",
796+
context_id="c",
797+
status=TaskStatus(state=TaskState.TASK_STATE_COMPLETED),
798+
),
799+
tenant_b,
800+
)
801+
await store.save(
802+
Task(
803+
id="a-1",
804+
context_id="c",
805+
status=TaskStatus(state=TaskState.TASK_STATE_COMPLETED),
806+
),
807+
tenant_a,
808+
)
809+
810+
page = await store.list(ListTasksRequest(page_size=10), tenant_a)
811+
assert [task.id for task in page.tasks] == ["a-1"]
812+
assert page.next_page_token == ""
813+
814+
asyncio.run(run())
815+
816+
736817
def test_push_validator_is_none_when_push_disabled():
737818
from veadk.a2a.push import build_push_url_validator
738819

@@ -796,10 +877,8 @@ def test_apply_tenant_requires_transport():
796877
apply_tenant(object(), "tenant-a")
797878

798879

799-
def test_remote_ve_agent_applies_tenant(monkeypatch):
800-
import veadk.a2a.remote_ve_agent as module
801-
802-
card = {
880+
def _remote_card():
881+
return {
803882
"name": "remote",
804883
"description": "remote",
805884
"version": "1.0.0",
@@ -815,21 +894,131 @@ def test_remote_ve_agent_applies_tenant(monkeypatch):
815894
}
816895
],
817896
}
897+
898+
899+
def test_remote_ve_agent_applies_tenant(monkeypatch):
900+
import asyncio
901+
902+
import veadk.a2a.remote_ve_agent as module
903+
818904
monkeypatch.setattr(
819905
module.requests,
820906
"get",
821-
lambda *args, **kwargs: SimpleNamespace(json=lambda: card),
907+
lambda *args, **kwargs: SimpleNamespace(json=lambda: _remote_card()),
822908
)
823909

824910
class FakeParent:
825911
def __init__(self, **kwargs):
826912
self._a2a_client = SimpleNamespace(_transport=object())
827913

828914
monkeypatch.setattr(module.RemoteA2aAgent, "__init__", FakeParent.__init__)
915+
916+
async def fake_resolved(self, ctx=None):
917+
return self._a2a_client
918+
919+
monkeypatch.setattr(module.RemoteA2aAgent, "_ensure_resolved", fake_resolved)
829920
agent = module.RemoteVeAgent(
830921
name="remote", url="https://example.com", tenant="tenant-a"
831922
)
832-
assert agent._a2a_client._transport._tenant == "tenant-a"
923+
client = asyncio.run(agent._ensure_resolved())
924+
assert client._transport._tenant == "tenant-a"
925+
926+
927+
def test_remote_ve_agent_tenant_constructs_before_client_exists(monkeypatch):
928+
import veadk.a2a.remote_ve_agent as module
929+
930+
monkeypatch.setattr(
931+
module.requests,
932+
"get",
933+
lambda *args, **kwargs: SimpleNamespace(json=lambda: _remote_card()),
934+
)
935+
936+
class LazyParent:
937+
def __init__(self, **kwargs):
938+
# ADK leaves the client None until _ensure_resolved runs.
939+
self._a2a_client = None
940+
941+
monkeypatch.setattr(module.RemoteA2aAgent, "__init__", LazyParent.__init__)
942+
agent = module.RemoteVeAgent(
943+
name="remote", url="https://example.com", tenant="tenant-a"
944+
)
945+
assert agent._tenant == "tenant-a"
946+
assert agent._a2a_client is None
947+
948+
949+
def test_remote_ve_agent_httpx_client_unwraps_tenant_decorator(monkeypatch):
950+
import httpx
951+
from a2a.client.transports.tenant_decorator import TenantTransportDecorator
952+
953+
import veadk.a2a.remote_ve_agent as module
954+
955+
monkeypatch.setattr(
956+
module.requests,
957+
"get",
958+
lambda *args, **kwargs: SimpleNamespace(json=lambda: _remote_card()),
959+
)
960+
httpx_client = httpx.AsyncClient()
961+
962+
class FakeParent:
963+
def __init__(self, **kwargs):
964+
self._a2a_client = SimpleNamespace(
965+
_transport=TenantTransportDecorator(
966+
SimpleNamespace(httpx_client=httpx_client), "tenant-a"
967+
)
968+
)
969+
970+
monkeypatch.setattr(module.RemoteA2aAgent, "__init__", FakeParent.__init__)
971+
agent = module.RemoteVeAgent(name="remote", url="https://example.com")
972+
assert agent._httpx_client() is httpx_client
973+
974+
975+
def test_inject_auth_token_works_through_tenant_decorator(monkeypatch):
976+
import asyncio
977+
978+
import httpx
979+
from a2a.client.transports.tenant_decorator import TenantTransportDecorator
980+
981+
import veadk.a2a.remote_ve_agent as module
982+
983+
monkeypatch.setattr(
984+
module.requests,
985+
"get",
986+
lambda *args, **kwargs: SimpleNamespace(json=lambda: _remote_card()),
987+
)
988+
989+
class FakeClient:
990+
def __init__(self):
991+
self.httpx_client = httpx.AsyncClient()
992+
self._transport = TenantTransportDecorator(
993+
SimpleNamespace(httpx_client=self.httpx_client), "tenant-a"
994+
)
995+
996+
monkeypatch.setattr(module, "BaseClient", FakeClient)
997+
monkeypatch.setattr(
998+
"google.adk.agents.callback_context.CallbackContext",
999+
lambda ctx: SimpleNamespace(ctx=ctx),
1000+
)
1001+
1002+
class LazyParent:
1003+
def __init__(self, **kwargs):
1004+
self._a2a_client = FakeClient()
1005+
1006+
monkeypatch.setattr(module.RemoteA2aAgent, "__init__", LazyParent.__init__)
1007+
agent = module.RemoteVeAgent(name="remote", url="https://example.com")
1008+
1009+
tip = SimpleNamespace(api_key="tip-token")
1010+
credential_service = SimpleNamespace(
1011+
load_credential=__import__("unittest.mock", fromlist=["AsyncMock"]).AsyncMock(
1012+
side_effect=[tip, None]
1013+
)
1014+
)
1015+
ctx = SimpleNamespace(credential_service=credential_service)
1016+
1017+
asyncio.run(agent._inject_auth_token(ctx))
1018+
assert (
1019+
agent._a2a_client.httpx_client.headers[module.VE_TIP_TOKEN_HEADER]
1020+
== "tip-token"
1021+
)
8331022

8341023

8351024
def test_cloud_app_applies_tenant(monkeypatch):

‎tests/cli/test_studio_update.py‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1671,6 +1671,7 @@ def test_update_application_code_bundle_merges_only_explicit_environment(
16711671
resource_requests: list[Any] = []
16721672
service = object.__new__(VeFaaS)
16731673
service.session_token = ""
1674+
monkeypatch.setattr(service, "merge_function_envs_and_release", Mock())
16741675
cast(Any, service).client = SimpleNamespace(
16751676
get_function=lambda _: SimpleNamespace(
16761677
command="./run.sh",
@@ -2192,6 +2193,7 @@ def test_update_application_code_bundle_preserves_unspecified_sandbox_tool(
21922193
updated_requests: list[Any] = []
21932194
service = object.__new__(VeFaaS)
21942195
service.session_token = ""
2196+
monkeypatch.setattr(service, "merge_function_envs_and_release", Mock())
21952197
cast(Any, service).client = SimpleNamespace(
21962198
get_function=lambda _: SimpleNamespace(
21972199
envs=[
@@ -2226,6 +2228,7 @@ def test_update_application_code_bundle_does_not_read_or_replace_environment(
22262228
updated_requests: list[Any] = []
22272229
service = object.__new__(VeFaaS)
22282230
service.session_token = ""
2231+
monkeypatch.setattr(service, "merge_function_envs_and_release", Mock())
22292232
cast(Any, service).client = SimpleNamespace(
22302233
get_function=lambda _: pytest.fail("environment should not be read"),
22312234
update_function=updated_requests.append,
@@ -2253,6 +2256,7 @@ def test_studio_update_preserves_custom_function_command(
22532256
updated_requests: list[Any] = []
22542257
service = object.__new__(VeFaaS)
22552258
service.session_token = ""
2259+
monkeypatch.setattr(service, "merge_function_envs_and_release", Mock())
22562260
cast(Any, service).client = SimpleNamespace(
22572261
get_function=lambda _: SimpleNamespace(
22582262
command="python3 custom_server.py",

‎tests/test_cloud.py‎

Lines changed: 77 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
from veadk.cloud.cloud_agent_engine import CloudAgentEngine
3232
from veadk.integrations.ve_apig.ve_apig import APIGateway
3333
from veadk.integrations.ve_code_pipeline.ve_code_pipeline import VeCodePipeline
34-
from veadk.integrations.ve_faas.ve_faas import VeFaaS
34+
from veadk.integrations.ve_faas.ve_faas import PENDING_PUBLIC_URL, VeFaaS
3535
from veadk.utils.cloud_provider import (
3636
CloudProvider,
3737
agentkit_openapi_base,
@@ -470,6 +470,82 @@ def _cookiecutter(*, output_dir: str, extra_context: dict, **_: object) -> None:
470470
assert "No requirements.txt found" in caplog.text
471471

472472

473+
def test_vefaas_update_code_seeds_public_url_before_release(
474+
monkeypatch: pytest.MonkeyPatch,
475+
tmp_path: Path,
476+
) -> None:
477+
project = tmp_path / "agent"
478+
project.mkdir()
479+
(project / "requirements.txt").write_text("requests\n")
480+
service = object.__new__(VeFaaS)
481+
service.find_app_id_by_name = Mock(return_value="application-id")
482+
service._get_application_status = Mock(
483+
return_value=(
484+
"deploy_success",
485+
{
486+
"Result": {
487+
"CloudResource": (
488+
'{"framework":{"function":{"Name":"studio-app-fn",'
489+
'"Id":"function-id"}}}'
490+
)
491+
}
492+
},
493+
)
494+
)
495+
service._replace_application_code_bundle = Mock()
496+
service._release_application = Mock(return_value="https://studio.example")
497+
order: list[str] = []
498+
service.merge_function_envs_and_release = Mock(
499+
side_effect=lambda **kwargs: order.append(
500+
kwargs["extra_envs"]["VEADK_A2A_PUBLIC_URL"]
501+
)
502+
)
503+
service._set_function_min_instance = Mock()
504+
service.ensure_application_route_methods = Mock()
505+
506+
def _cookiecutter(*, output_dir: str, extra_context: dict, **_: object) -> None:
507+
package = Path(output_dir) / str(extra_context["local_dir_name"])
508+
(package / "src" / "agent").mkdir(parents=True)
509+
510+
monkeypatch.setattr(
511+
"veadk.integrations.ve_faas.ve_faas.formatted_timestamp", lambda: "stamp"
512+
)
513+
monkeypatch.setattr(
514+
"veadk.integrations.ve_faas.ve_faas.tempfile.gettempdir",
515+
lambda: str(tmp_path),
516+
)
517+
monkeypatch.setattr(
518+
"veadk.integrations.ve_faas.ve_faas.cookiecutter", _cookiecutter
519+
)
520+
521+
service._update_function_code("studio-app", str(project))
522+
523+
assert order == [PENDING_PUBLIC_URL, "https://studio.example"]
524+
525+
526+
def test_vefaas_update_bundle_seeds_public_url_before_release() -> None:
527+
service = object.__new__(VeFaaS)
528+
service._replace_application_code_bundle = Mock()
529+
service._release_application = Mock(return_value="https://studio.example")
530+
order: list[str] = []
531+
service.merge_function_envs_and_release = Mock(
532+
side_effect=lambda **kwargs: order.append(
533+
kwargs["extra_envs"]["VEADK_A2A_PUBLIC_URL"]
534+
)
535+
)
536+
service._set_function_min_instance = Mock()
537+
service.ensure_application_route_methods = Mock()
538+
539+
result = service.update_application_code_bundle(
540+
application_id="application-id",
541+
function_id="function-id",
542+
path=".",
543+
)
544+
545+
assert result == "https://studio.example"
546+
assert order == [PENDING_PUBLIC_URL]
547+
548+
473549
def test_vefaas_deploy_updates_existing_application_in_place() -> None:
474550
service = object.__new__(VeFaaS)
475551
service.find_app_id_by_name = Mock(return_value="application-id")

‎veadk/a2a/push.py‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,12 @@ def __init__(
7373
self._default_url = default_url
7474
self._token = token
7575

76+
async def initialize(self) -> None:
77+
"""Initialize the wrapped store when it supports initialization."""
78+
initializer = getattr(self._inner, "initialize", None)
79+
if initializer is not None:
80+
await initializer()
81+
7682
async def set_info(
7783
self,
7884
task_id: str,

0 commit comments

Comments
 (0)