Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions bin/lib/platform.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ const os = require("os");
const path = require("path");

function isWsl(opts = {}) {
// Explicit override — lets tests pin behavior regardless of the host kernel.
// Useful because the WSL detection below consults `os.release()`, which
// returns a "microsoft"-tagged string on WSL2 hosts even when env vars are
// unset. Without this override, any test calling functions that consult
// `isWsl()` becomes non-deterministic on WSL2 dev machines.
if (typeof opts.isWsl === "boolean") return opts.isWsl;

const platform = opts.platform ?? process.platform;
if (platform !== "linux") return false;

Expand Down
21 changes: 16 additions & 5 deletions test/platform.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,22 @@ describe("platform helpers", () => {
});

describe("shouldPatchCoredns", () => {
it("patches CoreDNS for Colima and Podman", () => {
expect(shouldPatchCoredns("colima")).toBe(true);
expect(shouldPatchCoredns("podman")).toBe(true);
expect(shouldPatchCoredns("docker-desktop")).toBe(false);
expect(shouldPatchCoredns("docker")).toBe(false);
// Pass explicit `isWsl: false` so this test pins the function's runtime
// matching logic on every host. Without the override, `shouldPatchCoredns`
// consults `isWsl()`, which returns true on WSL2 dev machines (via
// `os.release()`), and the assertions flip below.
it("patches CoreDNS for Colima and Podman (non-WSL host)", () => {
expect(shouldPatchCoredns("colima", { isWsl: false })).toBe(true);
expect(shouldPatchCoredns("podman", { isWsl: false })).toBe(true);
expect(shouldPatchCoredns("docker-desktop", { isWsl: false })).toBe(false);
expect(shouldPatchCoredns("docker", { isWsl: false })).toBe(false);
});

it("never patches CoreDNS on WSL2 (host DNS unreachable from k3s pods)", () => {
expect(shouldPatchCoredns("colima", { isWsl: true })).toBe(false);
expect(shouldPatchCoredns("podman", { isWsl: true })).toBe(false);
expect(shouldPatchCoredns("docker-desktop", { isWsl: true })).toBe(false);
expect(shouldPatchCoredns("docker", { isWsl: true })).toBe(false);
Comment on lines +166 to +177

Copilot AI Apr 8, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test titles/descriptions imply they depend on the host being non-WSL/WSL2, but the behavior is actually pinned via the { isWsl: ... } override and should pass on any host. Consider renaming these to reflect the simulated condition (e.g., "when isWsl is false" / "when isWsl is true" or "on WSL" instead of "on WSL2") to avoid confusion for future maintainers running the suite on different environments.

Copilot uses AI. Check for mistakes.
});
});

Expand Down