From 2a680f571eae31737525ef96105e929ae420b061 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sun, 3 May 2026 22:26:55 +0900 Subject: fix(resolver): strip inline #ref and gate alias trace on alias stability Two related parity gaps surfaced by the `alias-with-reference` fixture: 1. A root require like `dev-main#abcd as 1.0.0` left the SAT-side constraint as `dev-main#abcd`, which no candidate matched, so resolution failed before the alias could be materialized. Mirror Composer's `extractAliases` regex (which captures only the constraint up to `#`) and `RootPackageLoader::extractReferences` (which records the hash separately): drop the trailing `#hex` from the resolver-side constraint and from the alias's left-hand side. Lockfile generation already pulls the reference back out of the raw require map for the post-resolve override. 2. `MarkAliasInstalled`'s trace line gated the reference suffix on the *target* package's stability, so a stable alias like `1.0.0` pointing at a dev-branch target rendered as `1.0.0 abcd`. Mirror `AliasPackage::getFullPrettyVersion`: the alias decides on its own whether to append the suffix based on its own normalized version, so a stable alias skips the suffix even when the target is dev. --- .../mozart-registry/src/installer_executor/mod.rs | 24 ++++++++++++++++++++++ .../src/installer_executor/trace_recorder.rs | 7 ++++--- 2 files changed, 28 insertions(+), 3 deletions(-) (limited to 'crates/mozart-registry/src/installer_executor') diff --git a/crates/mozart-registry/src/installer_executor/mod.rs b/crates/mozart-registry/src/installer_executor/mod.rs index c344ba4..c29e32c 100644 --- a/crates/mozart-registry/src/installer_executor/mod.rs +++ b/crates/mozart-registry/src/installer_executor/mod.rs @@ -110,6 +110,30 @@ pub fn format_full_pretty_with_pretty(pretty_version: &str, pkg: &LockedPackage) ) } +/// Render an alias's full pretty version: the alias's own pretty form for +/// the visible text, the alias's *normalized* version for the dev-stability +/// gate, and the target package's source/dist references for the suffix. +/// Mirrors `AliasPackage::getFullPrettyVersion`, where the alias decides on +/// its own whether to append a reference based on its own stability — so a +/// stable alias like `1.0.0` skips the suffix even when the target is a dev +/// branch. +pub fn format_full_pretty_alias( + alias_pretty: &str, + alias_version: &str, + target: &LockedPackage, +) -> String { + let source_ref = target.source.as_ref().and_then(|s| s.reference.as_deref()); + let dist_ref = target.dist.as_ref().and_then(|d| d.reference.as_deref()); + let source_type = target.source.as_ref().map(|s| s.source_type.as_str()); + format_full_pretty_with_refs( + alias_pretty, + alias_version, + source_ref, + dist_ref, + source_type, + ) +} + /// Same as [`format_full_pretty_version_for_installed`] but lets the caller /// supply an alternate pretty version. Used when emitting /// `MarkAliasUninstalled`: the alias's `1.0.x-dev` text needs to be rendered diff --git a/crates/mozart-registry/src/installer_executor/trace_recorder.rs b/crates/mozart-registry/src/installer_executor/trace_recorder.rs index 159d854..b60a869 100644 --- a/crates/mozart-registry/src/installer_executor/trace_recorder.rs +++ b/crates/mozart-registry/src/installer_executor/trace_recorder.rs @@ -17,8 +17,8 @@ use mozart_semver::Version; use super::{ - ExecuteContext, InstallerExecutor, PackageOperation, format_full_pretty_version, - format_full_pretty_with_pretty, + ExecuteContext, InstallerExecutor, PackageOperation, format_full_pretty_alias, + format_full_pretty_version, }; /// Recording-only executor. Construct with [`TraceRecorderExecutor::new`], @@ -84,7 +84,8 @@ impl InstallerExecutor for TraceRecorderExecutor { )); } PackageOperation::MarkAliasInstalled { alias, target } => { - let alias_full = format_full_pretty_with_pretty(&alias.alias, target); + let alias_full = + format_full_pretty_alias(&alias.alias, &alias.alias_normalized, target); let target_full = format_full_pretty_version(target); self.trace.push(format!( "Marking {} ({}) as installed, alias of {} ({})", -- cgit v1.3.1