Skip to content

Commit e3c68f4

Browse files
committed
chore: fix lint and typecheck
1 parent 5ce51f8 commit e3c68f4

9 files changed

+58
-60
lines changed

src/kernels/deepnote/deepnoteServerStarter.node.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { ISqlIntegrationEnvVarsProvider } from '../../platform/notebooks/deepnot
1919
import { PythonEnvironment } from '../../platform/pythonEnvironments/info';
2020
import * as path from '../../platform/vscode-path/path';
2121
import { DEEPNOTE_DEFAULT_PORT, DeepnoteServerInfo, IDeepnoteServerStarter, IDeepnoteToolkitInstaller } from './types';
22-
import { getDeepnoteNotebookStorageKey } from '../../platform/deepnote/deepnoteUriUtils';
22+
import { getDeepnoteNotebookStorageKey } from '../../platform/deepnote/deepnoteUriUtils.node';
2323

2424
/**
2525
* Lock file data structure for tracking server ownership
@@ -255,7 +255,6 @@ export class DeepnoteServerStarter implements IDeepnoteServerStarter, IExtension
255255
token?: CancellationToken
256256
): Promise<DeepnoteServerInfo> {
257257
const filePath = deepnoteFileUri.with({ query: '', fragment: '' }).fsPath;
258-
const legacyKey = getDeepnoteNotebookStorageKey(deepnoteFileUri.with({ query: '', fragment: '' }));
259258

260259
Cancellation.throwIfCanceled(token);
261260

@@ -445,6 +444,7 @@ export class DeepnoteServerStarter implements IDeepnoteServerStarter, IExtension
445444
token?: CancellationToken
446445
): Promise<void> {
447446
const filePath = deepnoteFileUri.with({ query: '', fragment: '' }).fsPath;
447+
const legacyKey = getDeepnoteNotebookStorageKey(deepnoteFileUri.with({ query: '', fragment: '' }));
448448

449449
Cancellation.throwIfCanceled(token);
450450

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import {
3030
import { getDisplayPath } from '../../../platform/common/platform/fs-paths';
3131
import { IKernelProvider } from '../../types';
3232
import { createDeepnoteServerConfigHandle } from '../../../platform/deepnote/deepnoteServerUtils.node';
33-
import { getDeepnoteProjectStorageKey } from '../../../platform/deepnote/deepnoteUriUtils';
33+
import { getDeepnoteProjectStorageKey } from '../../../platform/deepnote/deepnoteUriUtils.node';
3434

3535
/**
3636
* View controller for the Deepnote kernel environments tree view.

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { mockedVSCodeNamespaces, resetVSCodeMocks } from '../../../test/vscode-m
1313
import { DeepnoteEnvironmentTreeDataProvider } from './deepnoteEnvironmentTreeDataProvider.node';
1414
import * as interpreterHelpers from '../../../platform/interpreter/helpers';
1515
import { createDeepnoteServerConfigHandle } from '../../../platform/deepnote/deepnoteServerUtils.node';
16-
import { getDeepnoteProjectStorageKey } from '../../../platform/deepnote/deepnoteUriUtils';
16+
import { getDeepnoteProjectStorageKey } from '../../../platform/deepnote/deepnoteUriUtils.node';
1717

1818
suite('DeepnoteEnvironmentsView', () => {
1919
let view: DeepnoteEnvironmentsView;
@@ -621,9 +621,7 @@ suite('DeepnoteEnvironmentsView', () => {
621621
when(mockedVSCodeNamespaces.window.activeNotebookEditor).thenReturn(mockNotebookEditor as any);
622622

623623
// Mock current environment mapping
624-
when(mockNotebookEnvironmentMapper.getEnvironmentForNotebook(anything())).thenReturn(
625-
currentEnvironment.id
626-
);
624+
when(mockNotebookEnvironmentMapper.getEnvironmentForNotebook(anything())).thenReturn(currentEnvironment.id);
627625
when(mockConfigManager.getEnvironment(currentEnvironment.id)).thenReturn(currentEnvironment);
628626

629627
// Mock available environments

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { logger } from '../../../platform/logging';
88
import {
99
getDeepnoteNotebookStorageKey,
1010
getLegacyDeepnoteNotebookStorageKey
11-
} from '../../../platform/deepnote/deepnoteUriUtils';
11+
} from '../../../platform/deepnote/deepnoteUriUtils.node';
1212

1313
/**
1414
* Manages the mapping between notebooks and their selected environments

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import * as sinon from 'sinon';
33
import { Uri, Memento } from 'vscode';
44

55
import { DeepnoteNotebookEnvironmentMapper } from './deepnoteNotebookEnvironmentMapper.node';
6+
import { IExtensionContext } from '../../../platform/common/types';
67

78
class InMemoryMemento implements Memento {
89
private storage = new Map<string, unknown>();
@@ -28,14 +29,17 @@ class InMemoryMemento implements Memento {
2829
}
2930
}
3031

32+
function createExtensionContextStub(workspaceState: Memento): IExtensionContext {
33+
return { workspaceState } as unknown as IExtensionContext;
34+
}
35+
3136
suite('DeepnoteNotebookEnvironmentMapper', () => {
3237
let workspaceState: InMemoryMemento;
3338
let mapper: DeepnoteNotebookEnvironmentMapper;
3439

3540
setup(() => {
3641
workspaceState = new InMemoryMemento();
37-
const context = { workspaceState } as unknown as { workspaceState: Memento };
38-
mapper = new DeepnoteNotebookEnvironmentMapper(context);
42+
mapper = new DeepnoteNotebookEnvironmentMapper(createExtensionContextStub(workspaceState));
3943
});
4044

4145
teardown(() => {
@@ -59,11 +63,8 @@ suite('DeepnoteNotebookEnvironmentMapper', () => {
5963

6064
await workspaceState.update('deepnote.notebookEnvironmentMappings', { [legacyKey]: 'env-legacy' });
6165

62-
const freshMapper = new DeepnoteNotebookEnvironmentMapper({ workspaceState } as unknown as {
63-
workspaceState: Memento;
64-
});
66+
const freshMapper = new DeepnoteNotebookEnvironmentMapper(createExtensionContextStub(workspaceState));
6567

6668
assert.strictEqual(freshMapper.getEnvironmentForNotebook(legacyUri), 'env-legacy');
6769
});
6870
});
69-

src/notebooks/deepnote/deepnoteKernelAutoSelector.node.ts

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ import {
5454
getDeepnoteNotebookKeyHash,
5555
getDeepnoteNotebookStorageKey,
5656
getDeepnoteProjectStorageKey
57-
} from '../../platform/deepnote/deepnoteUriUtils';
57+
} from '../../platform/deepnote/deepnoteUriUtils.node';
5858

5959
/**
6060
* Automatically selects and starts Deepnote kernel for .deepnote notebooks
@@ -455,13 +455,7 @@ export class DeepnoteKernelAutoSelector implements IDeepnoteKernelAutoSelector,
455455
return false;
456456
}
457457

458-
await this.ensureKernelSelectedWithConfiguration(
459-
notebook,
460-
environment,
461-
notebookKey,
462-
progress,
463-
token
464-
);
458+
await this.ensureKernelSelectedWithConfiguration(notebook, environment, notebookKey, progress, token);
465459

466460
return true;
467461
}
@@ -676,13 +670,17 @@ export class DeepnoteKernelAutoSelector implements IDeepnoteKernelAutoSelector,
676670
};
677671

678672
const waitForSelection = async () =>
679-
waitForCondition(async () => {
680-
if (token.isCancellationRequested) {
681-
return true;
682-
}
683-
const selected = this.controllerRegistration.getSelected(notebook);
684-
return selected?.id === controller.id;
685-
}, 2000, 100);
673+
waitForCondition(
674+
async () => {
675+
if (token.isCancellationRequested) {
676+
return true;
677+
}
678+
const selected = this.controllerRegistration.getSelected(notebook);
679+
return selected?.id === controller.id;
680+
},
681+
2000,
682+
100
683+
);
686684

687685
let success = (await trySelect(1)) ? await waitForSelection() : true;
688686

@@ -699,9 +697,7 @@ export class DeepnoteKernelAutoSelector implements IDeepnoteKernelAutoSelector,
699697
}
700698

701699
if (success) {
702-
logger.info(
703-
`Confirmed Deepnote controller ${controller.id} selected for ${getDisplayPath(notebook.uri)}`
704-
);
700+
logger.info(`Confirmed Deepnote controller ${controller.id} selected for ${getDisplayPath(notebook.uri)}`);
705701
} else if (!token.isCancellationRequested) {
706702
logger.error(
707703
`Failed to confirm Deepnote controller selection for ${getDisplayPath(notebook.uri)} after retry`

src/notebooks/deepnote/deepnoteKernelAutoSelector.node.unit.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -780,7 +780,6 @@ suite('DeepnoteKernelAutoSelector - rebuildController', () => {
780780
// REAL TEST: This will FAIL if disposal happens too early
781781
//
782782
// Setup: Create a scenario where we have an old controller and create a new one
783-
const baseFileUri = mockNotebook.uri.with({ query: '', fragment: '' });
784783
// const notebookKey = baseFileUri.fsPath;
785784
const newEnv = createMockEnvironment('env-new', 'New Environment', true);
786785

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { createHash } from 'crypto';
2+
import { Uri } from 'vscode';
3+
4+
import { getDeepnoteNotebookStorageKey, getDeepnoteProjectStorageKey } from './deepnoteUriUtils';
5+
6+
/**
7+
* Legacy key that only relied on the file system path (used prior to multi-notebook support).
8+
* Retained for backwards compatibility with persisted workspace state.
9+
*/
10+
export function getLegacyDeepnoteNotebookStorageKey(uri: Uri): string {
11+
const normalized = uri.with({ query: '', fragment: '' });
12+
return normalized.fsPath;
13+
}
14+
15+
/**
16+
* Generates a short hash for a Deepnote notebook URI that can be safely embedded in identifiers.
17+
*/
18+
export function getDeepnoteNotebookKeyHash(uri: Uri, length = 16): string {
19+
const key = getDeepnoteNotebookStorageKey(uri);
20+
return createHash('sha256').update(key).digest('hex').slice(0, length);
21+
}
22+
23+
/**
24+
* Generates a hash for a Deepnote project key that can be embedded safely in identifiers.
25+
*/
26+
export function getDeepnoteProjectKeyHash(uri: Uri, projectId?: string | null, length = 24): string {
27+
const key = getDeepnoteProjectStorageKey(uri, projectId);
28+
return createHash('sha256').update(key).digest('hex').slice(0, length);
29+
}
30+
31+
export { getDeepnoteNotebookStorageKey, getDeepnoteProjectStorageKey } from './deepnoteUriUtils';
Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { createHash } from 'crypto';
21
import { Uri } from 'vscode';
32

43
/**
@@ -11,23 +10,6 @@ export function getDeepnoteNotebookStorageKey(uri: Uri): string {
1110
return normalized.toString();
1211
}
1312

14-
/**
15-
* Legacy key that only relied on the file system path (used prior to multi-notebook support).
16-
* Retained for backwards compatibility with persisted workspace state.
17-
*/
18-
export function getLegacyDeepnoteNotebookStorageKey(uri: Uri): string {
19-
const normalized = uri.with({ query: '', fragment: '' });
20-
return normalized.fsPath;
21-
}
22-
23-
/**
24-
* Generates a short hash for a Deepnote notebook URI that can be safely embedded in identifiers.
25-
*/
26-
export function getDeepnoteNotebookKeyHash(uri: Uri, length = 16): string {
27-
const key = getDeepnoteNotebookStorageKey(uri);
28-
return createHash('sha256').update(key).digest('hex').slice(0, length);
29-
}
30-
3113
/**
3214
* Returns a stable key for all notebooks within a Deepnote project.
3315
* Falls back to a hashed notebook path if a project identifier is unavailable.
@@ -39,12 +21,3 @@ export function getDeepnoteProjectStorageKey(uri: Uri, projectId?: string | null
3921

4022
return `notebook:${getDeepnoteNotebookStorageKey(uri)}`;
4123
}
42-
43-
/**
44-
* Generates a hash for a Deepnote project key that can be embedded safely in identifiers.
45-
*/
46-
export function getDeepnoteProjectKeyHash(uri: Uri, projectId?: string | null, length = 24): string {
47-
const key = getDeepnoteProjectStorageKey(uri, projectId);
48-
return createHash('sha256').update(key).digest('hex').slice(0, length);
49-
}
50-

0 commit comments

Comments
 (0)