Skip to content

Commit 1df677a

Browse files
committed
logging to determine CI error
1 parent b10cb5c commit 1df677a

4 files changed

Lines changed: 53 additions & 11 deletions

File tree

src/features/envManagers.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,13 @@ export class PythonEnvironmentManagers implements EnvironmentManagers {
329329
},
330330
]);
331331
}
332+
traceVerbose(
333+
`[setEnvironment] scope=${scope instanceof Uri ? scope.fsPath : scope}, ` +
334+
`env=${environment?.envId?.id ?? 'undefined'}, manager=${manager.id}, ` +
335+
`project=${project?.uri?.toString() ?? 'none'}, ` +
336+
`packageManager=${this.getPackageManager(environment)?.id ?? 'UNDEFINED'}, ` +
337+
`settingsPersisted=${!!(project && this.getPackageManager(environment))}`,
338+
);
332339
}
333340

334341
const key = project ? project.uri.toString() : 'global';
@@ -505,6 +512,10 @@ export class PythonEnvironmentManagers implements EnvironmentManagers {
505512
async getEnvironment(scope: GetEnvironmentScope): Promise<PythonEnvironment | undefined> {
506513
const manager = this.getEnvironmentManager(scope);
507514
if (!manager) {
515+
traceVerbose(
516+
`[getEnvironment] No manager found for scope=${scope instanceof Uri ? scope.fsPath : scope}, ` +
517+
`settingsManagerId=${getDefaultEnvManagerSetting(this.pm, scope instanceof Uri ? scope : undefined)}`,
518+
);
508519
return undefined;
509520
}
510521

src/managers/builtin/sysPythonManager.ts

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -166,13 +166,20 @@ export class SysPythonManager implements EnvironmentManager {
166166
const pw = this.api.getPythonProject(scope);
167167
if (!pw) {
168168
this.log.warn(
169-
`Unable to set environment for ${scope.fsPath}: Not a python project, folder or PEP723 script.`,
170-
this.api.getPythonProjects().map((p) => p.uri.fsPath),
169+
`[SYS_SET] Unable to set environment for ${scope.fsPath}: Not a python project. ` +
170+
`Known projects: [${this.api
171+
.getPythonProjects()
172+
.map((p) => p.uri.fsPath)
173+
.join(', ')}]`,
171174
);
172175
return;
173176
}
174177

175178
const normalizedPwPath = normalizePath(pw.uri.fsPath);
179+
this.log.info(
180+
`[SYS_SET] scope=${scope.fsPath}, project=${pw.uri.fsPath}, ` +
181+
`normalizedKey=${normalizedPwPath}, env=${environment?.envId?.id ?? 'undefined'}`,
182+
);
176183
if (environment) {
177184
this.fsPathToEnv.set(normalizedPwPath, environment);
178185
} else {
@@ -297,16 +304,28 @@ export class SysPythonManager implements EnvironmentManager {
297304
}
298305

299306
private fromEnvMap(uri: Uri): PythonEnvironment | undefined {
307+
const normalizedUri = normalizePath(uri.fsPath);
300308
// Find environment directly using the URI mapping
301-
const env = this.fsPathToEnv.get(normalizePath(uri.fsPath));
309+
const env = this.fsPathToEnv.get(normalizedUri);
302310
if (env) {
303311
return env;
304312
}
305313

306314
// Find environment using the Python project for the Uri
307315
const project = this.api.getPythonProject(uri);
308-
if (project) {
309-
return this.fsPathToEnv.get(normalizePath(project.uri.fsPath));
316+
const projectKey = project ? normalizePath(project.uri.fsPath) : undefined;
317+
const projectEnv = projectKey ? this.fsPathToEnv.get(projectKey) : undefined;
318+
319+
this.log.info(
320+
`[SYS_GET] uri=${uri.fsPath}, normalizedKey=${normalizedUri}, ` +
321+
`project=${project?.uri?.fsPath ?? 'none'}, projectKey=${projectKey ?? 'none'}, ` +
322+
`mapKeys=[${Array.from(this.fsPathToEnv.keys()).join(', ')}], ` +
323+
`directHit=${!!env}, projectHit=${!!projectEnv}, ` +
324+
`fallbackToGlobal=${!projectEnv}, globalEnv=${this.globalEnv?.envId?.id ?? 'none'}`,
325+
);
326+
327+
if (projectEnv) {
328+
return projectEnv;
310329
}
311330

312331
return this.globalEnv;

src/test/integration/pythonProjects.integration.test.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ suite('Integration: Python Projects', function () {
185185
// Track what getEnvironment returns during polling for diagnostics
186186
let pollCount = 0;
187187
let lastRetrievedId: string | undefined;
188+
let lastRetrievedManagerId: string | undefined;
188189

189190
// Wait for the environment to be retrievable with the correct ID
190191
// This handles async persistence across platforms
@@ -194,16 +195,18 @@ suite('Integration: Python Projects', function () {
194195
const retrieved = await api.getEnvironment(project.uri);
195196
pollCount++;
196197
const retrievedId = retrieved?.envId?.id;
198+
lastRetrievedManagerId = retrieved?.envId?.managerId;
197199
if (retrievedId !== lastRetrievedId) {
198200
console.log(
199-
`[TEST DEBUG] Poll #${pollCount}: getEnvironment returned envId=${retrievedId ?? 'undefined'}`,
201+
`[TEST DEBUG] Poll #${pollCount}: getEnvironment returned envId=${retrievedId ?? 'undefined'}, managerId=${lastRetrievedManagerId ?? 'undefined'}`,
200202
);
201203
lastRetrievedId = retrievedId;
202204
}
203205
return retrieved !== undefined && retrieved.envId.id === env.envId.id;
204206
},
205207
15_000,
206-
`Environment was not set correctly. Expected envId: ${env.envId.id}, last retrieved: ${lastRetrievedId}`,
208+
() =>
209+
`Environment was not set correctly. Expected envId: ${env.envId.id} (manager: ${env.envId.managerId}), last retrieved: ${lastRetrievedId ?? 'undefined'} (manager: ${lastRetrievedManagerId ?? 'undefined'}) after ${pollCount} polls`,
207210
);
208211

209212
// Final verification
@@ -285,13 +288,16 @@ suite('Integration: Python Projects', function () {
285288

286289
// Wait for it to be set
287290
// Use 15s timeout - CI runners can be slow with settings persistence
291+
let clearTestLastId: string | undefined;
288292
await waitForCondition(
289293
async () => {
290294
const retrieved = await api.getEnvironment(project.uri);
295+
clearTestLastId = retrieved?.envId?.id;
291296
return retrieved !== undefined && retrieved.envId.id === env.envId.id;
292297
},
293298
15_000,
294-
'Environment was not set before clearing',
299+
() =>
300+
`Environment was not set before clearing. Expected: ${env.envId.id} (manager: ${env.envId.managerId}), got: ${clearTestLastId ?? 'undefined'}`,
295301
);
296302

297303
// Verify it was set
@@ -344,13 +350,18 @@ suite('Integration: Python Projects', function () {
344350

345351
// Wait for it to be set
346352
// Use 15s timeout - CI runners can be slow with settings persistence
353+
let fileTestLastId: string | undefined;
354+
let fileTestLastManagerId: string | undefined;
347355
await waitForCondition(
348356
async () => {
349357
const retrieved = await api.getEnvironment(project.uri);
358+
fileTestLastId = retrieved?.envId?.id;
359+
fileTestLastManagerId = retrieved?.envId?.managerId;
350360
return retrieved !== undefined && retrieved.envId.id === env.envId.id;
351361
},
352362
15_000,
353-
'Environment was not set for project',
363+
() =>
364+
`Environment was not set for project. Expected: ${env.envId.id} (manager: ${env.envId.managerId}), got: ${fileTestLastId ?? 'undefined'} (manager: ${fileTestLastManagerId ?? 'undefined'})`,
354365
);
355366

356367
// Create a hypothetical file path inside the project

src/test/testUtils.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export function sleep(ms: number): Promise<void> {
4848
export async function waitForCondition(
4949
condition: () => boolean | Promise<boolean>,
5050
timeoutMs: number = 10_000,
51-
errorMessage: string = 'Condition not met within timeout',
51+
errorMessage: string | (() => string) = 'Condition not met within timeout',
5252
pollIntervalMs: number = 100,
5353
): Promise<void> {
5454
return new Promise<void>((resolve, reject) => {
@@ -66,7 +66,8 @@ export async function waitForCondition(
6666
}
6767

6868
if (Date.now() - startTime >= timeoutMs) {
69-
reject(new Error(`${errorMessage} (waited ${timeoutMs}ms)`));
69+
const msg = typeof errorMessage === 'function' ? errorMessage() : errorMessage;
70+
reject(new Error(`${msg} (waited ${timeoutMs}ms)`));
7071
return;
7172
}
7273

0 commit comments

Comments
 (0)