Skip to content

Commit 2a3d8cf

Browse files
committed
Fix remote manifest aggregate counts to use unique locators
1 parent e362796 commit 2a3d8cf

File tree

1 file changed

+80
-3
lines changed

1 file changed

+80
-3
lines changed

packages/zpm/src/report.rs

Lines changed: 80 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,6 @@ pub enum ReportMessage {
181181

182182
#[derive(Debug, Default)]
183183
struct RemoteManifestErrorAggregate {
184-
count: u32,
185184
locators: BTreeSet<String>,
186185
}
187186

@@ -330,7 +329,13 @@ impl Reporter {
330329
let mut entries = self.remote_manifest_errors
331330
.iter()
332331
.map(|((origin, path, reason), aggregate)| {
333-
(origin.clone(), path.clone(), reason.clone(), aggregate.count, aggregate.locators.clone())
332+
(
333+
origin.clone(),
334+
path.clone(),
335+
reason.clone(),
336+
aggregate.locators.len() as u32,
337+
aggregate.locators.clone(),
338+
)
334339
})
335340
.collect::<Vec<_>>();
336341

@@ -394,7 +399,6 @@ impl Reporter {
394399
.entry((origin, path, reason))
395400
.or_default();
396401

397-
aggregate.count += 1;
398402
aggregate.locators.insert(locator);
399403
}
400404

@@ -680,3 +684,76 @@ impl StreamReport {
680684
self.handle.join().unwrap();
681685
}
682686
}
687+
688+
#[cfg(test)]
689+
mod tests {
690+
use std::sync::Arc;
691+
692+
use super::{ReportCounters, Reporter, StreamReportConfig};
693+
694+
fn new_reporter() -> Reporter {
695+
let (prompt_tx, _prompt_rx) = std::sync::mpsc::channel();
696+
697+
Reporter::new(
698+
StreamReportConfig {
699+
enable_progress_bars: false,
700+
enable_timers: false,
701+
include_version: false,
702+
silent_or_error: false,
703+
},
704+
Arc::new(ReportCounters::default()),
705+
prompt_tx,
706+
)
707+
}
708+
709+
#[test]
710+
fn remote_manifest_summary_counts_unique_locators() {
711+
let mut reporter = new_reporter();
712+
713+
reporter.on_remote_manifest_parse(
714+
"sass-embedded-linux-x64@npm:1.97.3".to_string(),
715+
"npm registry metadata".to_string(),
716+
"package.json".to_string(),
717+
"type mismatch: expected a sequence, got string \"glibc\" (line 1 column 1672)".to_string(),
718+
);
719+
reporter.on_remote_manifest_parse(
720+
"sass-embedded-linux-x64@npm:1.97.3".to_string(),
721+
"npm registry metadata".to_string(),
722+
"package.json".to_string(),
723+
"type mismatch: expected a sequence, got string \"glibc\" (line 1 column 1672)".to_string(),
724+
);
725+
726+
let mut output = Vec::new();
727+
reporter.on_end(&mut output);
728+
let output = String::from_utf8(output).expect("report output should be valid utf8");
729+
730+
assert!(output.contains("Invalid package metadata in package.json (npm registry metadata): type mismatch: expected a sequence, got string \"glibc\" (line 1 column 1672)"));
731+
assert!(!output.contains("2 packages have invalid package metadata"));
732+
}
733+
734+
#[test]
735+
fn remote_manifest_hidden_count_uses_unique_locator_count() {
736+
let mut reporter = new_reporter();
737+
738+
for locator in [
739+
"sass-embedded-linux-x64@npm:1.97.3",
740+
"sass-embedded-linux-x64@npm:1.97.3",
741+
"sass-embedded-linux-arm64@npm:1.97.3",
742+
"sass-embedded-linux-arm64@npm:1.97.3",
743+
] {
744+
reporter.on_remote_manifest_parse(
745+
locator.to_string(),
746+
"npm registry metadata".to_string(),
747+
"package.json".to_string(),
748+
"type mismatch: expected a sequence, got string \"glibc\" (line 1 column 1672)".to_string(),
749+
);
750+
}
751+
752+
let mut output = Vec::new();
753+
reporter.on_end(&mut output);
754+
let output = String::from_utf8(output).expect("report output should be valid utf8");
755+
756+
assert!(output.contains("2 packages have invalid package metadata in package.json (npm registry metadata):"));
757+
assert!(!output.contains("(+2 more)"));
758+
}
759+
}

0 commit comments

Comments
 (0)