Path: blob/main/extensions/copilot/src/extension/test/node/testHelpers.ts
13399 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 type { ChatContext, ChatPromptReference, ChatRequest, ChatRequestTurn, ChatResponseTurn, ExtendedChatResponsePart, Uri } from 'vscode';6import { ChatResponseStreamImpl } from '../../../util/common/chatResponseStreamImpl';7import { MarkdownString } from '../../../util/vs/base/common/htmlContent';8import { URI } from '../../../util/vs/base/common/uri';9import { generateUuid } from '../../../util/vs/base/common/uuid';10import * as vscodeTypes from '../../../vscodeTypes';1112export class TestChatRequest implements ChatRequest {13public command: string | undefined;14public references: readonly ChatPromptReference[];15public location: vscodeTypes.ChatLocation;16public location2 = undefined;17public attempt: number;18public enableCommandDetection: boolean;19public isParticipantDetected: boolean;20public toolReferences = [];21public toolInvocationToken: never = undefined as never;22public model = null!;23public tools = new Map();24public id = generateUuid();25public sessionId = generateUuid();26public sessionResource = vscodeTypes.Uri.parse(`test://session/${this.sessionId}`);27public hasHooksEnabled = false;2829constructor(30public prompt: string,31references?: ChatPromptReference[]32) {33this.references = references ?? [];34this.location = vscodeTypes.ChatLocation.Panel;35this.attempt = 0;36this.enableCommandDetection = false;37this.isParticipantDetected = false;38}39}4041export class TestChatContext implements ChatContext {42readonly history: ReadonlyArray<ChatRequestTurn | ChatResponseTurn>;43readonly yieldRequested: boolean;4445constructor(history: ReadonlyArray<ChatRequestTurn | ChatResponseTurn> = [], yieldRequested = false) {46this.history = history;47this.yieldRequested = yieldRequested;48}49}5051export class MockChatResponseStream extends ChatResponseStreamImpl {5253public output: string[] = [];54public uris: string[] = [];55public externalEditUris: Uri[] = [];56constructor(push: ((part: ExtendedChatResponsePart) => void) = () => { }) {57super(push, () => { }, undefined, undefined, undefined, () => Promise.resolve(undefined));58}59override markdown(content: string | MarkdownString): void {60this.output.push(typeof content === 'string' ? content : content.value);61}62override warning(content: string | MarkdownString): void {63super.warning(content);64this.output.push(typeof content === 'string' ? content : content.value);65}66override codeblockUri(uri: URI): void {67this.uris.push(uri.toString());68}6970override async externalEdit(target: Uri | Uri[], callback: () => Thenable<void>): Promise<string> {71if (Array.isArray(target)) {72this.externalEditUris.push(...target);73} else {74this.externalEditUris.push(target);75}76await callback();77return '';78}79}808182