Files
makelore/tests/unit/coding-composition-paths.test.ts

83 lines
2.5 KiB
TypeScript

// @vitest-environment node
import path from 'node:path';
import { describe, expect, it, vi } from 'vitest';
import {
resolveCodingPiRuntimePaths,
resolvePiWorkerExecutablePath,
} from '../../electron/api/coding-composition';
describe('Pi worker executable resolution', () => {
const mainExecutable = path.join(
path.parse(process.cwd()).root,
'Applications',
'Makelore.app',
'Contents',
'MacOS',
'Makelore',
);
const helperExecutable = path.join(
path.parse(process.cwd()).root,
'Applications',
'Makelore.app',
'Contents',
'Frameworks',
'Makelore Helper.app',
'Contents',
'MacOS',
'Makelore Helper',
);
it('uses the LSUIElement Electron helper for macOS background workers', () => {
const canExecute = vi.fn((candidate: string) => candidate === helperExecutable);
expect(resolvePiWorkerExecutablePath(mainExecutable, {
platform: 'darwin',
canExecute,
})).toBe(helperExecutable);
expect(canExecute).toHaveBeenCalledOnce();
expect(canExecute).toHaveBeenCalledWith(helperExecutable);
});
it('falls back to the product executable when the macOS helper is unavailable', () => {
expect(resolvePiWorkerExecutablePath(mainExecutable, {
platform: 'darwin',
canExecute: () => false,
})).toBe(mainExecutable);
});
it.each(['win32', 'linux'] as const)(
'keeps the product executable on %s',
(platform) => {
const canExecute = vi.fn(() => true);
expect(resolvePiWorkerExecutablePath(mainExecutable, {
platform,
canExecute,
})).toBe(mainExecutable);
expect(canExecute).not.toHaveBeenCalled();
},
);
it('resolves the shared Agent Server beside product resources in development and packages', () => {
const appPath = path.resolve('project-root');
const resourcesPath = path.resolve('Makelore.app/Contents/Resources');
const development = resolveCodingPiRuntimePaths({
isPackaged: false,
resourcesPath,
appPath,
executablePath: mainExecutable,
});
const packaged = resolveCodingPiRuntimePaths({
isPackaged: true,
resourcesPath,
appPath,
executablePath: mainExecutable,
});
expect(development.serverPath).toBe(path.join(appPath, 'resources', 'pi-agent-server.mjs'));
expect(packaged.serverPath).toBe(path.join(resourcesPath, 'resources', 'pi-agent-server.mjs'));
expect(packaged.cliPath).toBe(path.join(resourcesPath, 'pi-runtime', 'dist', 'cli.js'));
});
});