Skip to content

Commit d4057b6

Browse files
committed
feat: enhance session deletion message and add tests for session creation and listing
1 parent 857d4ee commit d4057b6

File tree

2 files changed

+90
-1
lines changed

2 files changed

+90
-1
lines changed

cli/azd/extensions/azure.ai.agents/internal/cmd/session.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,10 @@ The isolation key is derived from the Entra token by default.`,
424424
)
425425
}
426426

427-
fmt.Printf("Session %q deleted.\n", sessionID)
427+
fmt.Printf(
428+
"Session %q deleted from agent %q.\n",
429+
sessionID, sc.agentName,
430+
)
428431
return nil
429432
},
430433
}

cli/azd/extensions/azure.ai.agents/internal/pkg/agents/agent_api/operations_test.go

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
package agent_api
55

66
import (
7+
"io"
78
"net/http"
9+
"strings"
810
"testing"
911

1012
"github.com/Azure/azure-sdk-for-go/sdk/azcore/policy"
@@ -86,3 +88,87 @@ func TestGetSession_404ReturnsError(t *testing.T) {
8688
)
8789
require.Error(t, err, "404 should be an error from GetSession")
8890
}
91+
92+
// fakeBodyTransport returns a canned status code and JSON body.
93+
type fakeBodyTransport struct {
94+
statusCode int
95+
body string
96+
}
97+
98+
func (f *fakeBodyTransport) Do(req *http.Request) (*http.Response, error) {
99+
return &http.Response{
100+
StatusCode: f.statusCode,
101+
Header: http.Header{"Content-Type": {"application/json"}},
102+
Body: io.NopCloser(strings.NewReader(f.body)),
103+
Request: req,
104+
}, nil
105+
}
106+
107+
func TestCreateSession_Returns201WithBody(t *testing.T) {
108+
body := `{
109+
"agent_session_id": "sess-new",
110+
"version_indicator": {"type": "version_ref", "agent_version": "3"},
111+
"status": "running",
112+
"created_at": 1700000000,
113+
"last_accessed_at": 1700000100,
114+
"expires_at": 1700086400
115+
}`
116+
117+
client := newTestClient(
118+
"https://test.example.com/api/projects/proj",
119+
&fakeBodyTransport{
120+
statusCode: http.StatusCreated,
121+
body: body,
122+
},
123+
)
124+
125+
session, err := client.CreateSession(
126+
t.Context(), "my-agent", "",
127+
&CreateAgentSessionRequest{
128+
VersionIndicator: &VersionIndicator{
129+
Type: "version_ref",
130+
AgentVersion: "3",
131+
},
132+
},
133+
"2025-11-15-preview",
134+
)
135+
136+
require.NoError(t, err)
137+
require.Equal(t, "sess-new", session.AgentSessionID)
138+
require.Equal(t, "3", session.VersionIndicator.AgentVersion)
139+
require.Equal(t, AgentSessionStatus("running"), session.Status)
140+
}
141+
142+
func TestListSessions_Returns200WithPagination(t *testing.T) {
143+
body := `{
144+
"data": [
145+
{
146+
"agent_session_id": "sess-1",
147+
"version_indicator": {"type": "version_ref", "agent_version": "2"},
148+
"status": "running",
149+
"created_at": 1700000000,
150+
"last_accessed_at": 1700000100,
151+
"expires_at": 1700086400
152+
}
153+
],
154+
"pagination_token": "next-page-abc"
155+
}`
156+
157+
client := newTestClient(
158+
"https://test.example.com/api/projects/proj",
159+
&fakeBodyTransport{
160+
statusCode: http.StatusOK,
161+
body: body,
162+
},
163+
)
164+
165+
result, err := client.ListSessions(
166+
t.Context(), "my-agent", nil, nil, "2025-11-15-preview",
167+
)
168+
169+
require.NoError(t, err)
170+
require.Len(t, result.Data, 1)
171+
require.Equal(t, "sess-1", result.Data[0].AgentSessionID)
172+
require.NotNil(t, result.PaginationToken)
173+
require.Equal(t, "next-page-abc", *result.PaginationToken)
174+
}

0 commit comments

Comments
 (0)