Skip to content

Commit bce9965

Browse files
committed
fix: simplify unified configuration resolution
1 parent d912651 commit bce9965

11 files changed

Lines changed: 124 additions & 169 deletions

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

Lines changed: 12 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,14 @@ func configureExtensionHost(host *azdext.ExtensionHost) {
6868
}
6969

7070
func preprovisionHandler(ctx context.Context, azdClient *azdext.AzdClient, args *azdext.ProjectEventArgs) error {
71-
deployments, err := collectProjectDeploymentsAtRoot(
71+
deployments, err := collectProjectDeployments(
7272
args.Project.Services,
7373
args.Project.Path,
7474
)
7575
if err != nil {
7676
return err
7777
}
78-
connections, err := collectConnectionsAtRoot(
78+
connections, err := collectConnections(
7979
args.Project.Services,
8080
args.Project.Path,
8181
)
@@ -86,9 +86,7 @@ func preprovisionHandler(ctx context.Context, azdClient *azdext.AzdClient, args
8686
for _, svc := range args.Project.Services {
8787
switch svc.Host {
8888
case AiAgentHost:
89-
if err := populateContainerSettings(
90-
ctx,
91-
azdClient,
89+
if err := prepareContainerSettings(
9290
svc,
9391
args.Project.Path,
9492
); err != nil {
@@ -205,24 +203,22 @@ func predeployHandler(ctx context.Context, azdClient *azdext.AzdClient, args *az
205203
warnDuplicateAgentNames(args.Project)
206204
})
207205

208-
deployments, err := collectProjectDeploymentsAtRoot(
206+
deployments, err := collectProjectDeployments(
209207
args.Project.Services,
210208
args.Project.Path,
211209
)
212210
if err != nil {
213211
return err
214212
}
215-
connections, err := collectConnectionsAtRoot(
213+
connections, err := collectConnections(
216214
args.Project.Services,
217215
args.Project.Path,
218216
)
219217
if err != nil {
220218
return err
221219
}
222220

223-
if err := populateContainerSettings(
224-
ctx,
225-
azdClient,
221+
if err := prepareContainerSettings(
226222
svc,
227223
args.Project.Path,
228224
); err != nil {
@@ -738,20 +734,10 @@ func setEnvVar(ctx context.Context, azdClient *azdext.AzdClient, envName string,
738734
return nil
739735
}
740736

741-
func populateContainerSettings(
742-
_ context.Context,
743-
_ *azdext.AzdClient,
744-
svc *azdext.ServiceConfig,
745-
projectRoot string,
746-
) error {
747-
_, err := prepareContainerSettings(svc, projectRoot)
748-
return err
749-
}
750-
751737
func prepareContainerSettings(
752738
svc *azdext.ServiceConfig,
753739
projectRoot string,
754-
) (*azdext.ServiceConfig, error) {
740+
) error {
755741
rawAdditional := svc.GetAdditionalProperties()
756742
rawConfig := svc.GetConfig()
757743
hasRootFileRef := rawAdditional != nil &&
@@ -762,20 +748,20 @@ func prepareContainerSettings(
762748
svc,
763749
projectRoot,
764750
); err != nil {
765-
return nil, fmt.Errorf(
751+
return fmt.Errorf(
766752
"failed to resolve agent config: %w",
767753
err,
768754
)
769755
}
770756
} else if err := project.NormalizeServiceConfigInPlace(svc); err != nil {
771-
return nil, fmt.Errorf(
757+
return fmt.Errorf(
772758
"failed to normalize agent config: %w",
773759
err,
774760
)
775761
}
776762
foundryAgentConfig, err := project.LoadServiceTargetAgentConfig(svc)
777763
if err != nil {
778-
return nil, fmt.Errorf(
764+
return fmt.Errorf(
779765
"failed to parse foundry agent config: %w",
780766
err,
781767
)
@@ -801,15 +787,12 @@ func prepareContainerSettings(
801787
svc,
802788
&project.ContainerSettings{Resources: result},
803789
); err != nil {
804-
return nil, fmt.Errorf(
790+
return fmt.Errorf(
805791
"failed to update agent container settings: %w",
806792
err,
807793
)
808794
}
809-
if hasRootFileRef {
810-
return nil, nil
811-
}
812-
return svc, nil
795+
return nil
813796
}
814797

815798
// resolveToolboxEnvVars resolves ${VAR} references in toolbox name, description,

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

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ func TestIsHostedAgentServiceRejectsTraversal(t *testing.T) {
131131
}
132132
}
133133

134-
func TestPopulateContainerSettings_DoesNotPersistResolvedFileRef(
134+
func TestPrepareContainerSettings_DoesNotPersistResolvedFileRef(
135135
t *testing.T,
136136
) {
137137
t.Parallel()
@@ -160,7 +160,7 @@ func TestPopulateContainerSettings_DoesNotPersistResolvedFileRef(
160160
AdditionalProperties: props,
161161
}
162162

163-
err = populateContainerSettings(t.Context(), nil, svc, root)
163+
err = prepareContainerSettings(svc, root)
164164

165165
require.NoError(t, err)
166166
require.Equal(t, "src/echo", svc.GetRelativePath())
@@ -189,11 +189,10 @@ func TestPrepareContainerSettings_PreservesNestedFileRef(t *testing.T) {
189189
AdditionalProperties: props,
190190
}
191191

192-
persisted, err := prepareContainerSettings(svc, t.TempDir())
192+
err = prepareContainerSettings(svc, t.TempDir())
193193

194194
require.NoError(t, err)
195-
require.Same(t, svc, persisted)
196-
deployments, ok := persisted.GetAdditionalProperties().
195+
deployments, ok := svc.GetAdditionalProperties().
197196
AsMap()["deployments"].([]any)
198197
require.True(t, ok)
199198
require.Len(t, deployments, 1)
@@ -204,7 +203,7 @@ func TestPrepareContainerSettings_PreservesNestedFileRef(t *testing.T) {
204203
"./missing-deployment.yaml",
205204
deployment["$ref"],
206205
)
207-
cfg, err := project.LoadServiceTargetAgentConfig(persisted)
206+
cfg, err := project.LoadServiceTargetAgentConfig(svc)
208207
require.NoError(t, err)
209208
require.NotNil(t, cfg.Container)
210209
require.NotNil(t, cfg.Container.Resources)
@@ -229,13 +228,13 @@ func TestPrepareContainerSettings_NormalizesInlineEnvironment(t *testing.T) {
229228
AdditionalProperties: props,
230229
}
231230

232-
persisted, err := prepareContainerSettings(svc, t.TempDir())
231+
err = prepareContainerSettings(svc, t.TempDir())
233232

234233
require.NoError(t, err)
235234
require.Equal(
236235
t,
237236
"true",
238-
persisted.GetAdditionalProperties().
237+
svc.GetAdditionalProperties().
239238
GetFields()["env"].GetStructValue().
240239
GetFields()["ENABLED"].GetStringValue(),
241240
)
@@ -244,13 +243,12 @@ func TestPrepareContainerSettings_NormalizesInlineEnvironment(t *testing.T) {
244243
func TestPrepareContainerSettings_WithoutProperties(t *testing.T) {
245244
t.Parallel()
246245

247-
persisted, err := prepareContainerSettings(
246+
err := prepareContainerSettings(
248247
&azdext.ServiceConfig{Name: "echo", Host: AiAgentHost},
249248
t.TempDir(),
250249
)
251250

252251
require.NoError(t, err)
253-
require.NotNil(t, persisted)
254252
}
255253

256254
func TestKindEnvUpdateRejectsTraversal(t *testing.T) {

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

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -137,13 +137,7 @@ func (a *OptimizeApplyAction) apply(
137137
svc.Name,
138138
)
139139
}
140-
servicePath, err := projectpkg.ResolvedServiceProjectPath(
141-
svc,
142-
project.Path,
143-
)
144-
if err != nil {
145-
return fmt.Errorf("failed to resolve service path: %w", err)
146-
}
140+
servicePath := svc.GetRelativePath()
147141
serviceDir, err := paths.JoinAllowRoot(project.Path, servicePath)
148142
if err != nil {
149143
return fmt.Errorf("invalid service path for %s: %w", svc.Name, err)

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

Lines changed: 12 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -356,11 +356,7 @@ func reserveServiceName(used map[string]string, name, source string) error {
356356
// Falls back to the deployments bundled on the agent service when no project
357357
// service carries any, so an azure.yaml written before the per-resource split
358358
// still provisions without re-running init.
359-
func collectProjectDeployments(services map[string]*azdext.ServiceConfig) ([]project.Deployment, error) {
360-
return collectProjectDeploymentsAtRoot(services, "")
361-
}
362-
363-
func collectProjectDeploymentsAtRoot(
359+
func collectProjectDeployments(
364360
services map[string]*azdext.ServiceConfig,
365361
projectRoot string,
366362
) ([]project.Deployment, error) {
@@ -390,7 +386,7 @@ func collectProjectDeploymentsAtRoot(
390386
if len(out) > 0 {
391387
return out, nil
392388
}
393-
legacy, err := collectLegacyAgentConfigsAtRoot(
389+
legacy, err := collectLegacyAgentConfigs(
394390
services,
395391
projectRoot,
396392
)
@@ -407,11 +403,7 @@ func collectProjectDeploymentsAtRoot(
407403
// azure.ai.connection services. Falls back to the connections bundled on the
408404
// agent service when no connection service carries any, so a pre-split
409405
// azure.yaml still provisions without re-running init.
410-
func collectConnections(services map[string]*azdext.ServiceConfig) ([]project.Connection, error) {
411-
return collectConnectionsAtRoot(services, "")
412-
}
413-
414-
func collectConnectionsAtRoot(
406+
func collectConnections(
415407
services map[string]*azdext.ServiceConfig,
416408
projectRoot string,
417409
) ([]project.Connection, error) {
@@ -444,7 +436,7 @@ func collectConnectionsAtRoot(
444436
if len(out) > 0 {
445437
return out, nil
446438
}
447-
legacy, err := collectLegacyAgentConfigsAtRoot(
439+
legacy, err := collectLegacyAgentConfigs(
448440
services,
449441
projectRoot,
450442
)
@@ -461,11 +453,7 @@ func collectConnectionsAtRoot(
461453
// services. Falls back to the toolboxes bundled on the agent service when no
462454
// toolbox service carries any, so a pre-split azure.yaml still provisions
463455
// without re-running init.
464-
func collectToolboxes(services map[string]*azdext.ServiceConfig) ([]project.Toolbox, error) {
465-
return collectToolboxesAtRoot(services, "")
466-
}
467-
468-
func collectToolboxesAtRoot(
456+
func collectToolboxes(
469457
services map[string]*azdext.ServiceConfig,
470458
projectRoot string,
471459
) ([]project.Toolbox, error) {
@@ -498,7 +486,7 @@ func collectToolboxesAtRoot(
498486
if len(out) > 0 {
499487
return out, nil
500488
}
501-
legacy, err := collectLegacyAgentConfigsAtRoot(
489+
legacy, err := collectLegacyAgentConfigs(
502490
services,
503491
projectRoot,
504492
)
@@ -515,8 +503,11 @@ func collectToolboxesAtRoot(
515503
// services. Tool connections stay on the agent service (they are agent tool
516504
// configuration), so toolbox enrichment still needs them alongside the
517505
// connections sourced from azure.ai.connection services.
518-
func collectAgentToolConnections(services map[string]*azdext.ServiceConfig) ([]project.ToolConnection, error) {
519-
configs, err := collectLegacyAgentConfigs(services)
506+
func collectAgentToolConnections(
507+
services map[string]*azdext.ServiceConfig,
508+
projectRoot string,
509+
) ([]project.ToolConnection, error) {
510+
configs, err := collectLegacyAgentConfigs(services, projectRoot)
520511
if err != nil {
521512
return nil, err
522513
}
@@ -532,11 +523,7 @@ func collectAgentToolConnections(services map[string]*azdext.ServiceConfig) ([]p
532523
// projects created before the per-resource split also carry their deployments,
533524
// connections, and toolboxes here rather than in sibling azure.ai.<kind>
534525
// services, so the collectors fall back to these when no sibling service exists.
535-
func collectLegacyAgentConfigs(services map[string]*azdext.ServiceConfig) ([]*project.ServiceTargetAgentConfig, error) {
536-
return collectLegacyAgentConfigsAtRoot(services, "")
537-
}
538-
539-
func collectLegacyAgentConfigsAtRoot(
526+
func collectLegacyAgentConfigs(
540527
services map[string]*azdext.ServiceConfig,
541528
projectRoot string,
542529
) ([]*project.ServiceTargetAgentConfig, error) {

0 commit comments

Comments
 (0)