Skip to content

Commit 4508491

Browse files
committed
fix: Fixed tests
1 parent 1b085df commit 4508491

5 files changed

Lines changed: 11 additions & 12 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@
144144
"start:vm": "npm run build && npm run pack:macos && npm run start:vm",
145145
"deploy": "npm run pkg && npm run notarize && npm run upload"
146146
},
147-
"version": "1.0.0-beta7",
147+
"version": "1.0.0-beta9",
148148
"bugs": "https://github.com/codifycli/codify/issues",
149149
"keywords": [
150150
"oclif",

src/utils/spawn.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,6 @@ export async function spawnSafe(cmd: string, options?: SpawnOptions, pluginName?
7373
command = options?.requiresRoot ? `sudo -k >/dev/null 2>&1; sudo -S <<< "${password}" -E ${ShellUtils.getDefaultShell()} ${options?.interactive ? '-i' : ''} -c '${cmd.replaceAll('\'', '\\\'')}'` : cmd;
7474
}
7575

76-
console.log(command);
77-
7876
const args = options?.interactive ? ['-i', '-c', command] : ['-c', command]
7977

8078
// Run the command in a pty for interactivity
@@ -100,7 +98,7 @@ export async function spawnSafe(cmd: string, options?: SpawnOptions, pluginName?
10098
mPty.resize(columns, rows);
10199
}
102100

103-
const stdinListener = (data) => {
101+
const stdinListener = (data: Buffer | string) => {
104102
// console.log('stdinListener', data);
105103
mPty.write(data.toString());
106104
}

test/integration/sudo.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { ctx } from '../../src/events/context.js';
88

99
vi.mock('node:child_process', async () => {
1010
const { ChildProcess } = await import('node:child_process');
11-
const { default: EventEmitter } = await import('node:events');
11+
const { EventEmitter } = await import('node:events');
1212

1313
const process = new ChildProcess();
1414
process.stdout = new EventEmitter() as Readable;
@@ -23,17 +23,17 @@ describe('Message sender tests', async () => {
2323
// Uses the child process from the mocks
2424
const mockChildProcess = fork('');
2525

26-
const sudoRequestedSpy = vi.spyOn(ctx, 'sudoRequested');
26+
const commandRequestedSpy = vi.spyOn(ctx, 'commandRequested');
2727
const processSpy = vi.spyOn(mockChildProcess, 'send');
2828

2929
const plugin = await PluginProcess.start('', 'TestPlugin', false);
3030

31-
mockChildProcess.emit('message', { cmd: MessageCmd.SUDO_REQUEST, data: { command: 'sudo something' }, requestId: 'requestId' })
32-
expect(sudoRequestedSpy).toHaveBeenCalledOnce();
31+
mockChildProcess.emit('message', { cmd: MessageCmd.COMMAND_REQUEST, data: { command: 'sudo something', options: { requiresRoot: true } }, requestId: 'requestId' })
32+
expect(commandRequestedSpy).toHaveBeenCalledOnce();
3333

34-
ctx.commandRequestCompleted('TestPlugin', { status: SpawnStatus.SUCCESS, data: 'success' })
34+
ctx.commandRequestCompleted('TestPlugin', { status: SpawnStatus.SUCCESS, data: 'success', exitCode: 0 })
3535
expect(processSpy).to.be.lastCalledWith({
36-
cmd: returnMessageCmd(MessageCmd.SUDO_REQUEST),
36+
cmd: returnMessageCmd(MessageCmd.COMMAND_REQUEST),
3737
requestId: 'requestId',
3838
data: expect.objectContaining({
3939
status: MessageStatus.SUCCESS,

test/orchestrator/mocks/plugin.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ export class MockPlugin implements IPlugin {
1515
path = '/'
1616
plugin!: PluginLibrary;
1717

18-
async initialize(secureMode: boolean): Promise<InitializeResponseData> {
18+
async initialize(secureMode: boolean, verbosityLevel: number = 0): Promise<InitializeResponseData> {
1919
this.plugin = PluginLibrary.create(
2020
'default',
2121
getMockResources(),
2222
);
2323

24-
return this.plugin.initialize();
24+
return this.plugin.initialize(secureMode, verbosityLevel);
2525
}
2626

2727
async validate(configs: ResourceConfig[]): Promise<ValidateResponseData> {

test/orchestrator/mocks/reporter.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export interface MockReporterConfig {
2626
}
2727

2828
export class MockReporter implements Reporter {
29+
silent = false;
2930
private config: MockReporterConfig | null;
3031

3132
constructor(config?: MockReporterConfig) {

0 commit comments

Comments
 (0)