diff --git a/test/e2e/live/gpu-e2e-helpers.ts b/test/e2e/live/gpu-e2e-helpers.ts index 3a2a24d3c57..026d2be622d 100644 --- a/test/e2e/live/gpu-e2e-helpers.ts +++ b/test/e2e/live/gpu-e2e-helpers.ts @@ -11,6 +11,7 @@ import { type SandboxClient, validateSandboxName } from "../fixtures/clients/san import { expect } from "../fixtures/e2e-test.ts"; import { CLI_ENTRYPOINT, REPO_ROOT } from "../fixtures/paths.ts"; import type { ShellProbeResult } from "../fixtures/shell-probe.ts"; +import { stripAnsi } from "./json-envelope.ts"; export { REPO_ROOT }; @@ -117,6 +118,14 @@ export function chatContent(raw: string): string { ); } +export function hasExactReadyPhase(output: string): boolean { + const phaseLines = stripAnsi(output) + .split(/\r?\n/) + .map((line) => line.trim()) + .filter((line) => line.startsWith("Phase:")); + return phaseLines.length === 1 && phaseLines[0] === "Phase: Ready"; +} + function asRecord(value: unknown): Record | undefined { return value && typeof value === "object" && !Array.isArray(value) ? (value as Record) diff --git a/test/e2e/live/gpu-e2e.test.ts b/test/e2e/live/gpu-e2e.test.ts index a11d562b43d..c48c12f8ee5 100644 --- a/test/e2e/live/gpu-e2e.test.ts +++ b/test/e2e/live/gpu-e2e.test.ts @@ -16,6 +16,7 @@ import { detectOllamaModel, ensureOllama, env, + hasExactReadyPhase, ollamaProxyTokenFile, openClawModelConfigProjectionScript, PROXY_PORT, @@ -184,7 +185,54 @@ test("GPU Ollama onboard enables CUDA, auth proxy, and sandbox inference", { expect(resultText(status)).toMatch(/CUDA verified|CUDA unverified|last CUDA proof failed/i); expect(resultText(status)).not.toMatch(/last CUDA proof failed|CUDA unverified/i); - assertGpuInstallProofs(resultText(install)); + const installLog = resultText(install); + assertGpuInstallProofs(installLog); + expect(installLog).toContain( + "Direct sandbox GPU enabled; allowing OpenShell GPU policy enrichment.", + ); + expect(installLog).not.toContain( + "Recreating OpenShell Docker sandbox container with NVIDIA GPU access", + ); + expect(installLog).not.toContain("Docker GPU mode selected"); + + const sandboxContainers = await host.command( + "docker", + [ + "ps", + "-a", + "--filter", + `label=openshell.ai/sandbox-name=${SANDBOX_NAME}`, + "--format", + "{{json .}}", + ], + { + artifactName: "gpu-native-route-sandbox-containers", + env: buildAvailabilityProbeEnv(), + timeoutMs: 30_000, + }, + ); + expect(sandboxContainers.exitCode, resultText(sandboxContainers)).toBe(0); + const sandboxContainerInventory = sandboxContainers.stdout + .split(/\r?\n/) + .map((line) => line.trim()) + .filter(Boolean) + .map( + (line) => + JSON.parse(line) as { + Names?: string; + State?: string; + Status?: string; + }, + ); + expect( + sandboxContainerInventory, + `native GPU route must retain exactly one sandbox container; got ${sandboxContainers.stdout}`, + ).toHaveLength(1); + const retainedSandboxContainer = sandboxContainerInventory[0]; + expect(retainedSandboxContainer.Names).not.toContain("-nemoclaw-gpu-backup-"); + expect(retainedSandboxContainer.State).toBe("running"); + expect(retainedSandboxContainer.Status).toMatch(/\(healthy\)/i); + const route = await sandbox.openshell(["inference", "get"], { artifactName: "openshell-inference-route", env: env(), @@ -255,6 +303,17 @@ test("GPU Ollama onboard enables CUDA, auth proxy, and sandbox inference", { expect(chat.exitCode, resultText(chat)).toBe(0); expect(chatContent(chat.stdout)).toMatch(/pong/i); + const readySandbox = await sandbox.openshell(["sandbox", "get", SANDBOX_NAME], { + artifactName: "openshell-sandbox-ready-after-inference", + env: buildAvailabilityProbeEnv(), + timeoutMs: 30_000, + }); + expect(readySandbox.exitCode, resultText(readySandbox)).toBe(0); + expect( + hasExactReadyPhase(readySandbox.stdout), + `OpenShell sandbox must be exactly Ready after routed inference; got ${resultText(readySandbox)}`, + ).toBe(true); + const restart = await host.command( "bash", [ diff --git a/test/e2e/support/gpu-e2e-helpers.test.ts b/test/e2e/support/gpu-e2e-helpers.test.ts index 81ae262eaed..5a0ae23e122 100644 --- a/test/e2e/support/gpu-e2e-helpers.test.ts +++ b/test/e2e/support/gpu-e2e-helpers.test.ts @@ -11,6 +11,7 @@ import { describe, expect, it } from "vitest"; import { assertAgentExecutionSucceeded, env, + hasExactReadyPhase, openClawModelConfigProjectionScript, } from "../live/gpu-e2e-helpers.ts"; @@ -139,6 +140,23 @@ describe("GPU E2E helpers", () => { ); }); + it("accepts an ANSI-colored exact Ready sandbox phase", () => { + expect(hasExactReadyPhase("Sandbox:\n \u001b[2mPhase:\u001b[0m Ready\n")).toBe(true); + }); + + it("rejects an ANSI-colored non-Ready sandbox phase", () => { + expect(hasExactReadyPhase("Sandbox:\n \u001b[2mPhase:\u001b[0m Error\n")).toBe(false); + }); + + it.each([ + ["Error before Ready", "Phase: Error\nPhase: Ready\n"], + ["Ready before Error", "Phase: Ready\nPhase: Error\n"], + ["prefixed Ready", "Current Phase: Ready\n"], + ["suffixed Ready", "Phase: Ready (stale)\n"], + ])("rejects %s output", (_case, output) => { + expect(hasExactReadyPhase(output)).toBe(false); + }); + it("accepts successful execution proof when the model suppresses visible text", () => { expect(() => assertAgentExecutionSucceeded(agentOutput(), "inference", GPU_MODEL),