diff --git a/.config/nextest.toml b/.config/nextest.toml index bfe7340b697..176bbf14a09 100644 --- a/.config/nextest.toml +++ b/.config/nextest.toml @@ -22,16 +22,13 @@ default-filter = ''' test(native_state_json_preserves_module_and_instance_identity_without_refresh) | (package(nemoclaw-sdk) & test(/^deployment::runtime::helm_recovery::tests::/)) | (package(nemoclaw-sdk) & test(runtime_export_declares_the_native_helm_provider_inputs)) -| (package(openshell-provider) & binary(=contract)) -| (package(fabric-provider) & binary(=contract)) +| ((package(nemoclaw-provider) | package(openshell-provider) | package(fabric-provider)) & binary(=contract)) | (package(nemoclaw-e2e) & binary(=integration) & ( test(/^provider_protocol::/) | test(/^service_capacity::/) | test(/^service_readiness::/) | test(/^sandbox_readiness::/) | 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::/) + | test(/^inference_discovery::/) )) ''' diff --git a/Cargo.lock b/Cargo.lock index da8c91130c8..9937cc3886a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2708,6 +2708,7 @@ dependencies = [ "nemoclaw-openshell", "nemoclaw-runtime", "nemoclaw-sdk", + "nemoclaw-test-fixtures", "nemoclaw-tofu", "openshell-core", "openshell-policy", diff --git a/crates/nemoclaw-e2e/tests/main.rs b/crates/nemoclaw-e2e/tests/main.rs index dc220f9f56e..ff24d91a28e 100644 --- a/crates/nemoclaw-e2e/tests/main.rs +++ b/crates/nemoclaw-e2e/tests/main.rs @@ -9,8 +9,6 @@ mod agent_compatibility; mod cache_provider; #[path = "deployment.rs"] mod deployment; -#[path = "discovery.rs"] -mod discovery; #[path = "docker_fixture.rs"] mod docker_fixture; #[path = "docker_provider_proxy.rs"] @@ -21,16 +19,12 @@ mod export_observations; mod fabric_deployment; #[path = "fabric_live.rs"] mod fabric_live; -#[path = "gateway_readiness.rs"] -mod gateway_readiness; #[path = "health.rs"] mod health; #[path = "hosted_parity.rs"] mod hosted_parity; #[path = "inference_discovery.rs"] mod inference_discovery; -#[path = "kubernetes_hcl.rs"] -mod kubernetes_hcl; #[path = "managed.rs"] mod managed; #[path = "model_live.rs"] @@ -46,26 +40,20 @@ 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; +// The fixture engine listens on a Unix socket. +#[cfg(unix)] #[path = "service_capacity.rs"] mod service_capacity; #[path = "service_readiness.rs"] mod service_readiness; -// The fixture engine listens on a Unix socket. -#[cfg(unix)] -#[path = "service_storage.rs"] -mod service_storage; #[path = "spark.rs"] mod spark; #[path = "tls.rs"] mod tls; // The fixture engine listens on a Unix socket. #[cfg(unix)] -#[path = "vllm_runtime.rs"] -mod vllm_runtime; #[path = "web_search.rs"] mod web_search; diff --git a/crates/nemoclaw-provider/Cargo.toml b/crates/nemoclaw-provider/Cargo.toml index 9ad6ce35dcc..cdc2c44db58 100644 --- a/crates/nemoclaw-provider/Cargo.toml +++ b/crates/nemoclaw-provider/Cargo.toml @@ -12,6 +12,10 @@ autotests = false name = "integration" path = "tests/main.rs" +[[test]] +name = "contract" +path = "tests/contract/main.rs" + [dependencies] nemoclaw-backend = { path = "../nemoclaw-backend" } nemoclaw-tofu = { path = "../nemoclaw-tofu" } @@ -49,6 +53,7 @@ rustix = { workspace = true, features = ["fs"] } [dev-dependencies] fabric-provider = { path = "../fabric-provider" } +nemoclaw-test-fixtures = { path = "../nemoclaw-test-fixtures" } prost.workspace = true tokio = { workspace = true, features = ["test-util"] } tempfile.workspace = true diff --git a/crates/nemoclaw-e2e/tests/discovery.rs b/crates/nemoclaw-provider/tests/contract/discovery.rs similarity index 98% rename from crates/nemoclaw-e2e/tests/discovery.rs rename to crates/nemoclaw-provider/tests/contract/discovery.rs index b3841a80b3c..22de685d76b 100644 --- a/crates/nemoclaw-e2e/tests/discovery.rs +++ b/crates/nemoclaw-provider/tests/contract/discovery.rs @@ -2,8 +2,8 @@ // SPDX-License-Identifier: Apache-2.0 #![cfg(unix)] -use nemoclaw_e2e::http_fixture as transport; -use nemoclaw_e2e::tofu::TofuWorkspace; +use crate::http_fixture as transport; +use crate::tofu::TofuWorkspace; use nemoclaw_sdk::fabric_catalog::{FabricCatalog, IMAGE_CATALOG_LABEL}; use serde_json::{Value, json}; use std::{ @@ -195,7 +195,7 @@ async fn compiled_discovery_requires_runtime_metadata_but_allows_unknown_capabil ); assert!(tofu.is_absolute() && provider.is_absolute()); let document = - Document::parse(include_bytes!("../../../examples/onboarding/openclaw.yaml").as_slice()) + Document::parse(include_bytes!("../../../../examples/onboarding/openclaw.yaml").as_slice()) .unwrap(); let image = document.spec.sandboxes[0].image.ref_.clone(); let mode = Arc::new(AtomicUsize::new(0)); @@ -210,7 +210,7 @@ async fn compiled_discovery_requires_runtime_metadata_but_allows_unknown_capabil json!({"ID":"fixture", "Architecture":"arm64", "ServerVersion":"28.0", "OSType":"linux"}) } else { assert!(request.path.starts_with("/images/") && request.path.ends_with("/json")); - let mut catalog=nemoclaw_e2e::image_runtime::catalog(); + let mut catalog=crate::image_runtime::catalog(); match current.load(Ordering::SeqCst) { 1=>{ catalog.adapters.retain(|adapter|adapter.adapter_id()!="nvidia.fabric.openclaw"); diff --git a/crates/nemoclaw-e2e/tests/gateway_readiness.rs b/crates/nemoclaw-provider/tests/contract/gateway_readiness.rs similarity index 95% rename from crates/nemoclaw-e2e/tests/gateway_readiness.rs rename to crates/nemoclaw-provider/tests/contract/gateway_readiness.rs index 071fb64754c..bf22b28c773 100644 --- a/crates/nemoclaw-e2e/tests/gateway_readiness.rs +++ b/crates/nemoclaw-provider/tests/contract/gateway_readiness.rs @@ -2,7 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 #![cfg(unix)] -use nemoclaw_e2e::{http_fixture as docker, openshell::Fixture, tofu::TofuWorkspace}; +use crate::{http_fixture as docker, openshell::Fixture, tofu::TofuWorkspace}; use serde_json::{Value, json}; use std::{ fs, @@ -98,7 +98,7 @@ async fn managed_gateway_exit_preserves_bootstrap_state_and_allows_recovery_or_t &["apply", "-auto-approve", "-input=false", "-no-color"], true, ); - nemoclaw_e2e::assert_same_managed_resources(&fs::read(&state_path).unwrap(), &first); + crate::assert_same_managed_resources(&fs::read(&state_path).unwrap(), &first); assert!(gateway.state.lock().unwrap().health_reads > 0); assert!(gateway.state.lock().unwrap().gateway_reads > 0); running.store(false, Ordering::SeqCst); @@ -112,7 +112,7 @@ async fn managed_gateway_exit_preserves_bootstrap_state_and_allows_recovery_or_t false, ); assert!(started.elapsed() < Duration::from_secs(5)); - nemoclaw_e2e::assert_same_managed_resources(&fs::read(&state_path).unwrap(), &first); + crate::assert_same_managed_resources(&fs::read(&state_path).unwrap(), &first); graph.as_object_mut().unwrap().remove("data"); fs::write(root.join("main.tf.json"), graph.to_string()).unwrap(); run( diff --git a/crates/nemoclaw-e2e/tests/kubernetes_hcl.rs b/crates/nemoclaw-provider/tests/contract/kubernetes_hcl.rs similarity index 99% rename from crates/nemoclaw-e2e/tests/kubernetes_hcl.rs rename to crates/nemoclaw-provider/tests/contract/kubernetes_hcl.rs index 171fa1f0cbd..e11cd936992 100644 --- a/crates/nemoclaw-e2e/tests/kubernetes_hcl.rs +++ b/crates/nemoclaw-provider/tests/contract/kubernetes_hcl.rs @@ -2,7 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 //! Managed Kubernetes resources written in HCL, planned without a cluster. -use nemoclaw_e2e::tofu::TofuWorkspace; +use crate::tofu::TofuWorkspace; use serde_json::{Value, json}; use std::{fs, path::PathBuf}; diff --git a/crates/nemoclaw-provider/tests/contract/main.rs b/crates/nemoclaw-provider/tests/contract/main.rs new file mode 100644 index 00000000000..9e99c8217cc --- /dev/null +++ b/crates/nemoclaw-provider/tests/contract/main.rs @@ -0,0 +1,114 @@ +// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 +//! Contract tests: each nemoclaw type through pinned OpenTofu against fake +//! Docker engines, gateways, and model servers. `every_type_has_a_contract_test` +//! requires one for every type the provider serves. + +#[path = "../../../test-support/http.rs"] +mod http_fixture; +/// Fabric catalog fixtures shared with the end-to-end tests. +#[path = "../../../nemoclaw-e2e/src/image_runtime.rs"] +#[allow(dead_code)] +mod image_runtime; + +mod discovery; +mod gateway_readiness; +mod kubernetes_hcl; +// Providers launched by OpenTofu reach these fake engines over a Unix socket; +// Windows needs the SSH relay beside them first (#12943). +#[cfg(unix)] +mod runtime_image; +#[cfg(unix)] +mod service_storage; +#[cfg(unix)] +mod vllm_runtime; + +pub use nemoclaw_test_fixtures::{openshell, tofu}; + +/// Failed apply may record new data-source observations and condition +/// results; its managed resources and lineage must still be preserved. +pub fn assert_same_managed_resources(actual: &[u8], expected: &[u8]) { + fn managed(bytes: &[u8]) -> (String, Vec) { + let state: serde_json::Value = serde_json::from_slice(bytes).unwrap(); + let resources = state["resources"] + .as_array() + .unwrap() + .iter() + .filter(|resource| resource["mode"] == "managed") + .cloned() + .collect(); + (state["lineage"].as_str().unwrap().into(), resources) + } + assert_eq!(managed(actual), managed(expected)); +} + +/// Types still tested only outside this binary, and why. +const ELSEWHERE: [(&str, &str); 5] = [ + ( + "gateway_storage", + "nemoclaw-e2e managed and the live Docker gateway tests, which need Docker (#12879)", + ), + ( + "managed_gateway", + "nemoclaw-e2e provider_protocol, which needs that crate's fixture provider (#12878)", + ), + ( + "service_capacity", + "nemoclaw-e2e service_capacity, which needs that crate's SSH fixture (#12878)", + ), + ( + "service_readiness", + "nemoclaw-e2e service_readiness, which needs that crate's SSH fixture (#12878)", + ), + ( + "inference_capabilities", + "nemoclaw-e2e inference_discovery, only through SDK deployments (#12879)", + ), +]; + +/// Every resource and data source the provider serves appears in a contract +/// test, or in [`ELSEWHERE`] with the reason it is not here yet. +#[test] +fn every_type_has_a_contract_test() { + use tf_provider::Provider; + let provider = nemoclaw_provider::NemoClawProvider::default(); + let mut diagnostics = tf_provider::Diagnostics::default(); + let types: Vec = provider + .get_resources(&mut diagnostics) + .unwrap() + .into_keys() + .chain( + provider + .get_data_sources(&mut diagnostics) + .unwrap() + .into_keys(), + ) + .collect(); + let sources = [ + include_str!("discovery.rs"), + include_str!("gateway_readiness.rs"), + include_str!("kubernetes_hcl.rs"), + include_str!("runtime_image.rs"), + include_str!("service_storage.rs"), + include_str!("vllm_runtime.rs"), + ] + .concat(); + let missing: Vec<_> = types + .iter() + .filter(|kind| { + !sources.contains(&format!("nemoclaw_{kind}")) + && !sources.contains(&format!("\"{kind}\"")) + && !ELSEWHERE.iter().any(|(elsewhere, _)| elsewhere == kind) + }) + .collect(); + for (kind, _) in ELSEWHERE { + assert!( + !sources.contains(&format!("nemoclaw_{kind}\"")), + "{kind} has a contract test; remove it from ELSEWHERE" + ); + } + assert!( + missing.is_empty(), + "types without a contract test: {missing:?}" + ); +} diff --git a/crates/nemoclaw-e2e/tests/runtime_image.rs b/crates/nemoclaw-provider/tests/contract/runtime_image.rs similarity index 98% rename from crates/nemoclaw-e2e/tests/runtime_image.rs rename to crates/nemoclaw-provider/tests/contract/runtime_image.rs index 2b02ce241f6..4f8dd0af2f4 100644 --- a/crates/nemoclaw-e2e/tests/runtime_image.rs +++ b/crates/nemoclaw-provider/tests/contract/runtime_image.rs @@ -2,7 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 //! Authored runtime image checks through pinned OpenTofu. -use nemoclaw_e2e::{http_fixture::Fixture, tofu::TofuWorkspace}; +use crate::{http_fixture::Fixture, tofu::TofuWorkspace}; use nemoclaw_sdk::managed::{RUNTIME_SPEC_VERSION, RUNTIME_SPEC_VERSION_LABEL}; use serde_json::{Value, json}; use std::{ diff --git a/crates/nemoclaw-e2e/tests/service_storage.rs b/crates/nemoclaw-provider/tests/contract/service_storage.rs similarity index 99% rename from crates/nemoclaw-e2e/tests/service_storage.rs rename to crates/nemoclaw-provider/tests/contract/service_storage.rs index 4e5d28e26e8..9456d361aee 100644 --- a/crates/nemoclaw-e2e/tests/service_storage.rs +++ b/crates/nemoclaw-provider/tests/contract/service_storage.rs @@ -2,7 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 //! Authored HCL for retained service storage through pinned OpenTofu. -use nemoclaw_e2e::{http_fixture::Fixture, tofu::TofuWorkspace}; +use crate::{http_fixture::Fixture, tofu::TofuWorkspace}; use serde_json::{Value, json}; use std::{ collections::BTreeMap, diff --git a/crates/nemoclaw-e2e/tests/vllm_runtime.rs b/crates/nemoclaw-provider/tests/contract/vllm_runtime.rs similarity index 99% rename from crates/nemoclaw-e2e/tests/vllm_runtime.rs rename to crates/nemoclaw-provider/tests/contract/vllm_runtime.rs index e9f475b3f62..0522fc5aaab 100644 --- a/crates/nemoclaw-e2e/tests/vllm_runtime.rs +++ b/crates/nemoclaw-provider/tests/contract/vllm_runtime.rs @@ -2,7 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 //! Authored HCL for a vLLM container whose runtime contract the provider computes. -use nemoclaw_e2e::http_fixture::Fixture; +use crate::http_fixture::Fixture; use serde_json::{Value, json}; use std::{fs, path::PathBuf}; diff --git a/docs/contributing/integration-tests.md b/docs/contributing/integration-tests.md index ac10d9cdc89..68bcdbe21d9 100644 --- a/docs/contributing/integration-tests.md +++ b/docs/contributing/integration-tests.md @@ -17,7 +17,7 @@ Tests install `terraform-provider-openshell` and `terraform-provider-fabric` fro cargo build -p nemoclaw-provider -p openshell-provider -p fabric-provider NEMOCLAW_TEST_TOFU=/absolute/path/to/tofu \ NEMOCLAW_TEST_PROVIDER=/absolute/path/to/terraform-provider-nemoclaw \ - cargo test -p nemoclaw-e2e --test integration provider_protocol:: -- --ignored + cargo test -p nemoclaw-provider --test contract provider_protocol:: -- --ignored ``` These tests launch a fixture provider built by that crate and use temporary files. @@ -30,7 +30,7 @@ On Unix, run from the repository root to test combined service capacity through ```sh NEMOCLAW_TEST_TOFU=/absolute/path/to/tofu \ NEMOCLAW_TEST_PROVIDER=/absolute/path/to/terraform-provider-nemoclaw \ - cargo test -p nemoclaw-e2e --test integration service_capacity:: -- --ignored + cargo test -p nemoclaw-provider --test contract service_capacity:: -- --ignored ``` This fixture checks shared-host overcommit, deferred reads, preserved state after failed observations, and cleanup without capacity checks. @@ -74,6 +74,21 @@ The export fixture checks provider refresh failures through OpenTofu, unchanged The web-search lifecycle case covers Brave and Tavily at deployment, sandbox, and agent scope, including profile and sandbox-grant drift. The mixed-search export case checks shared registrations, unused definitions, export without search keys, unchanged reapply, and rejected provider-type or credential-reference drift without changes to saved state. +## NemoClaw Provider Contract + +The `nemoclaw-provider` crate's `contract` tests run its types through OpenTofu against fake Docker engines, gateways, and model servers: + +```sh +NEMOCLAW_TEST_TOFU=/absolute/path/to/tofu \ +NEMOCLAW_TEST_PROVIDER=/absolute/path/to/terraform-provider-nemoclaw \ +NEMOCLAW_TEST_BUNDLE=/absolute/path/to/bundle \ + cargo test -p nemoclaw-provider --test contract -- --ignored +``` + +They cover service storage, Kubernetes planning, runtime images and runtime contracts, gateway readiness, and engine and hardware discovery. +`every_type_has_a_contract_test` requires a contract test for every type the provider serves. +Its `ELSEWHERE` list names the types still tested only in `nemoclaw-e2e` and why: the managed gateway, service capacity, and service readiness tests need that crate's fixture binaries, gateway storage needs Docker, and inference capabilities are read only through SDK deployments. + ## OpenShell Provider Contract The `openshell-provider` crate's `contract` tests apply each fixture in `crates/openshell-provider/tests/contract/fixtures` through OpenTofu against a fake OpenShell gateway from `nemoclaw-test-fixtures`. @@ -127,7 +142,7 @@ On Unix, build the production provider as above and run from the repository root ```sh NEMOCLAW_TEST_TOFU=/absolute/path/to/tofu \ NEMOCLAW_TEST_PROVIDER=/absolute/path/to/terraform-provider-nemoclaw \ - cargo test -p nemoclaw-e2e --test integration service_readiness:: -- --ignored + cargo test -p nemoclaw-provider --test contract service_readiness:: -- --ignored ``` The fixture uses an isolated SSH/Docker simulator and a builtin OpenTofu consumer, without SDK deployment orchestration or a reachable OpenShell gateway. diff --git a/docs/design/fabric-management.md b/docs/design/fabric-management.md index 0453c9a01a8..f1f9f29c6f2 100644 --- a/docs/design/fabric-management.md +++ b/docs/design/fabric-management.md @@ -156,5 +156,5 @@ The [image command suite](../../image/test_agent_contract.py) exercises the same Its successful dummy health results do not qualify a real adapter’s native health or cleanup through OpenShell. The existing installed Fabric fixture adapter remains authored and packaged in Fabric. The separate dummy backend is authored in NemoClaw and exercises the image interface without Fabric. -The [discovery tests](../../crates/nemoclaw-e2e/tests/discovery.rs) read that installed discovery output and image metadata through the real OpenTofu/provider planner. +The [discovery tests](../../crates/nemoclaw-provider/tests/contract/discovery.rs) read that installed discovery output and image metadata through the real OpenTofu/provider planner. [Bundle fixtures](../contributing/integration-tests.md#opentofu-and-bundle-lifecycle) separately exercise deployment recovery, export/reapply and ownership.