74 lines
2.3 KiB
TypeScript
74 lines
2.3 KiB
TypeScript
import { mkdir, mkdtemp, rm, writeFile } from 'fs/promises';
|
|
import os from 'os';
|
|
import path from 'path';
|
|
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
|
|
|
|
import { resolveAppManagedOpenCodeRuntimeBinaryPath } from '@main/services/infrastructure/OpenCodeRuntimeInstallerService';
|
|
import { setAppDataBasePath } from '@main/utils/pathDecoder';
|
|
|
|
let tempRoot: string | null = null;
|
|
|
|
describe('OpenCodeRuntimeInstallerService resolver', () => {
|
|
beforeEach(async () => {
|
|
tempRoot = await mkdtemp(path.join(os.tmpdir(), 'opencode-runtime-resolver-'));
|
|
setAppDataBasePath(tempRoot);
|
|
});
|
|
|
|
afterEach(async () => {
|
|
setAppDataBasePath(null);
|
|
if (tempRoot) {
|
|
await rm(tempRoot, { recursive: true, force: true });
|
|
tempRoot = null;
|
|
}
|
|
});
|
|
|
|
it('returns the current app-managed OpenCode binary path only when manifest and binary exist', async () => {
|
|
const binaryPath = path.join(
|
|
tempRoot!,
|
|
'data',
|
|
'runtimes',
|
|
'opencode',
|
|
'versions',
|
|
'1.0.0',
|
|
'opencode-test',
|
|
'opencode'
|
|
);
|
|
const manifestPath = path.join(tempRoot!, 'data', 'runtimes', 'opencode', 'current.json');
|
|
await mkdir(path.dirname(binaryPath), { recursive: true });
|
|
await mkdir(path.dirname(manifestPath), { recursive: true });
|
|
await writeFile(binaryPath, 'binary', { mode: 0o755 });
|
|
await writeFile(
|
|
manifestPath,
|
|
`${JSON.stringify({
|
|
schemaVersion: 1,
|
|
version: '1.0.0',
|
|
platformPackage: 'opencode-test',
|
|
binaryPath,
|
|
integrity: 'sha512-test',
|
|
installedAt: '2026-05-12T00:00:00.000Z',
|
|
})}\n`,
|
|
'utf8'
|
|
);
|
|
|
|
expect(resolveAppManagedOpenCodeRuntimeBinaryPath()).toBe(binaryPath);
|
|
});
|
|
|
|
it('ignores a manifest whose binary path is missing', async () => {
|
|
const manifestPath = path.join(tempRoot!, 'data', 'runtimes', 'opencode', 'current.json');
|
|
await mkdir(path.dirname(manifestPath), { recursive: true });
|
|
await writeFile(
|
|
manifestPath,
|
|
`${JSON.stringify({
|
|
schemaVersion: 1,
|
|
version: '1.0.0',
|
|
platformPackage: 'opencode-test',
|
|
binaryPath: path.join(tempRoot!, 'missing-opencode'),
|
|
integrity: 'sha512-test',
|
|
installedAt: '2026-05-12T00:00:00.000Z',
|
|
})}\n`,
|
|
'utf8'
|
|
);
|
|
|
|
expect(resolveAppManagedOpenCodeRuntimeBinaryPath()).toBeNull();
|
|
});
|
|
});
|