fix(setup): always resolve interpreter during setup probe
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user