mockFilesystem.ts ×16

Frontier kind: Code frontier

unlabeled · c_90d96bbf1e90

225 tests · 11695 LOC · 51 files · introduces 0 tests · 127 LOC · 1 file

Introduces — evidence that enters the hierarchy at this concept

Code
16 ranges127 lines · 1 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
1805 ranges11695 lines · 51 files · Browse complete extent
All tests (intent)
225 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: 127 introduced LOC across 16 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

src/vs/workbench/contrib/chat/test/common/promptSyntax/testUtils/mockFilesystem.ts 127 introduced LOC · 16 ranges

Open complete file

1 > /*--------------------------------------------------------------------------------------------- mockFilesystem.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 { VSBuffer } from '../../../../../../../base/common/buffer.js';
8 > import { FileSystemProviderCapabilities, FileType, IFileService, IFileSystemProviderWithFileRealpathCapability, IStat } from '../../../../../../../platform/files/common/files.js';
9 > import { dirname } from '../../../../../../../base/common/resources.js';
10 > import { InMemoryFileSystemProvider } from '../../../../../../../platform/files/common/inMemoryFilesystemProvider.js';
11 > import { ResourceMap } from '../../../../../../../base/common/map.js';
12 >
13 > /**
14 > * Test file system provider that extends InMemoryFileSystemProvider with realpath support.
15 > * Allows tests to define custom realpath mappings to simulate symlinks.
16 > */
17 > export class TestInMemoryFileSystemProviderWithRealPath extends InMemoryFileSystemProvider implements IFileSystemProviderWithFileRealpathCapability {
18 private readonly realPathMappings = new ResourceMap<URI>();
20 > override get capabilities(): FileSystemProviderCapabilities {
21 return super.capabilities | FileSystemProviderCapabilities.FileRealpath;
22 }
24 > /**
25 > * Defines a realpath mapping for a URI.
26 > * When realpath() is called for the given URI, it will return the mapped realPath.
27 > * Use this to simulate symlinks - multiple URIs can map to the same realPath.
28 > */
29 > setRealPath(uri: URI, realPath: URI): void {
30 this.realPathMappings.set(uri, realPath);
31 }
33 > /**
34 > * Clears all realpath mappings.
35 > */
36 > clearRealPathMappings(): void {
37 this.realPathMappings.clear();
38 }
40 > /**
41 > * Returns the realpath for the given resource.
42 > * If a mapping was set via setRealPath(), returns that mapped path.
43 > * Otherwise returns the original path (simulating a non-symlink file).
44 > */
45 > async realpath(resource: URI): Promise<string> {
46 const mapped = this.realPathMappings.get(resource);
47 if (mapped) {
51 return resource.path;
52 }
54 > /**
55 > * Override stat to mark files with realPath mappings as symbolic links.
56 > */
57 > override async stat(resource: URI): Promise<IStat> {
58 const baseStat = await super.stat(resource);
59 const isSymlink = this.realPathMappings.has(resource);
66 return baseStat;
67 }
69 > /**
70 > * Override readdir to mark files with realPath mappings as symbolic links.
71 > */
72 > override async readdir(resource: URI): Promise<[string, FileType][]> {
73 const entries = await super.readdir(resource);
74 return entries.map(([name, type]) => {
80 });
81 }
83 >
84 > /**
85 > * Represents a generic file system node.
86 > */
87 > interface IMockFilesystemNode {
88 > name: string;
89 > }
90 >
91 > /**
92 > * Represents a `file` node.
93 > */
94 > export interface IMockFile extends IMockFilesystemNode {
95 > contents: string | readonly string[];
96 > }
97 >
98 > /**
99 > * Represents a `folder` node.
100 > */
101 > export interface IMockFolder extends IMockFilesystemNode {
102 > children: (IMockFolder | IMockFile)[];
103 > }
104 >
105 >
106 > /**
107 > * Represents a file entry for simplified initialization.
108 > */
109 > export interface IMockFileEntry {
110 > path: string;
111 > contents: string[];
112 > }
113 >
114 > /**
115 > * Creates mock filesystem from provided file entries.
116 > * @param fileService File service instance
117 > * @param files Array of file entries with path and contents
118 > */
119 > export function mockFiles(fileService: IFileService, files: IMockFileEntry[], parentFolder?: URI): Promise<void> {
120 return new MockFilesystem(files, fileService).mock(parentFolder);
121 }
123 > /**
124 > * Utility to recursively creates provided filesystem structure.
125 > */
126 > export class MockFilesystem {
127 >
128 > private createdFiles: URI[] = [];
129 > private createdFolders: URI[] = [];
130 > private createdRootFolders: URI[] = [];
131 >
132 > constructor(
133 private readonly input: IMockFolder[] | IMockFileEntry[],
134 @IFileService private readonly fileService: IFileService,
135 ) { }
137 >
138 >
139 > /**
140 > * Starts the mock process.
141 > */
142 > public async mock(parentFolder?: URI): Promise<void> {
143 // Check if input is the new simplified format
144 if (this.input.length > 0 && 'path' in this.input[0]) {
149 return this.mockFromFolders(this.input as IMockFolder[], parentFolder);
150 }
152 > /**
153 > * Mock using the new simplified file entry format.
154 > */
155 > private async mockFromFileEntries(fileEntries: IMockFileEntry[]): Promise<void> {
156 // Create all files and their parent directories
157 for (const fileEntry of fileEntries) {
168 }
169 }
171 > /**
172 > * Mock using the old nested folder format.
173 > */
174 > private async mockFromFolders(folders: IMockFolder[], parentFolder?: URI): Promise<void> {
175 const result = await Promise.all(folders.map((folder) => this.mockFolder(folder, parentFolder)));
176 this.createdRootFolders.push(...result);
177 }
179 > public async delete(): Promise<void> {
180 // Delete files created by the new format
181 for (const fileUri of this.createdFiles) {
196 }
197 }
199 > /**
200 > * The internal implementation of the filesystem mocking process for the old format.
201 > */
202 > private async mockFolder(folder: IMockFolder, parentFolder?: URI): Promise<URI> {
203 const folderUri = parentFolder
204 ? URI.joinPath(parentFolder, folder.name)
235 return folderUri;
236 }
238 > /**
239 > * Ensures that all parent directories of the given file URI exist.
240 > */
241 > private async ensureParentDirectories(dirUri: URI): Promise<void> {
242 if (!await this.fileService.exists(dirUri)) {
243 // First ensure the parent directory exists (recursive call)