Skip to content

feat(powershell): az CLI work/personal account switch (azw/azp) + prompt tag - #30

Merged
jinyeow merged 2 commits into
mainfrom
feat/az-cli-account-switch
Jul 25, 2026
Merged

feat(powershell): az CLI work/personal account switch (azw/azp) + prompt tag#30
jinyeow merged 2 commits into
mainfrom
feat/az-cli-account-switch

Conversation

@jinyeow

@jinyeow jinyeow commented Jul 25, 2026

Copy link
Copy Markdown
Owner

Summary

Adds az (Azure CLI) work/personal account switching to the PowerShell profile — flip accounts in a running shell without a new terminal or re-login.

  • Switch-AzWork / Switch-AzPersonal (+ azw/azp aliases) in new powershell/Profile/AzCliAccount.ps1. Each account isolates its token cache via AZURE_CONFIG_DIR — asymmetric on purpose: work = default ~/.azure (existing login untouched), personal = ~/.azure-personal.
  • Last-used choice persists to ~/.azure-active-profile; restored in Phase 1. A work/missing/unrecognized state actively unsets the var so an inherited value can't leak.
  • Each switch clears the session-cached ADO bearer token ($global:__AdoAccessToken) so prr / Invoke-AdoPrReview re-authenticates against the now-active account (deliberately not pinned — it follows whichever account owns the PRs).
  • Always-visible prompt tag az:work (green) / az:personal (magenta) on the context line, driven by $env:AZURE_CONFIG_DIR alone — no az process.

Tests / gates

22 Pester green (7 AzCliAccount.Tests.ps1 + 2 new Set-Prompt segment tests + existing); PSScriptAnalyzer -Recurse gated-clean.

Review

Cross-model Codex review run: 1 HIGH + 3 MEDIUM, all evaluated and declined with grounds (fail-open default-to-work is deliberate for a Phase-1 load path; repo convention types params not locals).

One-time setup

az login per config dir is interactive. Work already lives in ~/.azure; personal needs one az login under AZURE_CONFIG_DIR=~/.azure-personal.

jinyeow and others added 2 commits July 25, 2026 15:40
Flip the Azure CLI between a work and personal account in a running shell
without a new terminal or re-login. Each account gets an isolated az config
dir via AZURE_CONFIG_DIR (asymmetric: work = default ~/.azure so the existing
login is untouched; personal = ~/.azure-personal). The last-used choice
persists to ~/.azure-active-profile and is restored in Phase 1 by the profile
(a work/missing/unrecognized state actively unsets the var so an inherited
value can't leak in).

Switching clears the session-cached ADO bearer token ($global:__AdoAccessToken)
so prr/Invoke-AdoPrReview re-authenticates against the now-active account.

The active account is always visible in the prompt (az:work / az:personal),
driven by $env:AZURE_CONFIG_DIR alone — no az process.

Covered by tests/AzCliAccount.Tests.ps1 and tests/Set-Prompt.Tests.ps1.
@jinyeow
jinyeow merged commit 9307f82 into main Jul 25, 2026
5 checks passed
@jinyeow
jinyeow deleted the feat/az-cli-account-switch branch July 25, 2026 13:34
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.

1 participant