sessionTestHelpers.ts ×33

Frontier kind: Code frontier

unlabeled · c_ad2896ec71af

1009 tests · 12626 LOC · 47 files · introduces 0 tests · 123 LOC · 1 file

Introduces — evidence that enters the hierarchy at this concept

Code
33 ranges123 lines · 1 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
971 ranges12626 lines · 47 files · Browse complete extent
All tests (intent)
1009 testsBrowse complete intent

Neighbourhood graph

The orange circle is the focus. Violet and green circles are every ancestor and descendant, broader and narrower, at any distance; blue squares and pink diamonds are the introduced files and exact introduced tests of every visible concept, not only the focus's. Arrows point from broader to narrower concepts and bridge only concepts omitted from this view. Undirected links show source or test introduction. Concept and file size follows LOC; exact test nodes use test-count units.

Introduced files, introduced tests, and structurally relevant concept specialization

In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the native relationship evidence on this page.

Graph controls are ready.

Interactive rendering requires JavaScript and WebGL. Use the native relationship evidence on this page while the interactive map is unavailable.

Native relationship evidence

Every exact file and test below is linked only from the concept that introduces it.

Introduced tests

Every collected test enters the hierarchy at exactly one concept.

No tests are introduced at this concept. Its intent tests are introduced by other concepts.

Introduced code

Every collected source range enters the hierarchy at exactly one concept.

1 file ranked by introduced lines: 123 introduced LOC across 33 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

src/vs/platform/agentHost/test/common/sessionTestHelpers.ts 123 introduced LOC · 33 ranges

Open complete file

1 > /*--------------------------------------------------------------------------------------------- sessionTestHelpers.ts
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 { IReference } from '../../../../base/common/lifecycle.js';
7 > import { Schemas } from '../../../../base/common/network.js';
8 > import { URI } from '../../../../base/common/uri.js';
9 > import { Event } from '../../../../base/common/event.js';
10 > import type { IDiffComputeService, IDiffCountResult } from '../../common/diffComputeService.js';
11 > import type { IFileEditContent, IFileEditRecord, ILocalTurnRecord, IReviewedFileRecord, ISessionDatabase, ISessionDataService } from '../../common/sessionDataService.js';
12 > import type { Message } from '../../common/state/sessionState.js';
13 >
14 > export class TestSessionDatabase implements ISessionDatabase {
15 private readonly _edits: (IFileEditRecord & IFileEditContent)[] = [];
16 private readonly _metadata = new Map<string, string>();
24 deleteAllTurnsCalls = 0;
25 setTurnEventIdCalls: Array<{ turnId: string; eventId: string }> = [];
27 > addEdit(edit: IFileEditRecord & IFileEditContent): void {
28 this._edits.push(edit);
29 }
31 > async createTurn(): Promise<void> { }
32 >
33 > async deleteTurn(turnId: string): Promise<void> {
34 for (let i = this._edits.length - 1; i >= 0; i--) {
35 if (this._edits[i].turnId === turnId) {
38 }
39 }
41 > async storeFileEdit(edit: IFileEditRecord & IFileEditContent): Promise<void> {
42 const existingIndex = this._edits.findIndex(e => e.toolCallId === edit.toolCallId && e.filePath === edit.filePath);
43 if (existingIndex >= 0) {
47 }
48 }
50 > async getFileEdits(toolCallIds: string[]): Promise<IFileEditRecord[]> {
51 const toolCallIdsSet = new Set(toolCallIds);
52 return this._toEditRecords(this._edits.filter(e => toolCallIdsSet.has(e.toolCallId)));
53 }
55 > async getAllFileEdits(): Promise<IFileEditRecord[]> {
56 this.getAllFileEditsCalls++;
57 return this._toEditRecords(this._edits);
58 }
60 > async getFileEditsByTurn(turnId: string): Promise<IFileEditRecord[]> {
61 this.getFileEditsByTurnCalls++;
62 return this._toEditRecords(this._edits.filter(e => e.turnId === turnId));
63 }
65 > async readFileEditContent(toolCallId: string, filePath: string): Promise<IFileEditContent | undefined> {
66 return this._edits.find(e => e.toolCallId === toolCallId && e.filePath === filePath);
67 }
69 > async getMetadata(key: string): Promise<string | undefined> {
70 return this._metadata.get(key);
71 }
73 > async getMetadataObject<T extends Record<string, unknown>>(obj: T): Promise<{ [K in keyof T]: string | undefined }> {
74 return Object.fromEntries(Object.keys(obj).map(key => [key, this._metadata.get(key)])) as { [K in keyof T]: string | undefined };
75 }
77 > async setMetadata(key: string, value: string): Promise<void> {
78 this._metadata.set(key, value);
79 }
81 > async setChatDraft(chat: URI, draft: Message | undefined): Promise<void> {
82 const key = chat.toString();
83 if (draft) {
87 }
88 }
90 > async getChatDraft(chat: URI): Promise<Message | undefined> {
91 return this._drafts.get(chat.toString());
92 }
94 > async close(): Promise<void> { }
95 >
96 > async vacuumInto(_targetPath: string): Promise<void> { }
97 >
98 > dispose(): void { }
99 >
100 > async setTurnEventId(turnId: string, eventId: string): Promise<void> {
101 this.setTurnEventIdCalls.push({ turnId, eventId });
102 }
104 > async getTurnEventId(_turnId: string): Promise<string | undefined> { return undefined; }
105 >
106 > async getNextTurnEventId(_turnId: string): Promise<string | undefined> { return undefined; }
107 >
108 > async getFirstTurnEventId(): Promise<string | undefined> { return undefined; }
109 >
110 > async truncateFromTurn(_turnId: string): Promise<void> { }
111 >
112 > async deleteTurnsAfter(turnId: string): Promise<void> {
113 this.deleteTurnsAfterCalls.push(turnId);
114 }
116 > async deleteAllTurns(): Promise<void> {
117 this.deleteAllTurnsCalls++;
118 this._edits.length = 0;
119 }
121 > async insertLocalTurn(record: ILocalTurnRecord): Promise<void> {
122 this._localTurns.set(record.turnId, record);
123 }
125 > async getLocalTurns(): Promise<ILocalTurnRecord[]> {
126 return [...this._localTurns.values()].sort((a, b) => a.seq - b.seq);
127 }
129 > async deleteLocalTurns(turnIds: readonly string[]): Promise<void> {
130 for (const id of turnIds) {
131 this._localTurns.delete(id);
132 }
133 }
134 > async remapTurnIds(_mapping: ReadonlyMap<string, string>): Promise<void> { } sessionTestHelpers.ts
135 >
136 > async markFileReviewed(uri: URI, nonce: string): Promise<void> {
137 if (!this._reviewedFiles.some(r => r.uri.toString() === uri.toString() && r.nonce === nonce)) {
138 this._reviewedFiles.push({ uri, nonce });
139 }
140 }
142 > async unmarkFileReviewed(uri: URI, nonce: string): Promise<void> {
143 const index = this._reviewedFiles.findIndex(r => r.uri.toString() === uri.toString() && r.nonce === nonce);
144 if (index >= 0) {
146 }
147 }
149 > async getReviewedFiles(): Promise<IReviewedFileRecord[]> {
150 return [...this._reviewedFiles];
151 }
153 > async getReviewedFilesForUri(uri: URI): Promise<IReviewedFileRecord[]> {
154 return this._reviewedFiles.filter(r => r.uri.toString() === uri.toString());
155 }
157 > async isFileReviewed(uri: URI, nonce: string): Promise<boolean> {
158 return this._reviewedFiles.some(r => r.uri.toString() === uri.toString() && r.nonce === nonce);
159 }
161 > async setTurnCheckpointRef(_turnId: string, _ref: string): Promise<void> { }
162 >
163 > async getTurnCheckpointRef(_turnId: string): Promise<string | undefined> { return undefined; }
164 >
165 > async getPreviousCheckpointRef(_turnId: string): Promise<string | undefined> { return undefined; }
166 >
167 > async getAllCheckpointRefs(): Promise<string[]> { return []; }
168 >
169 > async whenIdle(): Promise<void> { }
170 >
171 > private _toEditRecords(edits: (IFileEditRecord & IFileEditContent)[]): IFileEditRecord[] {
172 return edits.map(({ beforeContent: _, afterContent: _2, ...metadata }) => metadata);
173 }
175 >
176 > export class TestDiffComputeService implements IDiffComputeService {
177 > declare readonly _serviceBrand: undefined;
178 >
179 > callCount = 0;
180 >
181 > constructor(private readonly _result?: IDiffCountResult) { }
182 >
183 > async computeDiffCounts(original: string, modified: string): Promise<IDiffCountResult> {
184 this.callCount++;
185 if (this._result) {
194 };
195 }
197 >
198 > export function createZeroDiffComputeService(): IDiffComputeService {
199 return new TestDiffComputeService({ added: 0, removed: 0 });
200 }
202 > export function createSessionDataService(database: ISessionDatabase = new TestSessionDatabase()): ISessionDataService {
203 return {
204 _serviceBrand: undefined,
213 };
214 }
216 > export function createNullSessionDataService(): ISessionDataService {
217 return {
218 _serviceBrand: undefined,
227 };
228 }
230 > export function encodeString(text: string): Uint8Array {
231 return new TextEncoder().encode(text);
232 }
234 > /**
235 > * Returns a no-op {@link IAgentHostGitService} suitable for tests that
236 > * exercise the {@link AgentService} but don't care about git state.
237 > * Tests that DO care about git state should pass their own implementation.
238 > */
239 > export function createNoopGitService(): import('../../common/agentHostGitService.js').IAgentHostGitService {
240 return {
241 _serviceBrand: undefined,
276 };
277 }
279 > /**
280 > * Returns a no-op {@link IAgentHostChangesetService} for tests that need to
281 > * inject the changeset service but don't exercise changeset computation.
282 > * Individual methods can be reassigned by callers that want to spy on them.
283 > */
284 > export function createNoopChangesetService(): import('../../common/agentHostChangesetService.js').IAgentHostChangesetService {
285 return {
286 _serviceBrand: undefined,
308 };
309 }
311 function createReference<T>(object: T): IReference<T> {
312 return {