diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-07-19 17:43:27 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-07-19 17:53:42 +0900 |
| commit | d0cd98cd212bc13cbcfd0fd97fc245329b57f50f (patch) | |
| tree | 21bc56941b9f26247026893a9667450e275d5096 /crates | |
| parent | 7e84d9ea31584e0dc04f04d14f6905ab9d978c72 (diff) | |
| download | php-shirabe-d0cd98cd212bc13cbcfd0fd97fc245329b57f50f.tar.gz php-shirabe-d0cd98cd212bc13cbcfd0fd97fc245329b57f50f.tar.zst php-shirabe-d0cd98cd212bc13cbcfd0fd97fc245329b57f50f.zip | |
fix(search-command): un-ignore test_search by fixing JSON output and abandoned propagation
The json format branch ignored search results entirely and always wrote
null. Encode results into the same name/description/abandoned/url shape
Composer's array-backed repositories produce. Also fix
ComposerRepository's RepositoryInterface::search adapter, which dropped
the abandoned field from raw API results even when present.
Diffstat (limited to 'crates')
| -rw-r--r-- | crates/shirabe/src/command/search_command.rs | 34 | ||||
| -rw-r--r-- | crates/shirabe/src/repository/composer_repository.rs | 7 | ||||
| -rw-r--r-- | crates/shirabe/tests/command/search_command_test.rs | 1 |
3 files changed, 36 insertions, 6 deletions
diff --git a/crates/shirabe/src/command/search_command.rs b/crates/shirabe/src/command/search_command.rs index 6709613c..1f77889e 100644 --- a/crates/shirabe/src/command/search_command.rs +++ b/crates/shirabe/src/command/search_command.rs @@ -11,7 +11,7 @@ use crate::plugin::PluginEvents; use crate::repository::CompositeRepository; use crate::repository::PlatformRepository; use crate::repository::RepositoryInterfaceHandle; -use crate::repository::repository_interface::{self, RepositoryInterface}; +use crate::repository::repository_interface::{self, AbandonedInfo, RepositoryInterface}; use indexmap::IndexMap; use shirabe_external_packages::symfony::console::command::command::Command; use shirabe_external_packages::symfony::console::formatter::OutputFormatter; @@ -259,9 +259,35 @@ impl Command for SearchCommand { // TODO(phase-c): faithful JSON output requires SearchResult to retain the raw result // array. PHP's fulltext search passes through arbitrary API fields (downloads, favers, // repository, ...) which the typed SearchResult (name/description/abandoned/url) drops, - // so encoding it here would diverge from Composer's output. - let _ = &results; - io.write(&JsonFile::encode(&PhpMixed::Null)); + // so ComposerRepository-sourced results still diverge from Composer's raw JSON output. + let rows: Vec<PhpMixed> = results + .into_iter() + .map(|result| { + let mut entry = IndexMap::new(); + entry.insert("name".to_string(), PhpMixed::String(result.name)); + entry.insert( + "description".to_string(), + result + .description + .map(PhpMixed::String) + .unwrap_or(PhpMixed::Null), + ); + if let Some(abandoned) = result.abandoned { + entry.insert( + "abandoned".to_string(), + match abandoned { + AbandonedInfo::Replacement(s) => PhpMixed::String(s), + AbandonedInfo::Abandoned => PhpMixed::Bool(true), + }, + ); + } + if let Some(url) = result.url { + entry.insert("url".to_string(), PhpMixed::String(url)); + } + PhpMixed::Array(entry) + }) + .collect(); + io.write(&JsonFile::encode(&PhpMixed::List(rows))); } Ok(0) diff --git a/crates/shirabe/src/repository/composer_repository.rs b/crates/shirabe/src/repository/composer_repository.rs index 54edc39a..580667b5 100644 --- a/crates/shirabe/src/repository/composer_repository.rs +++ b/crates/shirabe/src/repository/composer_repository.rs @@ -3575,7 +3575,12 @@ impl RepositoryInterface for ComposerRepository { .get("description") .and_then(|v| v.as_string()) .map(|s| s.to_string()), - abandoned: None, + abandoned: m.get("abandoned").filter(|v| v.to_bool()).map(|v| { + match v.as_string() { + Some(s) => crate::repository::AbandonedInfo::Replacement(s.to_string()), + None => crate::repository::AbandonedInfo::Abandoned, + } + }), url: m .get("url") .and_then(|v| v.as_string()) diff --git a/crates/shirabe/tests/command/search_command_test.rs b/crates/shirabe/tests/command/search_command_test.rs index 69f2930c..7806ea0f 100644 --- a/crates/shirabe/tests/command/search_command_test.rs +++ b/crates/shirabe/tests/command/search_command_test.rs @@ -36,7 +36,6 @@ fn run_search_case(command: Vec<(PhpMixed, PhpMixed)>, expected: &str) { #[test] #[serial] -#[ignore = "searching a `package`-type repo returns incomplete results (some matching packages are dropped); the search/repository path is not yet fully ported"] fn test_search() { // 'by name and description' run_search_case( |
