Files
ide/test/test.installer.node.ts
T

117 lines
4.4 KiB
TypeScript

import { tap, expect } from '@git.zone/tstest/tapbundle';
import {
createRemoteEphemeralBootstrapCommand,
createRemoteEphemeralReadinessCommand,
createRemoteEphemeralRuntimeCacheCheckCommand,
createRemoteBootstrapCommand,
createRemoteInstallCommand,
createRemoteServerInstallPlan,
joinRemotePath,
quoteRemotePath,
quoteShellArg,
} from '../packages/server-installer/ts/index.js';
tap.test('should create stable remote install paths', async () => {
const plan = createRemoteServerInstallPlan({
serverVersion: '0.1.0',
artifactName: 'remote-theia-linux-x64.tgz',
platform: 'linux',
arch: 'x64',
});
expect(plan.paths.versionRoot).toEqual('~/.git.zone/ide/server/0.1.0');
expect(plan.paths.currentLink).toEqual('~/.git.zone/ide/server/current');
expect(plan.manifest.protocolVersion).toEqual(1);
expect(plan.manifest.artifactName).toEqual('remote-theia-linux-x64.tgz');
});
tap.test('should quote shell arguments safely', async () => {
expect(quoteShellArg("that's it")).toEqual("'that'\"'\"'s it'");
expect(quoteRemotePath('~/.git.zone/ide/server')).toEqual('"$HOME"/\'.git.zone/ide/server\'');
expect(quoteRemotePath('$HOME/work/project')).toEqual('"$HOME"/\'work/project\'');
expect(joinRemotePath('~/.git.zone/', '/ide/', '/0.1.0')).toEqual('~/.git.zone/ide/0.1.0');
});
tap.test('should render install and bootstrap commands', async () => {
const plan = createRemoteServerInstallPlan({
serverVersion: '0.1.0',
artifactName: 'remote-theia.tgz',
});
const installCommand = createRemoteInstallCommand(plan);
const bootstrapCommand = createRemoteBootstrapCommand({
serverVersion: '0.1.0',
workspacePath: '/srv/work/project',
theiaPort: 33990,
opencodePort: 4096,
opencodeUsername: 'opencode',
opencodePassword: 'secret',
});
expect(installCommand).toInclude('GITZONE_IDE_MANIFEST');
expect(installCommand).toInclude('"$HOME"/\'.git.zone/ide/server/0.1.0\'');
expect(bootstrapCommand).toInclude('GITZONE_IDE_OPENCODE_PORT');
expect(bootstrapCommand).toInclude('pnpm --dir');
});
tap.test('should render remote home paths as expandable shell paths', async () => {
const bootstrapCommand = createRemoteBootstrapCommand({
serverVersion: '0.1.0',
workspacePath: '$HOME',
theiaPort: 33990,
opencodePort: 4096,
opencodeUsername: 'opencode',
opencodePassword: 'secret',
});
expect(bootstrapCommand).toInclude('test -d "$HOME"');
expect(bootstrapCommand).toInclude('export GITZONE_IDE_WORKSPACE="$HOME"');
expect(bootstrapCommand).toInclude('"$HOME"/\'.git.zone/ide/server/0.1.0/applications/remote-theia\'');
});
tap.test('should render ephemeral runtime bootstrap without remote pnpm', async () => {
const bootstrapCommand = createRemoteEphemeralBootstrapCommand({
serverVersion: '0.1.0',
runtimeRoot: '/tmp/gitzone-ide-runtime-test',
workspacePath: '$HOME',
theiaPort: 33990,
opencodePort: 4096,
opencodeUsername: 'opencode',
opencodePassword: 'secret',
});
expect(bootstrapCommand).toInclude('/tmp/gitzone-ide-runtime-test/node/bin/node');
expect(bootstrapCommand).toInclude('lib/backend/main.js');
expect(bootstrapCommand).not.toInclude('pnpm');
expect(bootstrapCommand).toInclude('LD_LIBRARY_PATH');
expect(bootstrapCommand).toInclude('THEIA_CONFIG_DIR="$HOME"/\'.git.zone/ide/theia\'');
expect(bootstrapCommand).toInclude('"$HOME"/\'.git.zone/ide/logs\'');
expect(bootstrapCommand).toInclude('runtimeRoot=');
});
tap.test('should render ephemeral readiness check with remote logs', async () => {
const readinessCommand = createRemoteEphemeralReadinessCommand({
runtimeRoot: '/tmp/gitzone-ide-runtime-test',
theiaPort: 33990,
waitSeconds: 2,
});
expect(readinessCommand).toInclude('fetch');
expect(readinessCommand).toInclude('theia-33990.log');
expect(readinessCommand).toInclude('"$HOME"/\'.git.zone/ide/logs/theia-33990.log\'');
expect(readinessCommand).toInclude('LD_LIBRARY_PATH');
});
tap.test('should render ephemeral runtime cache check command', async () => {
const cacheCheckCommand = createRemoteEphemeralRuntimeCacheCheckCommand({
runtimeRoot: '/tmp/gitzone-ide-0.1.0-deadbeef',
runtimeSha256: 'deadbeef',
});
expect(cacheCheckCommand).toInclude('.gitzone-runtime-sha256');
expect(cacheCheckCommand).toInclude('test "$(cat');
expect(cacheCheckCommand).toInclude("'deadbeef'");
expect(cacheCheckCommand).toInclude('runtimeCache=hit');
});
export default tap.start();