Path: blob/main/extensions/copilot/src/extension/agents/vscode-node/test/mockOctoKitService.ts
13405 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import { AuthOptions, CCAEnabledResult, CustomAgentDetails, CustomAgentListItem, CustomAgentListOptions, GitHubOutageStatus, IOctoKitService, PermissiveAuthRequiredError } from '../../../../platform/github/common/githubService';67/**8* Mock implementation of IOctoKitService for testing9*/10export class MockOctoKitService implements IOctoKitService {11_serviceBrand: undefined;1213private customAgents: CustomAgentListItem[] = [];14private agentDetails: Map<string, CustomAgentDetails> = new Map();15private orgInstructions: Map<string, string> = new Map();16private userOrganizations: string[] = ['testorg'];1718getCurrentAuthedUser = async () => ({ login: 'testuser', name: 'Test User', avatar_url: '' });19getCopilotPullRequestsForUser = async () => [];20getGitHubOutageStatus = async (): Promise<GitHubOutageStatus> => GitHubOutageStatus.None;21getCopilotSessionsForPR = async () => [];22getSessionLogs = async () => '';23getSessionInfo = async () => undefined;24postCopilotAgentJob = async () => undefined;25getJobByJobId = async () => undefined;26getJobBySessionId = async () => undefined;27addPullRequestComment = async () => null;28getAllOpenSessions = async () => [];29getAllSessions = async () => [];30getPullRequestFromGlobalId = async () => null;31getPullRequestFiles = async () => [];32closePullRequest = async () => false;33findPullRequestByHeadBranch = async () => undefined;34getOpenPullRequestsForUser = async () => [];35getFileContent = async () => '';36getUserRepositories = async () => [];37getRecentlyCommittedRepositories = async () => [];38getCopilotAgentModels = async () => [];39getAssignableActors = async () => [];40isCCAEnabled = async (): Promise<CCAEnabledResult> => ({ enabled: true });4142getUserOrganizations = async (_authOptions?: AuthOptions, _pageSize?: number) => this.userOrganizations;43isUserMemberOfOrg = async (org: string, _authOptions?: AuthOptions) => this.userOrganizations.includes(org);44getOrganizationRepositories = async (org: string, _authOptions?: AuthOptions, _pageSize?: number) => [org === 'testorg' ? 'testrepo' : 'repo'];4546async getOrgCustomInstructions(orgLogin: string, _authOptions?: AuthOptions): Promise<string | undefined> {47return this.orgInstructions.get(orgLogin);48}4950async getCustomAgents(_owner: string, _repo: string, _options: CustomAgentListOptions, _authOptions: AuthOptions): Promise<CustomAgentListItem[]> {51if (!(await this.getCurrentAuthedUser())) {52throw new PermissiveAuthRequiredError();53}54return this.customAgents;55}5657async getCustomAgentDetails(_owner: string, _repo: string, agentName: string, _version: string, _authOptions: AuthOptions): Promise<CustomAgentDetails | undefined> {58return this.agentDetails.get(agentName);59}6061// Helper methods for test setup6263setOrgInstructions(orgLogin: string, instructions: string | undefined) {64if (instructions === undefined) {65this.orgInstructions.delete(orgLogin);66} else {67this.orgInstructions.set(orgLogin, instructions);68}69}7071clearInstructions() {72this.orgInstructions.clear();73}7475setCustomAgents(agents: CustomAgentListItem[]) {76this.customAgents = agents;77}7879setAgentDetails(name: string, details: CustomAgentDetails) {80this.agentDetails.set(name, details);81}8283setUserOrganizations(orgs: string[]) {84this.userOrganizations = orgs;85}8687clearAgents() {88this.customAgents = [];89this.agentDetails.clear();90}9192/**93* Resets all mock state94*/95reset() {96this.clearInstructions();97this.clearAgents();98this.userOrganizations = ['testorg'];99}100}101102103