fix(setup): always resolve interpreter during setup probe

This commit is contained in:
can1357
2026-08-02 20:47:36 +02:00
parent 46f780fedd
commit 46c66ac03a
3 changed files with 23 additions and 3 deletions
+1 -1
View File
@@ -83,7 +83,7 @@ function managedPythonPath(): string {
* Check Python environment and kernel dependencies.
*/
async function checkPythonSetup(cwd: string, interpreter?: string): Promise<PythonCheckResult> {
const availability = await checkPythonKernelAvailability(cwd, interpreter);
const availability = await checkPythonKernelAvailability(cwd, interpreter, { forceProbe: true });
return {
available: availability.ok,
pythonPath: availability.pythonPath,
+2 -1
View File
@@ -82,8 +82,9 @@ const availabilityCache = new Map<string, Promise<PythonKernelAvailability>>();
export async function checkPythonKernelAvailability(
cwd: string,
interpreter?: string,
options?: { forceProbe?: boolean },
): Promise<PythonKernelAvailability> {
if (isBunTestRuntime() || $flag("PI_PYTHON_SKIP_CHECK")) {
if (!options?.forceProbe && (isBunTestRuntime() || $flag("PI_PYTHON_SKIP_CHECK"))) {
return { ok: true };
}
const resolvedCwd = path.resolve(cwd);
+20 -1
View File
@@ -11,11 +11,12 @@ interface CliProcessResult {
error: string;
}
async function runSetupPython(cwd: string): Promise<CliProcessResult> {
async function runSetupPython(cwd: string, envOverrides?: NodeJS.ProcessEnv): Promise<CliProcessResult> {
const env: NodeJS.ProcessEnv = {
...process.env,
NO_COLOR: "1",
PI_CODING_AGENT_DIR: path.join(cwd, "agent"),
...envOverrides,
};
delete env.VIRTUAL_ENV;
delete env.CONDA_DEFAULT_ENV;
@@ -78,4 +79,22 @@ describe("omp setup python", () => {
usingManagedEnv: false,
});
});
it.skipIf(process.platform === "win32")("does not let the global probe bypass skip setup validation", async () => {
projectDir = TempDir.createSync("@omp-setup-python-");
const cwd = projectDir.path();
const interpreter = path.join(cwd, "configured-python");
await Bun.write(interpreter, "#!/bin/sh\nexit 23\n");
await fs.chmod(interpreter, 0o755);
await Bun.write(path.join(cwd, ".omp", "config.yml"), `python:\n interpreter: ${interpreter}\n`);
const result = await runSetupPython(cwd, { PI_PYTHON_SKIP_CHECK: "1" });
expect(result.error).toBe("");
expect(result.exitCode).toBe(1);
expect(JSON.parse(result.output)).toMatchObject({
available: false,
pythonPath: interpreter,
usingManagedEnv: false,
});
});
});