Commit da75a17
feat(nextstep): surface {{NAME}} placeholders left over in agent.yaml
Phase 2 commit 4.6 (MVP follow-up to 4.5). The toolbox sample exposes a
second MVP-level next-step bug: after `azd ai agent init` selects "Use
existing model deployment(s) from a Foundry project", the processed
`agent.yaml` retains a literal Mustache-style placeholder
`'{{TOOLBOX_ENDPOINT}}'` inside `environment_variables`. The current
Next: block flags only the sibling `${TOOLBOX_WEB_SEARCH_TOOLS_MCP_ENDPOINT}`
ref, leaving the user with the impression that one `azd env set` line
is the entire fix-up — when in reality the literal `{{TOOLBOX_ENDPOINT}}`
would land in the container as-is and break the agent on deploy.
Root cause: agent.manifest.yaml's parameter-substitution step
(`pkg/agents/agent_yaml/parameters.go:injectParameterValues`) is supposed
to replace every `{{NAME}}` and `{{ NAME }}` token with its parameter
value during init. When the manifest declares the placeholder but no
matching `parameters:` entry exists (or the user opts out at the
prompt), init prints a weak `Warning: Template contains unresolved
placeholders.` line at parameters.go:248 and moves on — the literal
`{{NAME}}` carries forward into the final agent.yaml. The nextstep
resolver had no concept of these placeholders: `extractAgentYamlEnvRefs`
matched only `${VAR}` refs, so the `{{NAME}}` was invisible.
Fix (resolver-side surfacing, as confirmed with user):
1. `types.go` — new `State.UnresolvedPlaceholders []string` field with
a doc-comment that explicitly contrasts placeholders against
Missing*Vars (cannot be supplied via `azd env set`; the literal lives
in agent.yaml itself).
2. `state.go` — new `placeholderPattern` regex
`\{\{\s*([A-Za-z_][A-Za-z0-9_]*)\s*\}\}`. Allows optional internal
whitespace because `injectParameterValues` substitutes both
`{{NAME}}` and `{{ NAME }}` forms (parameters.go:238,242).
`extractAgentYamlEnvRefs` signature changes from `[]string` to
`(refs, placeholders []string)`. `detectMissingVars` signature
extends from two return values to three (infra, manual,
placeholders). `assembleState` callsite captures the third slice
into `state.UnresolvedPlaceholders`. Read errors stay silent
(same best-effort contract as before).
3. `resolver.go` — `ResolveAfterInit` decision tree extended:
* Placeholder fix-ups ALWAYS come first when present, regardless of
other branches. One `edit agent.yaml: replace {{NAME}} with the
actual value` line per placeholder, capped at maxFixupLines (3),
sorted ascending. Rationale: deploy-time landmines that block both
`run` (literal `{{NAME}}` in container env) and `deploy`. They
never reach `azd env set`.
* Existing provision branch unchanged (still wins for
`!HasProjectEndpoint || MissingInfraVars`).
* Existing manual-vars branch unchanged.
* New `case hasPlaceholders` (sentinel) deliberately suppresses
`azd ai agent run` when only placeholders remain — running locally
with literal `{{NAME}}` values produces a broken agent, so we don't
suggest a path we know will fail.
The constant `maxManualVarLines` renames to `maxFixupLines` (now
shared between manual-vars and placeholder caps; same value = 3).
Decision scenarios validated (each covered by a new test case):
* Fresh init + Deploy new models → `azd provision` + deploy.
* Fresh init + Use existing + bare ${VAR} → `azd env set VAR` + deploy.
* Toolbox bug → `edit agent.yaml: replace {{X}}` +
`azd env set Y` + deploy.
* Placeholders only → `edit agent.yaml: replace {{X}}` +
deploy (NO run).
* Placeholders + no project endpoint → `edit agent.yaml: replace {{X}}` +
`azd provision` + deploy.
* Happy post-provision (no missing) → `azd ai agent run` + deploy.
Tests:
* `state_test.go` — extended `TestExtractAgentYamlEnvRefs` table to a
two-output schema (`wantRefs`, `wantPlaceholders`); 4 new table cases
cover placeholders alone, internal-whitespace form, dedup, and
ref+placeholder coexistence. New
`TestAssembleState_PopulatesUnresolvedPlaceholders` reproduces the
toolbox sample directly. New `TestAssembleState_PlaceholdersDeduped
AcrossServices` locks cross-service dedup.
* `resolver_test.go` — new `TestResolveAfterInit_UnresolvedPlaceholders`
table with 5 cases covering placeholders-alone, placeholders+manual,
placeholders+missing-endpoint, sort-ascending, and >3 cap.
Preflight clean (gofmt, vet, build, full extension test suite green,
golangci-lint 0 issues, cspell 0 issues on the 3 production files).
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>1 parent d1d213c commit da75a17
5 files changed
Lines changed: 387 additions & 69 deletions
File tree
- cli/azd/extensions/azure.ai.agents/internal/cmd/nextstep
Lines changed: 45 additions & 10 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
26 | | - | |
27 | | - | |
28 | | - | |
29 | | - | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
30 | 31 | | |
31 | 32 | | |
32 | 33 | | |
33 | 34 | | |
34 | 35 | | |
35 | 36 | | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
36 | 43 | | |
37 | 44 | | |
38 | 45 | | |
| |||
46 | 53 | | |
47 | 54 | | |
48 | 55 | | |
49 | | - | |
| 56 | + | |
50 | 57 | | |
| 58 | + | |
| 59 | + | |
51 | 60 | | |
52 | 61 | | |
53 | 62 | | |
| |||
56 | 65 | | |
57 | 66 | | |
58 | 67 | | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
59 | 88 | | |
60 | 89 | | |
61 | 90 | | |
62 | 91 | | |
63 | 92 | | |
64 | 93 | | |
65 | | - | |
| 94 | + | |
66 | 95 | | |
67 | 96 | | |
68 | 97 | | |
69 | 98 | | |
70 | | - | |
71 | | - | |
| 99 | + | |
| 100 | + | |
72 | 101 | | |
73 | 102 | | |
74 | 103 | | |
75 | | - | |
| 104 | + | |
76 | 105 | | |
| 106 | + | |
77 | 107 | | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
78 | 113 | | |
79 | 114 | | |
80 | 115 | | |
81 | 116 | | |
82 | | - | |
| 117 | + | |
83 | 118 | | |
84 | 119 | | |
85 | 120 | | |
| |||
Lines changed: 114 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
107 | 107 | | |
108 | 108 | | |
109 | 109 | | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
110 | 224 | | |
111 | 225 | | |
112 | 226 | | |
| |||
0 commit comments