Skip to content

Commit c446d8a

Browse files
committed
fix: Selectively sync either /usr/local/lib/codify or ~/.local/share/codify
1 parent c40aeea commit c446d8a

File tree

1 file changed

+19
-23
lines changed

1 file changed

+19
-23
lines changed

src/orchestrators/test.ts

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11

22
import { OS, SpawnStatus } from 'codify-schemas';
33
import os from 'node:os';
4+
import path from 'node:path';
45

56
import { PluginInitOrchestrator } from '../common/initialize-plugins.js';
6-
import { ProcessName, ctx, SubProcessName } from '../events/context.js';
7+
import { ProcessName, SubProcessName, ctx } from '../events/context.js';
78
import { Reporter } from '../ui/reporters/reporter.js';
89
import { StubReporter } from '../ui/reporters/stub-reporter.js';
10+
import { FileUtils } from '../utils/file.js';
911
import { sleep } from '../utils/index.js';
1012
import { spawn, spawnSafe } from '../utils/spawn.js';
1113
import { PlanOrchestrator, PlanOrchestratorResponse } from './plan.js';
1214
import { ValidateOrchestrator } from './validate.js';
13-
import { FileUtils } from '../utils/file.js';
1415

1516
export interface TestArgs {
1617
path?: string;
@@ -32,15 +33,19 @@ export const TestOrchestrator = {
3233

3334
await this.ensureVmIsInstalled(reporter, args.vmOs);
3435

35-
const password = await reporter.promptSecret('Password needed to copy Codify installation to VM...');
36-
3736
ctx.subprocessStarted(SubProcessName.TEST_STARTING_VM);
3837
const baseVmName = args.vmOs === OS.Darwin ? 'codify-test-vm-macos' : 'codify-test-vm-linux';
3938
const vmName = this.generateVmName();
4039
await spawnSafe(`tart clone ${baseVmName} ${vmName}`, { interactive: true });
4140

41+
// We want to install the latest Codify version which usually exists in ~/.local/share/codify/client/current unless it's not there.
42+
const codifyInstall = (await FileUtils.dirExists('~/.local/share/codify/client/current'))
43+
? '~/.local/share/codify/client/current'
44+
: '/usr/local/lib/codify';
45+
4246
// Run this in the background. The user will have to manually exit the GUI to stop the test.
43-
spawnSafe(`tart run ${vmName}`, { interactive: true })
47+
// We bind mount the codify installation and the codify config directory. We choose not use :ro (read-only) because live changes are not supported in read-only mode.
48+
spawnSafe(`tart run ${vmName} --dir=codify-lib:${codifyInstall}:ro --dir=codify-config:${path.dirname(initializationResult.project.codifyFiles[0])}:ro`, { interactive: true })
4449
.finally(() => {
4550
ctx.subprocessFinished(SubProcessName.TEST_USER_CONTINUE_ON_VM);
4651
ctx.subprocessStarted(SubProcessName.TEST_DELETING_VM);
@@ -52,7 +57,7 @@ export const TestOrchestrator = {
5257
console.log('VM has been killed... exiting.')
5358
process.exit(1);
5459
})
55-
await sleep(5_000);
60+
await sleep(5000);
5661
await this.waitUntilVmIsReady(vmName);
5762

5863
ctx.subprocessFinished(SubProcessName.TEST_STARTING_VM);
@@ -62,24 +67,15 @@ export const TestOrchestrator = {
6267
// await spawn(`tart exec ${vmName} /bin/bash -c "$(curl -fsSL https://releases.codifycli.com/install.sh)"`, { interactive: true });
6368
const { data: ip } = await spawnSafe(`tart ip ${vmName}`, { interactive: true });
6469

65-
await spawn(`sshpass -p "admin" rsync -avz -e 'ssh -o PubkeyAuthentication=no -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null' /usr/local/lib/codify admin@${ip}:~/codify-lib`, { requiresRoot: true }, undefined, password);
66-
67-
if (await FileUtils.dirExists('~/.local/share/codify')) {
68-
await spawn(`sshpass -p "admin" rsync -avz -e 'ssh -o PubkeyAuthentication=no -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null' ~/.local/share/codify admin@${ip}:~/.local/share/codify`, { interactive: true });
69-
}
70-
7170
try {
72-
await spawn(`tart exec ${vmName} sudo mv /Users/admin/codify-lib /usr/local/lib`, { interactive: true });
73-
await spawn(`tart exec ${vmName} sudo ln -s /usr/local/lib/codify/bin/codify /usr/local/bin/codify`, { interactive: true });
74-
await spawn(`sshpass -p "admin" scp -o PubkeyAuthentication=no -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null ${initializationResult.project.codifyFiles[0]} admin@${ip}:~/codify.jsonc`, { interactive: true });
75-
76-
if (args.vmOs === OS.Darwin) {
77-
await spawn(`tart exec ${vmName} osascript -e "tell application \\"Terminal\\" to do script \\"cd ~/ && codify apply\\""`, { interactive: true });
78-
} else {
79-
await spawn(`tart exec ${vmName} gnome-terminal -- bash -c "cd ~/ && codify apply"`, { interactive: true });
80-
}
81-
} catch (e) {
82-
ctx.log(`Error copying files to VM: ${e}`);
71+
// Add symlinks to the bind mount locations.
72+
await spawn(`tart exec ${vmName} sudo ln -s /Volumes/My\\ Shared\\ Files/codify-lib/bin/codify /usr/local/bin/codify`, { interactive: true });
73+
await spawn(`tart exec ${vmName} ln -s /Volumes/My\\ Shared\\ Files/codify-config/${path.basename(initializationResult.project.codifyFiles[0])} /Users/admin/codify.jsonc`, { interactive: true });
74+
// await spawn(`sshpass -p "admin" scp -o PubkeyAuthentication=no -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null ${initializationResult.project.codifyFiles[0]} admin@${ip}:~/codify.jsonc`, { interactive: true });
75+
76+
await (args.vmOs === OS.Darwin ? spawn(`tart exec ${vmName} osascript -e "tell application \\"Terminal\\" to do script \\"cd ~ && codify apply\\""`, { interactive: true }) : spawn(`tart exec ${vmName} gnome-terminal -- bash -c "cd ~/ && codify apply"`, { interactive: true }));
77+
} catch (error) {
78+
ctx.log(`Error copying files to VM: ${error}`);
8379
}
8480

8581
ctx.subprocessFinished(SubProcessName.TEST_COPYING_OVER_CONFIGS_AND_OPENING_TERMINAL);

0 commit comments

Comments
 (0)