Skip to content

Commit dd1fa01

Browse files
248369: Adding tests to verify path transformation logic works correctly
1 parent 31612a1 commit dd1fa01

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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 'mocha';
7+
import assert from 'assert';
8+
import path from 'path';
9+
10+
suite('Repository path handling', () => {
11+
// Test the path manipulation logic directly for subst drives
12+
test('subst drive path correction', () => {
13+
const root = 'X:\\repo';
14+
const rootRealPath = 'C:\\real\\path\\repo';
15+
const fsPath = 'X:\\repo\\file.txt';
16+
17+
// This is the logic from the fix we implemented
18+
const realPath = fsPath.startsWith(root)
19+
? path.join(rootRealPath, fsPath.substring(root.length))
20+
: fsPath;
21+
22+
// Verify the path is correctly transformed
23+
assert.strictEqual(realPath, 'C:\\real\\path\\repo\\file.txt');
24+
});
25+
26+
test('non-subst path should remain unchanged', () => {
27+
const root = 'C:\\repo';
28+
const rootRealPath = 'C:\\repo';
29+
const fsPath = 'C:\\repo\\file.txt';
30+
31+
// Same logic as implemented in the fix
32+
const realPath = fsPath.startsWith(root)
33+
? path.join(rootRealPath, fsPath.substring(root.length))
34+
: fsPath;
35+
36+
// Path should remain unchanged
37+
assert.strictEqual(realPath, 'C:\\repo\\file.txt');
38+
});
39+
40+
test('path outside repository should remain unchanged', () => {
41+
const root = 'X:\\repo';
42+
const rootRealPath = 'C:\\real\\path\\repo';
43+
const fsPath = 'D:\\other\\file.txt';
44+
45+
// Same logic as implemented in the fix
46+
const realPath = fsPath.startsWith(root)
47+
? path.join(rootRealPath, fsPath.substring(root.length))
48+
: fsPath;
49+
50+
// Path should remain unchanged
51+
assert.strictEqual(realPath, 'D:\\other\\file.txt');
52+
});
53+
});

0 commit comments

Comments
 (0)