Skip to content

fix(agents): resolve project root for infra eject - #9291

Merged
hund030 merged 8 commits into
mainfrom
fix/agents-adopt-infra-eject
Jul 27, 2026
Merged

fix(agents): resolve project root for infra eject#9291
hund030 merged 8 commits into
mainfrom
fix/agents-adopt-infra-eject

Conversation

@hund030

@hund030 hund030 commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #9287. azd ai agent init --infra now generates infrastructure after unified-manifest adoption and bare-definition reuse, including when invoked below the azd project root.

Changes

  • agent init flow: chain infrastructure ejection after successful unified azure.yaml adoption and bare agent.yaml reuse.
  • Infrastructure ejection: resolve the owning azd project with standard upward discovery and generate infra/ beside its azure.yaml.
  • Tests: cover parent-project resolution and the no-project post-init case.

Manual Validation

  • Initialized the hosted-agent hello-world unified manifest with --infra --no-prompt; Bicep files were generated in the adopted project.
  • Ran standalone --infra from a nested agent source directory; files were generated at the parent project root, with no nested infra/.
  • Reused a bare agent.yaml with --infra --no-prompt; init created azure.yaml and generated infra/main.bicep.

Copilot AI review requested due to automatic review settings July 24, 2026 05:15
@github-actions

Copy link
Copy Markdown

📋 Prioritization Note

Thanks for the contribution! The linked issue isn't in the current milestone yet.
Thank you for logging this issue; our team is reviewing it. If you need urgent prioritization, tag @RickWinter and @kristenwomack to let us know.

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).
21 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes infrastructure ejection after agent initialization and resolves the owning project root from nested directories.

Changes:

  • Chains ejection after unified-manifest adoption and definition reuse.
  • Uses upward project discovery.
  • Adds project-resolution tests.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
init.go Connects init flows to infrastructure ejection.
init_infra.go Resolves the project root before ejection.
init_infra_test.go Tests parent-project and missing-project behavior.

Comment thread cli/azd/extensions/azure.ai.agents/internal/cmd/init_infra.go
@github-actions github-actions Bot added the ext-agents azure.ai.agents extension label Jul 24, 2026
Copilot AI review requested due to automatic review settings July 24, 2026 05:20

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.

Comments suppressed due to low confidence (1)

cli/azd/extensions/azure.ai.agents/internal/cmd/init_infra.go:92

  • azd-code-reviewer: This suppresses every validation error from findFoundryServiceForEject, not only the intended no-Foundry case. For example, unified manifests are adopted when they contain at least one Foundry service, but the eject helper rejects multiple Foundry project services; this branch would then report success without generating infra/, recreating the silent failure this PR addresses. Ignore only CodeInfraEjectNoFoundryService and propagate other errors.
	if _, err := findFoundryServiceForEject(rawYAML); err != nil {
		return nil

Copilot AI review requested due to automatic review settings July 24, 2026 05:32

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.

@jongio jongio left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left one optional, non-blocking suggestion inline about test coverage for the post-init no-foundry-service skip path.

Comment thread cli/azd/extensions/azure.ai.agents/internal/cmd/init_infra.go

@jongio jongio left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-reviewed at db9d0e9. The propagation fix now only swallows the no-foundry-service case and surfaces every other validation error, so a malformed or ambiguous manifest no longer skips eject silently. Resolving the root through GetProjectDir matches how the rest of azd finds azure.yaml, and the new tests (parent-project, no-project, multiple-foundry-service) pass locally. My earlier note about a test for the silent-skip branch is still optional, not blocking.

@jongio jongio left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reconfirming approval. --infra now chains through ejectInfraAfterInit with upward project resolution, so eject runs after adopt and bare agent.yaml reuse, and from a nested source directory it writes infra/ at the parent project root. The foundry check only swallows the infra_eject_no_foundry_service code, so malformed or multi-service manifests still surface as errors instead of silently skipping. New tests cover the parent-project, no-project, and error-propagation paths, and CI is green.

@jongio jongio left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Post-init eject now resolves the owning azd project via upward discovery, so --infra works from a nested source directory and writes infra/ beside the project's azure.yaml. The validation-error handling in ejectInfraAfterInit skips only the no-foundry-service case and propagates the multiple-foundry-service and invalid-manifest cases, so --infra no longer reports success without generating infra when the manifest is ambiguous.

Copilot AI review requested due to automatic review settings July 27, 2026 03:05

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

Comment thread cli/azd/extensions/azure.ai.agents/internal/cmd/init_infra_test.go Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings July 27, 2026 03:21

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

Comment thread cli/azd/extensions/azure.ai.agents/internal/cmd/init.go
Copilot AI review requested due to automatic review settings July 27, 2026 03:28

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.

Comments suppressed due to low confidence (3)

cli/azd/extensions/azure.ai.agents/internal/cmd/init.go:1131

  • azd-code-reviewer: The parent-project regression is not covered at this branch. TestEjectInfraAfterInit_ResolvesParentProject calls the post-init helper directly, so it would still pass if standalone eject reverted to the old cwd-only check. Add a command-level test that invokes init --infra from a nested directory and verifies infra/ is created at the parent project root.
				projectRoot, projectRootErr := azdext.GetProjectDir()

cli/azd/extensions/azure.ai.agents/internal/cmd/init.go:1293

  • azd-code-reviewer: This fixes the bare-definition early return, but no automated test executes a successful reuse flow with --infra; the existing reuse tests explicitly cover only pre-gRPC failures. Add an integration or command-level regression test that starts with a bare agent.yaml and asserts that both azure.yaml and infra/main.bicep are produced.
						return ejectInfraAfterInit(infraProvider)

cli/azd/extensions/azure.ai.agents/internal/cmd/init.go:1319

  • azd-code-reviewer: The unified-manifest regression was an orchestration bug at this early return, but the added helper tests do not execute this path. Add an automated command/integration test for unified azure.yaml adoption with --infra that verifies the adopted project receives infra/main.bicep; otherwise removing this call would leave the suite green.
					return ejectInfraAfterInit(infraProvider)

@jongio jongio left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-reviewed at 976d2f2. Both open points are closed.

TestEjectInfraAfterInit_SkipsProjectWithoutFoundryService covers the post-init skip path I asked about. Since TestEjectInfraAfterInit_NoProject already covers project-not-found and this case writes an azure.yaml, the only way to reach a nil return is the CodeInfraEjectNoFoundryService swallow, so the branch is pinned.

The stdout capture on TestEjectInfraAfterInit_ResolvesParentProject is fixed. Before the wrap, go test -run TestEjectInfraAfterInit -v printed the whole eject summary between === RUN and --- PASS; at 976d2f2 that output is gone. forbidigo would not have caught it, since the write comes from printEjectSummary in production code rather than from the test, so the capture is the only guard.

All of internal/cmd passes locally, go vet ./... is clean, and CI is green on this commit.

@jongio jongio left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-checked at 976d2f2. The code is correct and go test ./internal/cmd/ is green, but scenario 3 from #9287 (standalone eject from a subdirectory) has no regression guard. I reverted this branch locally to the old cwd-only lookup and the entire package suite still passed. Details inline, with a test that fails on the old behavior.

Comment thread cli/azd/extensions/azure.ai.agents/internal/cmd/init.go

@jongio jongio left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-checked at 976d2f2. No new findings.

My open note on init.go:1130 is a test-coverage gap, not a correctness issue, so it isn't blocking merge.

Copilot AI review requested due to automatic review settings July 27, 2026 05:17

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.

@jongio jongio left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Incremental change since my last review is the new TestInitInfra_StandaloneEjectResolvesParentProject.

I verified it actually covers the branch I flagged rather than just passing alongside it. Reverting init.go back to fileExists("azure.yaml") plus os.Getwd() makes that test fail (--- FAIL: TestInitInfra_StandaloneEjectResolvesParentProject), while TestEjectInfraAfterInit_ResolvesParentProject still passes. So the standalone eject path from a subdirectory (scenario 3 in #9287) is genuinely covered now, and the rest of the package is green.

I also checked the --infra plus -m/--src combination from a nested directory. It returns the conflicting-arguments validation error, which matches what already happened from the project root, so this makes that behavior consistent instead of adding a new restriction.

@hund030
hund030 merged commit 7d34c7e into main Jul 27, 2026
30 checks passed
trangevi added a commit that referenced this pull request Jul 30, 2026
…leases (#9371)

* chore: prepare azure.ai.agents 1.0.0-beta.8 release

Bump version and add changelog for 10 PRs since beta.7:
- Features: max_stalls early-stopping (#9314), invocations protocol 2.0.0 default (#9327)
- Bug fixes: #9365, #9328, #9291, #9290, #9212, #9211, #9280, #9237

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* chore: prepare azure.ai.projects 1.0.0-beta.4 release

Bump version and add changelog for 1 PR since beta.3:
- Bug fix: cap Foundry ARM deployment names to 64 chars (#9292)

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* Potential fix for pull request finding

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

* chore: add imatiach to cspell contributor aliases

Fix cspell-ext CI gate failure for the azure.ai.agents CHANGELOG entry
referencing @imatiach-msft (PR #9314).

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

---------

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ext-agents azure.ai.agents extension

Projects

None yet

Development

Successfully merging this pull request may close these issues.

azd ai agent init --infra silently skips infra generation in some init flows

5 participants