From 8da98493daf5013585e07ec98ca6960a42924edf Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sat, 2 May 2026 22:21:25 +0900 Subject: feat(resolver): add branch-alias support across the resolution pipeline MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Plumb Composer's `extra.branch-alias` mechanism end-to-end so a dev branch (e.g. `dev-foobar`) can be installed alongside its numeric alias (e.g. `3.2.x-dev`) and resolve constraints written against the alias target. Concretely: - `mozart-semver`: stop treating pure-numeric `-dev` as a wildcard branch — `3.2.9999999.9999999-dev` (the form `normalizeBranch` emits) now parses as a classical version with `is_dev_branch=false`, so constraints like `3.2.*` match it. - `mozart-registry/composer_repo`: load `type: composer` repositories from `file://` URLs (legacy embedded `packages.json`). - `mozart-registry/resolver`: emit pool entries in pairs for dev branches with `extra.branch-alias`, link them via `is_alias_of`, and apply `@dev`/`@beta` etc. stability suffix flags from root requires. - `mozart-sat-resolver`: alias rules (`PackageAlias` / `PackageInverseAlias`) so alias and target install together; alias packages skipped from same-name conflict indexing. - `mozart-sat-resolver/policy`: `DefaultPolicy` now honors `prefer_stable` via Composer's stability-tier comparison. - `mozart-registry/lockfile`: split resolved set into real packages vs. alias entries; populate the `aliases[]` block. - `mozart-registry/installer_executor`: new `MarkAliasInstalled` operation; `format_full_pretty_version` mirroring `BasePackage::getFullPrettyVersion` (appends source ref[0..7] for dev/git packages). - Test harness rewrites fixture-relative `file://` URLs to absolute paths. Newly green fixtures: `install_branch_alias_composer_repo`, `alias_solver_problems`, `alias_solver_problems2`, `conflict_with_all_dependencies_option_dont_recommend_to_use_it`, `unbounded_conflict_does_not_match_default_branch_with_branch_alias`, `unbounded_conflict_does_not_match_default_branch_with_numeric_branch`. Co-Authored-By: Claude Opus 4.7 (1M context) --- crates/mozart/src/commands/install.rs | 16 +++++++++ crates/mozart/src/commands/update.rs | 1 + crates/mozart/tests/installer.rs | 67 ++++++++++++++++++++++++++--------- 3 files changed, 67 insertions(+), 17 deletions(-) (limited to 'crates/mozart') diff --git a/crates/mozart/src/commands/install.rs b/crates/mozart/src/commands/install.rs index 356d622..9555ba7 100644 --- a/crates/mozart/src/commands/install.rs +++ b/crates/mozart/src/commands/install.rs @@ -670,6 +670,22 @@ pub async fn install_from_lock( } }; executor.install_package(op, &exec_ctx).await?; + + // After the target install/update, emit MarkAliasInstalled for any + // aliases whose `package`+`version` (the target's pretty version) + // match. Mirrors Composer's `Transaction::calculateOperations` DFS + // which pushes alias targets first and emits MarkAliasInstalled + // when the alias itself is processed. + for alias in &lock.aliases { + if alias.package.eq_ignore_ascii_case(&pkg.name) && alias.version == pkg.version { + executor + .install_package( + PackageOperation::MarkAliasInstalled { alias, target: pkg }, + &exec_ctx, + ) + .await?; + } + } } // Step 8: Write updated vendor/composer/installed.json (unless download_only) diff --git a/crates/mozart/src/commands/update.rs b/crates/mozart/src/commands/update.rs index 9ac2664..847ccf7 100644 --- a/crates/mozart/src/commands/update.rs +++ b/crates/mozart/src/commands/update.rs @@ -1370,6 +1370,7 @@ mod tests { version: version.to_string(), version_normalized: format!("{}.0", version), is_dev: false, + alias_of_normalized: None, } } diff --git a/crates/mozart/tests/installer.rs b/crates/mozart/tests/installer.rs index 173418a..d674485 100644 --- a/crates/mozart/tests/installer.rs +++ b/crates/mozart/tests/installer.rs @@ -25,6 +25,47 @@ fn fixtures_dir() -> PathBuf { .join("../../composer/tests/Composer/Test/Fixtures/installer") } +/// Rewrite `file://foobar` URLs in COMPOSER content to absolute fixture +/// paths. Mirrors `composer/tests/Composer/Test/InstallerTest.php:540-542`: +/// when a fixture's repository entry uses a relative `file://` URL, anchor +/// it to the fixtures directory so the on-disk `packages.json` is reachable. +fn rewrite_fixture_file_urls(input: &str) -> String { + let fixtures = fixtures_dir(); + let canonical = fixtures + .canonicalize() + .unwrap_or(fixtures) + .display() + .to_string() + .replace('\\', "/"); + // Match `"file://X"` where X does not start with `/` — those are the + // fixture-relative form. Absolute URLs (`file:///abs/...`) are passed + // through. + let mut out = String::with_capacity(input.len()); + let mut rest = input; + while let Some(idx) = rest.find("file://") { + out.push_str(&rest[..idx]); + let after = &rest[idx + "file://".len()..]; + let first_byte = after.as_bytes().first().copied(); + if first_byte == Some(b'/') { + out.push_str("file://"); + rest = after; + continue; + } + // Read the rest of the URL until a `"` or whitespace. + let end = after + .find(|c: char| c == '"' || c.is_whitespace()) + .unwrap_or(after.len()); + let target = &after[..end]; + out.push_str("file://"); + out.push_str(&canonical); + out.push('/'); + out.push_str(target); + rest = &after[end..]; + } + out.push_str(rest); + out +} + struct InProcessRunResult { _working_dir: TempDir, trace: Vec, @@ -37,7 +78,8 @@ async fn run_fixture_in_process(test: &ParsedTest) -> anyhow::Result