收口 Makelore 客户端变更
This commit is contained in:
@@ -12,15 +12,27 @@ const fsMock = vi.hoisted(() => ({
|
||||
existingPaths: new Set<string>(),
|
||||
}));
|
||||
|
||||
const moduleMock = vi.hoisted(() => ({
|
||||
resolve: vi.fn(),
|
||||
}));
|
||||
|
||||
vi.mock('node:fs', () => ({
|
||||
existsSync: (path: string) => fsMock.packageJson !== undefined || fsMock.existingPaths.has(path),
|
||||
readFileSync: () => fsMock.packageJson,
|
||||
realpathSync: (path: string) => path,
|
||||
}));
|
||||
|
||||
vi.mock('node:module', () => ({
|
||||
createRequire: () => ({
|
||||
resolve: moduleMock.resolve,
|
||||
}),
|
||||
}));
|
||||
|
||||
describe('opencode runtime paths', () => {
|
||||
beforeEach(() => {
|
||||
fsMock.packageJson = undefined;
|
||||
fsMock.existingPaths.clear();
|
||||
moduleMock.resolve.mockReset();
|
||||
});
|
||||
|
||||
it('resolves packaged darwin runtime paths from resourcesPath', () => {
|
||||
@@ -78,6 +90,34 @@ describe('opencode runtime paths', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('resolves the platform-native binary from pnpm virtual store dependencies', () => {
|
||||
const appPath = '/Users/me/NianCode';
|
||||
const nativePackageRoot = join(
|
||||
appPath,
|
||||
'node_modules',
|
||||
'.pnpm',
|
||||
'opencode-darwin-arm64@1.18.9',
|
||||
'node_modules',
|
||||
'opencode-darwin-arm64',
|
||||
);
|
||||
const nativeBinPath = join(nativePackageRoot, 'bin', 'opencode');
|
||||
fsMock.existingPaths.add(nativeBinPath);
|
||||
moduleMock.resolve.mockReturnValue(join(nativePackageRoot, 'package.json'));
|
||||
|
||||
expect(resolveOpencodeRuntimePaths({
|
||||
isPackaged: false,
|
||||
resourcesPath: '/unused/resources',
|
||||
appPath,
|
||||
platform: 'darwin',
|
||||
arch: 'arm64',
|
||||
})).toMatchObject({
|
||||
runtimeDir: join(appPath, 'node_modules', 'opencode-ai'),
|
||||
binPath: nativeBinPath,
|
||||
packageJsonPath: join(appPath, 'node_modules', 'opencode-ai', 'package.json'),
|
||||
});
|
||||
expect(moduleMock.resolve).toHaveBeenCalledWith('opencode-darwin-arm64/package.json');
|
||||
});
|
||||
|
||||
it('resolves packaged Windows runtime paths to the bundled native exe', () => {
|
||||
const resourcesPath = 'C:\\Program Files\\NianCode\\resources';
|
||||
|
||||
|
||||
Reference in New Issue
Block a user