1616import asyncio
1717from agentic_sandbox import SandboxClient
1818
19+ POD_NAME_ANNOTATION = "agents.x-k8s.io/pod-name"
20+
1921
2022async 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