收口 Makelore 客户端变更
Some checks failed
Electron E2E / Electron E2E (macos-latest) (push) Has been cancelled
Electron E2E / Electron E2E (ubuntu-latest) (push) Has been cancelled
Electron E2E / Electron E2E (windows-latest) (push) Has been cancelled

This commit is contained in:
inman
2026-08-12 22:35:06 +08:00
parent 253bad8b40
commit f4113a872f
232 changed files with 4617 additions and 20121 deletions

View File

@@ -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';