Skip to content

Commit ca9aa24

Browse files
committed
Undo un-needed changes
1 parent c446d8a commit ca9aa24

File tree

10 files changed

+31
-44
lines changed

10 files changed

+31
-44
lines changed

src/orchestrators/test.ts

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11

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

67
import { PluginInitOrchestrator } from '../common/initialize-plugins.js';
@@ -71,9 +72,12 @@ export const TestOrchestrator = {
7172
// Add symlinks to the bind mount locations.
7273
await spawn(`tart exec ${vmName} sudo ln -s /Volumes/My\\ Shared\\ Files/codify-lib/bin/codify /usr/local/bin/codify`, { interactive: true });
7374
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 });
7575

76+
// Launch terminal and run codify apply
7677
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 }));
78+
79+
this.watchAndSyncFileChanges(initializationResult.project.codifyFiles[0], ip);
80+
7781
} catch (error) {
7882
ctx.log(`Error copying files to VM: ${error}`);
7983
}
@@ -148,5 +152,28 @@ export const TestOrchestrator = {
148152

149153
await sleep(1000);
150154
}
155+
},
156+
157+
watchAndSyncFileChanges(filePath: string, ip: string): void {
158+
const watcher = fs.watch(filePath, { persistent: false }, async (eventType) => {
159+
if (eventType === 'change') {
160+
ctx.log('Config file changed, syncing to VM...');
161+
try {
162+
// Copy the updated config file to the VM
163+
// This command will fail but it causes the bind mount to update for some reason. (seems like a bug in Tart). Leave this here for now.
164+
await spawn(`sshpass -p "admin" scp -o PubkeyAuthentication=no -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null ${filePath} admin@${ip}:~/codify.jsonc`, { interactive: true });
165+
// ctx.log('Config file synced successfully');
166+
} catch (error) {
167+
// ctx.log(`Error syncing config file: ${error}`);
168+
}
169+
}
170+
});
171+
172+
// Clean up the watcher when the process finishes
173+
const cleanupWatcher = () => {
174+
watcher.close();
175+
};
176+
177+
process.once('exit', cleanupWatcher);
151178
}
152179
};

src/ui/components/default-component.tsx

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -89,16 +89,6 @@ export function DefaultComponent(props: {
8989
</Box>
9090
)
9191
}
92-
{
93-
renderStatus === RenderStatus.SECRET_PROMPT && (
94-
<Box flexDirection="column">
95-
<Text>{renderData as string}</Text>
96-
<PasswordInput isDisabled={disableSudoPrompt} onSubmit={(password) => {
97-
emitter.emit(RenderEvent.PROMPT_RESULT, password);
98-
}}/>
99-
</Box>
100-
)
101-
}
10292
{
10393
renderStatus === RenderStatus.SUDO_PROMPT && (
10494
<Box flexDirection="column">

src/ui/reporters/default-reporter.tsx

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -189,16 +189,6 @@ export class DefaultReporter implements Reporter {
189189
return password;
190190
}
191191

192-
async promptSecret(prompt: string): Promise<string | undefined> {
193-
const password = await this.updateStateAndAwaitEvent<string>(
194-
() => this.updateRenderState(RenderStatus.SECRET_PROMPT, prompt),
195-
RenderEvent.PROMPT_RESULT,
196-
);
197-
198-
await this.displayProgress();
199-
return password;
200-
}
201-
202192
displayPlan(plan: Plan): void {
203193
this.updateRenderState(RenderStatus.DISPLAY_PLAN, plan)
204194
}

src/ui/reporters/json-reporter.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,6 @@ export class JsonReporter implements Reporter {
4747
throw new Error(`Json reporter error: sudo required for command: ${data.command}. Make sure to preconfigure the sudo password for the Json reporter using --sudoPassword`);
4848
}
4949

50-
promptSecret(prompt: string): Promise<string | undefined> {
51-
throw new Error('Json reporter error: cannot prompt user for values while using Json reporter. Use a different reporter.');
52-
}
53-
5450
async promptUserForValues(): Promise<ResourceConfig[]> {
5551
throw new Error('Json reporter error: cannot prompt user for values while using Json reporter. Use a different reporter.');
5652
}

src/ui/reporters/plain-reporter.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,6 @@ export class PlainReporter implements Reporter {
106106
return result;
107107
}
108108

109-
async promptSecret(prompt: string): Promise<string | undefined> {
110-
return new Promise((resolve) => {
111-
this.rl.question(`${prompt} (leave empty if not needed) `, (answer) => resolve(answer));
112-
});
113-
}
114-
115109
async displayProgress(): Promise<void> {}
116110

117111
async promptInput(prompt: string, error?: string): Promise<string> {

src/ui/reporters/reporter.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,6 @@ export interface Reporter {
6464

6565
promptSudo(pluginName: string, data: CommandRequestData, secureMode: boolean): Promise<string | undefined>;
6666

67-
promptSecret(prompt: string): Promise<string | undefined>;
68-
6967
promptUserForValues(resources: Array<ResourceInfo>, promptType: PromptType): Promise<ResourceConfig[]>;
7068

7169
promptPressKeyToContinue(message?: string): Promise<void>;

src/ui/reporters/stub-reporter.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ export class StubReporter implements Reporter {
1717
async promptConfirmation(message: string): Promise<boolean> { return true; }
1818
async promptOptions(message: string, options: string[]): Promise<number> { throw new Error('Method not implemented.'); }
1919
async promptSudo(pluginName: string, data: CommandRequestData): Promise<string | undefined> { throw new Error('Method not implemented.'); }
20-
async promptSecret(prompt: string): Promise<string | undefined> { throw new Error('Method not implemented.'); }
2120
async promptUserForValues(resources: Array<ResourceInfo>, promptType: PromptType): Promise<ResourceConfig[]> { throw new Error('Method not implemented.'); }
2221
async promptPressKeyToContinue(message?: string): Promise<void> {}
2322
async displayImportResult(importResult: ImportResult): Promise<void> {}

src/ui/store/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ export enum RenderStatus {
2222
PROMPT_INPUT,
2323
PROMPT_PRESS_KEY_TO_CONTINUE,
2424
SUDO_PROMPT,
25-
SECRET_PROMPT,
2625
DISPLAY_MESSAGE,
2726
}
2827

src/utils/spawn.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ export async function spawnSafe(cmd: string, options?: SpawnOptions, pluginName?
3737
throw new Error('Password must be specified!');
3838
}
3939

40-
// if (cmd.toLowerCase().includes('sudo')) {
41-
// throw new Error(`Command must not include sudo. Plugin (${pluginName})`)
42-
// }
40+
if (cmd.toLowerCase().includes('sudo')) {
41+
throw new Error(`Command must not include sudo. Plugin (${pluginName})`)
42+
}
4343

4444
if (pluginName) {
4545
ctx.pluginStdout(pluginName, `Running command: ${options?.requiresRoot ? 'sudo' : ''} ${cmd}` + (options?.cwd ? `(${options?.cwd})` : ''))
@@ -66,8 +66,6 @@ export async function spawnSafe(cmd: string, options?: SpawnOptions, pluginName?
6666
const initialRows = process.stdout.rows ?? 24;
6767

6868
const command = options?.requiresRoot ? `sudo -k >/dev/null 2>&1; sudo -S <<< "${password}" -E ${ShellUtils.getDefaultShell()} ${options?.interactive ? '-i' : ''} -c "${cmd.replaceAll('"', '\\"')}"` : cmd;
69-
console.log(command);
70-
7169
const args = options?.interactive ? ['-i', '-c', command] : ['-c', command]
7270

7371
// Run the command in a pty for interactivity

test/orchestrator/mocks/reporter.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,6 @@ export class MockReporter implements Reporter {
8989
return '';
9090
}
9191

92-
async promptSecret(prompt: string): Promise<string | undefined> {
93-
return '';
94-
}
95-
9692
async promptUserForValues(resourceInfo: ResourceInfo[], promptType: PromptType): Promise<ResourceConfig[]> {
9793
if (this.config?.promptUserForValues) {
9894
return this.config.promptUserForValues(resourceInfo);

0 commit comments

Comments
 (0)