Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions cli/azd/extensions/azure.ai.agents/internal/cmd/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ func resolveStoredID(
generateIfMissing bool,
) (string, error) {
if explicit != "" {
// Persist the explicit ID so that subsequent commands (e.g. monitor, invoke)
// can find it without the user passing it again.
saveContextValue(ctx, azdClient, agentKey, explicit, storeField)
return explicit, nil
Comment thread
therealjohn marked this conversation as resolved.
}
if forceNew && !generateIfMissing {
Expand Down
70 changes: 70 additions & 0 deletions cli/azd/extensions/azure.ai.agents/internal/cmd/monitor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,76 @@ func TestValidateMonitorFlags_ErrorMessages(t *testing.T) {
assert.Contains(t, err.Error(), "badtype")
}

func TestExplicitSessionID_PersistedAndReusable(t *testing.T) {
t.Parallel()

// Simulate the persistence that resolveStoredID now performs when an explicit
// session ID is provided. This verifies the round-trip: save an explicit ID,
// then load it back (as monitor's resolveMonitorSession would).
dir := t.TempDir()
configPath := filepath.Join(dir, ConfigFile)

agentName := "my-agent"
explicitSID := "user-provided-session-id"

// Before: no sessions stored
agentCtx := loadLocalContext(configPath)
assert.Empty(t, agentCtx.Sessions)

// Simulate what resolveStoredID now does: persist the explicit ID
store := contextMap(agentCtx, "sessions")
store[agentName] = explicitSID
require.NoError(t, saveLocalContext(agentCtx, configPath))

// Reload (as monitor or a subsequent invoke would)
loaded := loadLocalContext(configPath)
require.NotNil(t, loaded.Sessions)
assert.Equal(t, explicitSID, loaded.Sessions[agentName])
}
Comment thread
therealjohn marked this conversation as resolved.

func TestExplicitConversationID_PersistedAndReusable(t *testing.T) {
t.Parallel()

dir := t.TempDir()
configPath := filepath.Join(dir, ConfigFile)

agentName := "my-agent"
explicitConvID := "user-provided-conv-id"

agentCtx := loadLocalContext(configPath)
store := contextMap(agentCtx, "conversations")
store[agentName] = explicitConvID
require.NoError(t, saveLocalContext(agentCtx, configPath))

loaded := loadLocalContext(configPath)
require.NotNil(t, loaded.Conversations)
assert.Equal(t, explicitConvID, loaded.Conversations[agentName])
}

func TestExplicitID_OverwritesPreviousValue(t *testing.T) {
t.Parallel()

dir := t.TempDir()
configPath := filepath.Join(dir, ConfigFile)

agentName := "my-agent"

// Save an initial session ID
agentCtx := loadLocalContext(configPath)
store := contextMap(agentCtx, "sessions")
store[agentName] = "old-session-id"
require.NoError(t, saveLocalContext(agentCtx, configPath))

// Simulate a second invoke with a different explicit session ID
agentCtx = loadLocalContext(configPath)
store = contextMap(agentCtx, "sessions")
store[agentName] = "new-session-id"
require.NoError(t, saveLocalContext(agentCtx, configPath))

loaded := loadLocalContext(configPath)
assert.Equal(t, "new-session-id", loaded.Sessions[agentName])
}

func TestValidateMonitorFlags_SessionDoesNotAffectValidation(t *testing.T) {
t.Parallel()

Expand Down
Loading