From 17eaacb139029f481ff821768c386061886c7059 Mon Sep 17 00:00:00 2001 From: Florian Klink Date: Sun, 24 Dec 2023 23:46:03 +0200 Subject: feat(tvix/glue): add test for output path calculation This test serves as a minimal reproducer for output path calculation. Derivations with the same name and output hash, but different build recipe should end up with the same outPath. However derivations with different name should end up with a different outPath. Change-Id: I555be59dd87ea675a0816188ed973f96c311e4e1 Reviewed-on: https://cl.tvl.fyi/c/depot/+/10416 Autosubmit: flokli Reviewed-by: tazjin Reviewed-by: sterni Tested-by: BuildkiteCI --- tvix/glue/src/builtins/mod.rs | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'tvix/glue') diff --git a/tvix/glue/src/builtins/mod.rs b/tvix/glue/src/builtins/mod.rs index 6ae99ba14759..455fdbd0fc37 100644 --- a/tvix/glue/src/builtins/mod.rs +++ b/tvix/glue/src/builtins/mod.rs @@ -143,6 +143,42 @@ mod tests { ); } + /// Construct two FODs with the same name, and same known output (but + /// slightly different recipe), ensure they have the same output hash. + #[test] + fn test_fod_outpath() { + let code = r#" + (builtins.derivation { name = "foo"; builder = "/bin/sh"; system = "x86_64-linux"; outputHash = "sha256-Q3QXOoy+iN4VK2CflvRulYvPZXYgF0dO7FoF7CvWFTA="; }).outPath == + (builtins.derivation { name = "foo"; builder = "/bin/aa"; system = "x86_64-linux"; outputHash = "sha256-Q3QXOoy+iN4VK2CflvRulYvPZXYgF0dO7FoF7CvWFTA="; }).outPath + "#; + + let value = eval(code).value.expect("must succeed"); + match value { + tvix_eval::Value::Bool(v) => { + assert!(v); + } + _ => panic!("unexpected value type: {:?}", value), + } + } + + /// Construct two FODs with the same name, and same known output (but + /// slightly different recipe), ensure they have the same output hash. + #[test] + fn test_fod_outpath_different_name() { + let code = r#" + (builtins.derivation { name = "foo"; builder = "/bin/sh"; system = "x86_64-linux"; outputHash = "sha256-Q3QXOoy+iN4VK2CflvRulYvPZXYgF0dO7FoF7CvWFTA="; }).outPath == + (builtins.derivation { name = "foo"; builder = "/bin/aa"; system = "x86_64-linux"; outputHash = "sha256-Q3QXOoy+iN4VK2CflvRulYvPZXYgF0dO7FoF7CvWFTA="; }).outPath + "#; + + let value = eval(code).value.expect("must succeed"); + match value { + tvix_eval::Value::Bool(v) => { + assert!(v); + } + _ => panic!("unexpected value type: {:?}", value), + } + } + /// Construct two derivations with the same parameters except /// one of them lost a context string for a dependency, causing /// the loss of an element in the `inputDrvs` derivation. -- cgit 1.4.1