Skip to content

Commit 1f2e7b8

Browse files
committed
Fix authentication ext-host tests on Windows
- test-integration.bat: resolve TMP/TEMP to the long path, as upstream's test-remote-integration.bat and test-web-integration.bat already do. On CI TMP is C:\Users\RUNNER~1\..., and under Node 24.16+ fs.watch on an 8.3 short-name path drops every event (nodejs/node#63638), so the providerCatalog watcher test never saw its file edit. - authentication tests: remove watched temp dirs with an async fs.promises.rm retry. Windows releases a closed watcher's directory handle on a later event loop turn, so an immediate rmSync fails with ENOTEMPTY/EPERM, and rmSync's own retries block the loop. - snowflake test: build the expected path with path.join.
1 parent 5007e26 commit 1f2e7b8

8 files changed

Lines changed: 47 additions & 14 deletions

File tree

‎extensions/authentication/src/test/activationOrdering.test.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import * as path from 'path';
1010
import * as vscode from 'vscode';
1111
import { migrateSettingsAndPrimeCatalog } from '../extension';
1212
import { getCachedProvider } from '../providerCatalog';
13+
import { removeTempDir } from './tempDir';
1314

1415
/** Minimal ExtensionContext stub: only `subscriptions` is read by initProviderCatalog. */
1516
function fakeContext(): vscode.ExtensionContext {
@@ -45,7 +46,7 @@ suite('activation ordering', () => {
4546
for (const d of context.subscriptions) {
4647
d.dispose();
4748
}
48-
fs.rmSync(dir, { recursive: true, force: true });
49+
await removeTempDir(dir);
4950
await vscode.workspace.getConfiguration('authentication.aws')
5051
.update('credentials', undefined, vscode.ConfigurationTarget.Global);
5152
await vscode.workspace.getConfiguration('authentication.snowflake')

‎extensions/authentication/src/test/customProviders.test.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import {
3535
} from '../customProviderAuth';
3636
import { CustomProviderRegistry } from '../customProviderRegistry';
3737
import { customProviderSource, getRegistrableCustomProviders } from '../providerSources';
38+
import { removeTempDir } from './tempDir';
3839

3940
/** The model sources Positron registers for the catalog's custom entries. */
4041
function customSources() {
@@ -123,11 +124,11 @@ suite('custom providers', () => {
123124
context = fakeContext();
124125
});
125126

126-
teardown(() => {
127+
teardown(async () => {
127128
for (const d of context.subscriptions) {
128129
d.dispose();
129130
}
130-
fs.rmSync(dir, { recursive: true, force: true });
131+
await removeTempDir(dir);
131132
});
132133

133134
suite('write path', () => {

‎extensions/authentication/src/test/positOAuthProvider.test.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import * as path from 'path';
1010
import * as vscode from 'vscode';
1111
import { PositOAuthProvider } from '../positOAuthProvider';
1212
import { initProviderCatalog } from '../providerCatalog';
13+
import { removeTempDir } from './tempDir';
1314

1415
function storeValidTokens(secrets: Map<string, string>, overrides?: {
1516
accessToken?: string;
@@ -142,11 +143,11 @@ suite('PositOAuthProvider', () => {
142143
catalogContext = { subscriptions: [] } as unknown as vscode.ExtensionContext;
143144
});
144145

145-
teardown(() => {
146+
teardown(async () => {
146147
for (const d of catalogContext.subscriptions) {
147148
d.dispose();
148149
}
149-
fs.rmSync(dir, { recursive: true, force: true });
150+
await removeTempDir(dir);
150151
});
151152

152153
async function refreshAndCaptureRequest(): Promise<{ url: string; body: string }> {

‎extensions/authentication/src/test/providerCatalog.test.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import {
2222
saveProviderEnabled,
2323
saveSnowflakeAccount,
2424
} from '../providerCatalog';
25+
import { removeTempDir } from './tempDir';
2526

2627
/** Minimal ExtensionContext stub: only `subscriptions` is read by initProviderCatalog. */
2728
function fakeContext(): vscode.ExtensionContext {
@@ -67,12 +68,12 @@ suite('providerCatalog', () => {
6768
context = fakeContext();
6869
});
6970

70-
teardown(() => {
71+
teardown(async () => {
7172
// Dispose the watcher registered on the (soon-deleted) tmpdir.
7273
for (const d of context.subscriptions) {
7374
d.dispose();
7475
}
75-
fs.rmSync(dir, { recursive: true, force: true });
76+
await removeTempDir(dir);
7677
});
7778

7879
test('init loads the baseline catalog and getCachedProvider answers synchronously', async () => {

‎extensions/authentication/src/test/providerSources.test.ts‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import * as vscode from 'vscode';
1111
import { getProviderSources, getRegistrableProviderSources, PROVIDER_METADATA } from '../providerSources';
1212
import { POSITRON_CUSTOM_AUTH_PROVIDER_ID } from '../constants';
1313
import { getCachedProvider, initProviderCatalog } from '../providerCatalog';
14+
import { removeTempDir } from './tempDir';
1415

1516
/**
1617
* Guards against drift between PROVIDER_METADATA in providerSources.ts and the
@@ -77,11 +78,11 @@ suite('getProviderSources baseUrl defaults from the catalog', () => {
7778
context = fakeContext();
7879
});
7980

80-
teardown(() => {
81+
teardown(async () => {
8182
for (const d of context.subscriptions) {
8283
d.dispose();
8384
}
84-
fs.rmSync(dir, { recursive: true, force: true });
85+
await removeTempDir(dir);
8586
});
8687

8788
test('a saved catalog baseUrl overrides the per-provider default literal', async () => {
@@ -146,11 +147,11 @@ suite('the legacy openai-compatible provider', () => {
146147
context = fakeContext();
147148
});
148149

149-
teardown(() => {
150+
teardown(async () => {
150151
for (const d of context.subscriptions) {
151152
d.dispose();
152153
}
153-
fs.rmSync(dir, { recursive: true, force: true });
154+
await removeTempDir(dir);
154155
});
155156

156157
test('getRegistrableProviderSources leaves it out when providers.json has no openai-compatible block', async () => {
@@ -191,11 +192,11 @@ suite('getProviderSources connection provenance', () => {
191192
context = fakeContext();
192193
});
193194

194-
teardown(() => {
195+
teardown(async () => {
195196
for (const d of context.subscriptions) {
196197
d.dispose();
197198
}
198-
fs.rmSync(dir, { recursive: true, force: true });
199+
await removeTempDir(dir);
199200
});
200201

201202
function bedrockSource() {

‎extensions/authentication/src/test/snowflake.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ suite('Snowflake Credentials', () => {
9494
test('getSnowflakeConnectionsTomlPath derives the path from the slice home', () => {
9595
assert.strictEqual(
9696
getSnowflakeConnectionsTomlPath({ home: '/snowflake/home' }),
97-
'/snowflake/home/connections.toml'
97+
path.join('/snowflake/home', 'connections.toml')
9898
);
9999
assert.strictEqual(getSnowflakeConnectionsTomlPath({}), undefined);
100100
assert.strictEqual(getSnowflakeConnectionsTomlPath(undefined), undefined);
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (C) 2026 Posit Software, PBC. All rights reserved.
3+
* Licensed under the Elastic License 2.0. See LICENSE.txt for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
import * as fs from 'fs';
7+
8+
/**
9+
* Removes a temp directory that a provider catalog watcher was watching.
10+
*
11+
* On Windows, closing an `fs.watch` watcher releases its directory handle on
12+
* a later event loop turn, so deleting the directory right after disposing
13+
* the watcher fails with EPERM/ENOTEMPTY. This must be async: `fs.rmSync`
14+
* retries block the event loop, so the handle would never get released.
15+
*/
16+
export async function removeTempDir(dir: string): Promise<void> {
17+
await fs.promises.rm(dir, { recursive: true, force: true, maxRetries: 10, retryDelay: 100 });
18+
}

‎scripts/test-integration.bat‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,16 @@ set "SCRIPT_DIR=%~dp0"
66

77
pushd %SCRIPT_DIR%\..
88

9+
:: --- Start Positron ---
10+
:: Same workaround as test-remote-integration.bat and test-web-integration.bat:
11+
:: resolve TMP to its long form. On CI it is C:\Users\RUNNER~1\..., and under
12+
:: Node 24.16+ fs.watch on an 8.3 short-name path drops every event (libuv
13+
:: regression, https://github.com/nodejs/node/issues/63638), which breaks the
14+
:: extension tests that watch files in temp directories.
15+
for /f "delims=" %%i in ('node -p "require('fs').realpathSync.native(require('os').tmpdir())"') do set "TMP=%%i"
16+
set "TEMP=%TMP%"
17+
:: --- End Positron ---
18+
919
:: Parse arguments for help and filters
1020
set "HAS_FILTER="
1121
set "RUN_FILE="

0 commit comments

Comments
 (0)