Skip to content
15 changes: 10 additions & 5 deletions src/nix_bundle_write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,8 @@ fn repack_planned_artifact(requested_root: &Path, plan: &NixExportPlan) -> Resul
let bytes = fs::read(&packed.path)
.with_context(|| format!("reading repacked artifact {}", packed.path.display()))?;
let actual_sha256 = hex::encode(Sha256::digest(&bytes));
if actual_sha256 != plan.source.artifact.sha256 || bytes.len() as u64 != plan.source.artifact.size
if actual_sha256 != plan.source.artifact.sha256
|| bytes.len() as u64 != plan.source.artifact.size
{
bail!(
"deterministic repack does not match frozen Nix export plan (expected {} bytes at {}, got {} bytes at {})",
Expand Down Expand Up @@ -589,17 +590,21 @@ mod tests {
#[test]
fn augmented_command_contains_plan_and_bundle_write() {
let command = augment_root_command(crate::nix_export_plan::augment_root_command(
crate::fetch::augment_root_command(
crate::dev::augment_root_command(crate::cli::Cli::command()),
),
crate::fetch::augment_root_command(crate::dev::augment_root_command(
crate::cli::Cli::command(),
)),
));
let interop = command.find_subcommand("interop").unwrap();
let nix = interop.find_subcommand("nix").unwrap();
assert!(nix.find_subcommand("plan").is_some());
let bundle = nix.find_subcommand("bundle").unwrap();
let write = bundle.find_subcommand("write").unwrap();
for option in ["frozen", "target", "flake_lock", "out", "json"] {
assert!(write.get_arguments().any(|argument| argument.get_id() == option));
assert!(
write
.get_arguments()
.any(|argument| argument.get_id() == option)
);
}
}

Expand Down
7 changes: 1 addition & 6 deletions tests/nix_bundle_write_boundaries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,7 @@ outputs = ["out"]
fs::write(root.join("data/value.txt"), b"immutable payload\n").unwrap();
}

fn run_bundle(
cwd: &Path,
lock: &Path,
output: &Path,
additional_env: &[(&str, &str)],
) -> Output {
fn run_bundle(cwd: &Path, lock: &Path, output: &Path, additional_env: &[(&str, &str)]) -> Output {
let mut command = Command::new(zed());
command
.current_dir(cwd)
Expand Down
17 changes: 6 additions & 11 deletions tests/nix_bundle_write_cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,7 @@ fn command_creates_idempotent_no_clobber_bundle_from_nested_directory() {
first_receipt["destination"],
canonical_bundle.to_string_lossy().as_ref()
);
assert_eq!(
first_receipt["bundle_sha256"].as_str().unwrap().len(),
64
);
assert_eq!(first_receipt["bundle_sha256"].as_str().unwrap().len(), 64);
assert_bundle_shape(&bundle);
assert_eq!(snapshot(&project), project_before);
let bundle_before = snapshot(&bundle);
Expand All @@ -190,7 +187,10 @@ fn command_creates_idempotent_no_clobber_bundle_from_nested_directory() {
assert!(second.status.success(), "{}", stderr(&second));
let second_receipt: Value = serde_json::from_str(stdout(&second).trim()).unwrap();
assert_eq!(second_receipt["outcome"], "already-current");
assert_eq!(first_receipt["bundle_sha256"], second_receipt["bundle_sha256"]);
assert_eq!(
first_receipt["bundle_sha256"],
second_receipt["bundle_sha256"]
);
assert_eq!(snapshot(&bundle), bundle_before);

fs::write(bundle.join("README.md"), b"tampered\n").unwrap();
Expand Down Expand Up @@ -357,12 +357,7 @@ fn persisted_command_bundle_checks_and_builds_offline() {
"--print-out-paths",
".#dataset",
]);
nix(&[
"flake",
"check",
"--offline",
"--no-update-lock-file",
]);
nix(&["flake", "check", "--offline", "--no-update-lock-file"]);
let replay = nix(&[
"build",
"--offline",
Expand Down