Skip to content

Commit d2e175b

Browse files
committed
Adds tests for the pod name
1 parent 8f0eeb9 commit d2e175b

File tree

3 files changed

+34
-13
lines changed

3 files changed

+34
-13
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ bin/
99
dist/
1010
release_assets/
1111

12-
# Ignore temporary folders
12+
# Temporary folders
1313
tmp/
1414
temp/

clients/python/agentic-sandbox-client/agentic_sandbox/sandbox_client.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ def __init__(
8585
self.claim_name: str | None = None
8686
self.sandbox_name: str | None = None
8787
self.pod_name: str | None = None
88+
self.annotations: dict | None = None
8889

8990
try:
9091
config.load_incluster_config()
@@ -168,9 +169,9 @@ def _wait_for_sandbox_ready(self):
168169
"Could not determine sandbox name from sandbox object.")
169170
logging.info(f"Sandbox {self.sandbox_name} is ready.")
170171

171-
annotations = sandbox_object.get(
172+
self.annotations = sandbox_object.get(
172173
'metadata', {}).get('annotations', {})
173-
pod_name = annotations.get(POD_NAME_ANNOTATION)
174+
pod_name = self.annotations.get(POD_NAME_ANNOTATION)
174175
if pod_name:
175176
self.pod_name = pod_name
176177
logging.info(

clients/python/agentic-sandbox-client/test_client.py

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,17 @@
1616
import asyncio
1717
from agentic_sandbox import SandboxClient
1818

19+
POD_NAME_ANNOTATION = "agents.x-k8s.io/pod-name"
20+
1921

2022
async def main(template_name: str, gateway_name: str | None, api_url: str | None, namespace: str, server_port: int):
2123
"""
2224
Tests the Sandbox client by creating a sandbox, running a command,
2325
and then cleaning up.
2426
"""
2527

26-
print(f"--- Starting Sandbox Client Test (Namespace: {namespace}, Port: {server_port}) ---")
28+
print(
29+
f"--- Starting Sandbox Client Test (Namespace: {namespace}, Port: {server_port}) ---")
2730
if gateway_name:
2831
print(f"Mode: Gateway Discovery ({gateway_name})")
2932
elif api_url:
@@ -41,6 +44,20 @@ async def main(template_name: str, gateway_name: str | None, api_url: str | None
4144
server_port=server_port
4245
) as sandbox:
4346

47+
print("\n--- Testing Pod Name Discovery ---")
48+
assert sandbox.annotations is not None, "Sandbox annotations were not stored on the client"
49+
50+
pod_name_annotation = sandbox.annotations.get(POD_NAME_ANNOTATION)
51+
52+
if pod_name_annotation:
53+
print(f"Found pod name from annotation: {pod_name_annotation}")
54+
assert sandbox.pod_name == pod_name_annotation, f"Expected pod_name to be '{pod_name_annotation}', but got '{sandbox.pod_name}'"
55+
print("--- Pod Name Discovery Test Passed (Annotation) ---")
56+
else:
57+
print("Pod name annotation not found, falling back to sandbox name.")
58+
assert sandbox.pod_name == sandbox.sandbox_name, f"Expected pod_name to be '{sandbox.sandbox_name}', but got '{sandbox.pod_name}'"
59+
print("--- Pod Name Discovery Test Passed (Fallback) ---")
60+
4461
print("\n--- Testing Command Execution ---")
4562
command_to_run = "echo 'Hello from the sandbox!'"
4663
print(f"Executing command: '{command_to_run}'")
@@ -97,24 +114,27 @@ async def main(template_name: str, gateway_name: str | None, api_url: str | None
97114
default="python-sandbox-template",
98115
help="The name of the sandbox template to use for the test."
99116
)
100-
117+
101118
# Default is None to allow testing the Port-Forward fallback
102119
parser.add_argument(
103120
"--gateway-name",
104-
default=None,
121+
default=None,
105122
help="The name of the Gateway resource. If omitted, defaults to local port-forward mode."
106123
)
107-
108-
parser.add_argument("--api-url", help="Direct URL to router (e.g. http://localhost:8080)", default=None)
109-
parser.add_argument("--namespace", default="default", help="Namespace to create sandbox in")
110-
parser.add_argument("--server-port", type=int, default=8888, help="Port the sandbox container listens on")
111-
124+
125+
parser.add_argument(
126+
"--api-url", help="Direct URL to router (e.g. http://localhost:8080)", default=None)
127+
parser.add_argument("--namespace", default="default",
128+
help="Namespace to create sandbox in")
129+
parser.add_argument("--server-port", type=int, default=8888,
130+
help="Port the sandbox container listens on")
131+
112132
args = parser.parse_args()
113-
133+
114134
asyncio.run(main(
115135
template_name=args.template_name,
116136
gateway_name=args.gateway_name,
117137
api_url=args.api_url,
118138
namespace=args.namespace,
119139
server_port=args.server_port
120-
))
140+
))

0 commit comments

Comments
 (0)