Path: blob/main/extensions/copilot/src/extension/chatSessions/common/test/mockChatSessionMetadataStore.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 type * as vscode from 'vscode';6import { IChatSessionMetadataStore, RepositoryProperties, RequestDetails, WorkspaceFolderEntry } from '../chatSessionMetadataStore';7import { ChatSessionWorktreeProperties } from '../chatSessionWorktreeService';8import { IWorkspaceInfo } from '../workspaceInfo';910export class MockChatSessionMetadataStore implements IChatSessionMetadataStore {11getMetadataFileUri(sessionId: string): vscode.Uri {12throw new Error('Method not implemented.');13}14declare _serviceBrand: undefined;1516private readonly _worktreeProperties = new Map<string, ChatSessionWorktreeProperties>();17private readonly _workspaceFolders = new Map<string, WorkspaceFolderEntry>();18private readonly _additionalWorkspaces = new Map<string, IWorkspaceInfo[]>();19private readonly _firstUserMessages = new Map<string, string>();20private readonly _customTitles = new Map<string, string>();21private readonly _requestDetails = new Map<string, RequestDetails[]>();22private readonly _sessionOrigins = new Map<string, 'vscode' | 'other'>();2324async deleteSessionMetadata(sessionId: string): Promise<void> {25this._worktreeProperties.delete(sessionId);26this._workspaceFolders.delete(sessionId);27this._additionalWorkspaces.delete(sessionId);28this._firstUserMessages.delete(sessionId);29this._customTitles.delete(sessionId);30this._requestDetails.delete(sessionId);31}3233async refresh(): Promise<void> {34// no-op in mock — there is no on-disk state to reload.35}3637async storeWorktreeInfo(sessionId: string, properties: ChatSessionWorktreeProperties): Promise<void> {38this._worktreeProperties.set(sessionId, properties);39}4041async storeWorkspaceFolderInfo(sessionId: string, entry: WorkspaceFolderEntry): Promise<void> {42this._workspaceFolders.set(sessionId, entry);43}4445async storeRepositoryProperties(_sessionId: string, _properties: RepositoryProperties): Promise<void> {46}4748async getRepositoryProperties(_sessionId: string): Promise<RepositoryProperties | undefined> {49return undefined;50}5152async getSessionIdForWorktree(_folder: vscode.Uri): Promise<string | undefined> {53return undefined;54}5556async getWorktreeProperties(sessionId: string): Promise<ChatSessionWorktreeProperties | undefined> {57return this._worktreeProperties.get(sessionId);58}5960async getSessionWorkspaceFolder(_sessionId: string): Promise<vscode.Uri | undefined> {61return undefined;62}6364async getSessionWorkspaceFolderEntry(sessionId: string): Promise<WorkspaceFolderEntry | undefined> {65return undefined;66}6768async getAdditionalWorkspaces(sessionId: string): Promise<IWorkspaceInfo[]> {69return this._additionalWorkspaces.get(sessionId) ?? [];70}7172async setAdditionalWorkspaces(sessionId: string, workspaces: IWorkspaceInfo[]): Promise<void> {73this._additionalWorkspaces.set(sessionId, workspaces);74}7576async getSessionFirstUserMessage(sessionId: string): Promise<string | undefined> {77return this._firstUserMessages.get(sessionId);78}7980async setSessionFirstUserMessage(sessionId: string, message: string): Promise<void> {81this._firstUserMessages.set(sessionId, message);82}8384async getCustomTitle(sessionId: string): Promise<string | undefined> {85return this._customTitles.get(sessionId);86}8788async setCustomTitle(sessionId: string, title: string): Promise<void> {89this._customTitles.set(sessionId, title);90}9192async getRequestDetails(sessionId: string): Promise<RequestDetails[]> {93return this._requestDetails.get(sessionId) ?? [];94}9596async updateRequestDetails(sessionId: string, details: (Partial<RequestDetails> & { vscodeRequestId: string })[]): Promise<void> {97const existing = this._requestDetails.get(sessionId) ?? [];98for (const item of details) {99const entry = existing.find(e => e.vscodeRequestId === item.vscodeRequestId);100if (entry) {101Object.assign(entry, item);102} else {103existing.push({ ...item, toolIdEditMap: item.toolIdEditMap ?? {} } as RequestDetails);104}105}106this._requestDetails.set(sessionId, existing);107}108109async getSessionAgent(sessionId: string): Promise<string | undefined> {110const details = this._requestDetails.get(sessionId) ?? [];111for (let i = details.length - 1; i >= 0; i--) {112if (details[i].agentId) {113return details[i].agentId;114}115}116return undefined;117}118119async storeForkedSessionMetadata(sourceSessionId: string, targetSessionId: string, customTitle: string): Promise<void> {120await this.setCustomTitle(targetSessionId, customTitle);121const worktree = this._worktreeProperties.get(sourceSessionId);122if (worktree) {123this._worktreeProperties.set(targetSessionId, worktree);124}125const folder = this._workspaceFolders.get(sourceSessionId);126if (folder) {127this._workspaceFolders.set(targetSessionId, folder);128}129const additional = this._additionalWorkspaces.get(sourceSessionId);130if (additional) {131this._additionalWorkspaces.set(targetSessionId, additional);132}133const firstMsg = this._firstUserMessages.get(sourceSessionId);134if (firstMsg) {135this._firstUserMessages.set(targetSessionId, firstMsg);136}137}138139async setSessionOrigin(sessionId: string): Promise<void> {140this._sessionOrigins.set(sessionId, 'vscode');141}142143async getSessionOrigin(sessionId: string): Promise<'vscode' | 'other'> {144return this._sessionOrigins.get(sessionId) ?? 'vscode';145}146147setSessionParentId(_sessionId: string, _parentSessionId: string): Promise<void> {148return Promise.resolve();149}150151getSessionParentId(_sessionId: string): Promise<string | undefined> {152return Promise.resolve(undefined);153}154155getSessionIdsForFolder(folder: vscode.Uri): string[] {156const folderPath = folder.fsPath;157const sessionIds: string[] = [];158for (const [sessionId, props] of this._worktreeProperties) {159if (props.worktreePath === folderPath) {160sessionIds.push(sessionId);161}162}163for (const [sessionId, entry] of this._workspaceFolders) {164if (entry.folderPath === folderPath && !sessionIds.includes(sessionId)) {165sessionIds.push(sessionId);166}167}168return sessionIds;169}170171getWorktreeSessions(folder: vscode.Uri): string[] {172const folderPath = folder.fsPath;173const sessionIds: string[] = [];174for (const [sessionId, props] of this._worktreeProperties) {175if (props.worktreePath === folderPath) {176sessionIds.push(sessionId);177}178}179return sessionIds;180}181}182183184