Skip to content

Commit 7ebc91e

Browse files
committed
fix
1 parent 9402ff3 commit 7ebc91e

File tree

2 files changed

+10
-64
lines changed

2 files changed

+10
-64
lines changed

src/extension/agents/vscode-node/organizationAndEnterpriseAgentProvider.ts

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
import * as vscode from 'vscode';
77
import YAML from 'yaml';
8-
import { IAuthenticationService } from '../../../platform/authentication/common/authentication';
98
import { IVSCodeExtensionContext } from '../../../platform/extContext/common/extensionContext';
109
import { IFileSystemService } from '../../../platform/filesystem/common/fileSystemService';
1110
import { FileType } from '../../../platform/filesystem/common/fileTypes';
@@ -27,20 +26,15 @@ export class OrganizationAndEnterpriseAgentProvider extends Disposable implement
2726
readonly onDidChangeCustomAgents = this._onDidChangeCustomAgents.event;
2827

2928
private isFetching = false;
30-
private memoryCache: vscode.CustomAgentResource[] | undefined = undefined;
29+
private memoryCache = new Map<string, vscode.CustomAgentResource[]>();
3130

3231
constructor(
3332
@IOctoKitService private readonly octoKitService: IOctoKitService,
3433
@ILogService private readonly logService: ILogService,
3534
@IVSCodeExtensionContext readonly extensionContext: IVSCodeExtensionContext,
3635
@IFileSystemService private readonly fileSystem: IFileSystemService,
37-
@IAuthenticationService private readonly authenticationService: IAuthenticationService,
3836
) {
3937
super();
40-
this._register(this.authenticationService.onDidAuthenticationChange(() => {
41-
this.logService.trace('[OrganizationAndEnterpriseAgentProvider] Authentication changed, firing onDidChangeCustomAgents');
42-
this._onDidChangeCustomAgents.fire();
43-
}));
4438
}
4539

4640
private getCacheDir(): vscode.Uri {
@@ -52,9 +46,14 @@ export class OrganizationAndEnterpriseAgentProvider extends Disposable implement
5246
_token: vscode.CancellationToken
5347
): Promise<vscode.CustomAgentResource[]> {
5448
try {
49+
const user = await this.octoKitService.getCurrentAuthedUser();
50+
if (!user) {
51+
return [];
52+
}
53+
5554
// If we have successfully fetched and cached in memory, return from memory
56-
if (this.memoryCache !== undefined) {
57-
return this.memoryCache;
55+
if (this.memoryCache.has(user.login)) {
56+
return this.memoryCache.get(user.login)!;
5857
}
5958

6059
// Read from file cache first
@@ -321,8 +320,8 @@ export class OrganizationAndEnterpriseAgentProvider extends Disposable implement
321320
this.logService.trace(`[OrganizationAndEnterpriseAgentProvider] Updated cache with ${totalAgents} agents from ${organizations.length} organizations`);
322321

323322
// If all fetch operations succeeded, populate memory cache
324-
if (!hadAnyFetchErrors && this.memoryCache === undefined) {
325-
this.memoryCache = await this.readFromCache();
323+
if (!hadAnyFetchErrors && !this.memoryCache.has(user.login)) {
324+
this.memoryCache.set(user.login, await this.readFromCache());
326325
this.logService.trace('[OrganizationAndEnterpriseAgentProvider] Successfully populated memory cache');
327326
}
328327

src/extension/agents/vscode-node/test/organizationAndEnterpriseAgentProvider.spec.ts

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -6,54 +6,16 @@
66
import { assert } from 'chai';
77
import { afterEach, beforeEach, suite, test } from 'vitest';
88
import * as vscode from 'vscode';
9-
import { IAuthenticationService } from '../../../../platform/authentication/common/authentication';
109
import { IFileSystemService } from '../../../../platform/filesystem/common/fileSystemService';
1110
import { FileType } from '../../../../platform/filesystem/common/fileTypes';
1211
import { MockFileSystemService } from '../../../../platform/filesystem/node/test/mockFileSystemService';
1312
import { CustomAgentDetails, CustomAgentListItem, CustomAgentListOptions, IOctoKitService } from '../../../../platform/github/common/githubService';
1413
import { ILogService } from '../../../../platform/log/common/logService';
15-
import { Emitter } from '../../../../util/vs/base/common/event';
1614
import { DisposableStore } from '../../../../util/vs/base/common/lifecycle';
1715
import { URI } from '../../../../util/vs/base/common/uri';
1816
import { createExtensionUnitTestingServices } from '../../../test/node/services';
1917
import { OrganizationAndEnterpriseAgentProvider } from '../organizationAndEnterpriseAgentProvider';
2018

21-
class MockAuthenticationService implements IAuthenticationService {
22-
_serviceBrand: undefined;
23-
private readonly _onDidAuthenticationChange = new Emitter<void>();
24-
readonly onDidAuthenticationChange = this._onDidAuthenticationChange.event;
25-
readonly onDidAccessTokenChange = new Emitter<void>().event;
26-
readonly anyGitHubSession: vscode.AuthenticationSession | undefined;
27-
28-
readonly isMinimalMode = false;
29-
readonly permissiveGitHubSession: vscode.AuthenticationSession | undefined;
30-
speculativeDecodingEndpointToken: string | undefined;
31-
readonly onDidAdoAuthenticationChange = new Emitter<void>().event;
32-
33-
async getAnyGitHubSession(options?: vscode.AuthenticationGetSessionOptions): Promise<vscode.AuthenticationSession | undefined> {
34-
return undefined;
35-
}
36-
async getPermissiveGitHubSession(options: vscode.AuthenticationGetSessionOptions): Promise<vscode.AuthenticationSession | undefined> {
37-
return undefined;
38-
}
39-
readonly copilotToken = undefined;
40-
async getCopilotToken(forceRefresh?: boolean): Promise<any> {
41-
return undefined;
42-
}
43-
44-
resetCopilotToken(httpError?: number): void {
45-
// no-op
46-
}
47-
48-
async getAdoAccessTokenBase64(options?: vscode.AuthenticationGetSessionOptions): Promise<string | undefined> {
49-
return undefined;
50-
}
51-
52-
fireOnDidAuthenticationChange() {
53-
this._onDidAuthenticationChange.fire();
54-
}
55-
}
56-
5719
/**
5820
* Mock implementation of IOctoKitService for testing
5921
*/
@@ -124,7 +86,6 @@ suite('OrganizationAndEnterpriseAgentProvider', () => {
12486
let mockOctoKitService: MockOctoKitService;
12587
let mockFileSystem: MockFileSystemService;
12688
let mockExtensionContext: MockExtensionContext;
127-
let mockAuthenticationService: MockAuthenticationService;
12889
let accessor: any;
12990
let provider: OrganizationAndEnterpriseAgentProvider;
13091

@@ -133,7 +94,6 @@ suite('OrganizationAndEnterpriseAgentProvider', () => {
13394

13495
// Create mocks first
13596
mockOctoKitService = new MockOctoKitService();
136-
mockAuthenticationService = new MockAuthenticationService();
13797
const storageUri = URI.file('/test/storage');
13898
mockExtensionContext = new MockExtensionContext(storageUri);
13999

@@ -156,7 +116,6 @@ suite('OrganizationAndEnterpriseAgentProvider', () => {
156116
accessor.get(ILogService),
157117
mockExtensionContext as any,
158118
mockFileSystem,
159-
mockAuthenticationService
160119
);
161120
disposables.add(provider);
162121
return provider;
@@ -940,16 +899,4 @@ Test prompt
940899
// Should have aborted after first org, so second org shouldn't be processed
941900
assert.equal(callCount, 1);
942901
});
943-
944-
test('fires change event when authentication state changes', async () => {
945-
const provider = createProvider();
946-
let eventFired = false;
947-
provider.onDidChangeCustomAgents(() => {
948-
eventFired = true;
949-
});
950-
951-
mockAuthenticationService.fireOnDidAuthenticationChange();
952-
953-
assert.equal(eventFired, true);
954-
});
955902
});

0 commit comments

Comments
 (0)