Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
29 changes: 29 additions & 0 deletions e2e/cli/test_lock_resolution_failure
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env bash

export MISE_LOCKFILE=1

cat <<EOF >mise.toml
[tools]
dummy = "3.0.0"
EOF

cat <<EOF >mise.lock
$LOCKFILE_HEADER

[[tools.dummy]]
version = "1.0.0"
backend = "asdf:dummy"

[tools.dummy.platforms.linux-x64]
checksum = "sha256:old"
EOF

mise cache clear dummy

assert_fail_contains "RTX_FAILURE=1 mise lock dummy --platform linux-x64 2>&1" "failed to resolve"
assert_contains "cat mise.lock" 'version = "1.0.0"'
assert_not_contains "cat mise.lock" 'version = "3.0.0"'

assert_fail_contains "RTX_FAILURE=1 mise lock --platform linux-x64 2>&1" "failed to resolve"
assert_contains "cat mise.lock" 'version = "1.0.0"'
assert_not_contains "cat mise.lock" 'version = "3.0.0"'
60 changes: 42 additions & 18 deletions src/cli/lock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ use tokio::task::JoinSet;
/// A tool to lock for a specific lockfile target.
type LockTool = (crate::cli::args::BackendArg, crate::toolset::ToolVersion);

fn request_matches(a: &ToolRequest, b: &ToolRequest) -> bool {
a.version() == b.version() && a.options() == b.options()
}

/// Update lockfile checksums and URLs for all specified platforms
///
/// Updates checksums and download URLs for all platforms already specified in the lockfile.
Expand Down Expand Up @@ -108,7 +112,7 @@ impl Lock {
config_paths,
&lock_resolve_options,
)
.await;
.await?;

if tools.is_empty() {
// `tools` can be empty either because config has no tools, or because a filter excludes all.
Expand Down Expand Up @@ -505,7 +509,7 @@ impl Lock {
target_lockfile_path: &Path,
config_paths: &[PathBuf],
base_resolve_options: &ResolveOptions,
) -> Vec<LockTool> {
) -> Result<Vec<LockTool>> {
let config_paths_set: BTreeSet<&PathBuf> = config_paths.iter().collect();

let mut all_tools: Vec<LockTool> = Vec::new();
Expand Down Expand Up @@ -564,8 +568,7 @@ impl Lock {
let mut matched_resolved = false;
if let Some(resolved_tv) = ts.versions.get(ba.as_ref()) {
for tv in &resolved_tv.versions {
if tv.request.version() == request.version()
&& tv.request.options() == request.options()
if request_matches(&tv.request, request)
&& tv.version != "latest"
{
matched_resolved = true;
Expand All @@ -576,22 +579,36 @@ impl Lock {
}
}
}
let active_unresolved =
ts.versions.get(ba.as_ref()).is_some_and(|tvl| {
tvl.requests
.iter()
.any(|active| request_matches(active, request))
});
// Resolve overridden requests through the same path as active
// tools when the request cannot be copied from the resolved
// toolset. Keep this broad only for idiomatic version files;
// other sources preserve the previous latest-only behavior.
let should_resolve_overridden =
request.version() == "latest" || source.is_idiomatic_version_file();
let should_resolve_overridden = active_unresolved
|| request.version() == "latest"
|| source.is_idiomatic_version_file();
if !matched_resolved && should_resolve_overridden {
let mut resolve_options = match request
.resolve_options(base_resolve_options)
{
Ok(opts) => opts,
Err(err) => {
debug!("failed to resolve options for {request}: {err}");
continue;
}
};
let mut resolve_options =
match request.resolve_options(base_resolve_options) {
Ok(opts) => opts,
Err(err) => {
if active_unresolved {
return Err(err.wrap_err(format!(
"failed to resolve options for {request}"
)));
} else {
debug!(
"failed to resolve options for {request}: {err}"
);
continue;
}
Comment thread
greptile-apps[bot] marked this conversation as resolved.
Resolved
}
};
resolve_options.use_locked_version = false;
if resolve_options.before_date.is_some() {
resolve_options.latest_versions = true;
Expand All @@ -604,7 +621,14 @@ impl Lock {
}
}
Err(err) => {
debug!("failed to resolve overridden {request}: {err}");
if active_unresolved {
return Err(err.wrap_err(format!(
"failed to resolve {request} for lockfile {}",
display_path(target_lockfile_path)
)));
} else {
debug!("failed to resolve overridden {request}: {err}");
}
}
}
}
Expand All @@ -615,7 +639,7 @@ impl Lock {
}

if self.tool.is_empty() {
all_tools
Ok(all_tools)
} else {
// Build map of tool args with explicit versions
let specified_versions: std::collections::HashMap<String, Option<ToolRequest>> = self
Expand Down Expand Up @@ -671,7 +695,7 @@ impl Lock {
// Deduplicate after potential "latest" -> concrete-version resolution.
let mut seen_after: BTreeSet<(String, String)> = BTreeSet::new();
tools.retain(|(ba, tv)| seen_after.insert((ba.short.clone(), tv.version.clone())));
tools
Ok(tools)
}
}

Expand Down
Loading