-
Notifications
You must be signed in to change notification settings - Fork 770
Add Copilot multi-account support #637
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ajmccall
wants to merge
16
commits into
steipete:main
Choose a base branch
from
ajmccall:feat/copilot-multi-account
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 9 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
b69016e
feat: add Copilot to token account support catalog
ajmccall 8295649
feat: add GitHub username fetch to CopilotUsageFetcher
ajmccall 2910b32
feat: store Copilot OAuth tokens in multi-account system
ajmccall 6a29dee
feat: update Copilot settings UI for multi-account
ajmccall 17e5067
feat: auto-migrate Copilot config token to multi-account store
ajmccall ee7d3ba
test: add Copilot multi-account catalog, migration, and env precedenc…
ajmccall 5b626dc
docs: add spec, review, and implementation plan for Copilot multi-acc…
ajmccall 75eca6d
chore: update plan status to Shipped
ajmccall 67f244a
Delete .plans/2026-04-01-copilot-multi-account.md
ajmccall 7e57578
Delete specs/2026-04-01-copilot-multi-account.md
ajmccall 421ee74
Delete reviews/2026-04-01-copilot-multi-account.md
ajmccall 7aeb03e
fix: stack multi-account usage cards and refresh data on account switch
38b6bc9
fix: removed migration code
366a864
fix: token account update preserves identity and selection
4dadf7c
Refine Copilot multi-account UI
a7aae1d
Preserve active token account on removal
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,180 @@ | ||
| import CodexBarCore | ||
| import Foundation | ||
| import Testing | ||
| @testable import CodexBar | ||
|
|
||
| // MARK: - Catalog | ||
|
|
||
| @Test | ||
| func `copilot catalog entry exists`() { | ||
| let support = TokenAccountSupportCatalog.support(for: .copilot) | ||
| #expect(support != nil) | ||
| #expect(support?.requiresManualCookieSource == false) | ||
| #expect(support?.cookieName == nil) | ||
| } | ||
|
|
||
| @Test | ||
| func `copilot catalog entry uses environment injection`() { | ||
| let support = TokenAccountSupportCatalog.support(for: .copilot) | ||
| guard let support else { | ||
| Issue.record("Copilot catalog entry missing") | ||
| return | ||
| } | ||
| if case let .environment(key) = support.injection { | ||
| #expect(key == "COPILOT_API_TOKEN") | ||
| } else { | ||
| Issue.record("Expected .environment injection, got cookieHeader") | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| func `copilot env override uses correct key`() { | ||
| let override = TokenAccountSupportCatalog.envOverride(for: .copilot, token: "gh_abc") | ||
| #expect(override == ["COPILOT_API_TOKEN": "gh_abc"]) | ||
| } | ||
|
|
||
| // MARK: - Username Fetch (parsing only) | ||
|
|
||
| @Test | ||
| func `GitHub user response parses login`() throws { | ||
| let json = #"{"login": "testuser", "id": 123, "name": "Test User"}"# | ||
| struct GitHubUser: Decodable { let login: String } | ||
| let user = try JSONDecoder().decode(GitHubUser.self, from: Data(json.utf8)) | ||
| #expect(user.login == "testuser") | ||
| } | ||
|
|
||
| @Test | ||
| func `GitHub user response parses login with minimal fields`() throws { | ||
| let json = #"{"login": "minimaluser"}"# | ||
| struct GitHubUser: Decodable { let login: String } | ||
| let user = try JSONDecoder().decode(GitHubUser.self, from: Data(json.utf8)) | ||
| #expect(user.login == "minimaluser") | ||
| } | ||
|
|
||
| // MARK: - Migration | ||
|
|
||
| @MainActor | ||
| struct CopilotMigrationTests { | ||
| @Test | ||
| func `migration moves config token to account`() { | ||
| let settings = Self.makeSettingsStore(suite: "copilot-migration-move") | ||
| settings.copilotAPIToken = "gh_token_123" | ||
| #expect(settings.tokenAccounts(for: .copilot).isEmpty) | ||
|
|
||
| settings.migrateCopilotTokenToAccountIfNeeded() | ||
|
|
||
| #expect(settings.copilotAPIToken.isEmpty) | ||
| let accounts = settings.tokenAccounts(for: .copilot) | ||
| #expect(accounts.count == 1) | ||
| #expect(accounts.first?.token == "gh_token_123") | ||
| #expect(accounts.first?.label == "Account 1") | ||
| } | ||
|
|
||
| @Test | ||
| func `migration is idempotent`() { | ||
| let settings = Self.makeSettingsStore(suite: "copilot-migration-idempotent") | ||
| settings.copilotAPIToken = "gh_token_123" | ||
|
|
||
| settings.migrateCopilotTokenToAccountIfNeeded() | ||
| settings.migrateCopilotTokenToAccountIfNeeded() | ||
|
|
||
| #expect(settings.tokenAccounts(for: .copilot).count == 1) | ||
| } | ||
|
|
||
| @Test | ||
| func `migration no-op when no token`() { | ||
| let settings = Self.makeSettingsStore(suite: "copilot-migration-no-token") | ||
|
|
||
| settings.migrateCopilotTokenToAccountIfNeeded() | ||
|
|
||
| #expect(settings.tokenAccounts(for: .copilot).isEmpty) | ||
| } | ||
|
|
||
| @Test | ||
| func `migration no-op when accounts already exist`() { | ||
| let settings = Self.makeSettingsStore(suite: "copilot-migration-existing") | ||
| settings.copilotAPIToken = "gh_token_old" | ||
| settings.addTokenAccount(provider: .copilot, label: "existing", token: "gh_token_existing") | ||
|
|
||
| settings.migrateCopilotTokenToAccountIfNeeded() | ||
|
|
||
| #expect(settings.tokenAccounts(for: .copilot).count == 1) | ||
| #expect(settings.tokenAccounts(for: .copilot).first?.label == "existing") | ||
| } | ||
|
|
||
| private static func makeSettingsStore(suite: String) -> SettingsStore { | ||
| SettingsStore( | ||
| configStore: testConfigStore(suiteName: suite), | ||
| zaiTokenStore: NoopZaiTokenStore(), | ||
| syntheticTokenStore: NoopSyntheticTokenStore(), | ||
| codexCookieStore: InMemoryCookieHeaderStore(), | ||
| claudeCookieStore: InMemoryCookieHeaderStore(), | ||
| cursorCookieStore: InMemoryCookieHeaderStore(), | ||
| opencodeCookieStore: InMemoryCookieHeaderStore(), | ||
| factoryCookieStore: InMemoryCookieHeaderStore(), | ||
| minimaxCookieStore: InMemoryMiniMaxCookieStore(), | ||
| minimaxAPITokenStore: InMemoryMiniMaxAPITokenStore(), | ||
| kimiTokenStore: InMemoryKimiTokenStore(), | ||
| kimiK2TokenStore: InMemoryKimiK2TokenStore(), | ||
| augmentCookieStore: InMemoryCookieHeaderStore(), | ||
| ampCookieStore: InMemoryCookieHeaderStore(), | ||
| copilotTokenStore: InMemoryCopilotTokenStore(), | ||
| tokenAccountStore: InMemoryTokenAccountStore()) | ||
| } | ||
| } | ||
|
|
||
| // MARK: - Environment Precedence | ||
|
|
||
| @MainActor | ||
| struct CopilotEnvironmentPrecedenceTests { | ||
| @Test | ||
| func `token account overrides config API key`() { | ||
| let settings = Self.makeSettingsStore(suite: "copilot-env-override") | ||
| settings.copilotAPIToken = "old_config_token" | ||
| settings.addTokenAccount(provider: .copilot, label: "new", token: "new_account_token") | ||
|
|
||
| let account = settings.selectedTokenAccount(for: .copilot)! | ||
| let override = TokenAccountOverride(provider: .copilot, account: account) | ||
| let env = ProviderRegistry.makeEnvironment( | ||
| base: [:], | ||
| provider: .copilot, | ||
| settings: settings, | ||
| tokenOverride: override) | ||
|
|
||
| #expect(env["COPILOT_API_TOKEN"] == "new_account_token") | ||
| } | ||
|
|
||
| @Test | ||
| func `config API key used when no token accounts`() { | ||
| let settings = Self.makeSettingsStore(suite: "copilot-env-config-only") | ||
| settings.copilotAPIToken = "config_token" | ||
|
|
||
| let env = ProviderRegistry.makeEnvironment( | ||
| base: [:], | ||
| provider: .copilot, | ||
| settings: settings, | ||
| tokenOverride: nil) | ||
|
|
||
| #expect(env["COPILOT_API_TOKEN"] == "config_token") | ||
| } | ||
|
|
||
| private static func makeSettingsStore(suite: String) -> SettingsStore { | ||
| SettingsStore( | ||
| configStore: testConfigStore(suiteName: suite), | ||
| zaiTokenStore: NoopZaiTokenStore(), | ||
| syntheticTokenStore: NoopSyntheticTokenStore(), | ||
| codexCookieStore: InMemoryCookieHeaderStore(), | ||
| claudeCookieStore: InMemoryCookieHeaderStore(), | ||
| cursorCookieStore: InMemoryCookieHeaderStore(), | ||
| opencodeCookieStore: InMemoryCookieHeaderStore(), | ||
| factoryCookieStore: InMemoryCookieHeaderStore(), | ||
| minimaxCookieStore: InMemoryMiniMaxCookieStore(), | ||
| minimaxAPITokenStore: InMemoryMiniMaxAPITokenStore(), | ||
| kimiTokenStore: InMemoryKimiTokenStore(), | ||
| kimiK2TokenStore: InMemoryKimiK2TokenStore(), | ||
| augmentCookieStore: InMemoryCookieHeaderStore(), | ||
| ampCookieStore: InMemoryCookieHeaderStore(), | ||
| copilotTokenStore: InMemoryCopilotTokenStore(), | ||
| tokenAccountStore: InMemoryTokenAccountStore()) | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.