Commit 10f40f8
feat(azure.ai.agents): add doctor check remote.auth (P5.1 C11)
Implements Check 7 from the doctor remote-checks design as the first
populated entry in the remote chain wired up by C10. The check proves
that `azd auth token` can mint a token for the Foundry data-plane
scope and surfaces the result with branched severity:
- Pass: "<UPN> · token valid for <N> minutes"
- Warn (< 5 min remaining): suggest `azd auth login` proactively
- Fail (expired or acquisition error): suggest `azd auth login` with
a learn.microsoft.com link to the `azd auth login` reference
- Skip (user cancelled): no suggestion — Ctrl-C is not an auth bug
- Fail (probe deadline): distinct "timed out" message that does NOT
immediately accuse the user of being logged out
Skip-cascade: `local.environment-selected`. Per the design dependency
matrix, an env must be selected before remote checks have a project
to test against; otherwise the remote chain would run against the
wrong context. `local.grpc-extension` is intentionally NOT a
precondition — the auth probe goes straight to azidentity and does
not need the AzdClient gRPC channel.
Implementation notes:
- Uses `azidentity.NewAzureDeveloperCLICredential` (same as
`agent_context.go:newAgentCredential`) so the probe mirrors the
production credential exactly.
- Requests the production data-plane scope `https://ai.azure.com/
.default` (same as `agent_api/operations.go`) so a Pass here
matches what the runtime invoke flow needs — not a different
scope that might succeed when the runtime would fail.
- Wraps the probe in a 10s timeout to bound stuck shells. After the
probe returns the check classifies `context.Canceled` /
`context.DeadlineExceeded` separately from generic auth errors
so user Ctrl-C maps to Skip (not Fail) and a probe timeout maps
to a distinct Fail message instead of telling the user to log in
again when the real cause is a stuck `azd` invocation.
- UPN extraction is best-effort JWT payload decoding (stdlib only,
no third-party JWT lib). Tries `upn`, `unique_name`,
`preferred_username`, `email` in order. Decode failures return an
empty UPN and never an error: the auth check cares about the
token's validity, not how readable its claims are.
- The raw access token is never logged, returned, or exposed
outside `realProbeAuth`.
- Wrong-tenant detection is intentionally NOT done here — that's
the job of `remote.foundry-endpoint` (C12) where a 403 maps to a
precise "wrong tenant or insufficient RBAC" suggestion.
Surfacing the same failure mode here would produce false
positives — flagging auth as broken when the user IS
authenticated, just against the wrong tenant.
- `formatTokenWindow` substitutes "less than 1 minute" for any
sub-minute positive window so the Warn message can never read
"token expires in 0 minutes" — that wording is indistinguishable
from expiry to a reader scanning the report.
- `firstLine` strips a trailing `\r` after splitting on `\n` so
Windows CRLF stderr output from `os/exec`-invoked `azd` does not
leak a carriage return into the doctor report message.
- Every Fail branch that suggests `azd auth login` now carries the
same `authLoginLink` (a single package constant), so all four
suggestion paths point at the canonical MS Learn reference.
Testability:
- New `probeAuth` test seam on `Dependencies` matches the pattern
used by `assembleState`. Production wiring leaves it nil; the
check falls back to `realProbeAuth`. Tests inject deterministic
`authProbeResult` values to exercise each branch.
- 22 new tests cover: skip-cascade (Fail + Skip cases); default
seam fallback; all severity branches (Pass, Warn, sub-minute
Warn, expired Fail with Links, acquisition-error Fail with
Links, cancellation Skip, deadline Fail); singular / plural and
sub-minute formatting; 5-minute Warn/Pass boundary; UPN claim
ordering / empty / whitespace / non-string variants; and JWT
decode failure modes (empty token, wrong segment count, invalid
base64, non-JSON payload, non-object JSON root).
Files:
- checks_auth.go (new): newCheckAuth + realProbeAuth + extractUPN
+ format helpers + authLoginLink constant
- checks_auth_test.go (new): comprehensive table-driven coverage
- checks_local.go: add `probeAuth` test seam to Dependencies
- checks_remote.go: append newCheckAuth(deps) to the remote chain
- checks_remote_test.go: replace the empty-slice contract test
with one pinning the auth-only shape, so any future addition has
to touch this one assertion
Reviewer findings applied (3-reviewer pass: Opus xhigh + Sonnet 4.6 +
GPT-5.5):
- HIGH (Sonnet): Expired-token Fail was missing `Links` — fixed,
every Fail with `azd auth login` suggestion now carries the
reference link via the new `authLoginLink` constant.
- MEDIUM (GPT-5.5): Cancellation / timeout was classified as
generic auth failure — fixed, classified separately with
appropriate Skip / Fail and distinct messages.
- MEDIUM (Sonnet + Opus convergent): Sub-minute positive validity
rendered as "token expires in 0 minutes" — fixed via
`formatTokenWindow` substituting "less than 1 minute".
- MEDIUM (Sonnet): `firstLine` left trailing `\r` on Windows CRLF —
fixed with `strings.TrimRight(s[:i], "\r")` + CRLF test case.
- LOW (Sonnet): Doc said "false negatives" where logic required
"false positives" — corrected.
- LOW (Opus): 5-minute Warn/Pass boundary was not directly
tested — added `TestCheckAuth_WarnPassBoundaryAtFiveMinutes`.
- LOW (Opus): Doc comment cited a non-existent design path —
updated to the actual `.tmp/pr-8057/...` location.
Preflight: gofmt -s -w . ✓, go vet ./... ✓, go test ./... -count=1
(all packages) ✓, golangci-lint run ./internal/cmd/... ✓, cspell ✓.
Refs: Azure#7975
Refs: design `.tmp/pr-8057/azd-ai-agent-doctor-remote-checks.md`
Check 7 / dependency matrix lines 112-131
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>1 parent 8846fd5 commit 10f40f8
5 files changed
Lines changed: 790 additions & 24 deletions
File tree
- cli/azd/extensions/azure.ai.agents/internal/cmd/doctor
Lines changed: 297 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 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 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
0 commit comments