From f20a342ecb96734418d0817f841ea14fd9a448e3 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Fri, 8 May 2026 21:17:07 +0900 Subject: fix(diagnose): align with Composer's DiagnoseCommand orchestration Restructures diagnose to mirror Composer's 17-step DiagnoseCommand: adds composer.json schema validation, custom composer-repo connectivity, COMPOSER_IPRESOLVE warning, and the checkConnectivityAndComposerNetworkHttpEnablement preflight; drops Mozart-only extras (cache-dir, lock freshness, trailing summary). Extracts the manifest validator into mozart-core::config_validator so both ValidateCommand and DiagnoseCommand depend on the shared module rather than each other -- the same shape Composer uses with Util\\ConfigValidator. Adds a thin HttpDownloader wrapper in mozart-core::http, shadowing Composer's Util\\HttpDownloader. Co-Authored-By: Claude Opus 4.7 (1M context) --- crates/mozart/src/commands/diagnose.rs | 890 +++++++++++++-------------------- 1 file changed, 359 insertions(+), 531 deletions(-) (limited to 'crates/mozart/src/commands/diagnose.rs') diff --git a/crates/mozart/src/commands/diagnose.rs b/crates/mozart/src/commands/diagnose.rs index 8ea2098..fd2297a 100644 --- a/crates/mozart/src/commands/diagnose.rs +++ b/crates/mozart/src/commands/diagnose.rs @@ -2,295 +2,216 @@ use clap::Args; use colored::Colorize; use mozart_core::MOZART_VERSION; use mozart_core::composer::Composer; +use mozart_core::config::Config; +use mozart_core::config_validator::{ValidatorOptions, validate_manifest}; use mozart_core::console::Console; use mozart_core::console_writeln; use mozart_core::factory::create_config; +use mozart_core::http::HttpDownloader; use std::borrow::Cow; -use std::path::{Path, PathBuf}; +use std::path::Path; #[derive(Args)] pub struct DiagnoseArgs {} +/// Result of a single check, mirroring the `string|true|string[]|\Exception` +/// shape of `Composer\Command\DiagnoseCommand`'s private `checkX` methods. enum CheckResult { - /// OK, with optional detail string. + /// `OK` with optional detail string. Equivalent to PHP `true`. Ok(Option), - /// WARNING + message. - Warning(String), - /// FAIL + message. - Fail(String), - /// SKIP + reason. + /// `WARNING` + message lines. + Warning(Vec), + /// `FAIL` + message lines. + Fail(Vec), + /// `SKIP` + reason. Composer emits this inline for the + /// `allow_url_fopen` / `COMPOSER_DISABLE_NETWORK` cases via the same + /// `outputResult` path. Skip(String), - /// Informational line (no pass/fail prefix). - Info(String), } -/// Print "Checking {label}: OK/WARNING/FAIL/SKIP" and ratchet exit_code. +impl CheckResult { + fn ok() -> Self { + CheckResult::Ok(None) + } + + fn ok_with(detail: impl Into) -> Self { + CheckResult::Ok(Some(detail.into())) + } + + fn warn(msg: impl Into) -> Self { + CheckResult::Warning(vec![msg.into()]) + } + + fn fail(msg: impl Into) -> Self { + CheckResult::Fail(vec![msg.into()]) + } +} + +/// Mirror of `DiagnoseCommand::outputResult`. Writes the leading +/// `Checking