This commit is contained in:
matt korwel 2025-07-05 08:27:22 -07:00 committed by GitHub
parent ab96676e36
commit 4963a1eea8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 37 additions and 10 deletions

View File

@ -14,7 +14,18 @@ test('should be able to run a shell command', async (t) => {
rig.createFile('blah.txt', 'some content'); rig.createFile('blah.txt', 'some content');
const prompt = `Can you use ls to list the contexts of the current folder`; const prompt = `Can you use ls to list the contexts of the current folder`;
const result = await rig.run(prompt); const result = rig.run(prompt);
assert.ok(result.includes('blah.txt'));
});
test('should be able to run a shell command via stdin', async (t) => {
const rig = new TestRig();
rig.setup(t.name);
rig.createFile('blah.txt', 'some content');
const prompt = `Can you use ls to list the contexts of the current folder`;
const result = rig.run({ stdin: prompt });
assert.ok(result.includes('blah.txt')); assert.ok(result.includes('blah.txt'));
}); });

View File

@ -47,14 +47,30 @@ export class TestRig {
execSync('sync', { cwd: this.testDir }); execSync('sync', { cwd: this.testDir });
} }
run(prompt, ...args) { run(promptOrOptions, ...args) {
const output = execSync( let command = `node ${this.bundlePath} --yolo`;
`node ${this.bundlePath} --yolo --prompt "${prompt}" ${args.join(' ')}`, const execOptions = {
{ cwd: this.testDir,
cwd: this.testDir, encoding: 'utf-8',
encoding: 'utf-8', };
},
); if (typeof promptOrOptions === 'string') {
command += ` --prompt "${promptOrOptions}"`;
} else if (
typeof promptOrOptions === 'object' &&
promptOrOptions !== null
) {
if (promptOrOptions.prompt) {
command += ` --prompt "${promptOrOptions.prompt}"`;
}
if (promptOrOptions.stdin) {
execOptions.input = promptOrOptions.stdin;
}
}
command += ` ${args.join(' ')}`;
const output = execSync(command, execOptions);
if (env.KEEP_OUTPUT === 'true') { if (env.KEEP_OUTPUT === 'true') {
const testId = `${env.TEST_FILE_NAME.replace( const testId = `${env.TEST_FILE_NAME.replace(

View File

@ -184,7 +184,7 @@ export async function main() {
} }
// If not a TTY, read from stdin // If not a TTY, read from stdin
// This is for cases where the user pipes input directly into the command // This is for cases where the user pipes input directly into the command
if (!process.stdin.isTTY) { if (!process.stdin.isTTY && !input) {
input += await readStdin(); input += await readStdin();
} }
if (!input) { if (!input) {