feat(smartshell): Add secure spawn APIs, PTY support, interactive/streaming control, timeouts and buffer limits; update README and tests
This commit is contained in:
54
test/test.simpleInteractive.ts
Normal file
54
test/test.simpleInteractive.ts
Normal file
@@ -0,0 +1,54 @@
|
||||
import { expect, tap } from '@git.zone/tstest/tapbundle';
|
||||
import * as smartshell from '../ts/index.js';
|
||||
|
||||
tap.test('should send input to cat command', async (tools) => {
|
||||
const testSmartshell = new smartshell.Smartshell({
|
||||
executor: 'bash',
|
||||
sourceFilePaths: [],
|
||||
});
|
||||
|
||||
// Use cat which simply echoes what it receives
|
||||
const interactive = await testSmartshell.execInteractiveControl('cat');
|
||||
|
||||
// Send some text and close stdin
|
||||
await interactive.sendLine('Hello World');
|
||||
interactive.endInput(); // Close stdin properly
|
||||
|
||||
const result = await interactive.finalPromise;
|
||||
expect(result.exitCode).toEqual(0);
|
||||
expect(result.stdout).toContain('Hello World');
|
||||
});
|
||||
|
||||
tap.test('should work with simple echo', async () => {
|
||||
const testSmartshell = new smartshell.Smartshell({
|
||||
executor: 'bash',
|
||||
sourceFilePaths: [],
|
||||
});
|
||||
|
||||
// This should work without any input
|
||||
const interactive = await testSmartshell.execInteractiveControl('echo "Direct test"');
|
||||
const result = await interactive.finalPromise;
|
||||
expect(result.exitCode).toEqual(0);
|
||||
expect(result.stdout).toContain('Direct test');
|
||||
});
|
||||
|
||||
tap.test('should handle streaming with input control', async (tools) => {
|
||||
const testSmartshell = new smartshell.Smartshell({
|
||||
executor: 'bash',
|
||||
sourceFilePaths: [],
|
||||
});
|
||||
|
||||
// Test with streaming and cat
|
||||
const streaming = await testSmartshell.execStreamingInteractiveControl('cat');
|
||||
|
||||
await streaming.sendLine('Line 1');
|
||||
await streaming.sendLine('Line 2');
|
||||
streaming.endInput(); // Close stdin
|
||||
|
||||
const result = await streaming.finalPromise;
|
||||
expect(result.exitCode).toEqual(0);
|
||||
expect(result.stdout).toContain('Line 1');
|
||||
expect(result.stdout).toContain('Line 2');
|
||||
});
|
||||
|
||||
export default tap.start();
|
Reference in New Issue
Block a user