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
1 change: 1 addition & 0 deletions .config/nextest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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::/)
Expand Down
69 changes: 55 additions & 14 deletions crates/nemoclaw-e2e/tests/kubernetes_hcl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,26 +28,49 @@ 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"
context = "selected"
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}}}
"#
)
}

#[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"]);
Expand All @@ -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}"
Expand Down
3 changes: 3 additions & 0 deletions crates/nemoclaw-e2e/tests/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ 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"]
mod sandbox_readiness;
#[path = "service_capacity.rs"]
Expand Down
95 changes: 95 additions & 0 deletions crates/nemoclaw-e2e/tests/runtime_image.rs
Original file line number Diff line number Diff line change
@@ -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<Mutex<Value>>) -> 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}"
);
}
102 changes: 102 additions & 0 deletions crates/nemoclaw-e2e/tests/service_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Mutex<String>>) -> 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}");
}
Loading