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
29 changes: 2 additions & 27 deletions crates/nemoclaw-sdk/tests/deployment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,11 @@
// SPDX-License-Identifier: Apache-2.0

use nemoclaw_sdk::{
CancellationToken, Deployment, Error, ObservationError, Progress, Secrets,
bundle::{Bundle, Manifest, hash_file, required_files},
compile::OPENTOFU_VERSION,
CancellationToken, Deployment, Error, ObservationError, Progress, Secrets, bundle::Bundle,
config::Document,
};
use std::{
fs,
path::Path,
sync::{
Arc, Mutex,
atomic::{AtomicUsize, Ordering},
Expand All @@ -31,28 +28,6 @@ async fn invalid_programmatic_configuration_cannot_create_deployment_state() {
assert!(!state.exists());
}

/// A bundle whose hashes verify, so opening it succeeds. Its files cannot
/// execute, so no operation that reaches OpenTofu can do anything.
fn write_bundle(directory: &Path) {
let mut manifest = Manifest {
version: "0.1.0".into(),
rust: "1.98.1".into(),
opentofu: OPENTOFU_VERSION.into(),
files: Default::default(),
};
for name in required_files(&manifest.version).unwrap() {
let path = directory.join(&name);
fs::create_dir_all(path.parent().unwrap()).unwrap();
fs::write(&path, b"non-executable fixture").unwrap();
manifest.files.insert(name, hash_file(&path).unwrap());
}
fs::write(
directory.join("manifest.json"),
serde_json::to_vec(&manifest).unwrap(),
)
.unwrap();
}

#[derive(Default)]
struct CountingSecrets(AtomicUsize);
impl Secrets for CountingSecrets {
Expand All @@ -67,7 +42,7 @@ async fn a_document_that_fails_validation_is_rejected_before_the_bundle_opens_or
{
let directory = tempfile::tempdir().unwrap();
let bundle = directory.path().join("bundle");
write_bundle(&bundle);
crate::bundle::write_bundle(&bundle, None);
assert!(Bundle::open(&bundle).is_ok(), "the bundle must be valid");
let document = Document::default();
let mut defaulted = document.clone();
Expand Down
2 changes: 2 additions & 0 deletions crates/nemoclaw-sdk/tests/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
//! SDK integration tests, linked into one binary so the SDK links once.
//! Each file is a module; helpers under support/ are shared by all of them.

#[path = "support/bundle.rs"]
mod bundle;
#[path = "support/examples.rs"]
mod examples;
#[cfg(unix)]
Expand Down
48 changes: 48 additions & 0 deletions crates/nemoclaw-sdk/tests/support/bundle.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
//! Bundles that verify without a build, for tests that open one.

use nemoclaw_sdk::{
bundle::{Manifest, executable, hash_file, required_files},
compile::OPENTOFU_VERSION,
};
use std::{fs, path::Path};

/// Write a bundle whose hashes verify, so opening it succeeds. With `tofu`,
/// `libexec/tofu` is that shell script; every other file cannot execute, so
/// without it no operation that reaches OpenTofu can do anything. The SDK
/// requires `rust` to be non-empty and `version` to be a semantic version, so
/// these values need not match the toolchain or the workspace version.
pub fn write_bundle(directory: &Path, tofu: Option<&str>) {
let mut manifest = Manifest {
version: "0.1.0".into(),
rust: "1.98.1".into(),
opentofu: OPENTOFU_VERSION.into(),
files: Default::default(),
};
let tofu_file = format!("libexec/{}", executable("tofu"));
for name in required_files(&manifest.version).unwrap() {
let path = directory.join(&name);
fs::create_dir_all(path.parent().unwrap()).unwrap();
match tofu.filter(|_| name == tofu_file) {
Some(script) => write_script(&path, script),
None => fs::write(&path, b"non-executable fixture").unwrap(),
}
manifest.files.insert(name, hash_file(&path).unwrap());
}
fs::write(
directory.join("manifest.json"),
serde_json::to_vec(&manifest).unwrap(),
)
.unwrap();
}

#[cfg(unix)]
fn write_script(path: &Path, script: &str) {
crate::executable::write_executable(path, script);
}

#[cfg(not(unix))]
fn write_script(_: &Path, _: &str) {
panic!("a scripted tofu needs a Unix shell");
}
35 changes: 2 additions & 33 deletions crates/nemoclaw-sdk/tests/support/scripted_tofu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@

use nemoclaw_sdk::{
CancellationToken, Deployment, ObservationError, Progress, Secrets, StepOutcome,
bundle::{Manifest, executable, hash_file, required_files},
compile::{Generations, OPENTOFU_VERSION, Target},
compile::{Generations, Target},
config::Document,
kubernetes::{GATEWAY_KIND, STORAGE_KIND, gateway::ADDRESS as HELM_RELEASE},
};
Expand Down Expand Up @@ -62,36 +61,6 @@ case "$1" in
esac
"##;

/// A bundle whose files verify; only `libexec/tofu` can execute. Adapted from
/// `deployment.rs::write_bundle`, which keeps its own copy because it also runs
/// on Windows. The SDK requires `rust` to be non-empty and `version` to be a
/// semantic version, so these values need not match the toolchain or the
/// workspace version.
fn write_bundle(directory: &Path, script: &str) {
let mut manifest = Manifest {
version: "0.1.0".into(),
rust: "1.98.1".into(),
opentofu: OPENTOFU_VERSION.into(),
files: Default::default(),
};
let tofu = format!("libexec/{}", executable("tofu"));
for name in required_files(&manifest.version).unwrap() {
let path = directory.join(&name);
fs::create_dir_all(path.parent().unwrap()).unwrap();
if name == tofu {
crate::executable::write_executable(&path, script);
} else {
fs::write(&path, b"non-executable fixture").unwrap();
}
manifest.files.insert(name, hash_file(&path).unwrap());
}
fs::write(
directory.join("manifest.json"),
serde_json::to_vec(&manifest).unwrap(),
)
.unwrap();
}

/// A temporary bundle with a scripted `tofu`, a control directory, and the path
/// of a state directory that `Deployment` creates. A test creates one.
pub struct Scripted {
Expand Down Expand Up @@ -121,7 +90,7 @@ impl Scripted {
let script = SCRIPT
.replace("@CONTROL@", &quoted(scripted.control()))
.replace("@STATE@", &quoted(scripted.state()));
write_bundle(&scripted.bundle(), &script);
crate::bundle::write_bundle(&scripted.bundle(), Some(&script));
scripted
}

Expand Down