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
55 changes: 55 additions & 0 deletions src/lib/onboard/sandbox-gpu-preflight-routing.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,61 @@ describe("sandbox GPU preflight routing", () => {
expect(dockerInfo).not.toHaveBeenCalled();
});

it("falls back to Docker's default CDI spec dirs when docker info reports none (#7330)", () => {
const getDockerCdiSpecDirs = vi.fn(() => []);
const findReadableNvidiaCdiSpecFiles = (dirs: string[]) =>
dirs.length === 2 && dirs[0] === "/etc/cdi" && dirs[1] === "/var/run/cdi"
? ["/etc/cdi/nvidia.yaml"]
: [];
const exitProcess = (code: number): never => {
throw new Error(`exit:${code}`);
};

expect(() =>
validateSandboxGpuPreflight(
sandboxGpuConfig(),
{
platform: "linux",
env: {},
release: "6.8.0-generic",
procVersion: "Linux version 6.8.0-generic",
dockerInfoFormat: vi.fn(),
getDockerCdiSpecDirs,
findReadableNvidiaCdiSpecFiles,
},
exitProcess,
),
).not.toThrow();
});

it("still fails when the fallback CDI spec dirs hold no NVIDIA spec (#7330)", () => {
const errorSpy = vi.spyOn(console, "error").mockImplementation(() => undefined);
const exitSpy = vi.spyOn(process, "exit").mockImplementation(((
code?: number | string | null,
) => {
throw new Error(`exit:${code}`);
}) as never);

try {
expect(() =>
validateSandboxGpuPreflight(sandboxGpuConfig(), {
platform: "linux",
env: {},
release: "6.8.0-generic",
procVersion: "Linux version 6.8.0-generic",
dockerInfoFormat: vi.fn(),
getDockerCdiSpecDirs: vi.fn(() => []),
findReadableNvidiaCdiSpecFiles: vi.fn(() => []),
}),
).toThrow("exit:1");
const message = errorSpy.mock.calls.map((call) => call[0]).join("\n");
expect(message).toContain("Docker CDI GPU support was not detected");
} finally {
errorSpy.mockRestore();
exitSpy.mockRestore();
}
});

it("skips CDI spec validation on Docker Desktop WSL so Docker --gpus can be used", () => {
const logSpy = vi.spyOn(console, "log").mockImplementation(() => undefined);
const getDockerCdiSpecDirs = vi.fn(() => ["/etc/cdi"]);
Expand Down
10 changes: 9 additions & 1 deletion src/lib/onboard/sandbox-gpu-preflight.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ export { formatSandboxGpuPassthroughNote } from "./sandbox-gpu-notes";

const SANDBOX_GPU_PREFLIGHT_TIMEOUT_MS = 30_000;

// Docker Engine's built-in CDI spec directories. `docker info` can report no
// CDISpecDirs (daemon unreachable from this process, or an engine that omits
// the field) even though CDI works, so the preflight falls back to these
// before declaring CDI unsupported (#7330).
const FALLBACK_DOCKER_CDI_SPEC_DIRS = ["/etc/cdi", "/var/run/cdi"];

export type SandboxGpuPreflightDeps = WslDockerDesktopDetectionDeps & {
getDockerCdiSpecDirs?: () => string[];
findReadableNvidiaCdiSpecFiles?: (dirs: string[]) => string[];
Expand Down Expand Up @@ -368,7 +374,9 @@ export function validateSandboxGpuPreflight(
return;
}

const cdiSpecDirs = (deps.getDockerCdiSpecDirs ?? getDockerCdiSpecDirs)();
const reportedCdiSpecDirs = (deps.getDockerCdiSpecDirs ?? getDockerCdiSpecDirs)();
const cdiSpecDirs =
reportedCdiSpecDirs.length > 0 ? reportedCdiSpecDirs : FALLBACK_DOCKER_CDI_SPEC_DIRS;
const cdiSpecFiles = (deps.findReadableNvidiaCdiSpecFiles ?? findReadableNvidiaCdiSpecFiles)(
cdiSpecDirs,
);
Expand Down
Loading