nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: sindresorhus/execa
Pull request #464 (2021-05-30 16:58:32)

Fix randomly failing test
One of the tests is randomly failing due to a race condition.

The test checks that if a process spawns a `detached` process, the `detached` process outlives its parent. However, the current `detached` process is short-lived, therefore it might have exited or not depending on timing. This results in this test failing randomly in CI.

CI Tests on Node 16 are failing due to #463.


Patch:
diff --git a/index.js b/index.js
index 695fcb9..bbf0d29 100644
--- a/index.js
+++ b/index.js
@@ -7,7 +7,7 @@ const npmRunPath = require('npm-run-path');
 const onetime = require('onetime');
 const makeError = require('./lib/error');
 const normalizeStdio = require('./lib/stdio');
-const {spawnedKill, spawnedCancel, setupTimeout, setExitHandler} = require('./lib/kill');
+const {spawnedKill, spawnedCancel, setupTimeout, validateTimeout, setExitHandler} = require('./lib/kill');
 const {handleInput, getSpawnedResult, makeAllStream, validateInputSync} = require('./lib/stream');
 const {mergePromise, getSpawnedPromise} = require('./lib/promise');
 const {joinCommand, parseCommand} = require('./lib/command');
@@ -75,6 +75,8 @@ const execa = (file, args, options) => {
 	const parsed = handleArguments(file, args, options);
 	const command = joinCommand(file, args);
 
+	validateTimeout(parsed.options);
+
 	let spawned;
 	try {
 		spawned = childProcess.spawn(parsed.file, parsed.args, parsed.options);
diff --git a/lib/kill.js b/lib/kill.js
index 7f6f8dd..287a142 100644
--- a/lib/kill.js
+++ b/lib/kill.js
@@ -71,10 +71,6 @@ const setupTimeout = (spawned, {timeout, killSignal = 'SIGTERM'}, spawnedPromise
 		return spawnedPromise;
 	}
 
-	if (!Number.isFinite(timeout) || timeout < 0) {
-		throw new TypeError(`Expected the \`timeout\` option to be a non-negative integer, got \`${timeout}\` (${typeof timeout})`);
-	}
-
 	let timeoutId;
 	const timeoutPromise = new Promise((resolve, reject) => {
 		timeoutId = setTimeout(() => {
@@ -89,6 +85,12 @@ const setupTimeout = (spawned, {timeout, killSignal = 'SIGTERM'}, spawnedPromise
 	return Promise.race([timeoutPromise, safeSpawnedPromise]);
 };
 
+const validateTimeout = ({timeout}) => {
+	if (timeout !== undefined && (!Number.isFinite(timeout) || timeout < 0)) {
+		throw new TypeError(`Expected the \`timeout\` option to be a non-negative integer, got \`${timeout}\` (${typeof timeout})`);
+	}
+};
+
 // `cleanup` option handling
 const setExitHandler = async (spawned, {cleanup, detached}, timedPromise) => {
 	if (!cleanup || detached) {
@@ -108,5 +110,6 @@ module.exports = {
 	spawnedKill,
 	spawnedCancel,
 	setupTimeout,
+	validateTimeout,
 	setExitHandler
 };


Test patch:
diff --git a/test/fixtures/detach b/test/fixtures/detach
index eb50d7b..80f8980 100755
--- a/test/fixtures/detach
+++ b/test/fixtures/detach
@@ -3,6 +3,6 @@
 
 const execa = require('../..');
 
-const subprocess = execa('node', ['./test/fixtures/noop'], {detached: true});
+const subprocess = execa('node', ['./test/fixtures/forever'], {detached: true});
 console.log(subprocess.pid);
 process.exit();
Repository: sindresorhus/execa
Pull request #646 (2023-12-28 03:26:19)

Improve performance of `childProcess.all` when `stdout` or `stderr` is `undefined`
When `childProcess.stderr` is `undefined` (e.g. when the `stderr` option is `ignore`, `inherit`, etc.) but the `all` option is `true`, `childProcess.all` is currently a `PassThrough` piped from `childProcess.stdout`. However, in that case, `childProcess.all` could simplify be a reference to `childProcess.stdout`, there is no need to create two distinct streams.

Same for when `childProcess.stdout` is `undefined`.


Patch:
diff --git a/lib/stream.js b/lib/stream.js
index 3043b70..d2492b7 100644
--- a/lib/stream.js
+++ b/lib/stream.js
@@ -7,11 +7,19 @@ import mergeStreams from '@sindresorhus/merge-streams';
 
 // `all` interleaves `stdout` and `stderr`
 export const makeAllStream = (spawned, {all}) => {
-	if (!all || (!spawned.stdout && !spawned.stderr)) {
+	if (!all) {
 		return;
 	}
 
-	return mergeStreams([spawned.stdout, spawned.stderr].filter(Boolean));
+	if (!spawned.stdout) {
+		return spawned.stderr;
+	}
+
+	if (!spawned.stderr) {
+		return spawned.stdout;
+	}
+
+	return mergeStreams([spawned.stdout, spawned.stderr]);
 };
 
 // On failure, `result.stdout|stderr|all` should contain the currently buffered stream


Test patch:
diff --git a/test/stream.js b/test/stream.js
index f396b5e..c037a6c 100644
--- a/test/stream.js
+++ b/test/stream.js
@@ -70,6 +70,15 @@ test('result.all is undefined if ignored', async t => {
 	t.is(all, undefined);
 });
 
+const testAllIgnore = async (t, streamName, otherStreamName) => {
+	const childProcess = execa('noop.js', {[otherStreamName]: 'ignore', all: true});
+	t.is(childProcess.all, childProcess[streamName]);
+	await childProcess;
+};
+
+test('can use all: true with stdout: ignore', testAllIgnore, 'stderr', 'stdout');
+test('can use all: true with stderr: ignore', testAllIgnore, 'stdout', 'stderr');
+
 const testIgnore = async (t, streamName, execaMethod) => {
 	const result = await execaMethod('noop.js', {[streamName]: 'ignore'});
 	t.is(result[streamName], undefined);
@@ -145,14 +154,6 @@ test('buffer: false > emits end event when promise is rejected', async t => {
 	await t.notThrowsAsync(Promise.all([subprocess, pEvent(subprocess.stdout, 'end')]));
 });
 
-test('can use all: true with stdout: ignore', async t => {
-	await t.notThrowsAsync(execa('max-buffer.js', {buffer: false, stdout: 'ignore', all: true}));
-});
-
-test('can use all: true with stderr: ignore', async t => {
-	await t.notThrowsAsync(execa('max-buffer.js', ['stderr'], {buffer: false, stderr: 'ignore', all: true}));
-});
-
 const BUFFER_TIMEOUT = 1e3;
 
 // On Unix (not Windows), a process won't exit if stdout has not been read.