aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/mozart/src/commands/update.rs
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-05-02 18:04:29 +0900
committernsfisis <nsfisis@gmail.com>2026-05-02 18:04:29 +0900
commit33fe16285acbed1f5146c2d746eba2295bd57688 (patch)
tree0df8f83fd9e95e87406e350ce48816451b6d07af /crates/mozart/src/commands/update.rs
parent82501a36a0fa6725d656742da42c860e75a89b89 (diff)
parentc446337e75ba9fd674dd63d56ec25d7bd5b5fa31 (diff)
downloadphp-mozart-33fe16285acbed1f5146c2d746eba2295bd57688.tar.gz
php-mozart-33fe16285acbed1f5146c2d746eba2295bd57688.tar.zst
php-mozart-33fe16285acbed1f5146c2d746eba2295bd57688.zip
Merge branch 'test/di'
Diffstat (limited to 'crates/mozart/src/commands/update.rs')
-rw-r--r--crates/mozart/src/commands/update.rs59
1 files changed, 44 insertions, 15 deletions
diff --git a/crates/mozart/src/commands/update.rs b/crates/mozart/src/commands/update.rs
index b58155e..b4a3246 100644
--- a/crates/mozart/src/commands/update.rs
+++ b/crates/mozart/src/commands/update.rs
@@ -720,17 +720,38 @@ fn major_minor(version: &str) -> (u64, u64) {
// Main execute function
// ─────────────────────────────────────────────────────────────────────────────
+/// CLI entry point. Builds production [`RepositorySet`] (Packagist) and
+/// [`FilesystemExecutor`] from `cli`, then dispatches to [`run`].
pub async fn execute(
args: &UpdateArgs,
cli: &super::Cli,
console: &mozart_core::console::Console,
) -> anyhow::Result<()> {
let cache_config = mozart_registry::cache::build_cache_config(cli.no_cache);
- let repo_cache = mozart_registry::cache::Cache::repo(&cache_config);
-
- // Step 1: Resolve the working directory
+ let repositories =
+ std::sync::Arc::new(mozart_registry::repository::RepositorySet::with_packagist(
+ mozart_registry::cache::Cache::repo(&cache_config),
+ ));
+ let mut executor = mozart_registry::installer_executor::FilesystemExecutor::new(
+ mozart_registry::cache::Cache::files(&cache_config),
+ );
let working_dir = super::install::resolve_working_dir(cli);
+ run(&working_dir, args, console, repositories, &mut executor).await
+}
+/// Library entry point — pure logic, no CLI / Cli access.
+///
+/// In-process tests construct a `RepositorySet` without `PackagistRepository`
+/// (Composer's `'packagist' => false` test config) and a tracing
+/// `InstallerExecutor`, then call this function directly to exercise the
+/// update flow without spawning the binary.
+pub async fn run(
+ working_dir: &std::path::Path,
+ args: &UpdateArgs,
+ console: &mozart_core::console::Console,
+ repositories: std::sync::Arc<mozart_registry::repository::RepositorySet>,
+ executor: &mut dyn mozart_registry::installer_executor::InstallerExecutor,
+) -> anyhow::Result<()> {
// Step 2: Handle deprecated flags
if args.dev {
console.info(&console_format!(
@@ -863,9 +884,9 @@ pub async fn execute(
platform: PlatformConfig::new(),
ignore_platform_reqs: args.ignore_platform_reqs,
ignore_platform_req_list: args.ignore_platform_req.clone(),
- repo_cache: repo_cache.clone(),
+ repositories: repositories.clone(),
temporary_constraints,
- repositories: composer_json.repositories.clone(),
+ raw_repositories: composer_json.repositories.clone(),
};
// Step 6: Print header and run resolver
@@ -1021,7 +1042,7 @@ pub async fn execute(
composer_json_content: composer_json_content.clone(),
composer_json: composer_json.clone(),
include_dev: dev_mode,
- repo_cache: repo_cache.clone(),
+ repositories: repositories.clone(),
})
.await?;
@@ -1220,7 +1241,7 @@ pub async fn execute(
super::install::install_from_lock(
&new_lock,
- &working_dir,
+ working_dir,
&vendor_dir,
&super::install::InstallConfig {
dev_mode,
@@ -1235,9 +1256,9 @@ pub async fn execute(
apcu_autoloader_prefix: args.apcu_autoloader_prefix.clone(),
download_only: false,
prefer_source,
- no_cache: cli.no_cache,
},
console,
+ executor,
)
.await?;
}
@@ -1960,12 +1981,16 @@ mod tests {
platform: PlatformConfig::new(),
ignore_platform_reqs: false,
ignore_platform_req_list: vec![],
- repo_cache: mozart_registry::cache::Cache::new(
- std::env::temp_dir().join("mozart-test-cache"),
- false,
+ repositories: std::sync::Arc::new(
+ mozart_registry::repository::RepositorySet::with_packagist(
+ mozart_registry::cache::Cache::new(
+ std::env::temp_dir().join("mozart-test-cache"),
+ false,
+ ),
+ ),
),
temporary_constraints: HashMap::new(),
- repositories: vec![],
+ raw_repositories: vec![],
};
let resolved = resolve(&request).await.expect("Resolution should succeed");
@@ -1977,9 +2002,13 @@ mod tests {
composer_json_content: composer_json_content.to_string(),
composer_json,
include_dev: false,
- repo_cache: mozart_registry::cache::Cache::new(
- std::env::temp_dir().join("mozart-test-cache"),
- false,
+ repositories: std::sync::Arc::new(
+ mozart_registry::repository::RepositorySet::with_packagist(
+ mozart_registry::cache::Cache::new(
+ std::env::temp_dir().join("mozart-test-cache"),
+ false,
+ ),
+ ),
),
})
.await