Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/extensions/copilot/src/extension/agents/vscode-node/test/mockOctoKitService.ts
13405 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import { AuthOptions, CCAEnabledResult, CustomAgentDetails, CustomAgentListItem, CustomAgentListOptions, GitHubOutageStatus, IOctoKitService, PermissiveAuthRequiredError } from '../../../../platform/github/common/githubService';
7
8
/**
9
* Mock implementation of IOctoKitService for testing
10
*/
11
export class MockOctoKitService implements IOctoKitService {
12
_serviceBrand: undefined;
13
14
private customAgents: CustomAgentListItem[] = [];
15
private agentDetails: Map<string, CustomAgentDetails> = new Map();
16
private orgInstructions: Map<string, string> = new Map();
17
private userOrganizations: string[] = ['testorg'];
18
19
getCurrentAuthedUser = async () => ({ login: 'testuser', name: 'Test User', avatar_url: '' });
20
getCopilotPullRequestsForUser = async () => [];
21
getGitHubOutageStatus = async (): Promise<GitHubOutageStatus> => GitHubOutageStatus.None;
22
getCopilotSessionsForPR = async () => [];
23
getSessionLogs = async () => '';
24
getSessionInfo = async () => undefined;
25
postCopilotAgentJob = async () => undefined;
26
getJobByJobId = async () => undefined;
27
getJobBySessionId = async () => undefined;
28
addPullRequestComment = async () => null;
29
getAllOpenSessions = async () => [];
30
getAllSessions = async () => [];
31
getPullRequestFromGlobalId = async () => null;
32
getPullRequestFiles = async () => [];
33
closePullRequest = async () => false;
34
findPullRequestByHeadBranch = async () => undefined;
35
getOpenPullRequestsForUser = async () => [];
36
getFileContent = async () => '';
37
getUserRepositories = async () => [];
38
getRecentlyCommittedRepositories = async () => [];
39
getCopilotAgentModels = async () => [];
40
getAssignableActors = async () => [];
41
isCCAEnabled = async (): Promise<CCAEnabledResult> => ({ enabled: true });
42
43
getUserOrganizations = async (_authOptions?: AuthOptions, _pageSize?: number) => this.userOrganizations;
44
isUserMemberOfOrg = async (org: string, _authOptions?: AuthOptions) => this.userOrganizations.includes(org);
45
getOrganizationRepositories = async (org: string, _authOptions?: AuthOptions, _pageSize?: number) => [org === 'testorg' ? 'testrepo' : 'repo'];
46
47
async getOrgCustomInstructions(orgLogin: string, _authOptions?: AuthOptions): Promise<string | undefined> {
48
return this.orgInstructions.get(orgLogin);
49
}
50
51
async getCustomAgents(_owner: string, _repo: string, _options: CustomAgentListOptions, _authOptions: AuthOptions): Promise<CustomAgentListItem[]> {
52
if (!(await this.getCurrentAuthedUser())) {
53
throw new PermissiveAuthRequiredError();
54
}
55
return this.customAgents;
56
}
57
58
async getCustomAgentDetails(_owner: string, _repo: string, agentName: string, _version: string, _authOptions: AuthOptions): Promise<CustomAgentDetails | undefined> {
59
return this.agentDetails.get(agentName);
60
}
61
62
// Helper methods for test setup
63
64
setOrgInstructions(orgLogin: string, instructions: string | undefined) {
65
if (instructions === undefined) {
66
this.orgInstructions.delete(orgLogin);
67
} else {
68
this.orgInstructions.set(orgLogin, instructions);
69
}
70
}
71
72
clearInstructions() {
73
this.orgInstructions.clear();
74
}
75
76
setCustomAgents(agents: CustomAgentListItem[]) {
77
this.customAgents = agents;
78
}
79
80
setAgentDetails(name: string, details: CustomAgentDetails) {
81
this.agentDetails.set(name, details);
82
}
83
84
setUserOrganizations(orgs: string[]) {
85
this.userOrganizations = orgs;
86
}
87
88
clearAgents() {
89
this.customAgents = [];
90
this.agentDetails.clear();
91
}
92
93
/**
94
* Resets all mock state
95
*/
96
reset() {
97
this.clearInstructions();
98
this.clearAgents();
99
this.userOrganizations = ['testorg'];
100
}
101
}
102
103