feat(smartshell): Add passthrough option for exec methods and corresponding tests

This commit is contained in:
2025-08-17 14:01:04 +00:00
parent 5a32817349
commit f8e431f41e
3 changed files with 65 additions and 0 deletions

View File

@@ -25,6 +25,7 @@ interface IExecOptions {
strict?: boolean;
streaming?: boolean;
interactive?: boolean;
passthrough?: boolean;
}
export class Smartshell {
@@ -87,6 +88,11 @@ export class Smartshell {
this.smartexit.addProcess(execChildProcess);
// Connect stdin if passthrough is enabled
if (options.passthrough && execChildProcess.stdin) {
process.stdin.pipe(execChildProcess.stdin);
}
// Capture stdout and stderr output.
execChildProcess.stdout.on('data', (data) => {
if (!options.silent) {
@@ -107,6 +113,11 @@ export class Smartshell {
execChildProcess.on('exit', (code, signal) => {
this.smartexit.removeProcess(execChildProcess);
// Unpipe stdin when process ends if passthrough was enabled
if (options.passthrough) {
process.stdin.unpipe(execChildProcess.stdin);
}
const execResult: IExecResult = {
exitCode: typeof code === 'number' ? code : (signal ? 1 : 0),
stdout: shellLogInstance.logStore.toString(),
@@ -121,6 +132,10 @@ export class Smartshell {
execChildProcess.on('error', (error) => {
this.smartexit.removeProcess(execChildProcess);
// Unpipe stdin when process errors if passthrough was enabled
if (options.passthrough && execChildProcess.stdin) {
process.stdin.unpipe(execChildProcess.stdin);
}
reject(error);
});
});
@@ -181,6 +196,14 @@ export class Smartshell {
await this._exec({ commandString, interactive: true });
}
public async execPassthrough(commandString: string): Promise<IExecResult> {
return await this._exec({ commandString, passthrough: true }) as IExecResult;
}
public async execStreamingPassthrough(commandString: string): Promise<IExecResultStreaming> {
return await this._exec({ commandString, streaming: true, passthrough: true }) as IExecResultStreaming;
}
public async execAndWaitForLine(
commandString: string,
regex: RegExp,