Files
lix/tests/functional2/build/test_import_from_derivation.py
T
piegamesandeldritch horrors 567348a90c testlib: default nix fixture to also test all daemon protocols (2/3)
This commit enables the parametrization for "legacy-combined" protocol.
All failing tests with that have been either fixed or disabled. Notably:

- A couple of tests (e.g. involving builders) could be made to work with
a non-local store, but this would require some refactoring to testlib in
order to make certain configuration settings generic over local and
remote operations. We've disabled those for now, in order to make
progress
- The store tests all run locally only because of their nature
- The flakes tests also all run locally only because my energy for
fixing them is limited (and it's a *lot* of test failures, with probably
little overall benefit in terms of test coverage)

Change-Id: I56fa249a64f7c17c952f688ec89e9687f2a13f12
2026-06-28 18:17:57 +02:00

112 lines
3.3 KiB
Python

from collections.abc import Callable
from testlib.fixtures.file_helper import AssetSymlink, CopyFile, with_files
from testlib.fixtures.nix import Nix
from testlib.fixtures.snapshot import Snapshot
from testlib.utils import get_global_asset
import re
def filter_output(nix: Nix, output: str) -> str:
# Replace store hashes with something fixed, and also strip all daemon warnings about untrusted user settings
return re.sub(
r"(?m)^warning:.*trusted user.*\n?",
"",
re.sub(
r"/nix/store/[0-9a-z]{32}",
"/nix/store/hashfilteredforrepeatableoutputs",
output.replace(nix.env.dirs.test_root.as_posix(), ""),
),
)
@with_files(
{
"import-derivation.nix": CopyFile(
"assets/test_import_from_derivation/import-derivation.nix"
),
"config.nix": get_global_asset("config.nix"),
"error": AssetSymlink("assets/test_import_from_derivation/warn-ifd.err.exp"),
}
)
def test_warn_ifd(nix: Nix, snapshot: Callable[[str], Snapshot]):
error = (
nix.nix_build(
[
"./import-derivation.nix",
"--no-out-link",
*["--option", "warn-import-from-derivation", "true"],
]
)
.run()
.ok()
.stderr_plain
)
assert snapshot("error") == filter_output(nix, error)
@with_files(
{
"import-derivation.nix": CopyFile(
"assets/test_import_from_derivation/import-derivation.nix"
),
"config.nix": get_global_asset("config.nix"),
"error": AssetSymlink("assets/test_import_from_derivation/deny-ifd.err.exp"),
}
)
def test_deny_ifd(nix: Nix, snapshot: Callable[[str], Snapshot]):
error = (
nix.nix_build(
[
"./import-derivation.nix",
"--no-out-link",
*["--option", "allow-import-from-derivation", "false"],
]
)
.run()
.expect(1)
.stderr_plain
)
assert snapshot("error") == filter_output(nix, error)
@with_files(
{
"import-derivation.nix": CopyFile(
"assets/test_import_from_derivation/import-derivation.nix"
),
"config.nix": get_global_asset("config.nix"),
"error": AssetSymlink("assets/test_import_from_derivation/allow-ifd.err.exp"),
}
)
def test_allow_ifd(nix: Nix, snapshot: Callable[[str], Snapshot]):
build = nix.nix_build(["./import-derivation.nix", "--no-out-link"]).run().ok()
error = build.stderr_plain
out_path = build.stdout_plain
assert nix.physical_store_path_for(out_path).read_text() == "FOO579"
assert snapshot("error") == filter_output(nix, error)
@with_files(
{
"import-derivation.nix": CopyFile(
"assets/test_import_from_derivation/import-derivation.nix"
),
"config.nix": get_global_asset("config.nix"),
"error": AssetSymlink(
"assets/test_import_from_derivation/instantiate-ifd-readonly-fail.err.exp"
),
}
)
def test_instantiate_ifd_readonly_fail(nix: Nix, snapshot: Callable[[str], Snapshot]):
error = (
nix.nix_instantiate(["--readonly-mode", "./import-derivation.nix"])
.run()
.expect(1)
.stderr_plain
)
assert snapshot("error") == filter_output(nix, error)