From 1b4da13f9b927fc48b69fdb61094a2a524a6eec6 Mon Sep 17 00:00:00 2001 From: Julie Yaunches Date: Tue, 30 Jun 2026 18:13:19 -0400 Subject: [PATCH] fix(e2e): stage device auth through hosted inference --- test/e2e/live/device-auth-health-helpers.ts | 8 ++- .../device-auth-health-helpers.test.ts | 65 +++++++++++++++++++ 2 files changed, 71 insertions(+), 2 deletions(-) create mode 100644 test/e2e/support/device-auth-health-helpers.test.ts diff --git a/test/e2e/live/device-auth-health-helpers.ts b/test/e2e/live/device-auth-health-helpers.ts index 568a69514bd..e33f5122549 100644 --- a/test/e2e/live/device-auth-health-helpers.ts +++ b/test/e2e/live/device-auth-health-helpers.ts @@ -12,6 +12,7 @@ import { trustedSandboxShellScript, validateSandboxName, } from "../fixtures/clients/sandbox.ts"; +import { requireHostedInferenceConfig } from "../fixtures/hosted-inference.ts"; import type { ShellProbeResult } from "../fixtures/shell-probe.ts"; import { isTransientProviderValidationFailure } from "./network-policy-transient-provider.ts"; @@ -31,7 +32,10 @@ export function commandEnv(apiKey?: string): NodeJS.ProcessEnv { NEMOCLAW_SANDBOX_NAME: SANDBOX_NAME, OPENSHELL_GATEWAY: process.env.OPENSHELL_GATEWAY ?? "nemoclaw", }; - apiKey && Object.assign(env, { NVIDIA_INFERENCE_API_KEY: apiKey }); + if (apiKey) { + const hosted = requireHostedInferenceConfig({ required: () => apiKey }); + Object.assign(env, hosted.env); + } return env; } @@ -102,7 +106,7 @@ export async function installDeviceAuthSandbox( ): Promise { let install: ShellProbeResult | undefined; for (let attempt = 1; attempt <= INSTALL_ATTEMPTS; attempt += 1) { - install = await host.command("bash", ["install.sh", "--non-interactive"], { + install = await host.command("bash", ["install.sh", "--non-interactive", "--fresh"], { artifactName: attempt === 1 ? "phase-1-install-device-auth-health" diff --git a/test/e2e/support/device-auth-health-helpers.test.ts b/test/e2e/support/device-auth-health-helpers.test.ts new file mode 100644 index 00000000000..44fe3b46ef8 --- /dev/null +++ b/test/e2e/support/device-auth-health-helpers.test.ts @@ -0,0 +1,65 @@ +// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 + +import fs from "node:fs"; +import os from "node:os"; +import path from "node:path"; + +import { describe, expect, it } from "vitest"; + +import type { HostCliClient } from "../fixtures/clients/host.ts"; +import type { ShellProbeResult } from "../fixtures/shell-probe.ts"; +import { commandEnv, installDeviceAuthSandbox } from "../live/device-auth-health-helpers.ts"; + +function okResult(command: string[]): ShellProbeResult { + return { + artifacts: { result: "", stderr: "", stdout: "" }, + command, + exitCode: 0, + signal: null, + stderr: "", + stdout: "ok", + timedOut: false, + }; +} + +describe("device auth health hosted inference wiring", () => { + it("stages the repo NVIDIA_INFERENCE_API_KEY as a compatible endpoint credential", () => { + const env = commandEnv("repo-hosted-key"); + + expect(env.NEMOCLAW_E2E_USE_HOSTED_INFERENCE).toBe("1"); + expect(env.NEMOCLAW_PROVIDER).toBe("custom"); + expect(env.NEMOCLAW_ENDPOINT_URL).toBe("https://inference-api.nvidia.com/v1"); + expect(env.NEMOCLAW_MODEL).toBe("nvidia/nvidia/nemotron-3-ultra"); + expect(env.NEMOCLAW_COMPAT_MODEL).toBe("nvidia/nvidia/nemotron-3-ultra"); + expect(env.NEMOCLAW_PREFERRED_API).toBe("openai-completions"); + expect(env.NVIDIA_INFERENCE_API_KEY).toBe("repo-hosted-key"); + expect(env.COMPATIBLE_API_KEY).toBe("repo-hosted-key"); + }); + + it("runs install.sh fresh with hosted-compatible inference env", async () => { + const calls: Array<{ args: string[]; env?: NodeJS.ProcessEnv }> = []; + const host = { + command: async (_command: string, args: string[], options: { env?: NodeJS.ProcessEnv }) => { + calls.push({ args, env: options.env }); + return okResult([_command, ...args]); + }, + } as HostCliClient; + const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "device-auth-health-helper-")); + + try { + await installDeviceAuthSandbox(host, "repo-hosted-key", path.join(tmpDir, "install.log")); + } finally { + fs.rmSync(tmpDir, { recursive: true, force: true }); + } + + expect(calls).toHaveLength(1); + expect(calls[0].args).toEqual(["install.sh", "--non-interactive", "--fresh"]); + expect(calls[0].env).toMatchObject({ + COMPATIBLE_API_KEY: "repo-hosted-key", + NVIDIA_INFERENCE_API_KEY: "repo-hosted-key", + NEMOCLAW_E2E_USE_HOSTED_INFERENCE: "1", + NEMOCLAW_PROVIDER: "custom", + }); + }); +});