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
58 changes: 46 additions & 12 deletions src/lib/domain/sandbox/n1x-managed-vllm-rebuild.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,16 @@ describe("Deferred N1x managed-vLLM acceptance route", () => {
const accepted = {
provider: "vllm-local",
model: "nvidia/Qwen3.6-35B-A3B-NVFP4",
endpointUrl: null,
endpointUrl: "http://host.openshell.internal:8000/v1",
endpointSource: null,
nimContainer: null,
openshellDriver: "docker",
};

it.each([
["the exact route", accepted, true],
["a derived legacy endpoint", { ...accepted, endpointUrl: null }, true],
["another provider", { ...accepted, provider: "compatible-endpoint" }, false],
["another model", { ...accepted, model: "other" }, false],
["a recorded endpoint", { ...accepted, endpointUrl: "http://localhost:8000/v1" }, false],
["another endpoint source", { ...accepted, endpointSource: "inference-set" }, false],
Expand All @@ -37,6 +39,35 @@ describe("Deferred N1x managed-vLLM acceptance route", () => {
])("classifies %s", (_case, route, expected) => {
expect(isDeferredN1xManagedVllmAcceptanceRoute(route)).toBe(expected);
});

it.each([1024, 8000, 18000, 65535])(
"accepts the canonical endpoint on port %s (#11510)",
(port) => {
expect(
isDeferredN1xManagedVllmAcceptanceRoute({
...accepted,
endpointUrl: `http://host.openshell.internal:${port}/v1`,
}),
).toBe(true);
},
);

it.each([
undefined,
"",
"http://host.openshell.internal:1023/v1",
"http://host.openshell.internal:65536/v1",
"http://host.openshell.internal:08000/v1",
"http://host.openshell.internal.example:8000/v1",
"http://user:password@host.openshell.internal:8000/v1",
"https://host.openshell.internal:8000/v1",
"http://host.openshell.internal:8000/v1/",
"http://host.openshell.internal:8000/v1?target=other",
"http://host.openshell.internal:8000/v1#other",
"http://host.openshell.internal:8000/v1\n",
])("rejects noncanonical endpoint %s (#11510)", (endpointUrl) => {
expect(isDeferredN1xManagedVllmAcceptanceRoute({ ...accepted, endpointUrl })).toBe(false);
});
});

describe("recorded N1x managed-vLLM rebuild eligibility", () => {
Expand Down Expand Up @@ -84,15 +115,19 @@ describe("recorded N1x managed-vLLM rebuild eligibility", () => {
expect(eligible(sandboxEntry)).toBe(true);
});

it("accepts normalized N1x Express intent with a derived endpoint (#10959)", () => {
expect(
eligible({
...n1xExpressEntry,
endpointSource: null,
deferredN1xManagedVllmAccepted: true,
}),
).toBe(true);
});
it.each([null, "http://host.openshell.internal:8000/v1"])(
"accepts recorded N1x preview intent with endpoint %s (#11510)",
(endpointUrl) => {
expect(
eligible({
...n1xExpressEntry,
endpointUrl,
endpointSource: null,
deferredN1xManagedVllmAccepted: true,
}),
).toBe(true);
},
);

it("accepts an explicit preview retry for a normalized legacy record (#10959)", () => {
expect(
Expand Down Expand Up @@ -175,12 +210,11 @@ describe("recorded N1x managed-vLLM rebuild eligibility", () => {
rebuildSelection: n1xExpressSelection,
},
{
caseName: "normalized source with a recorded endpoint",
caseName: "recorded endpoint without preview provenance",
sandboxEntry: {
...n1xExpressEntry,
endpointUrl: "http://host.openshell.internal:8000/v1",
endpointSource: null,
deferredN1xManagedVllmAccepted: true,
},
rebuildSelection: n1xExpressSelection,
},
Expand Down
15 changes: 12 additions & 3 deletions src/lib/domain/sandbox/n1x-managed-vllm-rebuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,19 @@ export interface DeferredN1xManagedVllmAcceptanceRoute {
export function isDeferredN1xManagedVllmAcceptanceRoute(
route: DeferredN1xManagedVllmAcceptanceRoute,
): boolean {
// Persisted acceptance must remain readable without the original shell's vLLM port setting.
const endpointMatch =
typeof route.endpointUrl === "string"
? /^http:\/\/host\.openshell\.internal:([1-9][0-9]{3,4})\/v1$/u.exec(route.endpointUrl)
: null;
const canonicalEndpoint =
endpointMatch !== null &&
endpointMatch[0] === route.endpointUrl &&
Number(endpointMatch[1]) >= 1024 &&
Number(endpointMatch[1]) <= 65535;
return (
isN1xManagedVllmProviderModel(route.provider, route.model) &&
route.endpointUrl === null &&
(route.endpointUrl === null || canonicalEndpoint) &&
route.endpointSource === null &&
route.nimContainer == null &&
route.openshellDriver === "docker"
Expand Down Expand Up @@ -94,9 +104,8 @@ export function isRecordedN1xManagedVllmRebuildEligible(
const recordedSourceIsEligible =
sandboxEntry.endpointSource === "onboard" ||
(sandboxEntry.endpointSource === null &&
sandboxEntry.endpointUrl === null &&
(sandboxEntry.deferredN1xManagedVllmAccepted === true ||
options.explicitPreviewIntent === true));
(sandboxEntry.endpointUrl === null && options.explicitPreviewIntent === true)));
if (
!isN1xManagedVllmProviderModel(sandboxEntry.provider, sandboxEntry.model) ||
!recordedEndpointUsesCanonicalLocalRoute ||
Expand Down
60 changes: 55 additions & 5 deletions src/lib/onboard/created-sandbox-n1x-finalization.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ import fs from "node:fs/promises";
import os from "node:os";
import path from "node:path";

import { afterEach, expect, it, vi } from "vitest";
import { afterEach, beforeEach, expect, it, vi } from "vitest";

import { requireValue } from "../core/require-value";
import { isRecordedN1xManagedVllmRebuildEligible } from "../domain/sandbox/n1x-managed-vllm-rebuild";
import { createSession, type Session } from "../state/onboard-session";
import type { SandboxEntry } from "../state/registry";
import {
Expand All @@ -21,8 +23,11 @@ import {
type InitialOnboardFlowContext,
} from "./machine/initial-flow-phases";
import type { SandboxGpuCreateFlowResult } from "./sandbox-gpu-create-flow";
import { parseHostLocalInferenceReceipt } from "./runtime-provider/host-local-inference";
import type { SetupNimSelectionState } from "./setup-nim-flow";
import { createSetupNimVllmHandler } from "./setup-nim-vllm";

const sandboxName = "n1x-preview";
const sandboxName = "my-assistant";
const model = "nvidia/Qwen3.6-35B-A3B-NVFP4";
const provider = "vllm-local";
const previewEnv = { NEMOCLAW_PROVIDER: "install-vllm" };
Expand All @@ -32,18 +37,54 @@ afterEach(async () => {
vi.resetModules();
await Promise.all(homes.splice(0).map((home) => fs.rm(home, { recursive: true, force: true })));
});
const inferenceSelection = {
const inferenceSelection: SetupNimSelectionState & {
model: string;
endpointSource: null;
compatibleEndpointReasoning: null;
compatibleEndpointReasoningEffort: null;
} = {
provider,
model,
endpointUrl: null,
endpointSource: null,
credentialEnv: null,
hermesAuthMethod: null,
hermesToolGateways: [],
preferredInferenceApi: "openai-completions",
compatibleEndpointReasoning: null,
compatibleEndpointReasoningEffort: null,
nimContainer: null,
} as const;
allowToolsIncompatible: false,
};

beforeEach(async () => {
inferenceSelection.endpointUrl = null;
const handler = createSetupNimVllmHandler({
VLLM_PORT: 8000,
getLocalProviderBaseUrl: () => "http://host.openshell.internal:8000/v1",
getLocalProviderValidationBaseUrl: () => "http://127.0.0.1:8000/v1",
getManagedVllmProviderBinding: () => ({
baseUrl: "http://host.openshell.internal:8000/v1",
validationBaseUrl: "http://127.0.0.1:8000/v1",
apiKey: "test-key",
}),
runCapture: vi.fn(() => {
throw new Error("Unexpected unauthenticated vLLM query");
}),
queryVllmModels: () => JSON.stringify({ data: [{ id: model }] }),
isSafeModelId: () => true,
requireValue,
validateOpenAiLikeSelection: async () => ({ ok: true, api: "openai-completions" }),
applyVllmRuntimeContextWindow: vi.fn(),
persistConfiguredManagedVllmRuntimeReceipt: async () => ({ ok: true, persisted: true }),
exitProcess: (code) => {
throw new Error(`Unexpected vLLM setup exit ${code}`);
},
});
expect(await handler(inferenceSelection, { managedInstall: true, sparkHost: false })).toBe(
"selected",
);
});

type Gpu = { type: "nvidia"; platform: "n1x" | "spark" };
type GpuConfig = {
Expand Down Expand Up @@ -330,7 +371,7 @@ it.each([
["explicit rebuild denial", true, "n1x", false, previewEnv, false, false],
["ordinary N1x opt-out", false, "n1x", undefined, { NEMOCLAW_NO_EXPRESS: "1" }, false, false],
] as const)(
"carries %s preview acceptance through final registration (#10959)",
"carries %s preview acceptance through default-name registration (#11510)",
async (_case, resume, platform, allow, environment, legacyOnboardRoute, expected) => {
const flow = await createIntentThroughOnboardFlow({
resume,
Expand All @@ -341,6 +382,15 @@ it.each([
});
const registration = await completeRegistration(flow.createIntent);

expect(registration.endpointUrl).toBe("http://host.openshell.internal:8000/v1");
expect(
isRecordedN1xManagedVllmRebuildEligible(
registration,
{ provider, model, pinEndpoint: true, endpointUrl: null },
parseHostLocalInferenceReceipt,
),
).toBe(expected);

expect([
flow.accepted,
flow.createIntent.deferredN1xManagedVllmPreviewIntent,
Expand Down
41 changes: 27 additions & 14 deletions src/lib/state/registry-normalization.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,21 +201,34 @@ describe("sandbox registry normalization", () => {
);
});

it("round-trips only valid Deferred N1x preview acceptance (#10959)", async () => {
const registry = await loadRegistryWith({ legacy: { name: "legacy" } });
registry.registerSandbox({
name: "preview",
provider: "vllm-local",
model: "nvidia/Qwen3.6-35B-A3B-NVFP4",
endpointUrl: null,
endpointSource: null,
openshellDriver: "docker",
deferredN1xManagedVllmAccepted: true,
});
vi.resetModules();
const reloadedRegistry = await import("./registry");
it.each([
null,
"http://host.openshell.internal:8000/v1",
"http://host.openshell.internal:18000/v1",
])(
"round-trips valid Deferred N1x preview acceptance with endpoint %s (#11510)",
async (endpointUrl) => {
const registry = await loadRegistryWith({ legacy: { name: "legacy" } });
registry.registerSandbox({
name: "preview",
provider: "vllm-local",
model: "nvidia/Qwen3.6-35B-A3B-NVFP4",
endpointUrl,
endpointSource: null,
openshellDriver: "docker",
deferredN1xManagedVllmAccepted: true,
});
vi.resetModules();
const reloadedRegistry = await import("./registry");

expect(reloadedRegistry.getSandbox("preview")).toMatchObject({
endpointUrl,
deferredN1xManagedVllmAccepted: true,
});
},
);

expect(reloadedRegistry.getSandbox("preview")?.deferredN1xManagedVllmAccepted).toBe(true);
it("rejects malformed Deferred N1x preview acceptance (#10959)", async () => {
const malformed = await loadRegistryWith({
malformed: {
name: "malformed",
Expand Down
Loading