Skip to content

Commit 7f48555

Browse files
committed
Remove workspace from hash
1 parent bedc7d2 commit 7f48555

File tree

2 files changed

+13
-27
lines changed

2 files changed

+13
-27
lines changed

src/extension/noConfigDebugInit.ts

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import {
1111
env,
1212
l10n,
1313
RelativePattern,
14-
workspace,
1514
} from 'vscode';
1615
import { createFileSystemWatcher, debugStartDebugging } from './utils';
1716
import { traceError, traceVerbose } from './common/log/logging';
@@ -40,24 +39,12 @@ export async function registerNoConfigDebug(
4039
const collection = envVarCollection;
4140

4241
// create a temp directory for the noConfigDebugAdapterEndpoints
43-
// file path format: extPath/.noConfigDebugAdapterEndpoints/endpoint-stableWorkspaceHash.txt
44-
let workspaceString = workspace.workspaceFile?.fsPath;
45-
if (!workspaceString) {
46-
workspaceString = workspace.workspaceFolders?.map((e) => e.uri.fsPath).join(';');
47-
}
48-
if (!workspaceString) {
49-
traceError('No workspace folder found');
50-
return Promise.resolve(new Disposable(() => {}));
51-
}
52-
53-
// Create unique hash based on workspace and VS Code session ID
54-
const hash = crypto.createHash('sha256');
55-
hash.update(workspaceString.toString());
56-
hash.update(env.sessionId);
57-
const stableWorkspaceHash = hash.digest('hex').slice(0, 16);
42+
// file path format: extPath/.noConfigDebugAdapterEndpoints/endpoint-<sessionId>.txt
43+
// sessionId is unique per VS Code window, ensuring isolation between windows
5844

5945
const tempDirPath = path.join(extPath, '.noConfigDebugAdapterEndpoints');
60-
const endpointFilename = `endpoint-${stableWorkspaceHash}.txt`;
46+
const sessionIdHash = crypto.createHash('sha256').update(env.sessionId).digest('hex').slice(0, 16);
47+
const endpointFilename = `endpoint-${sessionIdHash}.txt`;
6148
const tempFilePath = path.join(tempDirPath, endpointFilename);
6249

6350
// create the temp directory if it doesn't exist

src/test/unittest/noConfigDebugInit.unit.test.ts

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { IExtensionContext } from '../../extension/common/types';
66
import { registerNoConfigDebug as registerNoConfigDebug } from '../../extension/noConfigDebugInit';
77
import * as TypeMoq from 'typemoq';
88
import * as sinon from 'sinon';
9-
import { DebugConfiguration, DebugSessionOptions, RelativePattern, Uri, workspace } from 'vscode';
9+
import { DebugConfiguration, DebugSessionOptions, env, RelativePattern, Uri } from 'vscode';
1010
import * as utils from '../../extension/utils';
1111
import { assert } from 'console';
1212
import * as fs from 'fs';
@@ -19,10 +19,10 @@ suite('setup for no-config debug scenario', function () {
1919
let context: TypeMoq.IMock<IExtensionContext>;
2020
let noConfigScriptsDir: string;
2121
let bundledDebugPath: string;
22-
let noConfigEndpointDir: string;
2322
let DEBUGPY_ADAPTER_ENDPOINTS = 'DEBUGPY_ADAPTER_ENDPOINTS';
2423
let BUNDLED_DEBUGPY_PATH = 'BUNDLED_DEBUGPY_PATH';
25-
let workspaceUriStub: sinon.SinonStub;
24+
const testSessionId = 'test-session-id-1234';
25+
const hashedSessionId = crypto.createHash('sha256').update(testSessionId).digest('hex').slice(0, 16);
2626

2727
const testDataDir = path.join(__dirname, 'testData');
2828
const testFilePath = path.join(testDataDir, 'debuggerAdapterEndpoint.txt');
@@ -34,21 +34,20 @@ suite('setup for no-config debug scenario', function () {
3434
context.setup((c) => c.subscriptions).returns(() => []);
3535
noConfigScriptsDir = path.join(context.object.extensionPath, 'bundled/scripts/noConfigScripts');
3636
bundledDebugPath = path.join(context.object.extensionPath, 'bundled/libs/debugpy');
37-
noConfigEndpointDir = path.join(context.object.extensionPath, '.noConfigDebugAdapterEndpoints');
3837

3938
// Stub crypto.randomBytes with proper typing
4039
let randomBytesStub = sinon.stub(crypto, 'randomBytes');
4140
// Provide a valid Buffer object
4241
randomBytesStub.callsFake((_size: number) => Buffer.from('1234567899', 'hex'));
4342

44-
workspaceUriStub = sinon.stub(workspace, 'workspaceFolders').value([{ uri: Uri.parse(os.tmpdir()) }]);
43+
// Stub env.sessionId to return a consistent value for tests
44+
sinon.stub(env, 'sessionId').value(testSessionId);
4545
} catch (error) {
4646
console.error('Error in setup:', error);
4747
}
4848
});
4949
teardown(() => {
5050
sinon.restore();
51-
workspaceUriStub.restore();
5251
});
5352

5453
test('should add environment variables for DEBUGPY_ADAPTER_ENDPOINTS, BUNDLED_DEBUGPY_PATH, and PATH', async () => {
@@ -195,10 +194,10 @@ suite('setup for no-config debug scenario', function () {
195194

196195
// Assert
197196
sinon.assert.calledOnce(createFileSystemWatcherFunct);
198-
const expectedPattern = sinon.match
199-
.instanceOf(RelativePattern)
200-
.and(sinon.match.has('base', Uri.file(noConfigEndpointDir).fsPath))
201-
.and(sinon.match.has('pattern', sinon.match(/^endpoint-[0-9a-f]{16}\.txt$/)));
197+
const expectedPattern = new RelativePattern(
198+
path.join(os.tmpdir(), '.noConfigDebugAdapterEndpoints'),
199+
`endpoint-${hashedSessionId}.txt`,
200+
);
202201
sinon.assert.calledWith(createFileSystemWatcherFunct, expectedPattern);
203202
});
204203

0 commit comments

Comments
 (0)