test: scope fake runtime path setup

This commit is contained in:
Shakker
2026-06-05 00:20:10 +01:00
parent 695e09d360
commit 638be00f4b

View File

@@ -5,6 +5,7 @@ import os from "node:os";
import path from "node:path";
import { afterAll, beforeAll, describe, expect, it, vi } from "vitest";
import { formatExecCommand } from "../infra/system-run-command.js";
import { withEnv } from "../test-utils/env.js";
import {
buildSystemRunApprovalPlan,
hardenApprovedExecutionPaths,
@@ -154,17 +155,10 @@ function withFakeRuntimeBins<T>(params: {
writeFakeRuntimeBin(sharedRuntimeBinDir, binName);
sharedRuntimeBins.add(binName);
}
const oldPath = process.env.PATH;
process.env.PATH = `${sharedRuntimeBinDir}${path.delimiter}${oldPath ?? ""}`;
try {
return params.run();
} finally {
if (oldPath === undefined) {
delete process.env.PATH;
} else {
process.env.PATH = oldPath;
}
}
return withEnv(
{ PATH: `${sharedRuntimeBinDir}${path.delimiter}${process.env.PATH ?? ""}` },
params.run,
);
}
function uniqueRuntimeBinNames(