Skip to content
Merged
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
41 changes: 40 additions & 1 deletion src/backend/static_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,13 @@ pub fn list_available_platforms_with_key(opts: &ToolVersionOptions, key_type: &s
.or_else(|| k.strip_prefix("platform_"))
{
if let Some(platform_part) = rest.strip_suffix(&format!("_{}", key_type)) {
let platform_key = platform_part.replace('_', "-");
// Only convert the OS/arch separator underscore to a dash, preserving
// underscores inside architecture names like x86_64
let platform_key = if let Some((os_part, rest)) = platform_part.split_once('_') {
format!("{os_part}-{rest}")
Comment on lines +139 to +140
Copy link

Copilot AI Sep 5, 2025

Choose a reason for hiding this comment

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

The logic assumes only one OS/arch separator underscore, but this could incorrectly handle platform parts like 'linux_musl_x86_64' where 'musl' is part of the OS identifier. The current implementation would produce 'linux-musl_x86_64' instead of the potentially expected 'linux-musl-x86_64' or preserve the original format.

Suggested change
let platform_key = if let Some((os_part, rest)) = platform_part.split_once('_') {
format!("{os_part}-{rest}")
let platform_key = if let Some(idx) = platform_part.rfind('_') {
let (os_part, arch_part) = platform_part.split_at(idx);
// os_part ends at idx, arch_part starts with '_'
format!("{}-{}", os_part, &arch_part[1..])

Copilot uses AI. Check for mistakes.
} else {
platform_part.to_string()
};
set.insert(platform_key);
}
}
Expand Down Expand Up @@ -528,6 +534,39 @@ mod tests {
assert_eq!(clean_binary_name("", None), "");
}

#[test]
fn test_list_available_platforms_with_key_flat_preserves_arch_underscore() {
let mut opts = IndexMap::new();
// Flat keys with os_arch_keytype naming
opts.insert(
"platforms_macos_x86_64_url".to_string(),
"https://example.com/macos-x86_64.tar.gz".to_string(),
);
opts.insert(
"platforms_linux_x64_url".to_string(),
"https://example.com/linux-x64.tar.gz".to_string(),
);
// Different prefix variant also supported
opts.insert(
"platform_windows_arm64_url".to_string(),
"https://example.com/windows-arm64.zip".to_string(),
);

let tool_opts = ToolVersionOptions {
opts,
..Default::default()
};

let platforms = list_available_platforms_with_key(&tool_opts, "url");

// Should convert only the OS/arch separator underscore to dash
assert!(platforms.contains(&"macos-x86_64".to_string()));
assert!(!platforms.contains(&"macos-x86-64".to_string()));

assert!(platforms.contains(&"linux-x64".to_string()));
assert!(platforms.contains(&"windows-arm64".to_string()));
}

#[test]
fn test_verify_artifact_platform_specific() {
let mut opts = IndexMap::new();
Expand Down
Loading