Skip to content

Commit 7e21b66

Browse files
committed
test: use safe environment in pipe cleanup fixture
1 parent 460f44f commit 7e21b66

1 file changed

Lines changed: 7 additions & 8 deletions

File tree

‎CodexSharpSDK.Tests/Unit/CliInstallationTests.cs‎

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,10 @@ public sealed class CliInstallationTests
4141
private const string HangMarkerName = "hang";
4242
private const string PipeHolderMarkerName = "pipe-holder";
4343
private const string PipeHolderPidFileName = "pipe-holder.pid";
44-
private const string SetsidPathEnvironmentName = "CODEX_TEST_SETSID_PATH";
45-
private const string PipeHolderPidFileEnvironmentName = "CODEX_TEST_PIPE_HOLDER_PID_FILE";
4644
private const string SetsidCommandName = "setsid";
4745
private const string CleanupMessage = "CLI installation process or output cleanup could not be confirmed within its configured timeout.";
4846
private const string DetachedPipeHolderSkipReason = "The detached pipe-holder cleanup fixture requires Linux setsid.";
47+
private const string SetsidRequiredMessage = "The detached pipe-holder cleanup fixture requires Linux setsid.";
4948
private const string OverflowMarkerName = "overflow";
5049
private const string PackagePlaceholder = "PACKAGE_NAME";
5150
private const string CliPlaceholder = "CLI_NAME";
@@ -88,9 +87,8 @@ public sealed class CliInstallationTests
8887
}
8988
if (fs.existsSync(path.join(__dirname, 'pipe-holder'))) {
9089
const { spawnSync } = require('node:child_process');
91-
const shellCommand = '"$1" /bin/sh -c \'echo $$ > "$1"; exec /bin/sleep 60\' holder "$2" &';
92-
spawnSync('/bin/sh', ['-c', shellCommand, 'fixture', process.env.CODEX_TEST_SETSID_PATH,
93-
process.env.CODEX_TEST_PIPE_HOLDER_PID_FILE], { stdio: 'inherit' });
90+
const shellCommand = `setsid /bin/sh -c 'echo $$ > ${shellQuote(path.join(__dirname, 'pipe-holder.pid'))}; exec /bin/sleep 60' holder &`;
91+
spawnSync('/bin/sh', ['-c', shellCommand], { stdio: 'inherit' });
9492
}
9593
if (fs.existsSync(path.join(__dirname, 'overflow'))) {
9694
process.stdout.write('x'.repeat(8192));
@@ -256,8 +254,9 @@ public async Task CancellationWithDetachedPipeHolderSurfacesUnconfirmedCleanup()
256254
await File.WriteAllTextAsync(Path.Combine(fixture.NpmRoot, BinDirectoryName, PipeHolderMarkerName), string.Empty);
257255
var environment = fixture.Options.EnvironmentVariables.ToDictionary(
258256
static pair => pair.Key, static pair => pair.Value, StringComparer.OrdinalIgnoreCase);
259-
environment[SetsidPathEnvironmentName] = FindExecutablePath(SetsidCommandName);
260-
environment[PipeHolderPidFileEnvironmentName] = holderPidFile;
257+
var setsidPath = FindExecutablePath(SetsidCommandName);
258+
environment[PathName] = string.Join(Path.PathSeparator, environment[PathName],
259+
Path.GetDirectoryName(setsidPath)!);
261260
var options = fixture.Options with
262261
{
263262
EnvironmentVariables = environment,
@@ -372,7 +371,7 @@ private static string FindExecutablePath(string executableName)
372371
var path = Environment.GetEnvironmentVariable(PathName) ?? string.Empty;
373372
var executable = path.Split(Path.PathSeparator, StringSplitOptions.RemoveEmptyEntries)
374373
.Select(directory => Path.Combine(directory, executableName)).FirstOrDefault(File.Exists);
375-
return Path.GetFullPath(executable ?? throw new InvalidOperationException(NodeRequiredMessage));
374+
return Path.GetFullPath(executable ?? throw new InvalidOperationException(SetsidRequiredMessage));
376375
}
377376

378377
private static async Task WaitForFileAsync(string path, CancellationToken cancellationToken)

0 commit comments

Comments
 (0)