From 966f630e021d4ca032f818a477926c42a7329b5e Mon Sep 17 00:00:00 2001 From: Carlos Villela Date: Thu, 8 Oct 2026 19:40:37 -0700 Subject: [PATCH 1/2] test(e2e): plan every remaining NemoClaw type from authored HCL #12782 requires each type to be exercised through pinned OpenTofu by an authored configuration. The Kubernetes authentication and gateway resources, the external Ollama model, and the runtime image check had none, and kubernetes_hcl was missing from the lifecycle profile, so CI never ran it. --- .config/nextest.toml | 1 + crates/nemoclaw-e2e/tests/kubernetes_hcl.rs | 69 ++++++++++--- crates/nemoclaw-e2e/tests/main.rs | 2 + crates/nemoclaw-e2e/tests/runtime_image.rs | 95 +++++++++++++++++ crates/nemoclaw-e2e/tests/service_storage.rs | 102 +++++++++++++++++++ 5 files changed, 255 insertions(+), 14 deletions(-) create mode 100644 crates/nemoclaw-e2e/tests/runtime_image.rs diff --git a/.config/nextest.toml b/.config/nextest.toml index 7a73e1fbfba..07709b53ff1 100644 --- a/.config/nextest.toml +++ b/.config/nextest.toml @@ -21,6 +21,7 @@ test(native_state_json_preserves_module_and_instance_identity_without_refresh) test(/^provider_protocol::/) | test(/^service_capacity::/) | test(/^service_readiness::/) | test(/^sandbox_readiness::/) | test(/^opentofu_openshell::/) | test(/^deployment::/) | test(/^service_storage::/) | test(/^vllm_runtime::/) + | test(/^kubernetes_hcl::/) | test(/^runtime_image::/) | test(/^export_observations::/) | test(/^fabric_deployment::/) | test(/^multiple_providers::/) | test(/^remote_service::/) | test(/^discovery::/) | test(/^inference_discovery::/) | test(/^gateway_readiness::/) diff --git a/crates/nemoclaw-e2e/tests/kubernetes_hcl.rs b/crates/nemoclaw-e2e/tests/kubernetes_hcl.rs index 44c91c731de..892313a8a84 100644 --- a/crates/nemoclaw-e2e/tests/kubernetes_hcl.rs +++ b/crates/nemoclaw-e2e/tests/kubernetes_hcl.rs @@ -28,10 +28,12 @@ provider "nemoclaw" {{}} workspace } -fn storage(namespace: &str) -> String { - format!( - r#"resource "nemoclaw_kubernetes_storage" "platform" {{ - name = "nc-0123456789abcdef-gateway" +/// Storage, authentication and the gateway for one cluster target. The +/// authentication and gateway resources take the storage's owner unless +/// `owner` names one for every resource. +fn platform(namespace: &str, owner: Option<&str>) -> String { + let target = format!( + r#" name = "nc-0123456789abcdef-gateway" compute_driver = "openshift" endpoint = "https://127.0.0.1:17671" kubeconfig_env = "TEST_CLUSTER_KUBECONFIG" @@ -39,7 +41,28 @@ fn storage(namespace: &str) -> String { namespace = "{namespace}" authentication_profile = "development" environment = ["AWS_PROFILE"] -}} +"# + ); + let (storage, auth, gateway) = match owner { + Some(owner) => { + let identity = format!(" owner = \"{owner}\"\n"); + (identity.clone(), identity.clone(), identity) + } + None => ( + String::new(), + " owner = nemoclaw_kubernetes_storage.platform.owner\n".to_owned(), + " owner = nemoclaw_kubernetes_storage.platform.owner\n generation = nemoclaw_kubernetes_auth.platform.generation\n".to_owned(), + ), + }; + format!( + r#"resource "nemoclaw_kubernetes_storage" "platform" {{ +{target}{storage}}} + +resource "nemoclaw_kubernetes_auth" "platform" {{ +{target}{auth}}} + +resource "nemoclaw_kubernetes_gateway" "platform" {{ +{target}{gateway}}} "# ) } @@ -47,7 +70,7 @@ fn storage(namespace: &str) -> String { #[test] #[ignore = "requires explicit NEMOCLAW_TEST_TOFU and NEMOCLAW_TEST_PROVIDER; no cluster"] fn kubernetes_resources_plan_from_typed_settings_and_reject_invalid_ones() { - let valid = workspace(&storage("agents")); + let valid = workspace(&platform("agents", None)); let run = |workspace: &TofuWorkspace, args: &[&str]| workspace.command().args(args).output().unwrap(); let output = run(&valid, &["plan", "-input=false", "-out=platform.plan"]); @@ -58,18 +81,36 @@ fn kubernetes_resources_plan_from_typed_settings_and_reject_invalid_ones() { ); let plan: Value = serde_json::from_slice(&run(&valid, &["show", "-json", "platform.plan"]).stdout).unwrap(); - let change = &plan["resource_changes"][0]["change"]; - assert_eq!(change["actions"], json!(["create"])); - assert_eq!(change["after"]["environment"], json!(["AWS_PROFILE"])); - assert_eq!(change["after"]["namespace"], "agents"); - // The provider generates the identity the author omits. - assert_eq!(change["after_unknown"]["owner"], true); - assert_eq!(change["after_unknown"]["generation"], true); + let changes = plan["resource_changes"].as_array().unwrap(); + assert_eq!(changes.len(), 3); + for change in changes { + let change = &change["change"]; + assert_eq!(change["actions"], json!(["create"])); + assert_eq!(change["after"]["environment"], json!(["AWS_PROFILE"])); + assert_eq!(change["after"]["namespace"], "agents"); + // The provider generates the storage's identity; the others share it. + assert_eq!(change["after_unknown"]["owner"], true); + } - let invalid = workspace(&storage("Not A Namespace")); + // OpenTofu skips resources whose dependencies fail validation, so each + // resource names its own owner here. + let invalid = workspace(&platform( + "Not A Namespace", + Some("302ff5e1-088d-42ce-959f-4ff4c3570c13"), + )); let output = run(&invalid, &["validate"]); assert!(!output.status.success()); let stderr = String::from_utf8_lossy(&output.stderr); + for kind in [ + "nemoclaw_kubernetes_storage", + "nemoclaw_kubernetes_auth", + "nemoclaw_kubernetes_gateway", + ] { + assert!( + stderr.contains(&format!("{kind}.platform")), + "{kind}: {stderr}" + ); + } assert!( stderr.contains("namespace must be a Kubernetes namespace name"), "{stderr}" diff --git a/crates/nemoclaw-e2e/tests/main.rs b/crates/nemoclaw-e2e/tests/main.rs index 8ac4531a4cb..8ff435cb708 100644 --- a/crates/nemoclaw-e2e/tests/main.rs +++ b/crates/nemoclaw-e2e/tests/main.rs @@ -45,6 +45,8 @@ mod opentofu_openshell; mod provider_protocol; #[path = "remote_service.rs"] mod remote_service; +#[path = "runtime_image.rs"] +mod runtime_image; #[path = "sandbox_readiness.rs"] mod sandbox_readiness; #[path = "service_capacity.rs"] diff --git a/crates/nemoclaw-e2e/tests/runtime_image.rs b/crates/nemoclaw-e2e/tests/runtime_image.rs new file mode 100644 index 00000000000..73ac6425cac --- /dev/null +++ b/crates/nemoclaw-e2e/tests/runtime_image.rs @@ -0,0 +1,95 @@ +// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 +//! Authored runtime image checks through pinned OpenTofu. + +use nemoclaw_e2e::{http_fixture::Fixture, tofu::TofuWorkspace}; +use nemoclaw_sdk::managed::{RUNTIME_SPEC_VERSION, RUNTIME_SPEC_VERSION_LABEL}; +use serde_json::{Value, json}; +use std::{ + fs, + path::PathBuf, + sync::{Arc, Mutex}, +}; + +/// A Docker engine that answers image inspection with `image`. +async fn image_engine(image: Arc>) -> Fixture { + Fixture::start(move |request| { + assert_eq!(request.method, "GET", "an image check must not mutate"); + let body = if request.path.starts_with("/images/") { + image.lock().unwrap().clone() + } else { + json!({"ID":"engine"}) + }; + Some((200, serde_json::to_vec(&body).unwrap())) + }) + .await +} + +fn workspace(engine: &str) -> TofuWorkspace { + let path = |name| PathBuf::from(std::env::var_os(name).expect("explicit qualification path")); + let (tofu, provider) = (path("NEMOCLAW_TEST_TOFU"), path("NEMOCLAW_TEST_PROVIDER")); + assert!(tofu.is_absolute() && provider.is_absolute()); + let workspace = TofuWorkspace::new(tofu, provider); + fs::write( + workspace.path().join("main.tf"), + format!( + r#"terraform {{ + required_providers {{ + nemoclaw = {{ source = "registry.opentofu.org/nvidia/nemoclaw" }} + }} +}} + +provider "nemoclaw" {{}} + +data "nemoclaw_runtime_image" "vllm" {{ + engine = "{engine}" + image = "runtime@sha256:{digest}" + architecture = "arm64" + labels = {{ + "org.nemoclaw.backend" = "vllm" + }} +}} + +output "observation" {{ + value = jsondecode(data.nemoclaw_runtime_image.vllm.observation_json) +}} +"#, + digest = "a".repeat(64), + ), + ) + .unwrap(); + workspace +} + +#[tokio::test(flavor = "multi_thread", worker_threads = 2)] +#[ignore = "requires explicit NEMOCLAW_TEST_TOFU and NEMOCLAW_TEST_PROVIDER; isolated Docker fixture"] +async fn authored_runtime_image_check_reads_labels_and_rejects_an_incompatible_image() { + let image = Arc::new(Mutex::new(json!({ + "Id": "sha256:runtime", "Os": "linux", "Architecture": "arm64", + "Config": {"Labels": { + RUNTIME_SPEC_VERSION_LABEL: RUNTIME_SPEC_VERSION, + "org.nemoclaw.backend": "vllm" + }} + }))); + let engine = image_engine(image.clone()).await; + let workspace = workspace(&engine.endpoint); + let run = |args: &[&str]| workspace.command().args(args).output().unwrap(); + let output = run(&["apply", "-input=false", "-auto-approve", "-no-color"]); + assert!( + output.status.success(), + "{}", + String::from_utf8_lossy(&output.stderr) + ); + let outputs: Value = serde_json::from_slice(&run(&["output", "-json"]).stdout).unwrap(); + assert_eq!(outputs["observation"]["value"]["status"], "available"); + + // An image without the required backend label fails the read. + image.lock().unwrap()["Config"]["Labels"]["org.nemoclaw.backend"] = json!("ollama"); + let output = run(&["plan", "-input=false", "-no-color"]); + assert!(!output.status.success()); + let stderr = String::from_utf8_lossy(&output.stderr); + assert!( + stderr.contains("Runtime image compatibility check failed"), + "{stderr}" + ); +} diff --git a/crates/nemoclaw-e2e/tests/service_storage.rs b/crates/nemoclaw-e2e/tests/service_storage.rs index 13ea82da9b3..a1d1e73a832 100644 --- a/crates/nemoclaw-e2e/tests/service_storage.rs +++ b/crates/nemoclaw-e2e/tests/service_storage.rs @@ -332,3 +332,105 @@ async fn omitted_proxy_storage_identity_is_generated_and_labels_its_credential_v String::from_utf8_lossy(&output.stdout) ); } + +/// An Ollama upstream that lists one model with the digest it holds. +async fn upstream(digest: Arc>) -> Fixture { + Fixture::start_tcp(move |request| { + if request.method != "GET" || request.path != "/api/tags" { + return Some((400, Vec::new())); + } + let body = + json!({"models":[{"name":"qwen3:0.6b","digest":*digest.lock().unwrap(),"size":42}]}); + Some((200, body.to_string().into_bytes())) + }) + .await +} + +#[tokio::test(flavor = "multi_thread", worker_threads = 2)] +#[ignore = "requires explicit NEMOCLAW_TEST_TOFU and NEMOCLAW_TEST_PROVIDER; isolated Docker and Ollama fixtures"] +async fn authored_external_model_shares_proxy_identity_and_rechecks_its_digest() { + let (engine, volumes) = volume_engine().await; + let digest = Arc::new(Mutex::new("a".repeat(64))); + let upstream = upstream(digest.clone()).await; + let workspace = workspace(); + fs::write( + workspace.path().join("main.tf"), + format!( + r#"terraform {{ + required_providers {{ + nemoclaw = {{ source = "registry.opentofu.org/nvidia/nemoclaw" }} + }} +}} + +provider "nemoclaw" {{}} + +resource "nemoclaw_ollama_proxy_storage" "credentials" {{ + name = "nc-0123456789abcdef-ollama-proxy-local" + engine = "{engine}" +}} + +# The model shares its proxy's identity, so a new proxy re-verifies it. +resource "nemoclaw_ollama_external_model" "model" {{ + name = nemoclaw_ollama_proxy_storage.credentials.name + owner = nemoclaw_ollama_proxy_storage.credentials.owner + generation = nemoclaw_ollama_proxy_storage.credentials.generation + engine = "{engine}" + upstream = "{upstream}/v1" + model = "qwen3:0.6b" + digest = "{digest}" +}} +"#, + engine = engine.endpoint, + upstream = upstream.endpoint, + digest = "a".repeat(64), + ), + ) + .unwrap(); + success( + &workspace, + &["apply", "-input=false", "-auto-approve", "-no-color"], + ); + assert!( + volumes + .lock() + .unwrap() + .volumes + .contains_key("nc-0123456789abcdef-ollama-proxy-local-auth") + ); + let state: Value = + serde_json::from_slice(&fs::read(workspace.path().join("terraform.tfstate")).unwrap()) + .unwrap(); + let attributes = |kind: &str| { + state["resources"] + .as_array() + .unwrap() + .iter() + .find(|resource| resource["type"] == kind) + .unwrap()["instances"][0]["attributes"] + .clone() + }; + let (storage, model) = ( + attributes("nemoclaw_ollama_proxy_storage"), + attributes("nemoclaw_ollama_external_model"), + ); + assert_eq!(model["owner"], storage["owner"]); + assert_eq!( + model["id"], + format!( + "{}/{}/{}", + storage["owner"].as_str().unwrap(), + storage["generation"].as_str().unwrap(), + "a".repeat(64) + ) + ); + success( + &workspace, + &["plan", "-input=false", "-no-color", "-detailed-exitcode"], + ); + // A changed upstream digest stops planning and names the service's upstream. + *digest.lock().unwrap() = "b".repeat(64); + let output = run(&workspace, &["plan", "-input=false", "-no-color"]); + assert!(!output.status.success()); + let stderr = String::from_utf8_lossy(&output.stderr); + assert!(stderr.contains("services.local.upstream"), "{stderr}"); +} From c974d338f0ae8a9add8b76ab8512b8788da30f87 Mon Sep 17 00:00:00 2001 From: Carlos Villela Date: Thu, 8 Oct 2026 22:41:07 -0700 Subject: [PATCH 2/2] test(e2e): build the runtime image fixture only on Unix The fixture's Docker engine listens on a Unix socket, which the Windows clippy step cannot build. --- crates/nemoclaw-e2e/tests/main.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/crates/nemoclaw-e2e/tests/main.rs b/crates/nemoclaw-e2e/tests/main.rs index 8ff435cb708..16f58c40fe1 100644 --- a/crates/nemoclaw-e2e/tests/main.rs +++ b/crates/nemoclaw-e2e/tests/main.rs @@ -45,6 +45,7 @@ mod opentofu_openshell; mod provider_protocol; #[path = "remote_service.rs"] mod remote_service; +#[cfg(unix)] #[path = "runtime_image.rs"] mod runtime_image; #[path = "sandbox_readiness.rs"]