Skip to content

feat(azure-devops): authenticate via az CLI Entra login with token fallback - #12201

Closed
yoyoys wants to merge 4 commits into
stablyai:mainfrom
yoyoys:feat/azure-devops-az-cli-auth
Closed

yoyoys wants to merge 4 commits into
stablyai:mainfrom
yoyoys:feat/azure-devops-az-cli-auth

Conversation

@yoyoys

@yoyoys yoyoys commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Summary

Azure DevOps requests now authenticate through the Azure CLI's existing az login when no ORCA_AZURE_DEVOPS_* token is configured, mirroring how GitHub and GitLab delegate credentials to gh/glab. Creating a PR against Azure Repos previously hard-failed with "set ORCA_AZURE_DEVOPS_TOKEN" and nothing documented where to set it or which scopes it needs (context: #11125 comment).

Resolution order, per request:

  1. ORCA_AZURE_DEVOPS_ACCESS_TOKEN / ORCA_AZURE_DEVOPS_TOKEN (unchanged, always win)
  2. Hosted Azure DevOps (dev.azure.com / *.visualstudio.com) only: an Entra token acquired via az account get-access-token --resource 499b84ac-1321-427f-aa17-267ca6975798 (Azure DevOps' fixed application ID, identical for every tenant; no azure-devops CLI extension needed)
  3. On-prem Azure DevOps Server never consults az — it only accepts PAT/Windows auth, so the token path stays required there

Details:

  • Tokens are cached in memory until 5 minutes before Entra expiry; az failures are negative-cached for 60s so a missing/logged-out az doesn't pay a ~1s Python spawn per poll, while a fresh az login is picked up without restarting Orca. Concurrent cold-cache callers share one in-flight az invocation. Older az versions that omit expires_on fall back to parsing local-time expiresOn; no parseable expiry caps the cache at 30 minutes instead of serving a stale token forever.
  • The duplicated env/auth-header logic in pull-request-creation.ts was collapsed into the shared azure-devops-api-request.ts resolver; the create gate is now async and resolves the repo's base URL to decide az eligibility.
  • Settings card reports an az-only login as Configured; "not authenticated" copy in the create-PR flow and Settings now mentions az login alongside the env vars.
  • New doc: docs/reference/azure-devops-authentication.md (both auth paths, env var table, PAT scopes, on-prem note) — previously docs/ had nothing on Azure.

Screenshots

No visual change beyond copy: the Settings card's not-configured hint now reads "Run az login (Azure CLI), set ORCA_AZURE_DEVOPS_TOKEN, or set ORCA_AZURE_DEVOPS_ACCESS_TOKEN…", and the blocked Create PR notice reads "…Next step: run az login or set ORCA_AZURE_DEVOPS_TOKEN in this environment."

Testing

  • pnpm lint
  • pnpm typecheck
  • pnpm test — 38,716 passed. 8 failures in the full run were investigated and none are attributable to this diff: 3 were a mid-edit snapshot of this branch's own new tests (green on the final commit), 3 pass in isolation and only flake under full-suite load (remote-runtime-shared-control-connection, managed-hook-install-lock, git-handler rebase timeout), and 2 (agent-exec-handler) fail identically on main in this environment
  • pnpm build
  • Added or updated high-quality tests (test-first; every new test was watched failing before the code that passes it): token acquisition, both cache layers, concurrent-spawn dedup, expiry-format fallbacks, host eligibility (including lookalike-host rejection), auth precedence, on-prem never invoking az, the async create gate, PR creation carrying the az Bearer header, auth-status reporting, and the renderer copy

Real-environment verification (macOS, az logged in, all ORCA_AZURE_DEVOPS_* unset): the unmocked modules acquired a real Entra token, produced Bearer headers for dev.azure.com, and authenticated a live REST call end to end (temporary test, run then removed).

Test isolation note: every suite touching this code mocks the az boundary with a default rejection, so results don't depend on whether the dev machine has az installed or logged in.

AI Review Report

Reviewed by Claude (Fable 5) with the diff-wide pass covering:

  • Cross-platform: az resolution goes through the existing resolveWindowsCommand + getSpawnArgsForWindows helpers, so Windows az.cmd gets the cmd.exe shim treatment with batch-unsafe-argument guards; no paths, shortcuts, or labels touched. macOS/Linux spawn az directly.
  • SSH/remote/local: requests and the az spawn both run in the main process on the local machine, matching the existing gh/glab behavior; repo refs for SSH worktrees still resolve through the SSH git provider (covered by an existing test that now also runs through the new auth path).
  • Provider compatibility: behavior is scoped to the Azure DevOps modules; the shared hosted-review gate only changed its Azure branch. GitHub/GitLab/Gitea/Bitbucket paths untouched.
  • Performance: flagged and fixed during review — concurrent cold-cache polls originally raced N az spawns (now share one in-flight promise), and an unparseable expiry originally cached forever (now bounded). Warm-path cost is a memory read; cold path is one az spawn per ~hour.
  • UI quality: copy-only changes; i18n catalogs re-synced (sync:localization-catalog), and the shared "Set" fragment key used by the Bitbucket card was left untouched (new keys introduced instead).

Security Audit

  • Tokens live only in main-process memory; nothing is written to disk or logged. az logout revokes the source of truth; the in-memory copy expires within the hour.
  • execFile (no shell) with constant arguments; the only variable is the fixed resource GUID constant, so no injection surface. On Windows the existing batch-argument safety check applies.
  • Host eligibility parses via new URL and compares hostnames exactly (dev.azure.com, *.visualstudio.com), so a lookalike host such as dev.azure.com.evil.example cannot lure an Entra token — tested. On-prem URLs never receive az tokens, and env tokens keep absolute priority, so no existing setup changes behavior.
  • IPC surface unchanged; preflight's auth status probe reuses the same guarded module.

Notes

  • Preflight now probes az once when no Azure env config exists (same spirit as the existing gh/glab probes); the 60s negative cache plus preflight's own caching bound the cost to effectively one spawn per session.
  • On-prem Azure DevOps Server behavior is intentionally unchanged: PAT via ORCA_AZURE_DEVOPS_TOKEN + ORCA_AZURE_DEVOPS_API_BASE_URL.
  • Follow-up candidates (out of scope here): surfacing the active auth source (PAT vs az) on the Settings card, and the Azure Boards discussion in [Feature]: Azure Boards as a task provider (work item types differ per process) #11125.

https://claude.ai/code/session_01CR2s8B3hk7fUHZTe58zdzy

@yoyoys
yoyoys requested a review from brennanb2025 as a code owner August 3, 2026 03:58
@yoyoys
yoyoys force-pushed the feat/azure-devops-az-cli-auth branch from a7f96ee to 6c51948 Compare August 3, 2026 04:03
@coderabbitai

coderabbitai Bot commented Aug 3, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Adds Azure CLI Entra token acquisition for Azure DevOps, including parsing, caching, expiry handling, failure cooldowns, concurrent request sharing, and hosted URL validation. Azure DevOps requests and pull-request creation now prefer configured credentials and otherwise use Azure CLI tokens for eligible hosted URLs. Client authentication status checks Azure CLI login state. Tests and localized guidance cover both az login and ORCA_AZURE_DEVOPS_TOKEN.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 22.73% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 22 functions across 13 files. (5 skipped:… Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the primary change: Azure DevOps authentication through Azure CLI Entra login with environment-token fallback.
Description check ✅ Passed The description is detailed, on-topic, and explains the authentication order, hosted versus on-premises behavior, caching, testing, security, compatibility, and documentation. It identifies issue #111…
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Full details: Description check

Explanation

The description is detailed, on-topic, and explains the authentication order, hosted versus on-premises behavior, caching, testing, security, compatibility, and documentation. It identifies issue #11125 and explains that the UI changes are copy-only. Some template headings and checklist formatting are not reproduced exactly, but the required information is mostly present.

Full details: Docstring Coverage

Explanation

Docstring coverage is 22.73% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 22 functions across 13 files. (5 skipped: 5 unsupported.)


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 8

🧹 Nitpick comments (4)
src/main/azure-devops/az-cli-access-token.ts (1)

48-58: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Log the acquisition failure reason.

The catch block discards every failure. An operator cannot distinguish a missing az, an expired login, and a 20-second timeout. Log the error message only. Do not log stdout, because it contains the access token.

♻️ Proposed logging
   } catch (error) {
     failedAtMs = Date.now()
+    console.warn(
+      'az access token acquisition failed:',
+      error instanceof Error ? error.message : String(error)
+    )
     return null
   }
src/main/azure-devops/az-cli-access-token.test.ts (1)

80-104: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add coverage for a malformed az response.

The suite covers a rejected az invocation. It does not cover a resolved invocation whose payload has no accessToken. That path also enters the failure cooldown through failedAtMs = cached ? null : Date.now(). A regression there would be silent.

💚 Proposed test
+  it('treats a response without an access token as a failure', async () => {
+    runAzAccessTokenCommandMock.mockResolvedValue(JSON.stringify({ tokenType: 'Bearer' }))
+
+    await expect(getAzCliAzureDevOpsAccessToken()).resolves.toBeNull()
+    await expect(getAzCliAzureDevOpsAccessToken()).resolves.toBeNull()
+    expect(runAzAccessTokenCommandMock).toHaveBeenCalledTimes(1)
+  })
src/main/azure-devops/pull-request-creation.ts (1)

27-30: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

createApiBaseUrl duplicates configuredApiBaseUrl.

src/main/azure-devops/azure-devops-api-request.ts lines 79-82 define the same function body under the name configuredApiBaseUrl. That module already owns getAzureDevOpsAuthConfig and normalizeAzureDevOpsApiBaseUrl. Export the existing helper and import it here, so the two resolution rules cannot diverge.

♻️ Proposed change

In src/main/azure-devops/azure-devops-api-request.ts:

-function configuredApiBaseUrl(repo: AzureDevOpsRepoRef): string {
+export function configuredApiBaseUrl(repo: AzureDevOpsRepoRef): string {

In this file:

 import {
   azureDevOpsTokenConfigured,
+  configuredApiBaseUrl,
   getAzureDevOpsAuthConfig,
   normalizeAzureDevOpsApiBaseUrl,
   resolveAzureDevOpsAuthHeaders
 } from './azure-devops-api-request'
@@
-function createApiBaseUrl(repo: AzureDevOpsRepoRef): string {
-  const configured = getAzureDevOpsAuthConfig().apiBaseUrl
-  return configured ? normalizeAzureDevOpsApiBaseUrl(configured) : repo.apiBaseUrl
-}
-

Then replace createApiBaseUrl(repo) on line 183 with configuredApiBaseUrl(repo).

src/main/azure-devops/pull-request-creation.test.ts (1)

90-100: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Assert the Authorization header after the call, not inside the mock.

createAzureDevOpsPullRequest catches every error thrown from the request and converts it into a classified failure. If this inner expect fails, the thrown assertion is swallowed and reported as an unexpected auth_required or unknown result. The test still fails, but the message hides the real cause. Capture the header and assert it after the call.

💚 Proposed change
-    const fetchMock = vi.fn(async (_input: string | URL | Request, init?: RequestInit) => {
-      expect((init?.headers as Record<string, string> | undefined)?.Authorization).toBe(
-        'Bearer entra-jwt'
-      )
-      return Response.json({
+    const capturedAuthorization: (string | undefined)[] = []
+    const fetchMock = vi.fn(async (_input: string | URL | Request, init?: RequestInit) => {
+      capturedAuthorization.push((init?.headers as Record<string, string> | undefined)?.Authorization)
+      return Response.json({
         pullRequestId: 39,
         title: 'Entra create',
         status: 'active',
         creationDate: '2026-06-01T00:00:00Z'
       })
     })

Then assert expect(capturedAuthorization).toEqual(['Bearer entra-jwt']) next to the existing expect(fetchMock).toHaveBeenCalledOnce().


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 05c159d1-5df8-4296-8469-2791c612b642

📥 Commits

Reviewing files that changed from the base of the PR and between f3e087e and a7f96ee860df3f206e1b822bba6d79b2bfb89ab9.

📒 Files selected for processing (18)
  • src/main/azure-devops/az-cli-access-token.test.ts
  • src/main/azure-devops/az-cli-access-token.ts
  • src/main/azure-devops/az-cli-invocation.ts
  • src/main/azure-devops/azure-devops-api-request.test.ts
  • src/main/azure-devops/azure-devops-api-request.ts
  • src/main/azure-devops/client.test.ts
  • src/main/azure-devops/client.ts
  • src/main/azure-devops/pull-request-creation.test.ts
  • src/main/azure-devops/pull-request-creation.ts
  • src/main/source-control/hosted-review-creation.ts
  • src/renderer/src/components/right-sidebar/source-control-create-review-blocked-action.ts
  • src/renderer/src/components/right-sidebar/source-control-dropdown-items.test.ts
  • src/renderer/src/components/settings/token-source-control-integration-cards.tsx
  • src/renderer/src/i18n/locales/en.json
  • src/renderer/src/i18n/locales/es.json
  • src/renderer/src/i18n/locales/ja.json
  • src/renderer/src/i18n/locales/ko.json
  • src/renderer/src/i18n/locales/zh.json

Comment thread src/renderer/src/i18n/locales/es.json Resolved
Comment thread src/renderer/src/i18n/locales/ja.json Resolved
Comment thread src/renderer/src/i18n/locales/ko.json Resolved
Comment thread src/renderer/src/i18n/locales/zh.json Resolved
@greptile-apps

greptile-apps Bot commented Aug 3, 2026 •

Copy link
Copy Markdown

Greptile Summary

This PR adds Azure CLI (az login) as a first-class authentication path for hosted Azure DevOps (dev.azure.com / *.visualstudio.com), mirroring how GitHub and GitLab delegate to gh/glab. Environment tokens retain absolute priority; on-prem Azure DevOps Server is explicitly excluded and never consulted.

  • New az-cli-access-token.ts implements a memory-resident token cache with a 5-minute expiry margin, 60-second failure cooldown, concurrent-spawn deduplication via an inFlight promise, and a 30-minute safety cap for tokens that report no parseable expiry.
  • azure-devops-api-request.ts consolidates auth-header resolution into a single async resolveAzureDevOpsAuthHeaders function; the previously duplicated env-reading and header-building logic in pull-request-creation.ts is removed.
  • UI and i18n copy updated across Settings card, Create PR blocked notice, and all five locale catalogs to surface az login as an alternative to environment variables.

Confidence Score: 5/5

  • Safe to merge. The auth fallback is well-isolated: env tokens always win, on-prem hosts are never consulted, and Entra tokens only travel over HTTPS to exactly-matched Azure DevOps hostnames.
  • The token cache handles all edge cases (concurrent callers, expired tokens, missing expiry fields, legacy az versions) and every case is covered by dedicated tests. The host-eligibility check uses url.hostname comparison rather than string prefix matching, so lookalike domains cannot receive tokens. Previously flagged issues (expired-token cooldown bypass, duplicate base-URL resolver, bare visualstudio.com apex) are all resolved. No GitHub/GitLab/Gitea/Bitbucket paths are touched.
  • No files require special attention.

Important Files Changed

Filename Overview
src/main/azure-devops/az-cli-access-token.ts New module implementing the Entra token cache: warm-path is a single memory read; cold path spawns az once with concurrent-dedup via inFlight, 5-min expiry margin, 60s failure cooldown, and a 30-min cap for tokens with no parseable expiry. Previously flagged issues (expired-token cooldown bypass, bare visualstudio.com apex) are resolved. isEntraEligibleAzureDevOpsBaseUrl correctly enforces https and exact hostname matching.
src/main/azure-devops/az-cli-invocation.ts Thin wrapper around runProcess to exec az account get-access-token with a 20s timeout. Uses resolveWindowsCommand for correct .cmd-shim resolution on Windows. The resource GUID is a compile-time constant so there is no injection surface.
src/main/azure-devops/azure-devops-api-request.ts authHeaders renamed to envAuthHeaders and new async resolveAzureDevOpsAuthHeaders centralises auth-header resolution: env tokens win, then az CLI for Entra-eligible hosts, then no-op for on-prem. doFetch inside requestAzureDevOpsJsonAtBase is now async to await resolveAzureDevOpsAuthHeaders; retry path re-evaluates headers via the same doFetch closure but the cached token makes this a memory read.
src/main/azure-devops/pull-request-creation.ts isAzureDevOpsReviewCreationAuthenticated is now async and resolves the repo's base URL to determine az CLI eligibility, matching the pattern used by isGitLabAuthenticated. Duplicate auth-header and env-reading logic was removed in favour of the shared resolvers. Error copy updated to mention az login. Previously flagged duplicate createApiBaseUrl is removed.
src/main/azure-devops/client.ts getAzureDevOpsAuthStatus probes az when no base URL and no env token are configured, setting configured: true when an az token exists. Returns authenticated: false in that path because there is no base URL to probe against — this is intentional and tested.
src/main/source-control/hosted-review-creation-provider.ts isProviderAuthenticated now forwards repoPath, connectionId, and options to isAzureDevOpsReviewCreationAuthenticated, enabling the repo-ref resolution needed for az CLI eligibility. authInstruction copy updated to mention az login.
src/main/azure-devops/az-cli-access-token.test.ts Comprehensive new test file covering token acquisition, caching, expiry-margin refresh, failure cooldown, concurrent-spawn dedup, legacy expiresOn fallback, already-expired-token cooldown (the previously flagged issue), unknown-expiry TTL cap, and host eligibility edge cases including lookalike hosts, non-https, and bare apex rejection.

Sequence Diagram

sequenceDiagram
    participant Caller as Orca Main Process
    participant Cache as AzTokenCache
    participant AZ as az CLI
    participant ADO as Azure DevOps API

    Caller->>Caller: resolveAzureDevOpsAuthHeaders(baseUrl)
    alt env token configured (ORCA_AZURE_DEVOPS_TOKEN / ACCESS_TOKEN)
        Caller-->>ADO: fetch with Basic/Bearer from env
    else "isEntraEligibleAzureDevOpsBaseUrl(baseUrl) = false (on-prem)"
        Caller-->>ADO: fetch with no Authorization header
    else "hosted Azure DevOps (dev.azure.com / *.visualstudio.com)"
        Caller->>Cache: getAzCliAzureDevOpsAccessToken()
        alt "token cached && not near expiry"
            Cache-->>Caller: cached token (memory read)
        else "failure cooldown active (< 60s since last az failure)"
            Cache-->>Caller: null
        else inFlight promise exists (concurrent dedup)
            Cache-->>Caller: share existing promise
        else cold cache / expired
            Cache->>AZ: execFile az account get-access-token --resource 499b84...
            AZ-->>Cache: "JSON {accessToken, expires_on/expiresOn}"
            Cache->>Cache: parseTokenResponse / expiry check
            Cache-->>Caller: token or null
        end
        Caller-->>ADO: fetch with Bearer entra-token (or no header if null)
    end
Loading

Reviews (2): Last reviewed commit: "fix(azure-devops): route the az invocati..." | Re-trigger Greptile

@AmethystLiang

Copy link
Copy Markdown
Contributor

thanks for reporting. looking into it

@coderabbitai

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 2


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 421aac0d-6af7-4ed7-b0dd-a71cee11d2ce

📥 Commits

Reviewing files that changed from the base of the PR and between a30e3b9 and e7f2c7425fcbbab724ad1367a3111f20a06e141a.

📒 Files selected for processing (18)
  • src/main/azure-devops/az-cli-access-token.test.ts
  • src/main/azure-devops/az-cli-access-token.ts
  • src/main/azure-devops/az-cli-invocation.ts
  • src/main/azure-devops/azure-devops-api-request.test.ts
  • src/main/azure-devops/azure-devops-api-request.ts
  • src/main/azure-devops/client.test.ts
  • src/main/azure-devops/client.ts
  • src/main/azure-devops/pull-request-creation.test.ts
  • src/main/azure-devops/pull-request-creation.ts
  • src/main/source-control/hosted-review-creation.ts
  • src/renderer/src/components/right-sidebar/source-control-create-review-blocked-action.ts
  • src/renderer/src/components/right-sidebar/source-control-dropdown-items.create-pr-intent.test.ts
  • src/renderer/src/components/settings/token-source-control-integration-cards.tsx
  • src/renderer/src/i18n/locales/en.json
  • src/renderer/src/i18n/locales/es.json
  • src/renderer/src/i18n/locales/ja.json
  • src/renderer/src/i18n/locales/ko.json
  • src/renderer/src/i18n/locales/zh.json
🚧 Files skipped from review as they are similar to previous changes (13)
  • src/main/azure-devops/azure-devops-api-request.test.ts
  • src/main/source-control/hosted-review-creation.ts
  • src/main/azure-devops/client.ts
  • src/renderer/src/components/right-sidebar/source-control-create-review-blocked-action.ts
  • src/main/azure-devops/azure-devops-api-request.ts
  • src/main/azure-devops/az-cli-access-token.test.ts
  • src/main/azure-devops/client.test.ts
  • src/main/azure-devops/az-cli-access-token.ts
  • src/main/azure-devops/pull-request-creation.ts
  • src/renderer/src/i18n/locales/en.json
  • src/main/azure-devops/pull-request-creation.test.ts
  • src/renderer/src/components/settings/token-source-control-integration-cards.tsx
  • src/renderer/src/i18n/locales/ko.json

Comment thread src/renderer/src/i18n/locales/ja.json Resolved
@yoyoys
yoyoys force-pushed the feat/azure-devops-az-cli-auth branch from e7f2c74 to a090e83 Compare August 7, 2026 02:31
@coderabbitai

coderabbitai Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@coderabbitai

coderabbitai Bot commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@yoyoys

yoyoys commented Aug 17, 2026

Copy link
Copy Markdown
Contributor Author

@brennanb2025 — no rush on this, just checking what's most useful from my side.

The branch is currently mergeable, but it's ~326 commits behind main. Would you like me to rebase before you take a look, or would you rather I leave it as-is until you're ready? I've been rebasing periodically, but I don't want to keep churning the diff while it's queued.

One thing that may need a nudge from your side: CI has never run on this PR — fork PRs appear to need a maintainer to approve the workflow, so there's no green check to look at yet.

In case it saves you a pass: this now sits cleanly on top of your #12832. The -preview retry and resolveAzureDevOpsGitApiBaseUrl are untouched — the az CLI path only adds an auth-header resolver, and it never applies to on-prem hosts (Azure DevOps Server isn't federated with Entra, so it stays on the PAT path by design, with a test pinning that).

@nwparker nwparker removed the P2 label Aug 19, 2026
@yoyoys
yoyoys force-pushed the feat/azure-devops-az-cli-auth branch from 6644bcc to 97323ba Compare August 25, 2026 05:37
@coderabbitai

coderabbitai Bot commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 9abd9052-6796-4485-a1a2-189ec1cb8073

📥 Commits

Reviewing files that changed from the base of the PR and between a7505fd and 97323ba204fb6d16df1ecac96c220b7a2737a9d1.

📒 Files selected for processing (18)
  • src/main/azure-devops/az-cli-access-token.test.ts
  • src/main/azure-devops/az-cli-access-token.ts
  • src/main/azure-devops/az-cli-invocation.ts
  • src/main/azure-devops/azure-devops-api-request.test.ts
  • src/main/azure-devops/azure-devops-api-request.ts
  • src/main/azure-devops/client.test.ts
  • src/main/azure-devops/client.ts
  • src/main/azure-devops/pull-request-creation.test.ts
  • src/main/azure-devops/pull-request-creation.ts
  • src/main/source-control/hosted-review-creation.ts
  • src/renderer/src/components/right-sidebar/source-control-create-review-blocked-action.ts
  • src/renderer/src/components/right-sidebar/source-control-dropdown-items.create-pr-intent.test.ts
  • src/renderer/src/components/settings/token-source-control-integration-cards.tsx
  • src/renderer/src/i18n/locales/en.json
  • src/renderer/src/i18n/locales/es.json
  • src/renderer/src/i18n/locales/ja.json
  • src/renderer/src/i18n/locales/ko.json
  • src/renderer/src/i18n/locales/zh.json
🚧 Files skipped from review as they are similar to previous changes (17)
  • src/renderer/src/components/right-sidebar/source-control-create-review-blocked-action.ts
  • src/renderer/src/components/right-sidebar/source-control-dropdown-items.create-pr-intent.test.ts
  • src/main/source-control/hosted-review-creation.ts
  • src/main/azure-devops/client.ts
  • src/main/azure-devops/client.test.ts
  • src/main/azure-devops/az-cli-access-token.test.ts
  • src/renderer/src/i18n/locales/en.json
  • src/renderer/src/components/settings/token-source-control-integration-cards.tsx
  • src/renderer/src/i18n/locales/es.json
  • src/renderer/src/i18n/locales/zh.json
  • src/main/azure-devops/az-cli-access-token.ts
  • src/main/azure-devops/pull-request-creation.ts
  • src/renderer/src/i18n/locales/ja.json
  • src/main/azure-devops/azure-devops-api-request.ts
  • src/main/azure-devops/azure-devops-api-request.test.ts
  • src/main/azure-devops/pull-request-creation.test.ts
  • src/renderer/src/i18n/locales/ko.json

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.

@yoyoys

yoyoys commented Aug 26, 2026

Copy link
Copy Markdown
Contributor Author

@nwparker — this is ready whenever you have a moment, and I'd love to get it in.

What it does: hosted Azure DevOps authenticates through the Azure CLI's existing az login, the same way Orca already delegates to gh and glab. Env tokens keep absolute priority, and on-prem Azure DevOps Server is untouched — it never consults az, because Azure DevOps Server isn't federated with Entra at all (there's a test pinning that).

Why it's better than documenting the token:

  • Simpler — it removes the setup step instead of explaining it. Today Create PR fails with "set ORCA_AZURE_DEVOPS_TOKEN", and nothing says where to set it so a packaged app picks it up, or which PAT scopes it needs. With this, a developer who has already run az login needs no configuration at all.
  • More reliable — Entra tokens refresh automatically (~1h, cached in memory, one az spawn per hour), whereas a PAT silently expires and takes Create PR down until someone re-issues it. Orca also stops holding a credential: az logout revokes access, and nothing is written to disk or logged.

Tested against a real org, not just unit tests: with every ORCA_AZURE_DEVOPS_* variable unset, the unmocked modules acquired a real Entra token, produced the Bearer header for dev.azure.com, and authenticated a live REST call end to end. I use Azure DevOps at work, so I can keep verifying against a real tenant on request.

Current state: 23 days open, rebased onto today's main (MERGEABLE), 14 review threads all resolved, pnpm lint / typecheck / targeted tests green. The latest commit addresses the child-process chokepoint from #15746 — that landed after this branch was written, and rebasing onto it turned the direct child_process import into a ratchet failure, so runProcess is now used (which also let me drop the hand-rolled Windows .cmd argument encoding).

One thing only you can unblock: CI has never run on this PR — fork PRs seem to need a maintainer to approve the workflow, so there's no green check to look at. If you approve a run, you'll have the full signal.

Happy to split, reshape, or rebase this however suits you.

yoyoys added 4 commits August 31, 2026 15:26
…llback

Hosted Azure DevOps (dev.azure.com / *.visualstudio.com) now authenticates
through the az CLI's existing login when no ORCA_AZURE_DEVOPS_* token is
configured, mirroring how GitHub/GitLab delegate credentials to gh/glab.
Env tokens keep priority; on-prem Azure DevOps Server never consults az
and still requires a PAT.

Claude-Session: https://claude.ai/code/session_01CR2s8B3hk7fUHZTe58zdzy
…lifetime

Concurrent cold-cache polls now share one in-flight az invocation. Older
az versions that omit expires_on fall back to parsing expiresOn, and a
token with no parseable expiry is capped at 30 minutes instead of being
served stale forever.

Claude-Session: https://claude.ai/code/session_01CR2s8B3hk7fUHZTe58zdzy
- Require HTTPS before a base URL is Entra-eligible so a bearer token
  never travels in cleartext (CodeRabbit)
- Drop the dead bare visualstudio.com apex branch (Greptile)
- Treat an already-expired az token as a failure so the 60s cooldown
  applies to sequential polls (Greptile)
- Forward hosted-review local git exec options (wslDistro) into the
  auth gate's repo-ref resolution (CodeRabbit)
- Reuse configuredApiBaseUrl instead of a duplicated resolver (Greptile)
- Mint a new i18n key for the changed Azure card description so the
  copy change actually reaches users instead of being shadowed by the
  stale catalog entry (CodeRabbit)

Claude-Session: https://claude.ai/code/session_01CR2s8B3hk7fUHZTe58zdzy
The child_process chokepoint landed in stablyai#15746 after this branch was
written; rebasing onto it made the direct node:child_process import a
ratchet violation. runProcess also encapsulates the Windows .cmd
argument encoding this file was doing by hand, so getSpawnArgsForWindows
is no longer needed here — only the absolute-path resolution is, since
runProcess spawns without a shell.

runProcess reports failure in its result rather than throwing, so
non-zero exits and timeouts are converted to a thrown error to preserve
the token cache's failure-cooldown behavior.

Claude-Session: https://claude.ai/code/session_01CR2s8B3hk7fUHZTe58zdzy
@yoyoys

yoyoys commented Sep 1, 2026

Copy link
Copy Markdown
Contributor Author

Filed #17908 to describe the motivation on its own terms — that hosted Azure DevOps should be able to authenticate the way Microsoft's own Azure DevOps MCP server does (AzureCliCredential, scope 499b84ac-…/.default, no token in the environment), rather than asking the user to manage a PAT.

Splitting it out because #11125 is about Azure Boards as a task provider, which is a different subsystem from source-control auth, so this PR had no issue that actually described it.

@yoyoys

yoyoys commented Sep 17, 2026

Copy link
Copy Markdown
Contributor Author

Closing this in favour of a broader change: Azure DevOps Boards as a task provider (backlog and board views rendered from the team's own configuration), which carries this auth work with it — the az CLI path turned out to be the only route that works from a Dock-launched app, since the packaged app never reads the shell environment the Settings card tells users to set.

Motivation for the auth piece on its own is in #17908. If you'd rather take the auth change standalone after all, say so and I'll reopen — the branch is still mergeable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants