test: dedupe shell env coverage from infra runtime suite

This commit is contained in:
Peter Steinberger
2026-02-19 07:21:26 +00:00
parent c37cf02f29
commit 192366e0e8

View File

@@ -14,7 +14,6 @@ import {
setPreRestartDeferralCheck,
} from "./restart.js";
import { createTelegramRetryRunner } from "./retry-policy.js";
import { getShellPathFromLoginShell, resetShellPathCacheForTests } from "./shell-env.js";
import { listTailnetAddresses } from "./tailnet.js";
describe("infra runtime", () => {
@@ -220,42 +219,6 @@ describe("infra runtime", () => {
});
});
describe("getShellPathFromLoginShell", () => {
afterEach(() => resetShellPathCacheForTests());
it("returns PATH from login shell env", () => {
const exec = vi
.fn()
.mockReturnValue(Buffer.from("PATH=/custom/bin\0HOME=/home/user\0", "utf-8"));
const result = getShellPathFromLoginShell({
env: { SHELL: "/bin/sh" },
exec,
platform: "linux",
});
expect(result).toBe("/custom/bin");
});
it("caches the value", () => {
const exec = vi.fn().mockReturnValue(Buffer.from("PATH=/custom/bin\0", "utf-8"));
const env = { SHELL: "/bin/sh" } as NodeJS.ProcessEnv;
expect(getShellPathFromLoginShell({ env, exec, platform: "linux" })).toBe("/custom/bin");
expect(getShellPathFromLoginShell({ env, exec, platform: "linux" })).toBe("/custom/bin");
expect(exec).toHaveBeenCalledTimes(1);
});
it("returns null on exec failure", () => {
const exec = vi.fn(() => {
throw new Error("boom");
});
const result = getShellPathFromLoginShell({
env: { SHELL: "/bin/sh" },
exec,
platform: "linux",
});
expect(result).toBeNull();
});
});
describe("tailnet address detection", () => {
it("detects tailscale IPv4 and IPv6 addresses", () => {
vi.spyOn(os, "networkInterfaces").mockReturnValue({