Repository navigation
Conversation
a7f96ee to
6c51948
Compare
|
Note Reviews pausedIt 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 Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughAdds 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 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Full details: Description checkExplanation 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 Full details: Docstring CoverageExplanation 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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 8
🧹 Nitpick comments (4)
src/main/azure-devops/az-cli-access-token.ts (1)
48-58: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winLog 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 logstdout, 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 winAdd coverage for a malformed az response.
The suite covers a rejected
azinvocation. It does not cover a resolved invocation whose payload has noaccessToken. That path also enters the failure cooldown throughfailedAtMs = 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
createApiBaseUrlduplicatesconfiguredApiBaseUrl.
src/main/azure-devops/azure-devops-api-request.tslines 79-82 define the same function body under the nameconfiguredApiBaseUrl. That module already ownsgetAzureDevOpsAuthConfigandnormalizeAzureDevOpsApiBaseUrl. 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 withconfiguredApiBaseUrl(repo).src/main/azure-devops/pull-request-creation.test.ts (1)
90-100: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAssert the Authorization header after the call, not inside the mock.
createAzureDevOpsPullRequestcatches every error thrown from the request and converts it into a classified failure. If this innerexpectfails, the thrown assertion is swallowed and reported as an unexpectedauth_requiredorunknownresult. 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 existingexpect(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.tssrc/main/azure-devops/az-cli-access-token.tssrc/main/azure-devops/az-cli-invocation.tssrc/main/azure-devops/azure-devops-api-request.test.tssrc/main/azure-devops/azure-devops-api-request.tssrc/main/azure-devops/client.test.tssrc/main/azure-devops/client.tssrc/main/azure-devops/pull-request-creation.test.tssrc/main/azure-devops/pull-request-creation.tssrc/main/source-control/hosted-review-creation.tssrc/renderer/src/components/right-sidebar/source-control-create-review-blocked-action.tssrc/renderer/src/components/right-sidebar/source-control-dropdown-items.test.tssrc/renderer/src/components/settings/token-source-control-integration-cards.tsxsrc/renderer/src/i18n/locales/en.jsonsrc/renderer/src/i18n/locales/es.jsonsrc/renderer/src/i18n/locales/ja.jsonsrc/renderer/src/i18n/locales/ko.jsonsrc/renderer/src/i18n/locales/zh.json
Greptile SummaryThis PR adds Azure CLI (
Confidence Score: 5/5
|
| 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
Reviews (2): Last reviewed commit: "fix(azure-devops): route the az invocati..." | Re-trigger Greptile
|
thanks for reporting. looking into it |
7e895db to
e7f2c74
Compare
|
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. |
There was a problem hiding this comment.
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.tssrc/main/azure-devops/az-cli-access-token.tssrc/main/azure-devops/az-cli-invocation.tssrc/main/azure-devops/azure-devops-api-request.test.tssrc/main/azure-devops/azure-devops-api-request.tssrc/main/azure-devops/client.test.tssrc/main/azure-devops/client.tssrc/main/azure-devops/pull-request-creation.test.tssrc/main/azure-devops/pull-request-creation.tssrc/main/source-control/hosted-review-creation.tssrc/renderer/src/components/right-sidebar/source-control-create-review-blocked-action.tssrc/renderer/src/components/right-sidebar/source-control-dropdown-items.create-pr-intent.test.tssrc/renderer/src/components/settings/token-source-control-integration-cards.tsxsrc/renderer/src/i18n/locales/en.jsonsrc/renderer/src/i18n/locales/es.jsonsrc/renderer/src/i18n/locales/ja.jsonsrc/renderer/src/i18n/locales/ko.jsonsrc/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
e7f2c74 to
a090e83
Compare
|
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. |
a090e83 to
6644bcc
Compare
|
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. |
|
@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 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 |
6644bcc to
97323ba
Compare
|
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. |
There was a problem hiding this comment.
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.tssrc/main/azure-devops/az-cli-access-token.tssrc/main/azure-devops/az-cli-invocation.tssrc/main/azure-devops/azure-devops-api-request.test.tssrc/main/azure-devops/azure-devops-api-request.tssrc/main/azure-devops/client.test.tssrc/main/azure-devops/client.tssrc/main/azure-devops/pull-request-creation.test.tssrc/main/azure-devops/pull-request-creation.tssrc/main/source-control/hosted-review-creation.tssrc/renderer/src/components/right-sidebar/source-control-create-review-blocked-action.tssrc/renderer/src/components/right-sidebar/source-control-dropdown-items.create-pr-intent.test.tssrc/renderer/src/components/settings/token-source-control-integration-cards.tsxsrc/renderer/src/i18n/locales/en.jsonsrc/renderer/src/i18n/locales/es.jsonsrc/renderer/src/i18n/locales/ja.jsonsrc/renderer/src/i18n/locales/ko.jsonsrc/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.
|
@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 Why it's better than documenting the token:
Tested against a real org, not just unit tests: with every Current state: 23 days open, rebased onto today's 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. |
…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
e6c9c1b to
e5949a0
Compare
|
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 ( 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. |
|
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. |
Summary
Azure DevOps requests now authenticate through the Azure CLI's existing
az loginwhen noORCA_AZURE_DEVOPS_*token is configured, mirroring how GitHub and GitLab delegate credentials togh/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:
ORCA_AZURE_DEVOPS_ACCESS_TOKEN/ORCA_AZURE_DEVOPS_TOKEN(unchanged, always win)dev.azure.com/*.visualstudio.com) only: an Entra token acquired viaaz account get-access-token --resource 499b84ac-1321-427f-aa17-267ca6975798(Azure DevOps' fixed application ID, identical for every tenant; noazure-devopsCLI extension needed)az— it only accepts PAT/Windows auth, so the token path stays required thereDetails:
azfailures are negative-cached for 60s so a missing/logged-outazdoesn't pay a ~1s Python spawn per poll, while a freshaz loginis picked up without restarting Orca. Concurrent cold-cache callers share one in-flightazinvocation. Olderazversions that omitexpires_onfall back to parsing local-timeexpiresOn; no parseable expiry caps the cache at 30 minutes instead of serving a stale token forever.pull-request-creation.tswas collapsed into the sharedazure-devops-api-request.tsresolver; the create gate is now async and resolves the repo's base URL to decide az eligibility.az loginalongside the env vars.docs/reference/azure-devops-authentication.md(both auth paths, env var table, PAT scopes, on-prem note) — previouslydocs/had nothing on Azure.Screenshots
No visual change beyond copy: the Settings card's not-configured hint now reads "Run
az login(Azure CLI), setORCA_AZURE_DEVOPS_TOKEN, or setORCA_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 lintpnpm typecheckpnpm 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-handlerrebase timeout), and 2 (agent-exec-handler) fail identically onmainin this environmentpnpm buildReal-environment verification (macOS,
azlogged in, allORCA_AZURE_DEVOPS_*unset): the unmocked modules acquired a real Entra token, produced Bearer headers fordev.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
azboundary with a default rejection, so results don't depend on whether the dev machine hasazinstalled or logged in.AI Review Report
Reviewed by Claude (Fable 5) with the diff-wide pass covering:
azresolution goes through the existingresolveWindowsCommand+getSpawnArgsForWindowshelpers, so Windowsaz.cmdgets the cmd.exe shim treatment with batch-unsafe-argument guards; no paths, shortcuts, or labels touched. macOS/Linux spawnazdirectly.azspawn both run in the main process on the local machine, matching the existinggh/glabbehavior; 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).azspawns (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 oneazspawn per ~hour.sync:localization-catalog), and the shared "Set" fragment key used by the Bitbucket card was left untouched (new keys introduced instead).Security Audit
az logoutrevokes 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.new URLand compares hostnames exactly (dev.azure.com,*.visualstudio.com), so a lookalike host such asdev.azure.com.evil.examplecannot lure an Entra token — tested. On-prem URLs never receive az tokens, and env tokens keep absolute priority, so no existing setup changes behavior.Notes
azonce when no Azure env config exists (same spirit as the existinggh/glabprobes); the 60s negative cache plus preflight's own caching bound the cost to effectively one spawn per session.ORCA_AZURE_DEVOPS_TOKEN+ORCA_AZURE_DEVOPS_API_BASE_URL.https://claude.ai/code/session_01CR2s8B3hk7fUHZTe58zdzy