Skip to content

Commit

Permalink
fix: global update
Browse files Browse the repository at this point in the history
  • Loading branch information
nichmor committed Nov 21, 2024
1 parent 903284a commit 13a5a90
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/global/trampoline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,10 @@ impl Trampoline {
}

async fn write_trampoline(&self) -> miette::Result<()> {
if !self.trampoline_path().exists() {
// We need to check whether the trampoline binary is already saved and it have the trampoline content
if !self.trampoline_path().exists()
|| !Trampoline::is_trampoline(&self.trampoline_path()).await?
{
tokio_fs::create_dir_all(self.root_path.join(TRAMPOLINE_CONFIGURATION))
.await
.into_diagnostic()?;
Expand Down
71 changes: 71 additions & 0 deletions tests/integration_python/global/test_trampoline.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json
import os
import pathlib
from pathlib import Path
import platform
Expand Down Expand Up @@ -158,3 +159,73 @@ def test_trampoline_dot_in_exe(pixi: Path, tmp_path: Path, trampoline_channel_1:
exe_test = tmp_path / "bin" / exec_extension("exe.test")
# The binary execute should succeed
verify_cli_command([exe_test], stdout_contains="Success:")


def test_trampoline_migrate_with_newer_trampoline(
pixi: Path, tmp_path: Path, trampoline_channel_1: str
) -> None:
# this test will validate if new trampoline will migrate the older trampoline
env = {"PIXI_HOME": str(tmp_path)}

# create a dummy bin that will act as already installed package
dummy_trampoline = tmp_path / "bin" / exec_extension("dummy-trampoline")
os.makedirs(dummy_trampoline.parent, exist_ok=True)
dummy_trampoline.write_text("hello")

# now run install again, this time it should migrate the script to the new trampoline
verify_cli_command(
[
pixi,
"global",
"install",
"--channel",
trampoline_channel_1,
"dummy-trampoline",
],
env=env,
)

assert dummy_trampoline.is_file()
assert is_binary(dummy_trampoline)

dummy_trampoline_json = tmp_path / "bin" / "trampoline_configuration" / "dummy-trampoline.json"

assert dummy_trampoline_json.is_file()
# run an update, it should say that everything is up to date
verify_cli_command(
[
pixi,
"global",
"update",
],
env=env,
stderr_contains="Environment dummy-trampoline was already up-to-date",
stderr_excludes="Updated executable dummy-trampoline of environment dummy-trampoline",
)

# now change the trampoline binary , and verify that it will install newever
dummy_trampoline.unlink()
dummy_trampoline.write_bytes(b"new content")

# run an update again it should remove the old trampoline and install the new one
verify_cli_command(
[
pixi,
"global",
"update",
],
env=env,
stderr_contains="Updated executable dummy-trampoline of environment dummy-trampoline",
)

# run an update again
verify_cli_command(
[
pixi,
"global",
"update",
],
env=env,
stderr_contains="Environment dummy-trampoline was already up-to-date",
stderr_excludes="Updated executable dummy-trampoline of environment dummy-trampoline",
)

0 comments on commit 13a5a90

Please sign in to comment.