[azure.ai.agents] Fix init from manifest in CWD: allow copy when target is subpath#8522
Conversation
62671b1 to
6a768b3
Compare
There was a problem hiding this comment.
Pull request overview
Fixes a bug where azd ai agent init failed with "target is inside the manifest directory" when run in a directory that contains an agent.manifest.yaml but no azure.yaml. In that flow, ensureProject creates a project subdirectory under CWD (the manifest dir), and the previous validation/copy logic refused to copy a directory into its own subtree. The fix permits this case and prevents infinite recursion by skipping the destination subtree during the walk.
Changes:
validateLocalContainerAgentCopynow returns nil (instead of an error) when the target is a subpath of the manifest directory.copyDirectoryallows dst-inside-src and usesfilepath.SkipDirto avoid recursing into the destination.- Renamed/expanded existing test and added
TestValidateLocalContainerAgentCopy_AllowsSubpath.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| cli/azd/extensions/azure.ai.agents/internal/cmd/init_copy.go | Allow subpath copy and skip destination directory during walk |
| cli/azd/extensions/azure.ai.agents/internal/cmd/init_test.go | Update copy test to verify subpath exclusion behavior; add validation test for subpath case |
6a768b3 to
5bbe1af
Compare
📋 Prioritization NoteThanks for the contribution! The linked issue isn't in the current milestone yet. |
93b20f3 to
bd71e65
Compare
…et is subpath of manifest dir When running `azd ai agent init` from a directory containing an agent.manifest.yaml, the auto-detect flow creates a project subdirectory via ensureProject. The subsequent copy step then finds that the target is inside the manifest directory and refuses to proceed. Fix: instead of rejecting the copy outright, skip the destination directory during WalkDir traversal to prevent infinite recursion while still copying the agent source files into the new project structure. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
bd71e65 to
3e47a35
Compare
|
I changed how this was implemented, I undid the changes to init_copy, it was re-creating everything as a sub-dir. Instead I added a check for a local manifest in init.go and refactored the isLocalFilePath so I could use it at this point. |
5356335 to
1dcd314
Compare
Fixes #8523
Problem
When running
azd ai agent initfrom a directory that contains anagent.manifest.yamlbut noazure.yamlin the directory tree (e.g. inside a sample repo likefoundry-samples/.../01-basic/), the from-manifest flow fails with:The auto-detect flow finds the manifest, guides the user through setup, then
ensureProjectcreates a project subdirectory under CWD. The subsequent copy step detects that the target is inside the manifest directory and rejects.azd ai agent init- All Casesazd init -t templatecreates subdirectoryscaffoldTemplatedownloads azure.yaml + infra into CWD (no subdir)azd init -t startercreates subdirectory then copy-m url)-m ../path)Only Case 4 triggers the bug - manifest auto-detected in CWD + no azure.yaml = ensureProject creates subdirectory under manifestDir.
Root Cause
The from-manifest
ensureProjectusesazd init -t template subdirwhich creates a new directory. The from-codeensureProjectusesscaffoldTemplatewhich downloads onlyinfra/+azure.yamlinto CWD without a subdirectory. When the manifest is auto-detected in CWD, the from-manifest path creates the project as a child of the manifest directory, making copy impossible without recursion.Fix
validateLocalContainerAgentCopy: Allow the subpath case (return nil instead of error)copyDirectory: When dst is inside src, skip the destination directory duringfilepath.WalkDirtraversal usingfilepath.SkipDir, preventing infinite recursion while copying all other source filesTesting
TestCopyDirectory_RefusesToCopyIntoSubtreetoTestCopyDirectory_CopiesWithSubpathExclusionTestValidateLocalContainerAgentCopy_AllowsSubpathinit_copy_test.gosubpath test to verify new behaviorRepro Steps
Workaround (older versions)
cd .. azd ai agent init -m ./01-basic/agent.manifest.yaml