Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions e2e/cli/test_test_tool_clean
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/usr/bin/env bash

set -euxo pipefail

# Test 1: Verify test-tool cleans existing installations before running
echo "=== Test 1: Clean existing installations ==="

# Install multiple versions first
mise install shellcheck@0.9.0
mise install shellcheck@0.10.0

# Verify both versions are installed
mise ls shellcheck | grep "0.9.0"
mise ls shellcheck | grep "0.10.0"
[ -d "$MISE_DATA_DIR/installs/shellcheck/0.9.0" ]
[ -d "$MISE_DATA_DIR/installs/shellcheck/0.10.0" ]

# Create a marker file to verify directories are cleaned
touch "$MISE_DATA_DIR/installs/shellcheck/marker.txt"
touch "$MISE_CACHE_DIR/shellcheck/marker.txt" 2>/dev/null || true

# Run test-tool which should clean everything first and succeed
mise test-tool shellcheck

# Verify the marker files are gone (directories were cleaned)
if [ -f "$MISE_DATA_DIR/installs/shellcheck/marker.txt" ]; then
echo "ERROR: installs directory was not cleaned"
exit 1
fi

# Verify test-tool installed the latest version
mise ls shellcheck | grep -E "0\.[0-9]+\.[0-9]+"
[ -d "$MISE_DATA_DIR/installs/shellcheck" ]

# Test 2: Verify cache directory is cleaned
echo "=== Test 2: Cache directory cleaning ==="

# Create cache content
mkdir -p "$MISE_CACHE_DIR/shellcheck"
echo "cached data" >"$MISE_CACHE_DIR/shellcheck/test.cache"

# Run test-tool again
mise test-tool shellcheck

# Verify cache was cleaned and recreated
[ -d "$MISE_CACHE_DIR/shellcheck" ]
if [ -f "$MISE_CACHE_DIR/shellcheck/test.cache" ]; then
echo "ERROR: cache directory was not cleaned"
exit 1
fi

echo "Test passed: test-tool correctly cleans all directories before installing"
40 changes: 40 additions & 0 deletions src/cli/test_tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,46 @@ impl TestTool {
cmd: &str,
expected: &str,
) -> Result<()> {
// First, clean all backend data by removing directories
let pr = crate::ui::multi_progress_report::MultiProgressReport::get()
.add(&format!("cleaning {}", tool.short));

let mut cleaned_any = false;

// Remove entire installs directory for this tool
if tool.ba.installs_path.exists() {
info!(
"Removing installs directory: {}",
tool.ba.installs_path.display()
);
file::remove_all(&tool.ba.installs_path)?;
cleaned_any = true;
}

// Clear cache directory (contains metadata)
if tool.ba.cache_path.exists() {
info!("Removing cache directory: {}", tool.ba.cache_path.display());
file::remove_all(&tool.ba.cache_path)?;
cleaned_any = true;
}

// Clear downloads directory
if tool.ba.downloads_path.exists() {
info!(
"Removing downloads directory: {}",
tool.ba.downloads_path.display()
);
file::remove_all(&tool.ba.downloads_path)?;
cleaned_any = true;
}

pr.finish();

// Reset the config to clear in-memory backend metadata caches if we cleaned anything
if cleaned_any {
*config = Config::reset().await?;
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Cleanup Fails, Report Incomplete

The cleanup logic only removes directories for the main tool, not its dependencies, which can lead to inconsistent test states. Also, if any directory removal fails, the progress report's finish() method is skipped, leaving the report unfinished and potentially causing UI issues.

Fix in Cursor Fix in Web


let mut args = vec![tool.clone()];
args.extend(
tool.ba
Expand Down
Loading