test(docker): make bash 3.2 compatibility check portable

This commit is contained in:
Sebastian
2026-02-10 18:04:37 -05:00
parent 31f616d45b
commit 90f58333e9

View File

@@ -73,6 +73,17 @@ function createEnv(
};
}
function resolveBashForCompatCheck(): string | null {
for (const candidate of ["/bin/bash", "bash"]) {
const probe = spawnSync(candidate, ["-c", "exit 0"], { encoding: "utf8" });
if (!probe.error && probe.status === 0) {
return candidate;
}
}
return null;
}
describe("docker-setup.sh", () => {
it("handles unset optional env vars under strict mode", async () => {
const sandbox = await createDockerSetupSandbox();
@@ -121,11 +132,15 @@ describe("docker-setup.sh", () => {
const script = await readFile(join(repoRoot, "docker-setup.sh"), "utf8");
expect(script).not.toMatch(/^\s*declare -A\b/m);
const systemBash = "/bin/bash";
const systemBash = resolveBashForCompatCheck();
if (!systemBash) {
return;
}
const assocCheck = spawnSync(systemBash, ["-c", "declare -A _t=()"], {
encoding: "utf8",
});
if (assocCheck.status === 0) {
if (assocCheck.status === null || assocCheck.status === 0) {
return;
}