historyRecordFixtures.ts ×6

Frontier kind: Code frontier

unlabeled · c_bfdbe53797bf

344 tests · 26083 LOC · 126 files · introduces 0 tests · 132 LOC · 1 file

Introduces — evidence that enters the hierarchy at this concept

Code
6 ranges132 lines · 1 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
2284 ranges26083 lines · 126 files · Browse complete extent
All tests (intent)
344 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: 132 introduced LOC across 6 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

src/vs/platform/agentHost/test/node/historyRecordFixtures.ts 132 introduced LOC · 6 ranges

Open complete file

1 > /*--------------------------------------------------------------------------------------------- historyRecordFixtures.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 { URI } from '../../../../base/common/uri.js';
7 > import { generateUuid } from '../../../../base/common/uuid.js';
8 > import { isString } from '../../../../base/common/types.js';
9 > import { stripRedundantCdPrefix } from '../../common/commandLineHelpers.js';
10 > import { IFileEditRecord, ISessionDatabase } from '../../common/sessionDataService.js';
11 > import { MessageKind, ResponsePartKind, ToolCallConfirmationReason, ToolCallStatus, ToolResultContentType, TurnState, buildSubagentSessionUri, type Message, type ResponsePart, type StringOrMarkdown, type ToolCallCompletedState, type ToolResultContent, type Turn } from '../../common/state/sessionState.js';
12 > import { getInvocationMessage, getPastTenseMessage, getShellLanguage, getSubagentMetadata, getToolDisplayName, getToolInputString, getToolKind, isEditTool, isHiddenTool, synthesizeSkillToolCall } from '../../node/copilot/copilotToolDisplay.js';
13 > import { buildSessionDbUri } from '../../node/shared/fileEditTracker.js';
14 > import type { ISessionEvent, ISessionEventMessage, ISessionEventSkillInvoked, ISessionEventSubagentStarted, ISessionEventToolComplete, ISessionEventToolStart } from './copilotTestEvents.js';
15 >
16 > // =============================================================================
17 > // History-record test fixtures
18 > //
19 > // Flat, declarative DSL used by mock agents and unit tests to build session
20 > // history without manually constructing `Turn[]`. Records mirror the wire
21 > // shape of an SDK event stream — `message`, `tool_start`, `tool_complete`,
22 > // `subagent_started` — so transcripts read like the protocol they're
23 > // emulating.
24 > //
25 > // Production code does NOT depend on this module. The real
26 > // SDK-events-to-Turn[] pipeline in `node/copilot/mapSessionEvents.ts` runs
27 > // in a single pass without producing the intermediate record shape.
28 > // =============================================================================
29 >
30 > interface IHistoryRecordBase {
31 > readonly session: URI;
32 > }
33 >
34 > interface IHistoryMessageRecord extends IHistoryRecordBase {
35 > readonly type: 'message';
36 > readonly role: 'user' | 'assistant';
37 > readonly messageId: string;
38 > readonly content: string;
39 > readonly toolRequests?: readonly {
40 > readonly toolCallId: string;
41 > readonly name: string;
42 > readonly arguments?: string;
43 > readonly type?: 'function' | 'custom';
44 > }[];
45 > readonly reasoningOpaque?: string;
46 > readonly reasoningText?: string;
47 > readonly encryptedContent?: string;
48 > readonly parentToolCallId?: string;
49 > }
50 >
51 > export interface IHistoryToolStartRecord extends IHistoryRecordBase {
52 > readonly type: 'tool_start';
53 > readonly toolCallId: string;
54 > readonly toolName: string;
55 > readonly displayName: string;
56 > readonly invocationMessage: StringOrMarkdown;
57 > readonly toolInput?: string;
58 > readonly toolKind?: 'terminal' | 'subagent' | 'search';
59 > readonly language?: string;
60 > readonly toolArguments?: string;
61 > readonly subagentAgentName?: string;
62 > readonly subagentDescription?: string;
63 > readonly mcpServerName?: string;
64 > readonly mcpToolName?: string;
65 > readonly parentToolCallId?: string;
66 > }
67 >
68 > interface IHistoryToolCompleteRecord extends IHistoryRecordBase {
69 > readonly type: 'tool_complete';
70 > readonly toolCallId: string;
71 > readonly result: {
72 > readonly success: boolean;
73 > readonly pastTenseMessage: StringOrMarkdown;
74 > readonly content?: ToolResultContent[];
75 > readonly error?: { readonly message: string; readonly code?: string };
76 > };
77 > readonly isUserRequested?: boolean;
78 > readonly toolTelemetry?: string;
79 > readonly parentToolCallId?: string;
80 > }
81 >
82 > interface IHistorySubagentStartedRecord extends IHistoryRecordBase {
83 > readonly type: 'subagent_started';
84 > readonly toolCallId: string;
85 > readonly agentName: string;
86 > readonly agentDisplayName: string;
87 > readonly agentDescription?: string;
88 > }
89 >
90 > /** Test fixture record. Hand-constructed by tests to seed mock session histories. */
91 > export type IHistoryRecord =
92 > | IHistoryMessageRecord
93 > | IHistoryToolStartRecord
94 > | IHistoryToolCompleteRecord
95 > | IHistorySubagentStartedRecord;
96 >
97 function extractSubagentMeta(start: IHistoryToolStartRecord | undefined): { subagentDescription?: string; subagentAgentName?: string } {
98 if (!start) {
104 };
105 }
107 > /**
108 > * Builds a parent session's {@link Turn}s from a flat list of history
109 > * records.
110 > *
111 > * Each `user` message starts a new turn. Inner subagent records (those
112 > * carrying `parentToolCallId`) are skipped — see
113 > * {@link buildSubagentTurnsFromHistory}.
114 > */
115 > export function buildTurnsFromHistory(messages: readonly IHistoryRecord[]): Turn[] {
116 const turns: Turn[] = [];
117 const subagentsByToolCallId = new Map<string, IHistorySubagentStartedRecord>();
231 return turns;
232 }
234 > /**
235 > * Builds the {@link Turn}s for a subagent child session by filtering the
236 > * parent's history for records carrying the matching `parentToolCallId`.
237 > * Returns a single turn containing all inner tool calls and assistant
238 > * messages.
239 > */
240 > export function buildSubagentTurnsFromHistory(
241 parentMessages: readonly IHistoryRecord[],
242 parentToolCallId: string,
345 }];
346 }
348 > // =============================================================================
349 > // SDK-events-to-history-records (test fixture loader)
350 > //
351 > // Translates raw Copilot SDK session events into a flat IHistoryRecord
352 > // stream. This is the test-side equivalent of the production single-pass
353 > // `mapSessionEvents` (which goes directly to Turn[]). It exists so JSONL
354 > // fixtures captured from real `~/.copilot/session-state/` files can be
355 > // loaded into the test DSL without forcing tests to also adopt Turn[].
356 > // =============================================================================
357 >
358 function tryStringify(value: unknown): string | undefined {
359 try {
363 }
364 }
366 function isSyntheticUserMessage(event: ISessionEvent): boolean {
367 if (event.type !== 'user.message') {
371 return !!source && source.toLowerCase() !== 'user';
372 }
374 > /**
375 > * Maps raw SDK session events into a flat list of {@link IHistoryRecord}s,
376 > * restoring stored file-edit metadata from the session database when
377 > * available. Test-fixture-only.
378 > */
379 export async function mapSessionEventsToHistoryRecords(
380 session: URI,