Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/extensions/copilot/src/extension/chatSessions/common/test/mockChatSessionMetadataStore.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 type * as vscode from 'vscode';
7
import { IChatSessionMetadataStore, RepositoryProperties, RequestDetails, WorkspaceFolderEntry } from '../chatSessionMetadataStore';
8
import { ChatSessionWorktreeProperties } from '../chatSessionWorktreeService';
9
import { IWorkspaceInfo } from '../workspaceInfo';
10
11
export class MockChatSessionMetadataStore implements IChatSessionMetadataStore {
12
getMetadataFileUri(sessionId: string): vscode.Uri {
13
throw new Error('Method not implemented.');
14
}
15
declare _serviceBrand: undefined;
16
17
private readonly _worktreeProperties = new Map<string, ChatSessionWorktreeProperties>();
18
private readonly _workspaceFolders = new Map<string, WorkspaceFolderEntry>();
19
private readonly _additionalWorkspaces = new Map<string, IWorkspaceInfo[]>();
20
private readonly _firstUserMessages = new Map<string, string>();
21
private readonly _customTitles = new Map<string, string>();
22
private readonly _requestDetails = new Map<string, RequestDetails[]>();
23
private readonly _sessionOrigins = new Map<string, 'vscode' | 'other'>();
24
25
async deleteSessionMetadata(sessionId: string): Promise<void> {
26
this._worktreeProperties.delete(sessionId);
27
this._workspaceFolders.delete(sessionId);
28
this._additionalWorkspaces.delete(sessionId);
29
this._firstUserMessages.delete(sessionId);
30
this._customTitles.delete(sessionId);
31
this._requestDetails.delete(sessionId);
32
}
33
34
async refresh(): Promise<void> {
35
// no-op in mock — there is no on-disk state to reload.
36
}
37
38
async storeWorktreeInfo(sessionId: string, properties: ChatSessionWorktreeProperties): Promise<void> {
39
this._worktreeProperties.set(sessionId, properties);
40
}
41
42
async storeWorkspaceFolderInfo(sessionId: string, entry: WorkspaceFolderEntry): Promise<void> {
43
this._workspaceFolders.set(sessionId, entry);
44
}
45
46
async storeRepositoryProperties(_sessionId: string, _properties: RepositoryProperties): Promise<void> {
47
}
48
49
async getRepositoryProperties(_sessionId: string): Promise<RepositoryProperties | undefined> {
50
return undefined;
51
}
52
53
async getSessionIdForWorktree(_folder: vscode.Uri): Promise<string | undefined> {
54
return undefined;
55
}
56
57
async getWorktreeProperties(sessionId: string): Promise<ChatSessionWorktreeProperties | undefined> {
58
return this._worktreeProperties.get(sessionId);
59
}
60
61
async getSessionWorkspaceFolder(_sessionId: string): Promise<vscode.Uri | undefined> {
62
return undefined;
63
}
64
65
async getSessionWorkspaceFolderEntry(sessionId: string): Promise<WorkspaceFolderEntry | undefined> {
66
return undefined;
67
}
68
69
async getAdditionalWorkspaces(sessionId: string): Promise<IWorkspaceInfo[]> {
70
return this._additionalWorkspaces.get(sessionId) ?? [];
71
}
72
73
async setAdditionalWorkspaces(sessionId: string, workspaces: IWorkspaceInfo[]): Promise<void> {
74
this._additionalWorkspaces.set(sessionId, workspaces);
75
}
76
77
async getSessionFirstUserMessage(sessionId: string): Promise<string | undefined> {
78
return this._firstUserMessages.get(sessionId);
79
}
80
81
async setSessionFirstUserMessage(sessionId: string, message: string): Promise<void> {
82
this._firstUserMessages.set(sessionId, message);
83
}
84
85
async getCustomTitle(sessionId: string): Promise<string | undefined> {
86
return this._customTitles.get(sessionId);
87
}
88
89
async setCustomTitle(sessionId: string, title: string): Promise<void> {
90
this._customTitles.set(sessionId, title);
91
}
92
93
async getRequestDetails(sessionId: string): Promise<RequestDetails[]> {
94
return this._requestDetails.get(sessionId) ?? [];
95
}
96
97
async updateRequestDetails(sessionId: string, details: (Partial<RequestDetails> & { vscodeRequestId: string })[]): Promise<void> {
98
const existing = this._requestDetails.get(sessionId) ?? [];
99
for (const item of details) {
100
const entry = existing.find(e => e.vscodeRequestId === item.vscodeRequestId);
101
if (entry) {
102
Object.assign(entry, item);
103
} else {
104
existing.push({ ...item, toolIdEditMap: item.toolIdEditMap ?? {} } as RequestDetails);
105
}
106
}
107
this._requestDetails.set(sessionId, existing);
108
}
109
110
async getSessionAgent(sessionId: string): Promise<string | undefined> {
111
const details = this._requestDetails.get(sessionId) ?? [];
112
for (let i = details.length - 1; i >= 0; i--) {
113
if (details[i].agentId) {
114
return details[i].agentId;
115
}
116
}
117
return undefined;
118
}
119
120
async storeForkedSessionMetadata(sourceSessionId: string, targetSessionId: string, customTitle: string): Promise<void> {
121
await this.setCustomTitle(targetSessionId, customTitle);
122
const worktree = this._worktreeProperties.get(sourceSessionId);
123
if (worktree) {
124
this._worktreeProperties.set(targetSessionId, worktree);
125
}
126
const folder = this._workspaceFolders.get(sourceSessionId);
127
if (folder) {
128
this._workspaceFolders.set(targetSessionId, folder);
129
}
130
const additional = this._additionalWorkspaces.get(sourceSessionId);
131
if (additional) {
132
this._additionalWorkspaces.set(targetSessionId, additional);
133
}
134
const firstMsg = this._firstUserMessages.get(sourceSessionId);
135
if (firstMsg) {
136
this._firstUserMessages.set(targetSessionId, firstMsg);
137
}
138
}
139
140
async setSessionOrigin(sessionId: string): Promise<void> {
141
this._sessionOrigins.set(sessionId, 'vscode');
142
}
143
144
async getSessionOrigin(sessionId: string): Promise<'vscode' | 'other'> {
145
return this._sessionOrigins.get(sessionId) ?? 'vscode';
146
}
147
148
setSessionParentId(_sessionId: string, _parentSessionId: string): Promise<void> {
149
return Promise.resolve();
150
}
151
152
getSessionParentId(_sessionId: string): Promise<string | undefined> {
153
return Promise.resolve(undefined);
154
}
155
156
getSessionIdsForFolder(folder: vscode.Uri): string[] {
157
const folderPath = folder.fsPath;
158
const sessionIds: string[] = [];
159
for (const [sessionId, props] of this._worktreeProperties) {
160
if (props.worktreePath === folderPath) {
161
sessionIds.push(sessionId);
162
}
163
}
164
for (const [sessionId, entry] of this._workspaceFolders) {
165
if (entry.folderPath === folderPath && !sessionIds.includes(sessionId)) {
166
sessionIds.push(sessionId);
167
}
168
}
169
return sessionIds;
170
}
171
172
getWorktreeSessions(folder: vscode.Uri): string[] {
173
const folderPath = folder.fsPath;
174
const sessionIds: string[] = [];
175
for (const [sessionId, props] of this._worktreeProperties) {
176
if (props.worktreePath === folderPath) {
177
sessionIds.push(sessionId);
178
}
179
}
180
return sessionIds;
181
}
182
}
183
184