From dfc2468e45fee640c681e0442da63ae0c8359b5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81rp=C3=A1d=20Csepi?= Date: Wed, 21 Oct 2026 22:57:35 +0200 Subject: [PATCH 1/3] feat: add runtime discovery client (agntcy.dir.runtime.v1) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Árpád Csepi --- CHANGELOG.md | 6 ++ .../agntcy/dir_sdk/client/__init__.py | 3 +- .../agntcy/dir_sdk/client/runtime_client.py | 55 +++++++++++++ .../dir_sdk/client/services/__init__.py | 2 + .../agntcy/dir_sdk/client/services/runtime.py | 44 ++++++++++ .../agntcy/dir_sdk/models/__init__.py | 1 + .../agntcy/dir_sdk/models/runtime_v1.py | 6 ++ .../agntcy/dir_sdk/tests/test_runtime.py | 81 +++++++++++++++++++ uv.lock | 12 +-- 9 files changed, 203 insertions(+), 7 deletions(-) create mode 100644 dir-sdk-python/agntcy/dir_sdk/client/runtime_client.py create mode 100644 dir-sdk-python/agntcy/dir_sdk/client/services/runtime.py create mode 100644 dir-sdk-python/agntcy/dir_sdk/models/runtime_v1.py create mode 100644 dir-sdk-python/agntcy/dir_sdk/tests/test_runtime.py diff --git a/CHANGELOG.md b/CHANGELOG.md index aa9666f..28f8fd7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,12 @@ [agntcy/dir]: https://github.com/agntcy/dir [agntcy/dir-sdk-python]: https://github.com/agntcy/dir-sdk-python +## Unreleased + +### Added + +- `RuntimeClient` for the runtime discovery API (`agntcy.dir.runtime.v1.DiscoveryService`): `get_workload` and `list_workloads` (with all `ListWorkloadsRequest` filters). It connects to dir-runtime's own address, separately from `Client`, so Directory credentials are never sent to it. Models are exposed as `agntcy.dir_sdk.models.runtime_v1`. + ## 1.8.1 (2026-10-21) ### Changed diff --git a/dir-sdk-python/agntcy/dir_sdk/client/__init__.py b/dir-sdk-python/agntcy/dir_sdk/client/__init__.py index 5aff8ec..8c3f1f3 100644 --- a/dir-sdk-python/agntcy/dir_sdk/client/__init__.py +++ b/dir-sdk-python/agntcy/dir_sdk/client/__init__.py @@ -4,5 +4,6 @@ from agntcy.dir_sdk.client.auth.oauth_pkce import OAuthPkceError from agntcy.dir_sdk.client.client import Client from agntcy.dir_sdk.client.config import Config +from agntcy.dir_sdk.client.runtime_client import RuntimeClient -__all__ = ["Client", "Config", "OAuthPkceError"] +__all__ = ["Client", "Config", "OAuthPkceError", "RuntimeClient"] diff --git a/dir-sdk-python/agntcy/dir_sdk/client/runtime_client.py b/dir-sdk-python/agntcy/dir_sdk/client/runtime_client.py new file mode 100644 index 0000000..4f013d6 --- /dev/null +++ b/dir-sdk-python/agntcy/dir_sdk/client/runtime_client.py @@ -0,0 +1,55 @@ +# Copyright AGNTCY Contributors (https://github.com/agntcy) +# SPDX-License-Identifier: Apache-2.0 + +"""Client for the runtime discovery API served by dir-runtime.""" + +from __future__ import annotations + +import logging +from collections.abc import Sequence + +import grpc +from agntcy.dir_sdk.client.services.runtime import RuntimeService +from agntcy.dir_sdk.models import runtime_v1 + +logger = logging.getLogger("agntcy.dir_sdk.runtime") + + +class RuntimeClient: + """Client for ``agntcy.dir.runtime.v1.DiscoveryService``. + + dir-runtime (and ``dirctl daemon``) runs at its own address, so this is + separate from :class:`~agntcy.dir_sdk.client.Client`: the Directory's + credentials, such as the OIDC token, are never sent to it. + """ + + DEFAULT_SERVER_ADDRESS = "localhost:8888" + + def __init__( + self, + server_address: str = DEFAULT_SERVER_ADDRESS, + channel: grpc.Channel | None = None, + ) -> None: + self.server_address = server_address + self.channel = channel or grpc.insecure_channel(server_address) + + # Expose the raw stub for advanced callers. + self.discovery_client = runtime_v1.DiscoveryServiceStub(self.channel) + self.runtime_service = RuntimeService(self.discovery_client, logger) + + def close(self) -> None: + self.channel.close() + + def get_workload( + self, + req: runtime_v1.GetWorkloadRequest, + metadata: Sequence[tuple[str, str]] | None = None, + ) -> runtime_v1.Workload: + return self.runtime_service.get_workload(req, metadata) + + def list_workloads( + self, + req: runtime_v1.ListWorkloadsRequest, + metadata: Sequence[tuple[str, str]] | None = None, + ) -> list[runtime_v1.Workload]: + return self.runtime_service.list_workloads(req, metadata) diff --git a/dir-sdk-python/agntcy/dir_sdk/client/services/__init__.py b/dir-sdk-python/agntcy/dir_sdk/client/services/__init__.py index c1b5668..ab8cf56 100644 --- a/dir-sdk-python/agntcy/dir_sdk/client/services/__init__.py +++ b/dir-sdk-python/agntcy/dir_sdk/client/services/__init__.py @@ -7,6 +7,7 @@ from agntcy.dir_sdk.client.services.identity import IdentityService from agntcy.dir_sdk.client.services.publication import PublicationService from agntcy.dir_sdk.client.services.routing import RoutingService +from agntcy.dir_sdk.client.services.runtime import RuntimeService from agntcy.dir_sdk.client.services.search import SearchService from agntcy.dir_sdk.client.services.signing import SignService from agntcy.dir_sdk.client.services.store import StoreService @@ -17,6 +18,7 @@ "IdentityService", "PublicationService", "RoutingService", + "RuntimeService", "SearchService", "SignService", "StoreService", diff --git a/dir-sdk-python/agntcy/dir_sdk/client/services/runtime.py b/dir-sdk-python/agntcy/dir_sdk/client/services/runtime.py new file mode 100644 index 0000000..42d58d3 --- /dev/null +++ b/dir-sdk-python/agntcy/dir_sdk/client/services/runtime.py @@ -0,0 +1,44 @@ +# Copyright AGNTCY Contributors (https://github.com/agntcy) +# SPDX-License-Identifier: Apache-2.0 + +"""Runtime discovery service wrappers.""" + +from __future__ import annotations + +import logging +from collections.abc import Sequence + +from agntcy.dir_sdk.client.services.base import RpcServiceBase +from agntcy.dir_sdk.models import runtime_v1 + + +class RuntimeService(RpcServiceBase): + def __init__( + self, + discovery_client: runtime_v1.DiscoveryServiceStub, + logger: logging.Logger, + ) -> None: + super().__init__(logger) + self._discovery_client = discovery_client + + def get_workload( + self, + req: runtime_v1.GetWorkloadRequest, + metadata: Sequence[tuple[str, str]] | None = None, + ) -> runtime_v1.Workload: + return self._invoke( + "get_workload", + "Failed to get workload", + lambda: self._discovery_client.GetWorkload(req, metadata=metadata), + ) + + def list_workloads( + self, + req: runtime_v1.ListWorkloadsRequest, + metadata: Sequence[tuple[str, str]] | None = None, + ) -> list[runtime_v1.Workload]: + return self._collect_stream( + "list_workloads", + "Failed to list workloads", + lambda: self._discovery_client.ListWorkloads(req, metadata=metadata), + ) diff --git a/dir-sdk-python/agntcy/dir_sdk/models/__init__.py b/dir-sdk-python/agntcy/dir_sdk/models/__init__.py index 158ecb4..2acd8d5 100644 --- a/dir-sdk-python/agntcy/dir_sdk/models/__init__.py +++ b/dir-sdk-python/agntcy/dir_sdk/models/__init__.py @@ -8,6 +8,7 @@ from . import events_v1 as events_v1 from . import identity_v1 as identity_v1 from . import routing_v1 as routing_v1 +from . import runtime_v1 as runtime_v1 from . import search_v1 as search_v1 from . import sign_v1 as sign_v1 from . import store_v1 as store_v1 diff --git a/dir-sdk-python/agntcy/dir_sdk/models/runtime_v1.py b/dir-sdk-python/agntcy/dir_sdk/models/runtime_v1.py new file mode 100644 index 0000000..5206586 --- /dev/null +++ b/dir-sdk-python/agntcy/dir_sdk/models/runtime_v1.py @@ -0,0 +1,6 @@ +# Copyright AGNTCY Contributors (https://github.com/agntcy) +# SPDX-License-Identifier: Apache-2.0 + +from agntcy.dir.runtime.v1.discovery_service_pb2 import * +from agntcy.dir.runtime.v1.discovery_service_pb2_grpc import * +from agntcy.dir.runtime.v1.workload_pb2 import * diff --git a/dir-sdk-python/agntcy/dir_sdk/tests/test_runtime.py b/dir-sdk-python/agntcy/dir_sdk/tests/test_runtime.py new file mode 100644 index 0000000..f425549 --- /dev/null +++ b/dir-sdk-python/agntcy/dir_sdk/tests/test_runtime.py @@ -0,0 +1,81 @@ +# Copyright AGNTCY Contributors (https://github.com/agntcy) +# SPDX-License-Identifier: Apache-2.0 + +"""Tests for the runtime discovery client against an in-process server.""" + +from __future__ import annotations + +import unittest +from collections.abc import Iterator +from concurrent import futures + +import grpc +from agntcy.dir_sdk.client import RuntimeClient +from agntcy.dir_sdk.models import runtime_v1 + +WORKLOADS = [ + runtime_v1.Workload( + id="a", + runtime="docker", + locators=[ + runtime_v1.WorkloadLocator(protocol="http", url="http://10.0.0.1:80") + ], + ), + runtime_v1.Workload(id="b", runtime="kubernetes"), +] + + +class FakeDiscovery(runtime_v1.DiscoveryServiceServicer): + """In-process dir-runtime; applies only the runtime_types filter.""" + + def GetWorkload( # noqa: N802 + self, + request: runtime_v1.GetWorkloadRequest, + context: grpc.ServicerContext, + ) -> runtime_v1.Workload: + for w in WORKLOADS: + if w.id == request.id: + return w + context.abort(grpc.StatusCode.NOT_FOUND, request.id) + raise AssertionError # abort() raises; unreachable + + def ListWorkloads( # noqa: N802 + self, + request: runtime_v1.ListWorkloadsRequest, + _context: grpc.ServicerContext, + ) -> Iterator[runtime_v1.Workload]: + for w in WORKLOADS: + if not request.runtime_types or w.runtime in request.runtime_types: + yield w + + +class TestRuntimeClient(unittest.TestCase): + def setUp(self) -> None: + self.server = grpc.server(futures.ThreadPoolExecutor(max_workers=2)) + runtime_v1.add_DiscoveryServiceServicer_to_server(FakeDiscovery(), self.server) + port = self.server.add_insecure_port("127.0.0.1:0") + self.server.start() + self.client = RuntimeClient(f"127.0.0.1:{port}") + + def tearDown(self) -> None: + self.client.close() + self.server.stop(None) + + def test_list_workloads_with_filters(self) -> None: + everything = self.client.list_workloads(runtime_v1.ListWorkloadsRequest()) + assert [w.id for w in everything] == ["a", "b"] + + docker = self.client.list_workloads( + runtime_v1.ListWorkloadsRequest(runtime_types=["docker"]) + ) + assert len(docker) == 1 + assert docker[0].locators[0].url == "http://10.0.0.1:80" + + def test_get_workload(self) -> None: + w = self.client.get_workload(runtime_v1.GetWorkloadRequest(id="b")) + assert w.runtime == "kubernetes" + + def test_get_workload_not_found(self) -> None: + with self.assertRaises(grpc.RpcError) as ctx: + self.client.get_workload(runtime_v1.GetWorkloadRequest(id="missing")) + assert ctx.exception.code() == grpc.StatusCode.NOT_FOUND diff --git a/uv.lock b/uv.lock index adf51e2..3a5a86b 100644 --- a/uv.lock +++ b/uv.lock @@ -1,5 +1,5 @@ version = 1 -revision = 5 +revision = 3 requires-python = ">=3.10" resolution-markers = [ "python_full_version >= '3.15'", @@ -78,7 +78,7 @@ wheels = [ [[package]] name = "agntcy-dir-protocolbuffers-pyi" -version = "36.2.0.1.20261006085230+1106da22f446" +version = "36.2.0.1.20261021152154+2602649e5543" source = { registry = "https://buf.build/gen/python" } dependencies = [ { name = "bufbuild-protovalidate-protocolbuffers-pyi" }, @@ -87,7 +87,7 @@ dependencies = [ { name = "types-protobuf" }, ] wheels = [ - { url = "https://buf.build/gen/python/agntcy-dir-protocolbuffers-pyi/agntcy_dir_protocolbuffers_pyi-36.2.0.1.20261006085230+1106da22f446-py3-none-any.whl", upload-time = "2026-10-06T08:52:30Z" }, + { url = "https://buf.build/gen/python/agntcy-dir-protocolbuffers-pyi/agntcy_dir_protocolbuffers_pyi-36.2.0.1.20261021152154+2602649e5543-py3-none-any.whl", upload-time = "2026-10-21T15:21:54Z" }, ] [[package]] @@ -707,7 +707,7 @@ name = "exceptiongroup" version = "1.3.1" source = { registry = "https://pypi.org/simple" } dependencies = [ - { name = "typing-extensions" }, + { name = "typing-extensions", marker = "python_full_version < '3.11'" }, ] sdist = { url = "https://files.pythonhosted.org/packages/50/79/66800aadf48771f6b62f7eb014e352e5d06856655206165d775e675a02c9/exceptiongroup-1.3.1.tar.gz", hash = "sha256:8b412432c6055b0b7d14c310000ae93352ed6754f70fa8f7c34141f91c4e3219", size = 30371, upload-time = "2025-11-21T23:01:54.787Z" } wheels = [ @@ -728,14 +728,14 @@ wheels = [ [[package]] name = "googleapis-googleapis-protocolbuffers-pyi" -version = "36.2.0.1.20260414192239+c17df5b2beca" +version = "36.2.0.1.20261015202054+8ac61b9e5023" source = { registry = "https://buf.build/gen/python" } dependencies = [ { name = "protobuf" }, { name = "types-protobuf" }, ] wheels = [ - { url = "https://buf.build/gen/python/googleapis-googleapis-protocolbuffers-pyi/googleapis_googleapis_protocolbuffers_pyi-36.2.0.1.20260414192239+c17df5b2beca-py3-none-any.whl", upload-time = "2026-09-19T01:44:49Z" }, + { url = "https://buf.build/gen/python/googleapis-googleapis-protocolbuffers-pyi/googleapis_googleapis_protocolbuffers_pyi-36.2.0.1.20261015202054+8ac61b9e5023-py3-none-any.whl", upload-time = "2026-10-15T20:20:54Z" }, ] [[package]] From 081cb7077d98b348cffde43157693ca1bef4c8a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81rp=C3=A1d=20Csepi?= Date: Wed, 21 Oct 2026 23:02:28 +0200 Subject: [PATCH 2/3] test: add runtime discovery E2E test against dirctl daemon MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Árpád Csepi --- Taskfile.yml | 10 ++ .../agntcy/dir_sdk/tests/test_runtime_e2e.py | 91 +++++++++++++++++++ tests/runtime-e2e/daemon.config.yaml | 67 ++++++++++++++ tests/runtime-e2e/run.sh | 60 ++++++++++++ 4 files changed, 228 insertions(+) create mode 100644 dir-sdk-python/agntcy/dir_sdk/tests/test_runtime_e2e.py create mode 100644 tests/runtime-e2e/daemon.config.yaml create mode 100755 tests/runtime-e2e/run.sh diff --git a/Taskfile.yml b/Taskfile.yml index 75dc48f..b03186c 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -66,6 +66,16 @@ tasks: cmds: - task: test-env:deploy:cleanup + test:runtime: + desc: Run the runtime discovery E2E test against a local `dirctl daemon` and a labelled Docker container + deps: + - task: deps:dirctl + - task: deps:uv + preconditions: + - which docker + cmds: + - tests/runtime-e2e/run.sh "${DIRCTL_PATH:-{{ .DIRCTL_BIN }}}" '{{ .UV_BIN }}' run pytest dir-sdk-python/agntcy/dir_sdk/tests/test_runtime_e2e.py -v + test: desc: Test python client SDK package deps: diff --git a/dir-sdk-python/agntcy/dir_sdk/tests/test_runtime_e2e.py b/dir-sdk-python/agntcy/dir_sdk/tests/test_runtime_e2e.py new file mode 100644 index 0000000..c8bf94d --- /dev/null +++ b/dir-sdk-python/agntcy/dir_sdk/tests/test_runtime_e2e.py @@ -0,0 +1,91 @@ +# Copyright AGNTCY Contributors (https://github.com/agntcy) +# SPDX-License-Identifier: Apache-2.0 + +"""End-to-end tests of the runtime discovery client. + +They run against a real ``dirctl daemon`` that discovers a labelled Docker +container, and skip unless ``DIRECTORY_RUNTIME_ADDRESS`` is set. Run them with +``task test:runtime``, which starts the daemon and the container. +""" + +from __future__ import annotations + +import os +import time +import unittest + +import grpc +from agntcy.dir_sdk.client import RuntimeClient +from agntcy.dir_sdk.models import runtime_v1 + +ADDRESS = os.environ.get("DIRECTORY_RUNTIME_ADDRESS", "") +NAME = os.environ.get("RUNTIME_E2E_WORKLOAD_NAME", "") +LABELS = {"sdk.agntcy/discover": "true"} + + +@unittest.skipUnless(ADDRESS, "DIRECTORY_RUNTIME_ADDRESS not set") +class TestRuntimeE2E(unittest.TestCase): + def setUp(self) -> None: + self.client = RuntimeClient(ADDRESS) + + def tearDown(self) -> None: + self.client.close() + + def _list( + self, + labels: dict[str, str] | None = None, + runtime_types: list[str] | None = None, + locator_protocols: list[str] | None = None, + ) -> list[runtime_v1.Workload]: + return self.client.list_workloads( + runtime_v1.ListWorkloadsRequest( + labels=LABELS if labels is None else labels, + runtime_types=runtime_types, + locator_protocols=locator_protocols, + ) + ) + + def _discovered(self) -> runtime_v1.Workload: + deadline = time.monotonic() + 60 + while time.monotonic() < deadline: + for w in self._list(): + if w.name == NAME: + return w + time.sleep(2) + self.fail(f"workload {NAME} was never discovered") + + def _matches( + self, + labels: dict[str, str] | None = None, + runtime_types: list[str] | None = None, + locator_protocols: list[str] | None = None, + ) -> bool: + listed = self._list(labels, runtime_types, locator_protocols) + return any(w.name == NAME for w in listed) + + def test_lists_and_gets_the_discovered_workload(self) -> None: + listed = self._discovered() + assert listed.runtime == "docker" + assert listed.type == "container" + assert listed.labels["sdk.agntcy/agent-type"] == "a2a" + assert any( + loc.protocol == "tcp" and loc.url.startswith("tcp://") + for loc in listed.locators + ) + + got = self.client.get_workload(runtime_v1.GetWorkloadRequest(id=listed.id)) + assert got.id == listed.id + assert got.name == NAME + + def test_filters_narrow_the_result(self) -> None: + self._discovered() + assert self._matches(runtime_types=["docker"]) + assert self._matches(locator_protocols=["tcp"]) + assert not self._matches(runtime_types=["kubernetes"]) + assert not self._matches(locator_protocols=["slim"]) + assert not self._matches(labels={"sdk.agntcy/discover": "false"}) + + def test_unknown_workload_fails(self) -> None: + with self.assertRaises(grpc.RpcError) as ctx: + self.client.get_workload(runtime_v1.GetWorkloadRequest(id="does-not-exist")) + assert "workload not found" in str(ctx.exception.details()) diff --git a/tests/runtime-e2e/daemon.config.yaml b/tests/runtime-e2e/daemon.config.yaml new file mode 100644 index 0000000..fe21d0f --- /dev/null +++ b/tests/runtime-e2e/daemon.config.yaml @@ -0,0 +1,67 @@ +# Copyright AGNTCY Contributors (https://github.com/agntcy) +# SPDX-License-Identifier: Apache-2.0 + +# Minimal `dirctl daemon` configuration for the runtime discovery E2E test. +# Everything except runtime discovery is switched off, and the ports differ +# from the defaults so it can run next to a regular Directory node. +# Only containers labelled `sdk.agntcy/discover` are discovered. + +server: + listen_address: "localhost:18888" + store: + provider: "oci" + oci: + local_dir: "store" + registry_address: "localhost:15555" + repository_name: "dir" + auth_config: + insecure: true + routing: + listen_address: "/ip4/127.0.0.1/tcp/18999" + key_path: "node.key" + datastore_dir: "routing" + gossipsub: + enabled: false + database: + type: "sqlite" + sqlite: + path: "dir.db" + publication: + scheduler_interval: 5m + worker_count: 1 + worker_timeout: 30m + http_gateway: + enabled: false + policy: + validators: [] +reconciler: + regsync: {enabled: false} + metrics: {enabled: false} + indexer: {enabled: false} + signature: {enabled: false} + identity: {enabled: false} + scan: {enabled: false} + record_events: {enabled: false} + local_registry: + registry_address: "localhost:15555" + repository_name: "dir" + auth_config: + insecure: true + database: + type: "sqlite" + sqlite: + path: "dir.db" +runtime: + enabled: true + adapter: + type: "docker" + docker: + host: "unix:///var/run/docker.sock" + label_key: "sdk.agntcy/discover" + resolver: + a2a: + enabled: true + label_key: "sdk.agntcy/agent-type" + oasf: {enabled: false} + store: + type: "sqlite" diff --git a/tests/runtime-e2e/run.sh b/tests/runtime-e2e/run.sh new file mode 100755 index 0000000..3dc4717 --- /dev/null +++ b/tests/runtime-e2e/run.sh @@ -0,0 +1,60 @@ +#!/usr/bin/env bash +# Copyright AGNTCY Contributors (https://github.com/agntcy) +# SPDX-License-Identifier: Apache-2.0 + +# Runs a command against a throwaway `dirctl daemon` (runtime discovery on, +# Docker adapter) and a labelled container it discovers. +# +# Usage: run.sh [args...] +# +# The command gets DIRECTORY_RUNTIME_ADDRESS (the daemon's address) and +# RUNTIME_E2E_WORKLOAD_NAME (the name of the container to expect). + +set -euo pipefail + +if [ "$#" -lt 2 ]; then + echo "usage: $0 [args...]" >&2 + exit 2 +fi + +DIRCTL="$1" +shift + +HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +DATA_DIR="$(mktemp -d)" +WORKLOAD_NAME="sdk-runtime-e2e-$$" +DAEMON_LOG="${DATA_DIR}/daemon.log" + +cleanup() { + docker rm -f "${WORKLOAD_NAME}" >/dev/null 2>&1 || true + "${DIRCTL}" daemon stop --data-dir "${DATA_DIR}" >/dev/null 2>&1 || true + rm -rf "${DATA_DIR}" +} +trap cleanup EXIT + +cp "${HERE}/daemon.config.yaml" "${DATA_DIR}/daemon.config.yaml" +"${DIRCTL}" daemon start --data-dir "${DATA_DIR}" --config "${DATA_DIR}/daemon.config.yaml" >"${DAEMON_LOG}" 2>&1 & + +ready() { + "${DIRCTL}" daemon status --data-dir "${DATA_DIR}" 2>&1 | grep -q "Daemon is running" && + (exec 3<>/dev/tcp/127.0.0.1/18888) 2>/dev/null +} + +for _ in $(seq 1 60); do + ready && break + sleep 1 +done +if ! ready; then + echo "daemon did not start:" >&2 + cat "${DAEMON_LOG}" >&2 + exit 1 +fi + +docker run -d --name "${WORKLOAD_NAME}" \ + --label sdk.agntcy/discover=true \ + --label sdk.agntcy/agent-type=a2a \ + -p 80 nginx:alpine >/dev/null + +export DIRECTORY_RUNTIME_ADDRESS="localhost:18888" +export RUNTIME_E2E_WORKLOAD_NAME="${WORKLOAD_NAME}" +"$@" From c027ef89cd3e187d4cef2615048d3dc39f20c3bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81rp=C3=A1d=20Csepi?= Date: Wed, 21 Oct 2026 23:19:17 +0200 Subject: [PATCH 3/3] test: run runtime discovery E2E against dir-runtime in kind MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replace the dirctl daemon based E2E setup: deploy dir-runtime (Helm chart from the dir-runtime release) and a labelled pod into the kind cluster used by 'task test'. The server image is built from source because the published dir-runtime-server image ships the discovery binary. Signed-off-by: Árpád Csepi --- Taskfile.yml | 63 ++++++++++++++--- .../agntcy/dir_sdk/tests/test_runtime_e2e.py | 22 +++--- tests/runtime-e2e/daemon.config.yaml | 67 ------------------- tests/runtime-e2e/run.sh | 60 ----------------- tests/runtime-e2e/workload.yaml | 18 +++++ 5 files changed, 81 insertions(+), 149 deletions(-) delete mode 100644 tests/runtime-e2e/daemon.config.yaml delete mode 100755 tests/runtime-e2e/run.sh create mode 100644 tests/runtime-e2e/workload.yaml diff --git a/Taskfile.yml b/Taskfile.yml index b03186c..4e75d6c 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -41,6 +41,12 @@ vars: KIND_CLUSTER_NAME: "sdk-py-test" + # dir-runtime serves the runtime discovery API (agntcy.dir.runtime.v1) on its own address. + # renovate: datasource=github-releases depName=agntcy/dir-runtime versioning=semver + RUNTIME_VERSION: '{{ .RUNTIME_VERSION | default "v1.5.0" }}' + RUNTIME_API_HOSTPORT: '{{ .RUNTIME_API_HOSTPORT | default "18888" }}' + RUNTIME_API_NODEPORT: '{{ .RUNTIME_API_NODEPORT | default "30180" }}' + tasks: # --------------------------------------------------------------------------- # SDK tasks (top-level, user-facing) @@ -66,16 +72,6 @@ tasks: cmds: - task: test-env:deploy:cleanup - test:runtime: - desc: Run the runtime discovery E2E test against a local `dirctl daemon` and a labelled Docker container - deps: - - task: deps:dirctl - - task: deps:uv - preconditions: - - which docker - cmds: - - tests/runtime-e2e/run.sh "${DIRCTL_PATH:-{{ .DIRCTL_BIN }}}" '{{ .UV_BIN }}' run pytest dir-sdk-python/agntcy/dir_sdk/tests/test_runtime_e2e.py -v - test: desc: Test python client SDK package deps: @@ -86,6 +82,8 @@ tasks: - | export COSIGN_PATH="$(printf "%s" "${COSIGN_PATH:-{{ .COSIGN_BIN }}}")" export DIRCTL_PATH="$(printf "%s" "${DIRCTL_PATH:-{{ .DIRCTL_BIN }}}")" + export DIRECTORY_RUNTIME_ADDRESS="localhost:{{ .RUNTIME_API_HOSTPORT }}" + export RUNTIME_E2E_WORKLOAD_NAME="sdk-runtime-e2e" # Run SDK tests '{{ .UV_BIN }}' run pytest \ @@ -220,7 +218,7 @@ tasks: deps: - task: test-env:setup-cluster vars: - KIND_EXTRA_PORT_MAPPING: "{{.API_HOSTPORT}}:{{.API_NODEPORT}},{{.METRICS_HOSTPORT}}:{{.METRICS_NODEPORT}}" + KIND_EXTRA_PORT_MAPPING: "{{.API_HOSTPORT}}:{{.API_NODEPORT}},{{.METRICS_HOSTPORT}}:{{.METRICS_NODEPORT}},{{.RUNTIME_API_HOSTPORT}}:{{.RUNTIME_API_NODEPORT}}" vars: # Kind args KIND_CLUSTER_NAME: '{{ .KIND_CLUSTER_NAME | default "sdk-py-test" }}' @@ -280,6 +278,49 @@ tasks: --wait-for-jobs \ --timeout "15m" + # Deploy dir-runtime and the workload it discovers + - task: test-env:runtime:deploy + + test-env:runtime:deploy: + desc: Deploy dir-runtime and a labelled workload for the runtime discovery E2E tests + deps: + - deps:helm + - deps:kubectl + - deps:kind + vars: + KIND_CLUSTER_NAME: '{{ .KIND_CLUSTER_NAME | default "sdk-py-test" }}' + preconditions: + - which docker + - which curl + cmds: + - | + set -euo pipefail + SRC="$(mktemp -d)" + trap 'rm -rf "$SRC"' EXIT + curl -sfL "https://github.com/agntcy/dir-runtime/archive/refs/tags/{{ .RUNTIME_VERSION }}.tar.gz" | tar -xz -C "$SRC" --strip-components=1 + + # The published dir-runtime-server image contains the discovery binary + # (same digest as dir-runtime-discovery), so build the server from source. + docker build -q -f "$SRC/server/Dockerfile" --target production -t dir-runtime-server:sdk-e2e "$SRC" + {{ .KIND_BIN }} load docker-image dir-runtime-server:sdk-e2e --name {{ .KIND_CLUSTER_NAME }} + + {{ .HELM_BIN }} install runtime "$SRC/install/chart" \ + --namespace dir-runtime \ + --create-namespace \ + --set discovery.image.tag="{{ trimPrefix "v" .RUNTIME_VERSION }}" \ + --set server.image.repository=dir-runtime-server \ + --set server.image.tag=sdk-e2e \ + --set server.image.pullPolicy=Never \ + --set discovery.config.store.crd.namespace=dir-runtime \ + --set server.config.store.crd.namespace=dir-runtime \ + --set server.service.type=NodePort \ + --set server.service.nodePort="{{ .RUNTIME_API_NODEPORT }}" \ + --wait \ + --timeout "5m" + + {{ .KUBECTL_BIN }} apply -f "{{ .ROOT_DIR }}/tests/runtime-e2e/workload.yaml" + {{ .KUBECTL_BIN }} wait --for=condition=Ready pod/sdk-runtime-e2e --timeout=2m + test-env:deploy:cleanup: desc: Cleanup Kubernetes environment for local deployment deps: diff --git a/dir-sdk-python/agntcy/dir_sdk/tests/test_runtime_e2e.py b/dir-sdk-python/agntcy/dir_sdk/tests/test_runtime_e2e.py index c8bf94d..3f014c5 100644 --- a/dir-sdk-python/agntcy/dir_sdk/tests/test_runtime_e2e.py +++ b/dir-sdk-python/agntcy/dir_sdk/tests/test_runtime_e2e.py @@ -3,9 +3,10 @@ """End-to-end tests of the runtime discovery client. -They run against a real ``dirctl daemon`` that discovers a labelled Docker -container, and skip unless ``DIRECTORY_RUNTIME_ADDRESS`` is set. Run them with -``task test:runtime``, which starts the daemon and the container. +They run against a real dir-runtime that discovers a labelled pod, and skip +unless ``DIRECTORY_RUNTIME_ADDRESS`` is set. ``task test`` sets it after +deploying dir-runtime and the pod (``tests/runtime-e2e/workload.yaml``) to the +kind cluster. """ from __future__ import annotations @@ -20,7 +21,7 @@ ADDRESS = os.environ.get("DIRECTORY_RUNTIME_ADDRESS", "") NAME = os.environ.get("RUNTIME_E2E_WORKLOAD_NAME", "") -LABELS = {"sdk.agntcy/discover": "true"} +LABELS = {"org.agntcy/discover": "true"} @unittest.skipUnless(ADDRESS, "DIRECTORY_RUNTIME_ADDRESS not set") @@ -65,9 +66,8 @@ def _matches( def test_lists_and_gets_the_discovered_workload(self) -> None: listed = self._discovered() - assert listed.runtime == "docker" - assert listed.type == "container" - assert listed.labels["sdk.agntcy/agent-type"] == "a2a" + assert listed.runtime == "kubernetes" + assert listed.type == "pod" assert any( loc.protocol == "tcp" and loc.url.startswith("tcp://") for loc in listed.locators @@ -79,13 +79,13 @@ def test_lists_and_gets_the_discovered_workload(self) -> None: def test_filters_narrow_the_result(self) -> None: self._discovered() - assert self._matches(runtime_types=["docker"]) + assert self._matches(runtime_types=["KUBERNETES"]) assert self._matches(locator_protocols=["tcp"]) - assert not self._matches(runtime_types=["kubernetes"]) + assert not self._matches(runtime_types=["docker"]) assert not self._matches(locator_protocols=["slim"]) - assert not self._matches(labels={"sdk.agntcy/discover": "false"}) + assert not self._matches(labels={"org.agntcy/discover": "false"}) def test_unknown_workload_fails(self) -> None: with self.assertRaises(grpc.RpcError) as ctx: self.client.get_workload(runtime_v1.GetWorkloadRequest(id="does-not-exist")) - assert "workload not found" in str(ctx.exception.details()) + assert "not found" in str(ctx.exception.details()) diff --git a/tests/runtime-e2e/daemon.config.yaml b/tests/runtime-e2e/daemon.config.yaml deleted file mode 100644 index fe21d0f..0000000 --- a/tests/runtime-e2e/daemon.config.yaml +++ /dev/null @@ -1,67 +0,0 @@ -# Copyright AGNTCY Contributors (https://github.com/agntcy) -# SPDX-License-Identifier: Apache-2.0 - -# Minimal `dirctl daemon` configuration for the runtime discovery E2E test. -# Everything except runtime discovery is switched off, and the ports differ -# from the defaults so it can run next to a regular Directory node. -# Only containers labelled `sdk.agntcy/discover` are discovered. - -server: - listen_address: "localhost:18888" - store: - provider: "oci" - oci: - local_dir: "store" - registry_address: "localhost:15555" - repository_name: "dir" - auth_config: - insecure: true - routing: - listen_address: "/ip4/127.0.0.1/tcp/18999" - key_path: "node.key" - datastore_dir: "routing" - gossipsub: - enabled: false - database: - type: "sqlite" - sqlite: - path: "dir.db" - publication: - scheduler_interval: 5m - worker_count: 1 - worker_timeout: 30m - http_gateway: - enabled: false - policy: - validators: [] -reconciler: - regsync: {enabled: false} - metrics: {enabled: false} - indexer: {enabled: false} - signature: {enabled: false} - identity: {enabled: false} - scan: {enabled: false} - record_events: {enabled: false} - local_registry: - registry_address: "localhost:15555" - repository_name: "dir" - auth_config: - insecure: true - database: - type: "sqlite" - sqlite: - path: "dir.db" -runtime: - enabled: true - adapter: - type: "docker" - docker: - host: "unix:///var/run/docker.sock" - label_key: "sdk.agntcy/discover" - resolver: - a2a: - enabled: true - label_key: "sdk.agntcy/agent-type" - oasf: {enabled: false} - store: - type: "sqlite" diff --git a/tests/runtime-e2e/run.sh b/tests/runtime-e2e/run.sh deleted file mode 100755 index 3dc4717..0000000 --- a/tests/runtime-e2e/run.sh +++ /dev/null @@ -1,60 +0,0 @@ -#!/usr/bin/env bash -# Copyright AGNTCY Contributors (https://github.com/agntcy) -# SPDX-License-Identifier: Apache-2.0 - -# Runs a command against a throwaway `dirctl daemon` (runtime discovery on, -# Docker adapter) and a labelled container it discovers. -# -# Usage: run.sh [args...] -# -# The command gets DIRECTORY_RUNTIME_ADDRESS (the daemon's address) and -# RUNTIME_E2E_WORKLOAD_NAME (the name of the container to expect). - -set -euo pipefail - -if [ "$#" -lt 2 ]; then - echo "usage: $0 [args...]" >&2 - exit 2 -fi - -DIRCTL="$1" -shift - -HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" -DATA_DIR="$(mktemp -d)" -WORKLOAD_NAME="sdk-runtime-e2e-$$" -DAEMON_LOG="${DATA_DIR}/daemon.log" - -cleanup() { - docker rm -f "${WORKLOAD_NAME}" >/dev/null 2>&1 || true - "${DIRCTL}" daemon stop --data-dir "${DATA_DIR}" >/dev/null 2>&1 || true - rm -rf "${DATA_DIR}" -} -trap cleanup EXIT - -cp "${HERE}/daemon.config.yaml" "${DATA_DIR}/daemon.config.yaml" -"${DIRCTL}" daemon start --data-dir "${DATA_DIR}" --config "${DATA_DIR}/daemon.config.yaml" >"${DAEMON_LOG}" 2>&1 & - -ready() { - "${DIRCTL}" daemon status --data-dir "${DATA_DIR}" 2>&1 | grep -q "Daemon is running" && - (exec 3<>/dev/tcp/127.0.0.1/18888) 2>/dev/null -} - -for _ in $(seq 1 60); do - ready && break - sleep 1 -done -if ! ready; then - echo "daemon did not start:" >&2 - cat "${DAEMON_LOG}" >&2 - exit 1 -fi - -docker run -d --name "${WORKLOAD_NAME}" \ - --label sdk.agntcy/discover=true \ - --label sdk.agntcy/agent-type=a2a \ - -p 80 nginx:alpine >/dev/null - -export DIRECTORY_RUNTIME_ADDRESS="localhost:18888" -export RUNTIME_E2E_WORKLOAD_NAME="${WORKLOAD_NAME}" -"$@" diff --git a/tests/runtime-e2e/workload.yaml b/tests/runtime-e2e/workload.yaml new file mode 100644 index 0000000..1ab822a --- /dev/null +++ b/tests/runtime-e2e/workload.yaml @@ -0,0 +1,18 @@ +# Copyright AGNTCY Contributors (https://github.com/agntcy) +# SPDX-License-Identifier: Apache-2.0 + +# Workload the runtime discovery E2E tests expect dir-runtime to discover: +# dir-runtime's Kubernetes adapter picks up pods labelled org.agntcy/discover. +apiVersion: v1 +kind: Pod +metadata: + name: sdk-runtime-e2e + namespace: default + labels: + org.agntcy/discover: "true" +spec: + containers: + - name: web + image: nginx:alpine + ports: + - containerPort: 80