From e7af8e0d62603f5fdf85307dc57b2c9599aa1936 Mon Sep 17 00:00:00 2001 From: Ryan Lahfa Date: Mon, 25 Mar 2024 01:25:19 +0100 Subject: feat(tvix/eval): implement `appendContext` `appendContext s ctx` will just append a user-crafted context attrs to `s`. The most important part of this builtin is to perform all the relevant invariant validations to avoid letting the user craft invalid contexts which can never be built, e.g. invalid store paths, inexistent derivations, etc. This version is incomplete and full of TODOs, but passes all the Nix's context strings tests, so we turn them on. Change-Id: I625dc5e7c4f5b784f078b390f04b0ee5a8d65a7c Signed-off-by: Ryan Lahfa Reviewed-on: https://cl.tvl.fyi/c/depot/+/11263 Reviewed-by: flokli Tested-by: BuildkiteCI --- tvix/glue/src/tests/mod.rs | 16 +++++---- .../nix_tests/eval-okay-context-introspection.exp | 1 + .../nix_tests/eval-okay-context-introspection.nix | 42 ++++++++++++++++++++++ .../eval-okay-context-introspection.exp | 1 - .../eval-okay-context-introspection.nix | 42 ---------------------- 5 files changed, 53 insertions(+), 49 deletions(-) create mode 100644 tvix/glue/src/tests/nix_tests/eval-okay-context-introspection.exp create mode 100644 tvix/glue/src/tests/nix_tests/eval-okay-context-introspection.nix delete mode 100644 tvix/glue/src/tests/nix_tests/notyetpassing/eval-okay-context-introspection.exp delete mode 100644 tvix/glue/src/tests/nix_tests/notyetpassing/eval-okay-context-introspection.nix (limited to 'tvix/glue') diff --git a/tvix/glue/src/tests/mod.rs b/tvix/glue/src/tests/mod.rs index 469ed17a51..e66f484e3d 100644 --- a/tvix/glue/src/tests/mod.rs +++ b/tvix/glue/src/tests/mod.rs @@ -134,9 +134,13 @@ fn nix_eval_okay(#[files("src/tests/nix_tests/eval-okay-*.nix")] code_path: Path // notyetpassing; this makes the test suite much more useful for // regression testing, since there should always be zero non-ignored // failing tests. -#[rstest] -fn nix_eval_okay_currently_failing( - #[files("src/tests/nix_tests/notyetpassing/eval-okay-*.nix")] code_path: PathBuf, -) { - eval_test(code_path, false) -} +// +// NOTE: There's no such test anymore. `rstest` does not handle empty directories, so, we +// just comment it for now. +// +// #[rstest] +// fn nix_eval_okay_currently_failing( +// #[files("src/tests/nix_tests/notyetpassing/eval-okay-*.nix")] code_path: PathBuf, +// ) { +// eval_test(code_path, false) +// } diff --git a/tvix/glue/src/tests/nix_tests/eval-okay-context-introspection.exp b/tvix/glue/src/tests/nix_tests/eval-okay-context-introspection.exp new file mode 100644 index 0000000000..03b400cc88 --- /dev/null +++ b/tvix/glue/src/tests/nix_tests/eval-okay-context-introspection.exp @@ -0,0 +1 @@ +[ true true true true true true ] diff --git a/tvix/glue/src/tests/nix_tests/eval-okay-context-introspection.nix b/tvix/glue/src/tests/nix_tests/eval-okay-context-introspection.nix new file mode 100644 index 0000000000..354376b895 --- /dev/null +++ b/tvix/glue/src/tests/nix_tests/eval-okay-context-introspection.nix @@ -0,0 +1,42 @@ +let + drv = derivation { + name = "fail"; + builder = "/bin/false"; + system = "x86_64-linux"; + outputs = [ "out" "foo" ]; + }; + + path = "${./eval-okay-context-introspection.nix}"; + + desired-context = { + "${builtins.unsafeDiscardStringContext path}" = { + path = true; + }; + "${builtins.unsafeDiscardStringContext drv.drvPath}" = { + outputs = [ "foo" "out" ]; + allOutputs = true; + }; + }; + + combo-path = "${path}${drv.outPath}${drv.foo.outPath}${drv.drvPath}"; + legit-context = builtins.getContext combo-path; + + reconstructed-path = builtins.appendContext + (builtins.unsafeDiscardStringContext combo-path) + desired-context; + + # Eta rule for strings with context. + etaRule = str: + str == builtins.appendContext + (builtins.unsafeDiscardStringContext str) + (builtins.getContext str); + +in +[ + (legit-context == desired-context) + (reconstructed-path == combo-path) + (etaRule "foo") + (etaRule drv.drvPath) + (etaRule drv.foo.outPath) + (etaRule (builtins.unsafeDiscardOutputDependency drv.drvPath)) +] diff --git a/tvix/glue/src/tests/nix_tests/notyetpassing/eval-okay-context-introspection.exp b/tvix/glue/src/tests/nix_tests/notyetpassing/eval-okay-context-introspection.exp deleted file mode 100644 index 03b400cc88..0000000000 --- a/tvix/glue/src/tests/nix_tests/notyetpassing/eval-okay-context-introspection.exp +++ /dev/null @@ -1 +0,0 @@ -[ true true true true true true ] diff --git a/tvix/glue/src/tests/nix_tests/notyetpassing/eval-okay-context-introspection.nix b/tvix/glue/src/tests/nix_tests/notyetpassing/eval-okay-context-introspection.nix deleted file mode 100644 index 354376b895..0000000000 --- a/tvix/glue/src/tests/nix_tests/notyetpassing/eval-okay-context-introspection.nix +++ /dev/null @@ -1,42 +0,0 @@ -let - drv = derivation { - name = "fail"; - builder = "/bin/false"; - system = "x86_64-linux"; - outputs = [ "out" "foo" ]; - }; - - path = "${./eval-okay-context-introspection.nix}"; - - desired-context = { - "${builtins.unsafeDiscardStringContext path}" = { - path = true; - }; - "${builtins.unsafeDiscardStringContext drv.drvPath}" = { - outputs = [ "foo" "out" ]; - allOutputs = true; - }; - }; - - combo-path = "${path}${drv.outPath}${drv.foo.outPath}${drv.drvPath}"; - legit-context = builtins.getContext combo-path; - - reconstructed-path = builtins.appendContext - (builtins.unsafeDiscardStringContext combo-path) - desired-context; - - # Eta rule for strings with context. - etaRule = str: - str == builtins.appendContext - (builtins.unsafeDiscardStringContext str) - (builtins.getContext str); - -in -[ - (legit-context == desired-context) - (reconstructed-path == combo-path) - (etaRule "foo") - (etaRule drv.drvPath) - (etaRule drv.foo.outPath) - (etaRule (builtins.unsafeDiscardOutputDependency drv.drvPath)) -] -- cgit 1.4.1