From e91996a31f732bd5116defc58ee5661a17501981 Mon Sep 17 00:00:00 2001 From: Julian Hofer Date: Tue, 22 Jul 2025 16:48:37 +0200 Subject: [PATCH 1/3] Verify that backend environment solving use the pixi config --- .../pixi_build/config-pickup-test/pixi.toml | 21 +++++++ .../pixi_build/config-pickup-test/recipe.yaml | 6 ++ .../integration_python/test_config_pickup.py | 55 +++++++++++++++++++ 3 files changed, 82 insertions(+) create mode 100644 tests/data/pixi_build/config-pickup-test/pixi.toml create mode 100644 tests/data/pixi_build/config-pickup-test/recipe.yaml create mode 100644 tests/integration_python/test_config_pickup.py diff --git a/tests/data/pixi_build/config-pickup-test/pixi.toml b/tests/data/pixi_build/config-pickup-test/pixi.toml new file mode 100644 index 0000000..8008f81 --- /dev/null +++ b/tests/data/pixi_build/config-pickup-test/pixi.toml @@ -0,0 +1,21 @@ +[workspace] +channels = ["https://prefix.dev/conda-forge"] +platforms = ["win-64", "linux-64", "osx-arm64", "osx-64"] +preview = ["pixi-build"] + +[dependencies] +simple-config-test = { path = "." } + +[tasks] +start = "simple-config-test" + +[package] +name = "simple-config-test" +version = "0.1.0" + +[package.build] +backend = { name = "pixi-build-rattler-build", version = "*" } +channels = [ + "https://prefix.dev/pixi-build-backends", + "https://prefix.dev/conda-forge", +] diff --git a/tests/data/pixi_build/config-pickup-test/recipe.yaml b/tests/data/pixi_build/config-pickup-test/recipe.yaml new file mode 100644 index 0000000..531e13b --- /dev/null +++ b/tests/data/pixi_build/config-pickup-test/recipe.yaml @@ -0,0 +1,6 @@ +package: + name: simple-config-test + version: "0.1.0" + +build: + noarch: generic diff --git a/tests/integration_python/test_config_pickup.py b/tests/integration_python/test_config_pickup.py new file mode 100644 index 0000000..1d7f7c1 --- /dev/null +++ b/tests/integration_python/test_config_pickup.py @@ -0,0 +1,55 @@ +import shutil +from pathlib import Path + +from .common import ExitCode, verify_cli_command + + +def test_config_pickup_by_build_backends( + pixi: Path, build_data: Path, tmp_pixi_workspace: Path +) -> None: + """ + Test that pixi build backends pick up config from .pixi/config.toml. + + First tests with working config, then verifies the config is actually + being used by checking the log output for mirror usage. + """ + # Copy our test workspace + test_data = build_data.joinpath("config-pickup-test") + target_dir = tmp_pixi_workspace.joinpath("config-pickup-test") + shutil.copytree(test_data, target_dir) + + manifest_path = target_dir.joinpath("pixi.toml") + + # First test: should work without config + verify_cli_command( + [ + pixi, + "install", + "-v", + "--manifest-path", + manifest_path, + ], + ) + + # Create .pixi/config.toml with mirror that redirects to broken URL + pixi_dir = target_dir.joinpath(".pixi") + shutil.rmtree(pixi_dir) + pixi_dir.mkdir() + config_content = """[mirrors] +# redirect pixi-build-backends channel to a broken URL +"https://prefix.dev/pixi-build-backends" = ["https://broken.mirror.url"] +""" + pixi_dir.joinpath("config.toml").write_text(config_content) + + # Second test: should fail if the backend picks up the config + # because the mirror redirects to a broken URL and pixi install needs to resolve the backend + verify_cli_command( + [ + pixi, + "install", + "-v", + "--manifest-path", + manifest_path, + ], + expected_exit_code=ExitCode.FAILURE, + ) From 582a439221ea646cacef4729817fe094f05e0bb2 Mon Sep 17 00:00:00 2001 From: Julian Hofer Date: Wed, 23 Jul 2025 10:35:09 +0200 Subject: [PATCH 2/3] Finish up failing test --- .../pixi_build/config-pickup-test/pixi.toml | 7 +-- .../pixi_build/config-pickup-test/recipe.yaml | 22 +++++++- .../integration_python/test_config_pickup.py | 50 ++++++------------- 3 files changed, 38 insertions(+), 41 deletions(-) diff --git a/tests/data/pixi_build/config-pickup-test/pixi.toml b/tests/data/pixi_build/config-pickup-test/pixi.toml index 8008f81..f559a84 100644 --- a/tests/data/pixi_build/config-pickup-test/pixi.toml +++ b/tests/data/pixi_build/config-pickup-test/pixi.toml @@ -1,5 +1,5 @@ [workspace] -channels = ["https://prefix.dev/conda-forge"] +channels = [] platforms = ["win-64", "linux-64", "osx-arm64", "osx-64"] preview = ["pixi-build"] @@ -15,7 +15,4 @@ version = "0.1.0" [package.build] backend = { name = "pixi-build-rattler-build", version = "*" } -channels = [ - "https://prefix.dev/pixi-build-backends", - "https://prefix.dev/conda-forge", -] +channels = ["https://broken.url/conda-forge"] diff --git a/tests/data/pixi_build/config-pickup-test/recipe.yaml b/tests/data/pixi_build/config-pickup-test/recipe.yaml index 531e13b..3f295d4 100644 --- a/tests/data/pixi_build/config-pickup-test/recipe.yaml +++ b/tests/data/pixi_build/config-pickup-test/recipe.yaml @@ -1,6 +1,24 @@ package: name: simple-config-test - version: "0.1.0" + version: 0.1.0 + +source: + path: . build: - noarch: generic + number: 0 + script: + - if: win + then: + - mkdir -p %PREFIX%\bin + - echo @echo off > %PREFIX%\bin\simple-config-test.bat + - echo echo Build backend works >> %PREFIX%\bin\simple-config-test.bat + else: + - mkdir -p $PREFIX/bin + - echo "#!/usr/bin/env bash" > $PREFIX/bin/simple-config-test + - echo "echo Build backend works" >> $PREFIX/bin/simple-config-test + - chmod +x $PREFIX/bin/simple-config-test + +requirements: + host: + - fd-find diff --git a/tests/integration_python/test_config_pickup.py b/tests/integration_python/test_config_pickup.py index 1d7f7c1..3fd2c5a 100644 --- a/tests/integration_python/test_config_pickup.py +++ b/tests/integration_python/test_config_pickup.py @@ -1,7 +1,10 @@ import shutil from pathlib import Path -from .common import ExitCode, verify_cli_command +import tomli_w +import tomllib + +from .common import verify_cli_command def test_config_pickup_by_build_backends( @@ -15,41 +18,20 @@ def test_config_pickup_by_build_backends( """ # Copy our test workspace test_data = build_data.joinpath("config-pickup-test") - target_dir = tmp_pixi_workspace.joinpath("config-pickup-test") - shutil.copytree(test_data, target_dir) + shutil.copytree(test_data, tmp_pixi_workspace, dirs_exist_ok=True) - manifest_path = target_dir.joinpath("pixi.toml") + manifest_path = tmp_pixi_workspace.joinpath("pixi.toml") - # First test: should work without config - verify_cli_command( - [ - pixi, - "install", - "-v", - "--manifest-path", - manifest_path, - ], - ) + # Create .pixi/config.toml with mirror that redirects from the broken URL to our backends channel + pixi_dir = tmp_pixi_workspace.joinpath(".pixi") + config_path = pixi_dir.joinpath("config.toml") + config = tomllib.loads(config_path.read_text()) + config["mirrors"] = { + "https://broken.url/conda-forge": ["https://prefix.dev/conda-forge"], + } + config_path.write_text(tomli_w.dumps(config)) - # Create .pixi/config.toml with mirror that redirects to broken URL - pixi_dir = target_dir.joinpath(".pixi") - shutil.rmtree(pixi_dir) - pixi_dir.mkdir() - config_content = """[mirrors] -# redirect pixi-build-backends channel to a broken URL -"https://prefix.dev/pixi-build-backends" = ["https://broken.mirror.url"] -""" - pixi_dir.joinpath("config.toml").write_text(config_content) - - # Second test: should fail if the backend picks up the config - # because the mirror redirects to a broken URL and pixi install needs to resolve the backend verify_cli_command( - [ - pixi, - "install", - "-v", - "--manifest-path", - manifest_path, - ], - expected_exit_code=ExitCode.FAILURE, + [pixi, "run", "-v", "--manifest-path", manifest_path, "start"], + stdout_contains="Build backend works", ) From a53723eb5228f77fd6bc4f5f84396488c24d2100 Mon Sep 17 00:00:00 2001 From: Julian Hofer Date: Wed, 23 Jul 2025 10:48:16 +0200 Subject: [PATCH 3/3] Small improvement --- tests/data/pixi_build/config-pickup-test/recipe.yaml | 3 --- 1 file changed, 3 deletions(-) diff --git a/tests/data/pixi_build/config-pickup-test/recipe.yaml b/tests/data/pixi_build/config-pickup-test/recipe.yaml index 3f295d4..8626923 100644 --- a/tests/data/pixi_build/config-pickup-test/recipe.yaml +++ b/tests/data/pixi_build/config-pickup-test/recipe.yaml @@ -2,9 +2,6 @@ package: name: simple-config-test version: 0.1.0 -source: - path: . - build: number: 0 script: