From 21701a0d8af5a0903610dfcd6763178130d625b6 Mon Sep 17 00:00:00 2001 From: GitHub Copilot Date: Thu, 22 Jan 2026 18:06:57 +0000 Subject: [PATCH 1/2] cognitiveservices agent: add status command --- .../cli/command_modules/cognitiveservices/_help.py | 12 ++++++++++++ .../cli/command_modules/cognitiveservices/_params.py | 7 +++++++ .../command_modules/cognitiveservices/commands.py | 1 + .../cli/command_modules/cognitiveservices/custom.py | 11 +++++++++++ 4 files changed, 31 insertions(+) diff --git a/src/azure-cli/azure/cli/command_modules/cognitiveservices/_help.py b/src/azure-cli/azure/cli/command_modules/cognitiveservices/_help.py index 59f09be6d5d..cbe6292fdca 100644 --- a/src/azure-cli/azure/cli/command_modules/cognitiveservices/_help.py +++ b/src/azure-cli/azure/cli/command_modules/cognitiveservices/_help.py @@ -657,6 +657,18 @@ text: az cognitiveservices agent stop --account-name myAccount --project-name myProject --name myAgent --agent-version 1 """ +helps[ + "cognitiveservices agent status" +] = """ +type: command +short-summary: Get the status of a hosted agent deployment. +long-summary: | + Calls the agent container status endpoint and returns the raw service payload. +examples: + - name: Get hosted agent deployment status. + text: az cognitiveservices agent status --account-name myAccount --project-name myProject --name myAgent --agent-version 1 +""" + helps[ "cognitiveservices agent update" ] = """ diff --git a/src/azure-cli/azure/cli/command_modules/cognitiveservices/_params.py b/src/azure-cli/azure/cli/command_modules/cognitiveservices/_params.py index efc3cf77da0..075b538aea7 100644 --- a/src/azure-cli/azure/cli/command_modules/cognitiveservices/_params.py +++ b/src/azure-cli/azure/cli/command_modules/cognitiveservices/_params.py @@ -387,6 +387,13 @@ def load_arguments(self, _): ) c.argument("agent_version", help="Cognitive Services hosted agent version") + with self.argument_context("cognitiveservices agent status") as c: + c.argument( + "agent_version", + help="Cognitive Services hosted agent version", + required=True, + ) + with self.argument_context('cognitiveservices agent create') as c: c.argument( 'agent_name', diff --git a/src/azure-cli/azure/cli/command_modules/cognitiveservices/commands.py b/src/azure-cli/azure/cli/command_modules/cognitiveservices/commands.py index 3432cd5f514..2d0601598ab 100644 --- a/src/azure-cli/azure/cli/command_modules/cognitiveservices/commands.py +++ b/src/azure-cli/azure/cli/command_modules/cognitiveservices/commands.py @@ -124,6 +124,7 @@ def load_command_table(self, _): g.custom_command('update', 'agent_update') g.custom_command('stop', 'agent_stop') g.custom_command('start', 'agent_start') + g.custom_show_command('status', 'agent_status') g.custom_command('delete-deployment', 'agent_delete_deployment') g.custom_command('delete', 'agent_delete') g.custom_command('list', 'agent_list') diff --git a/src/azure-cli/azure/cli/command_modules/cognitiveservices/custom.py b/src/azure-cli/azure/cli/command_modules/cognitiveservices/custom.py index 9db5eb1c7ff..314af448878 100644 --- a/src/azure-cli/azure/cli/command_modules/cognitiveservices/custom.py +++ b/src/azure-cli/azure/cli/command_modules/cognitiveservices/custom.py @@ -1393,6 +1393,17 @@ def agent_show( return response.json() +def agent_status( + client, + account_name, + project_name, + agent_name, + agent_version, +): # pylint: disable=unused-argument + """Get the status of a hosted agent deployment (default container).""" + return _get_agent_container_status(client, agent_name, agent_version) + + def _get_resource_group_by_account_name(cmd, account_name): """ Get resource group name for a Cognitive Services account by querying ARM. From 5f4caad5890771fc752259dbd875bdf45f53dedf Mon Sep 17 00:00:00 2001 From: Zhidong Zhu Date: Fri, 23 Jan 2026 03:17:34 +0000 Subject: [PATCH 2/2] test: add unit coverage for agent status --- .../tests/latest/test_agent.py | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/azure-cli/azure/cli/command_modules/cognitiveservices/tests/latest/test_agent.py b/src/azure-cli/azure/cli/command_modules/cognitiveservices/tests/latest/test_agent.py index 534545e2801..521307372cd 100644 --- a/src/azure-cli/azure/cli/command_modules/cognitiveservices/tests/latest/test_agent.py +++ b/src/azure-cli/azure/cli/command_modules/cognitiveservices/tests/latest/test_agent.py @@ -39,6 +39,8 @@ import os import tempfile import shutil +from unittest import mock +from urllib.parse import urlparse, parse_qs from azure.cli.testsdk import ScenarioTest, ResourceGroupPreparer from azure.cli.testsdk.decorators import serial_test @@ -55,12 +57,42 @@ _is_docker_running, _is_fully_qualified_image, _validate_path_for_subprocess, + _get_agent_container_status, + AGENT_API_VERSION_PARAMS, ) from azure.cli.command_modules.cognitiveservices._params import _environment_variables_type class CognitiveServicesAgentHelperTests(unittest.TestCase): """Unit tests for agent helper functions.""" + + def test_get_agent_container_status_builds_expected_request(self): + """Test that agent status calls the default container endpoint and returns payload.""" + expected_payload = {"status": "Running"} + + client = mock.Mock() + response = mock.Mock() + response.json.return_value = expected_payload + client.send_request.return_value = response + + result = _get_agent_container_status(client, "myAgent", "10") + + self.assertEqual(result, expected_payload) + client.send_request.assert_called_once() + response.raise_for_status.assert_called_once() + + request = client.send_request.call_args[0][0] + self.assertEqual(getattr(request, "method", None), "GET") + + parsed = urlparse(getattr(request, "url", "")) + self.assertEqual( + parsed.path, + "/agents/myAgent/versions/10/containers/default", + ) + self.assertEqual( + parse_qs(parsed.query).get("api-version"), + [AGENT_API_VERSION_PARAMS["api-version"]], + ) def test_validate_image_tag_valid(self): """Test tag validation and extraction from valid image URIs."""