diff --git a/test/e2e/fixtures/managed-image-receipt.ts b/test/e2e/fixtures/managed-image-receipt.ts index 0b340071abb..3b9a1e8f6bc 100644 --- a/test/e2e/fixtures/managed-image-receipt.ts +++ b/test/e2e/fixtures/managed-image-receipt.ts @@ -9,8 +9,10 @@ import { isShippedManagedImageAgent, MANAGED_IMAGE_PLATFORMS, MANAGED_IMAGE_REPOSITORIES, + managedImagePlatformForNodeArchitecture, SHIPPED_MANAGED_IMAGE_AGENTS, type ManagedImageContractV1, + type ManagedImagePlatform, type ShippedManagedImageAgent, } from "../../../src/lib/onboard/managed-image/contract.ts"; import { readManagedWorkloadAuthority } from "../../../src/lib/onboard/workload/authority.ts"; @@ -55,11 +57,19 @@ function selectedManagedImageRevision(environment: NodeJS.ProcessEnv): string { return catalog.revision; } -export function assertManagedImageReceiptMatchesSelectedCohort(options: { +interface SelectedManagedImageAuthority { + readonly platform: ManagedImagePlatform; + readonly reference: string; + readonly release: string | null; + readonly sourceCohort: string; + readonly sourceRevision: string; +} + +function selectedManagedImageAuthority(options: { readonly environment: NodeJS.ProcessEnv; readonly expectedAgent: ShippedManagedImageAgent; - readonly workload?: Record; -}): void { + readonly platform: unknown; +}): SelectedManagedImageAuthority { const revision = options.environment.E2E_MANAGED_IMAGE_REVISION?.trim() ?? ""; const rawReceipt = options.environment.E2E_MANAGED_IMAGE_COHORT_RECEIPT?.trim() ?? ""; if (!revision) { @@ -68,26 +78,23 @@ export function assertManagedImageReceiptMatchesSelectedCohort(options: { "stock onboarding requires the complete selected managed-image cohort receipt", ); } - const platform = options.workload?.platform; if ( - typeof platform !== "string" || - !(MANAGED_IMAGE_PLATFORMS as readonly string[]).includes(platform) + typeof options.platform !== "string" || + !(MANAGED_IMAGE_PLATFORMS as readonly string[]).includes(options.platform) ) { throw new Error("stock onboarding candidate managed-image catalog is invalid"); } const contract = readCandidateCatalog(options.environment).get(options.expectedAgent); - if ( - !contract || - contract.platform !== platform || - options.workload?.kind !== "managed-image" || - options.workload.reference !== contract.reference || - options.workload.release !== contract.source.release || - options.workload.sourceRevision !== contract.source.revision || - options.workload.sourceCohort !== contract.source.cohort - ) { + if (!contract || contract.platform !== options.platform) { throw new Error("stock onboarding must use the exact agent image from the selected cohort"); } - return; + return { + platform: contract.platform, + reference: contract.reference, + release: contract.source.release, + sourceCohort: contract.source.cohort, + sourceRevision: contract.source.revision, + }; } if (!REVISION_PATTERN.test(revision) || !rawReceipt || Buffer.byteLength(rawReceipt) > 8 * 1024) { throw new Error("stock onboarding requires the complete selected managed-image cohort receipt"); @@ -123,11 +130,10 @@ export function assertManagedImageReceiptMatchesSelectedCohort(options: { throw new Error("stock onboarding selected managed-image cohort receipt is invalid"); } - const platform = options.workload?.platform; const agentImages = (images as Record)[options.expectedAgent]; if ( - typeof platform !== "string" || - !(MANAGED_IMAGE_PLATFORMS as readonly string[]).includes(platform) || + typeof options.platform !== "string" || + !(MANAGED_IMAGE_PLATFORMS as readonly string[]).includes(options.platform) || !agentImages || typeof agentImages !== "object" || Array.isArray(agentImages) || @@ -136,14 +142,56 @@ export function assertManagedImageReceiptMatchesSelectedCohort(options: { ) { throw new Error("stock onboarding selected managed-image cohort receipt is invalid"); } - const expectedReference = (agentImages as Record)[platform]; + const reference = (agentImages as Record)[options.platform]; + const referencePrefix = `${MANAGED_IMAGE_REPOSITORIES[options.expectedAgent]}@sha256:`; + if ( + typeof reference !== "string" || + !reference.startsWith(referencePrefix) || + !/^[a-f0-9]{64}$/i.test(reference.slice(referencePrefix.length)) + ) { + throw new Error("stock onboarding must use the exact agent image from the selected cohort"); + } + return { + platform: options.platform as ManagedImagePlatform, + reference, + release: null, + sourceCohort: cohort as string, + sourceRevision: revision, + }; +} + +/** Resolve the selected E2E image from its candidate catalog or publication receipt. */ +export function selectedE2eManagedImageReference(options: { + readonly environment: NodeJS.ProcessEnv; + readonly expectedAgent: ShippedManagedImageAgent; + readonly nodeArchitecture?: string; +}): string { + const nodeArchitecture = options.nodeArchitecture ?? process.arch; + const platform = managedImagePlatformForNodeArchitecture(nodeArchitecture); + if (platform === null) { + throw new Error( + `selected E2E managed image does not support host architecture '${nodeArchitecture}'`, + ); + } + return selectedManagedImageAuthority({ ...options, platform }).reference; +} + +export function assertManagedImageReceiptMatchesSelectedCohort(options: { + readonly environment: NodeJS.ProcessEnv; + readonly expectedAgent: ShippedManagedImageAgent; + readonly workload?: Record; +}): void { + const selected = selectedManagedImageAuthority({ + environment: options.environment, + expectedAgent: options.expectedAgent, + platform: options.workload?.platform, + }); if ( - typeof expectedReference !== "string" || - !expectedReference.startsWith(`${MANAGED_IMAGE_REPOSITORIES[options.expectedAgent]}@sha256:`) || options.workload?.kind !== "managed-image" || - options.workload.reference !== expectedReference || - options.workload.sourceRevision !== revision || - options.workload.sourceCohort !== cohort + options.workload.reference !== selected.reference || + (selected.release !== null && options.workload.release !== selected.release) || + options.workload.sourceRevision !== selected.sourceRevision || + options.workload.sourceCohort !== selected.sourceCohort ) { throw new Error("stock onboarding must use the exact agent image from the selected cohort"); } diff --git a/test/e2e/live/openclaw-inference-switch.test.ts b/test/e2e/live/openclaw-inference-switch.test.ts index 83c26b71513..5405a8fc20c 100644 --- a/test/e2e/live/openclaw-inference-switch.test.ts +++ b/test/e2e/live/openclaw-inference-switch.test.ts @@ -16,10 +16,6 @@ import type { AddressInfo } from "node:net"; import os from "node:os"; import path from "node:path"; -import { - liveE2eManagedImageCatalog, - readLiveE2eManagedImageCatalogContracts, -} from "../../../src/lib/onboard/workload/preparation.ts"; import { execTimeout, testTimeout } from "../../helpers/timeouts.ts"; import type { ArtifactSink } from "../fixtures/artifacts.ts"; import { buildAvailabilityProbeEnv } from "../fixtures/availability-env.ts"; @@ -43,6 +39,7 @@ import { startFakeOpenAiCompatibleServer, } from "../fixtures/fake-openai-compatible.ts"; import { requireHostedInferenceConfig } from "../fixtures/hosted-inference.ts"; +import { selectedE2eManagedImageReference } from "../fixtures/managed-image-receipt.ts"; import type { TestProgress } from "../fixtures/progress.ts"; import { inferenceResponseModel, @@ -99,6 +96,13 @@ interface AnthropicResponse { content?: Array<{ text?: unknown }>; } +interface OpenClawModelConfig { + id?: unknown; + name?: unknown; + contextWindow?: unknown; + maxTokens?: unknown; +} + interface OpenClawConfig { agents?: { defaults?: { @@ -114,12 +118,7 @@ interface OpenClawConfig { baseUrl?: unknown; apiKey?: unknown; api?: unknown; - models?: Array<{ - id?: unknown; - name?: unknown; - contextWindow?: unknown; - maxTokens?: unknown; - }>; + models?: OpenClawModelConfig[]; } >; }; @@ -257,8 +256,10 @@ function commandEnv(home: string, extra: NodeJS.ProcessEnv = {}): NodeJS.Process function writeCustomOpenClawDockerfile(home: string): string { const environment = commandEnv(home); - const selectedCatalog = liveE2eManagedImageCatalog(environment)!; - const contract = readLiveE2eManagedImageCatalogContracts(selectedCatalog).get("openclaw")!; + const baseImage = selectedE2eManagedImageReference({ + environment, + expectedAgent: "openclaw", + }); const buildContext = path.join(home, "custom-openclaw-image"); const dockerfilePath = path.join(buildContext, "Dockerfile"); @@ -276,7 +277,7 @@ function writeCustomOpenClawDockerfile(home: string): string { fs.writeFileSync( dockerfilePath, [ - `FROM ${contract.reference}`, + `FROM ${baseImage}`, "ARG NEMOCLAW_TOOL_DISCLOSURE=progressive", "ENV NEMOCLAW_TOOL_DISCLOSURE=${NEMOCLAW_TOOL_DISCLOSURE}", `RUN node -e ${shellQuote(bakeRoute)}`, @@ -592,17 +593,15 @@ async function assertRegistryAndSession( } } -async function assertOpenClawConfig( +async function readAndAssertOpenClawConfig( sandbox: SandboxClient, home: string, expected: { model: string; inferenceApi: string; artifactName: string; - contextWindow?: number | null; - maxTokens?: number | null; }, -): Promise { +): Promise { const configResult = await sandbox.exec( SANDBOX_NAME, ["cat", "/sandbox/.openclaw/openclaw.json"], @@ -629,18 +628,34 @@ async function assertOpenClawConfig( expect(provider?.apiKey).toBe("unused"); expect(provider?.api).toBe(expected.inferenceApi); expect(selectedModel?.name).toBe(expectedPrimary); - const expectedContextWindow = - expected.contextWindow === null - ? undefined - : (expected.contextWindow ?? selectedModel?.contextWindow); - const expectedMaxTokens = - expected.maxTokens === null ? undefined : (expected.maxTokens ?? selectedModel?.maxTokens); - expect(selectedModel?.contextWindow).toBe(expectedContextWindow); - expect(selectedModel?.maxTokens).toBe(expectedMaxTokens); - expect( - expected.maxTokens === null || - (typeof selectedModel?.maxTokens === "number" && selectedModel.maxTokens > 0), - ).toBe(true); + return selectedModel; +} + +async function assertOpenClawConfig( + sandbox: SandboxClient, + home: string, + expected: { + model: string; + inferenceApi: string; + artifactName: string; + }, +): Promise { + const selectedModel = await readAndAssertOpenClawConfig(sandbox, home, expected); + expect(typeof selectedModel?.maxTokens === "number" && selectedModel.maxTokens > 0).toBe(true); +} + +async function assertInitialOpenClawConfig( + sandbox: SandboxClient, + home: string, + expected: { + model: string; + inferenceApi: string; + artifactName: string; + }, +): Promise { + const selectedModel = await readAndAssertOpenClawConfig(sandbox, home, expected); + expect(selectedModel?.contextWindow).toBeUndefined(); + expect(selectedModel?.maxTokens).toBeUndefined(); } function httpStatusFromResponse(response: string): string { @@ -933,11 +948,9 @@ async function runInitialRouteLifecycle(options: { sandbox: SandboxClient; }): Promise { const verify = async (artifactSuffix: string): Promise => { - await assertOpenClawConfig(options.sandbox, options.home, { + await assertInitialOpenClawConfig(options.sandbox, options.home, { model: options.model, inferenceApi: "openai-completions", - contextWindow: null, - maxTokens: null, artifactName: `read-openclaw-initial-route-${artifactSuffix}`, }); await checkOpenClawGatewayInference( @@ -1130,7 +1143,6 @@ test( ); const home = fs.mkdtempSync(path.join(os.tmpdir(), "nemoclaw-openclaw-switch-home-")); - const customDockerfile = writeCustomOpenClawDockerfile(home); let mockProvider: MockAnthropicProvider | undefined; cleanup.trackDisposable( `remove OpenClaw inference switch test home for ${SANDBOX_NAME}`, @@ -1144,6 +1156,7 @@ test( cleanup.trackDisposable("close baseline inference provider", async () => { await baselineProvider?.close(); }); + const customDockerfile = writeCustomOpenClawDockerfile(home); cleanup.trackGateway(host, "nemoclaw", { artifactName: "cleanup-openshell-gateway-destroy-openclaw-inference-switch", env: commandEnv(home), diff --git a/test/e2e/mock-parity.json b/test/e2e/mock-parity.json index af54bb106ff..190f9974538 100644 --- a/test/e2e/mock-parity.json +++ b/test/e2e/mock-parity.json @@ -833,7 +833,8 @@ "test/e2e/live/openclaw-admin-scope.ts", "test/e2e/fixtures/admin-approval-connect.ts", "test/e2e/fixtures/admin-approval-connect.sh", - "test/e2e/fixtures/issue-4462-admin-approval-evidence.ts" + "test/e2e/fixtures/issue-4462-admin-approval-evidence.ts", + "test/e2e/fixtures/managed-image-receipt.ts" ], "fast": [ "src/lib/actions/inference-set-compatible-provider.test.ts", @@ -842,6 +843,7 @@ "test/e2e/support/compatible-anthropic-switch.test.ts", "test/e2e/support/e2e-cleanup-resources.test.ts", "test/e2e/support/e2e-clients.test.ts", + "test/e2e/support/managed-image-receipt.test.ts", "test/e2e/support/openclaw-inference-switch-helpers.test.ts", "test/security/admin-approval-helper.test.ts", "test/e2e/support/hosted-inference.test.ts" diff --git a/test/e2e/support/managed-image-receipt.test.ts b/test/e2e/support/managed-image-receipt.test.ts index 0d7928baee7..11b24cfdfda 100644 --- a/test/e2e/support/managed-image-receipt.test.ts +++ b/test/e2e/support/managed-image-receipt.test.ts @@ -21,6 +21,7 @@ import { encodeManagedStartupProfile } from "../../../src/lib/onboard/managed-st import { nemoclawStateRoot } from "../../../src/lib/state/state-root.ts"; import { assertStockManagedImageReceipt, + selectedE2eManagedImageReference, shouldAssertStockManagedImageReceipt, } from "../fixtures/managed-image-receipt.ts"; import { ArtifactSink } from "../fixtures/artifacts.ts"; @@ -35,6 +36,7 @@ const SANDBOX_NAME = "managed-only-stock"; const REVISION = "d".repeat(40); const COHORT = "ghrun-32707920950-1"; const REFERENCE = `${MANAGED_IMAGE_REPOSITORIES.openclaw}@sha256:${"a".repeat(64)}`; +const ARM64_REFERENCE = `${MANAGED_IMAGE_REPOSITORIES.openclaw}@sha256:${"b".repeat(64)}`; const CATALOG_REFERENCES = { openclaw: REFERENCE, hermes: `${MANAGED_IMAGE_REPOSITORIES.hermes}@sha256:${"c".repeat(64)}`, @@ -82,7 +84,7 @@ function selectedEnvironment(home: string): NodeJS.ProcessEnv { images: { openclaw: { "linux/amd64": REFERENCE, - "linux/arm64": `${MANAGED_IMAGE_REPOSITORIES.openclaw}@sha256:${"b".repeat(64)}`, + "linux/arm64": ARM64_REFERENCE, }, hermes: { "linux/amd64": `${MANAGED_IMAGE_REPOSITORIES.hermes}@sha256:${"c".repeat(64)}`, @@ -169,6 +171,86 @@ function writeRegistry( return home; } +describe("selected E2E managed-image reference", () => { + it("uses the main-run cohort receipt when no candidate catalog exists (#12421)", () => { + const home = writeRegistry(managedReceipt()); + const environment = { + ...selectedEnvironment(home), + GITHUB_ACTIONS: "true", + NEMOCLAW_E2E_MANAGED_IMAGE_CATALOG_JSON: "", + NEMOCLAW_RUN_LIVE_E2E: "1", + }; + + expect( + selectedE2eManagedImageReference({ + environment, + expectedAgent: "openclaw", + nodeArchitecture: "x64", + }), + ).toBe(REFERENCE); + }); + + it("uses the trusted candidate catalog when no cohort revision exists (#12421)", () => { + const home = writeRegistry(managedReceipt()); + + expect( + selectedE2eManagedImageReference({ + environment: candidateInlineCatalogEnvironment(home), + expectedAgent: "openclaw", + nodeArchitecture: "x64", + }), + ).toBe(REFERENCE); + }); + + it("selects the arm64 image from the main-run cohort receipt (#12421)", () => { + expect( + selectedE2eManagedImageReference({ + environment: selectedEnvironment("/tmp/unused"), + expectedAgent: "openclaw", + nodeArchitecture: "arm64", + }), + ).toBe(ARM64_REFERENCE); + }); + + it("rejects a main-run revision without its cohort receipt (#12421)", () => { + expect(() => + selectedE2eManagedImageReference({ + environment: { E2E_MANAGED_IMAGE_REVISION: REVISION }, + expectedAgent: "openclaw", + nodeArchitecture: "x64", + }), + ).toThrow("complete selected managed-image cohort receipt"); + }); + + it("rejects a cohort receipt with a malformed image digest (#12421)", () => { + const environment = selectedEnvironment("/tmp/unused"); + const receipt = JSON.parse(environment.E2E_MANAGED_IMAGE_COHORT_RECEIPT!) as { + images: { openclaw: { "linux/amd64": string } }; + }; + receipt.images.openclaw["linux/amd64"] = + `${MANAGED_IMAGE_REPOSITORIES.openclaw}@sha256:not-a-digest`; + environment.E2E_MANAGED_IMAGE_COHORT_RECEIPT = JSON.stringify(receipt); + + expect(() => + selectedE2eManagedImageReference({ + environment, + expectedAgent: "openclaw", + nodeArchitecture: "x64", + }), + ).toThrow("exact agent image from the selected cohort"); + }); + + it("rejects a host architecture that has no managed image (#12421)", () => { + expect(() => + selectedE2eManagedImageReference({ + environment: selectedEnvironment("/tmp/unused"), + expectedAgent: "openclaw", + nodeArchitecture: "riscv64", + }), + ).toThrow("does not support host architecture 'riscv64'"); + }); +}); + describe("stock E2E managed-image receipt assertion", () => { it.each([ ["accepts a valid", REVISION, "accepted"],