Skip to content

Commit e09011e

Browse files
committed
chore: code review comment
1 parent d191542 commit e09011e

File tree

2 files changed

+37
-6
lines changed

2 files changed

+37
-6
lines changed

src/kernels/deepnote/environments/deepnoteEnvironmentManager.node.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,13 @@ export class DeepnoteEnvironmentManager implements IExtensionSyncActivationServi
6363
const actualVenvParent = path.dirname(config.venvPath.fsPath);
6464
const isInCorrectStorage = actualVenvParent === expectedVenvParent;
6565

66-
const uuidPattern = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
67-
const isHashBasedName = !uuidPattern.test(venvDirName);
68-
69-
const needsPathMigration = isHashBasedName || !isInCorrectStorage;
66+
// Check if directory name matches the environment ID and is in correct storage
67+
const isExpectedPath = venvDirName === config.id && isInCorrectStorage;
68+
const needsPathMigration = !isExpectedPath;
7069

7170
if (needsPathMigration) {
7271
logger.info(
73-
`Migrating environment "${config.name}" from old venv path ${config.venvPath.fsPath} to UUID-based path`
72+
`Migrating environment "${config.name}" from ${config.venvPath.fsPath} to ID-based path`
7473
);
7574

7675
config.venvPath = Uri.joinPath(this.context.globalStorageUri, 'deepnote-venvs', config.id);

src/kernels/deepnote/environments/deepnoteEnvironmentManager.unit.test.ts

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ suite('DeepnoteEnvironmentManager', () => {
335335
verify(mockStorage.saveEnvironments(anything())).once();
336336
});
337337

338-
test('should not migrate environments with correct UUID paths in correct storage', async () => {
338+
test('should not migrate environments with correct ID-based paths in correct storage', async () => {
339339
const testDate = new Date();
340340
const correctConfig = {
341341
id: '12345678-1234-1234-1234-123456789abc',
@@ -372,6 +372,38 @@ suite('DeepnoteEnvironmentManager', () => {
372372
verify(mockStorage.saveEnvironments(anything())).never();
373373
});
374374

375+
test('should not migrate environments with non-UUID IDs when path already matches', async () => {
376+
const testDate = new Date();
377+
const customIdConfig = {
378+
id: 'my-custom-env-id',
379+
name: 'Custom ID Environment',
380+
pythonInterpreter: testInterpreter,
381+
venvPath: Uri.file('/global/storage/deepnote-venvs/my-custom-env-id'),
382+
createdAt: testDate,
383+
lastUsedAt: testDate,
384+
toolkitVersion: '1.0.0'
385+
};
386+
387+
when(mockStorage.loadEnvironments()).thenResolve([customIdConfig]);
388+
when(mockStorage.saveEnvironments(anything())).thenResolve();
389+
when(mockContext.globalStorageUri).thenReturn(Uri.file('/global/storage'));
390+
391+
manager.activate();
392+
await manager.waitForInitialization();
393+
394+
const configs = manager.listEnvironments();
395+
assert.strictEqual(configs.length, 1);
396+
397+
// Path should remain unchanged
398+
assert.strictEqual(configs[0].venvPath.fsPath, '/global/storage/deepnote-venvs/my-custom-env-id');
399+
400+
// Toolkit version should NOT be cleared
401+
assert.strictEqual(configs[0].toolkitVersion, '1.0.0');
402+
403+
// Should NOT have saved (no migration needed)
404+
verify(mockStorage.saveEnvironments(anything())).never();
405+
});
406+
375407
test('should migrate multiple environments at once', async () => {
376408
const configs = [
377409
{

0 commit comments

Comments
 (0)