fix: 修复 OpenCode 运行时启动与本地打包
This commit is contained in:
@@ -2,7 +2,12 @@ import { mkdir, mkdtemp, rm, writeFile } from 'node:fs/promises';
|
||||
import { tmpdir } from 'node:os';
|
||||
import { delimiter, dirname, join } from 'node:path';
|
||||
import { afterEach, describe, expect, it } from 'vitest';
|
||||
import { prependPythonToPath, resolvePythonRuntime } from '@electron/utils/python-runtime';
|
||||
import {
|
||||
prependManagedRuntimesToPath,
|
||||
prependPythonToPath,
|
||||
resolvePythonRuntime,
|
||||
resolveUvRuntime,
|
||||
} from '@electron/utils/python-runtime';
|
||||
|
||||
const temporaryDirectories: string[] = [];
|
||||
|
||||
@@ -54,6 +59,21 @@ describe('managed Python runtime resolution', () => {
|
||||
})).toEqual({ executable, binDir: dirname(executable), source: 'bundled' });
|
||||
});
|
||||
|
||||
it('does not allow a packaged build to override Python outside the installation', async () => {
|
||||
const resourcesPath = await temporaryDirectory('niancode-python-packaged-local-');
|
||||
const executable = await createFile(join(resourcesPath, 'python', 'python.exe'));
|
||||
const configuredPath = await createFile(join(resourcesPath, 'external', 'python.exe'));
|
||||
|
||||
expect(resolvePythonRuntime({
|
||||
isPackaged: true,
|
||||
resourcesPath,
|
||||
appPath: resourcesPath,
|
||||
platform: 'win32',
|
||||
arch: 'x64',
|
||||
configuredPath,
|
||||
})).toEqual({ executable, binDir: dirname(executable), source: 'bundled' });
|
||||
});
|
||||
|
||||
it('resolves the packaged Unix interpreter', async () => {
|
||||
const resourcesPath = await temporaryDirectory('niancode-python-packaged-unix-');
|
||||
const executable = await createFile(join(resourcesPath, 'python', 'bin', 'python3'));
|
||||
@@ -110,4 +130,45 @@ describe('managed Python runtime resolution', () => {
|
||||
expect(result.Path).toBe(`${runtime.binDir}${delimiter}existing-bin`);
|
||||
expect(result).not.toHaveProperty('PATH');
|
||||
});
|
||||
|
||||
it('resolves packaged uv and prepends both managed runtime directories', async () => {
|
||||
const resourcesPath = await temporaryDirectory('niancode-uv-packaged-');
|
||||
const uvExecutable = await createFile(join(resourcesPath, 'bin', 'uv.exe'));
|
||||
const pythonExecutable = await createFile(join(resourcesPath, 'python', 'python.exe'));
|
||||
const uvRuntime = resolveUvRuntime({
|
||||
isPackaged: true,
|
||||
resourcesPath,
|
||||
appPath: resourcesPath,
|
||||
platform: 'win32',
|
||||
arch: 'x64',
|
||||
});
|
||||
|
||||
expect(uvRuntime).toEqual({
|
||||
executable: uvExecutable,
|
||||
binDir: dirname(uvExecutable),
|
||||
source: 'bundled',
|
||||
});
|
||||
expect(prependManagedRuntimesToPath(
|
||||
{ Path: 'C:\\Windows\\System32' },
|
||||
{ executable: pythonExecutable, binDir: dirname(pythonExecutable), source: 'bundled' },
|
||||
uvRuntime,
|
||||
'win32',
|
||||
)).toEqual({
|
||||
Path: `${dirname(uvExecutable)}${delimiter}${dirname(pythonExecutable)}${delimiter}C:\\Windows\\System32`,
|
||||
NIANCODE_PYTHON_PATH: pythonExecutable,
|
||||
NIANCODE_UV_PATH: uvExecutable,
|
||||
});
|
||||
});
|
||||
|
||||
it('fails closed when packaged uv is missing', async () => {
|
||||
const resourcesPath = await temporaryDirectory('niancode-uv-packaged-missing-');
|
||||
|
||||
expect(() => resolveUvRuntime({
|
||||
isPackaged: true,
|
||||
resourcesPath,
|
||||
appPath: resourcesPath,
|
||||
platform: 'win32',
|
||||
arch: 'x64',
|
||||
})).toThrow(`Bundled uv runtime is missing: ${join(resourcesPath, 'bin', 'uv.exe')}`);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user