mockAgent.ts ×31

Frontier kind: Code frontier

unlabeled · c_351ac3404616

324 tests · 26786 LOC · 131 files · introduces 0 tests · 76 LOC · 1 file

Introduces — evidence that enters the hierarchy at this concept

Code
31 ranges76 lines · 1 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
2420 ranges26786 lines · 131 files · Browse complete extent
All tests (intent)
324 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: 76 introduced LOC across 31 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

src/vs/platform/agentHost/test/node/mockAgent.ts 76 introduced LOC · 31 ranges

Open complete file

91
92 constructor(readonly id: AgentProvider = 'mock') { }
94 > getDescriptor(): IAgentDescriptor {
95 return { provider: this.id, displayName: `Agent ${this.id}`, description: `Test ${this.id} agent` };
96 }
98 > getProtectedResources(): ProtectedResourceMetadata[] {
99 if (this.id === 'copilot') {
100 return [{ resource: 'https://api.github.com', authorization_servers: ['https://github.com/login/oauth'], required: true }];
102 return [];
103 }
104 > mockAgent.ts
105 > setModels(models: readonly IAgentModelInfo[]): void {
106 this._models.set(models, undefined);
107 }
108 > mockAgent.ts
109 > async listSessions(): Promise<IAgentSessionMetadata[]> {
110 return [...this._sessions.values()].map(s => ({ session: s, startTime: Date.now(), modifiedTime: Date.now(), project: mockProject(this.id), ...this.sessionMetadataOverrides }));
111 }
112 > mockAgent.ts
113 > async getSessionMetadata(session: URI): Promise<IAgentSessionMetadata | undefined> {
114 if (!this._sessions.has(AgentSession.id(session))) {
115 return undefined;
117 return { session, startTime: Date.now(), modifiedTime: Date.now(), project: mockProject(this.id), ...this.sessionMetadataOverrides };
118 }
119 > mockAgent.ts
120 > /** Optional override for the working directory returned by createSession. */
121 > resolvedWorkingDirectory: URI | undefined;
122 >
123 > /**
124 > * When set, {@link sendMessage} rejects with this error after recording the
125 > * call — used to simulate a failed first-turn materialization (e.g. worktree
126 > * or branch setup throwing).
127 > */
128 > sendMessageError: Error | undefined;
129 > async createSession(config?: IAgentCreateSessionConfig): Promise<IAgentCreateSessionResult> {
130 const session = config?.session ?? AgentSession.uri(this.id, `${this.id}-session-${this._nextId++}`);
131 const rawId = AgentSession.id(session);
133 return { session, project: mockProject(this.id), workingDirectory: this.resolvedWorkingDirectory };
134 }
135 > mockAgent.ts
136 > async resolveSessionConfig(params: IAgentResolveSessionConfigParams): Promise<ResolveSessionConfigResult> {
137 return { schema: { type: 'object', properties: {} }, values: params.config ?? {} };
138 }
139 > mockAgent.ts
140 > async sessionConfigCompletions(_params: IAgentSessionConfigCompletionsParams): Promise<SessionConfigCompletionsResult> {
141 return { items: [] };
142 }
143 > mockAgent.ts
144 > async sendMessage(session: URI, chat: URI, prompt: string, attachments?: readonly MessageAttachment[], turnId?: string, senderClientId?: string): Promise<void> {
145 const call = { session, prompt, attachments, chat, ...(senderClientId ? { senderClientId } : {}) };
146 this.sendMessageCalls.push(call);
153 }
154 }
155 > mockAgent.ts
156 > setPendingMessages(chat: URI, steeringMessage: PendingMessage | undefined, queuedMessages: readonly PendingMessage[]): void {
157 this.setPendingMessagesCalls.push({ chat, steeringMessage, queuedMessages });
158 }
159 > mockAgent.ts
160 > readonly onSessionConfigChangedCalls: { session: URI; values: Record<string, unknown> }[] = [];
161 > onSessionConfigChanged(session: URI, values: Record<string, unknown>): void {
162 this.onSessionConfigChangedCalls.push({ session, values });
163 }
164 > mockAgent.ts
165 > async getSessionMessages(session: URI): Promise<readonly Turn[]> {
166 const subagentInfo = parseSubagentSessionUri(session);
167 if (subagentInfo) {
170 return buildTurnsFromHistory(this.sessionMessages);
171 }
172 > mockAgent.ts
173 > async disposeSession(session: URI): Promise<void> {
174 this.disposeSessionCalls.push(session);
175 this._sessions.delete(AgentSession.id(session));
176 }
177 > mockAgent.ts
178 > async releaseSession(session: URI): Promise<void> {
179 // Non-destructive: record the call but keep the session in the catalog
180 // so a later restore/resume still finds its durable data.
181 this.releaseSessionCalls.push(session);
182 }
183 > mockAgent.ts
184 > async abortSession(session: URI): Promise<void> {
185 this.abortSessionCalls.push(session);
186 }
187 > mockAgent.ts
188 > async truncateSession(session: URI, turnId?: string, chat?: URI): Promise<void> {
189 this.truncateSessionCalls.push({ session, turnId, chat });
190 }
191 > mockAgent.ts
192 > respondToPermissionRequest(requestId: string, approved: boolean): void {
193 this.respondToPermissionCalls.push({ requestId, approved });
194 }
195 > mockAgent.ts
196 > respondToUserInputRequest(): void {
197 // no-op for tests
198 }
199 > mockAgent.ts
200 > async changeModel(session: URI, model: ModelSelection, chat?: URI): Promise<void> {
201 this.changeModelCalls.push({ session, model, chat });
202 }
203 > mockAgent.ts
204 > async changeAgent(session: URI, agent: AgentSelection | undefined, chat?: URI): Promise<void> {
205 this.changeAgentCalls.push({ session, agent, chat });
206 }
207 > mockAgent.ts
208 > /**
209 > * Create an additional (peer) chat. The base mock is single-chat and
210 > * rejects; multi-chat test subclasses override this.
211 > */
212 > async createChat(_session: URI, _chat: URI, _options?: IAgentCreateChatOptions): Promise<IAgentCreateChatResult | void> {
213 throw new Error(`Agent ${this.id} does not support multiple chats`);
214 }
215 > mockAgent.ts
216 > /** Dispose an additional (peer) chat. Overridden by multi-chat subclasses. */
217 > async disposeChat(_session: URI, _chat: URI): Promise<void> { }
218 >
219 > /**
220 > * Map an already-resolved chat URI to the `(session, chat)` pair the
221 > * mock records calls against (mirroring the real agents).
222 > */
223 > private _resolveChatTarget(chat: URI): { session: URI; chat: URI } {
224 const parsed = parseChatUri(chat);
225 if (!parsed) {
228 return { session: URI.parse(parsed.session), chat: URI.parse(chat.toString()) };
229 }
230 > mockAgent.ts
231 > readonly chats: IAgentChats = {
232 > createChat: (chatUri: URI, options?: IAgentCreateChatOptions): Promise<IAgentCreateChatResult | void> => {
233 const { session, chat } = this._resolveChatTarget(chatUri);
234 return this.createChat(session, chat, options);
235 },
236 > fork: (chatUri: URI, source: IAgentCreateChatForkSource, options?: IAgentCreateChatOptions): Promise<IAgentCreateChatResult | void> => { mockAgent.ts
237 const { session, chat } = this._resolveChatTarget(chatUri);
238 return this.createChat(session, chat, { ...options, fork: source });
239 },
240 > disposeChat: (chatUri: URI): Promise<void> => { mockAgent.ts
241 const { session, chat } = this._resolveChatTarget(chatUri);
242 return this.disposeChat(session, chat);
243 },
244 > sendMessage: (chatUri: URI, prompt: string, _workingDirectory: URI | undefined, attachments?: readonly MessageAttachment[], turnId?: string, senderClientId?: string): Promise<void> => { mockAgent.ts
245 const { session, chat } = this._resolveChatTarget(chatUri);
246 return this.sendMessage(session, chat, prompt, attachments, turnId, senderClientId);
247 },
248 > abort: (chat: URI): Promise<void> => { mockAgent.ts
249 const { session } = this._resolveChatTarget(chat);
250 return this.abortSession(session);
251 },
252 > changeModel: (chatUri: URI, model: ModelSelection): Promise<void> => { mockAgent.ts
253 const { session, chat } = this._resolveChatTarget(chatUri);
254 return this.changeModel(session, model, chat);
255 },
256 > changeAgent: (chatUri: URI, agent: AgentSelection | undefined): Promise<void> => { mockAgent.ts
257 const { session, chat } = this._resolveChatTarget(chatUri);
258 return this.changeAgent(session, agent, chat);
259 },
260 > getMessages: (chat: URI): Promise<readonly Turn[]> => { mockAgent.ts
261 return this.getSessionMessages(chat);
262 },
263 > }; mockAgent.ts
264
265 async authenticate(resource: string, token: string): Promise<boolean> {