From db0a461bbb1c16bccf86ae57637d5b2e50fa7d29 Mon Sep 17 00:00:00 2001 From: Harnoor Lal Date: Sun, 8 Mar 2026 19:42:06 -0700 Subject: [PATCH] fix(report): rename DiffPackageEntry.size to total_size_bytes Aligns DiffPackageEntry field names with PackageEntry and PackageListEntry conventions. All package-type report structs now use total_size_bytes for the same semantic data. Fixes #149 --- src/query.rs | 22 +++++++++---------- src/report.rs | 61 +++++++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 63 insertions(+), 20 deletions(-) diff --git a/src/query.rs b/src/query.rs index bf32e49..69dad98 100644 --- a/src/query.rs +++ b/src/query.rs @@ -724,7 +724,7 @@ impl TraceResult { #[non_exhaustive] pub struct DiffPackage { pub name: String, - pub size: u64, + pub total_size_bytes: u64, } /// Compute a diff between two trace snapshots. @@ -754,19 +754,19 @@ pub fn diff_snapshots(a: &TraceSnapshot, b: &TraceSnapshot) -> DiffResult { .difference(&keys_b) .map(|&name| DiffPackage { name: name.to_string(), - size: a.packages[name], + total_size_bytes: a.packages[name], }) .collect(); - only_in_a.sort_by(|x, y| y.size.cmp(&x.size)); + only_in_a.sort_by(|x, y| y.total_size_bytes.cmp(&x.total_size_bytes)); let mut only_in_b: Vec = keys_b .difference(&keys_a) .map(|&name| DiffPackage { name: name.to_string(), - size: b.packages[name], + total_size_bytes: b.packages[name], }) .collect(); - only_in_b.sort_by(|x, y| y.size.cmp(&x.size)); + only_in_b.sort_by(|x, y| y.total_size_bytes.cmp(&x.total_size_bytes)); let dyn_keys_a: HashSet<&str> = a.dynamic_packages.keys().map(String::as_str).collect(); let dyn_keys_b: HashSet<&str> = b.dynamic_packages.keys().map(String::as_str).collect(); @@ -775,19 +775,19 @@ pub fn diff_snapshots(a: &TraceSnapshot, b: &TraceSnapshot) -> DiffResult { .difference(&dyn_keys_b) .map(|&name| DiffPackage { name: name.to_string(), - size: a.dynamic_packages[name], + total_size_bytes: a.dynamic_packages[name], }) .collect(); - dynamic_only_in_a.sort_by(|x, y| y.size.cmp(&x.size)); + dynamic_only_in_a.sort_by(|x, y| y.total_size_bytes.cmp(&x.total_size_bytes)); let mut dynamic_only_in_b: Vec = dyn_keys_b .difference(&dyn_keys_a) .map(|&name| DiffPackage { name: name.to_string(), - size: b.dynamic_packages[name], + total_size_bytes: b.dynamic_packages[name], }) .collect(); - dynamic_only_in_b.sort_by(|x, y| y.size.cmp(&x.size)); + dynamic_only_in_b.sort_by(|x, y| y.total_size_bytes.cmp(&x.total_size_bytes)); DiffResult { entry_a_weight: a.static_weight, @@ -1212,10 +1212,10 @@ mod tests { assert_eq!(diff.weight_delta, -200); assert_eq!(diff.only_in_a.len(), 1); assert_eq!(diff.only_in_a[0].name, "zod"); - assert_eq!(diff.only_in_a[0].size, 500); + assert_eq!(diff.only_in_a[0].total_size_bytes, 500); assert_eq!(diff.only_in_b.len(), 1); assert_eq!(diff.only_in_b[0].name, "ajv"); - assert_eq!(diff.only_in_b[0].size, 100); + assert_eq!(diff.only_in_b[0].total_size_bytes, 100); assert_eq!(diff.shared_count, 2); } diff --git a/src/report.rs b/src/report.rs index 651600c..f46e991 100644 --- a/src/report.rs +++ b/src/report.rs @@ -343,7 +343,7 @@ pub struct DiffReport { #[derive(Debug, Clone, Serialize)] pub struct DiffPackageEntry { pub name: String, - pub size: u64, + pub total_size_bytes: u64, } /// Display-ready packages list. Produced by `Session::packages_report()`. @@ -632,7 +632,7 @@ impl DiffReport { .iter() .map(|p| DiffPackageEntry { name: p.name.clone(), - size: p.size, + total_size_bytes: p.total_size_bytes, }) .collect(), only_in_b: diff @@ -640,7 +640,7 @@ impl DiffReport { .iter() .map(|p| DiffPackageEntry { name: p.name.clone(), - size: p.size, + total_size_bytes: p.total_size_bytes, }) .collect(), dynamic_only_in_a: diff @@ -648,7 +648,7 @@ impl DiffReport { .iter() .map(|p| DiffPackageEntry { name: p.name.clone(), - size: p.size, + total_size_bytes: p.total_size_bytes, }) .collect(), dynamic_only_in_b: diff @@ -656,7 +656,7 @@ impl DiffReport { .iter() .map(|p| DiffPackageEntry { name: p.name.clone(), - size: p.size, + total_size_bytes: p.total_size_bytes, }) .collect(), limit, @@ -729,7 +729,11 @@ impl DiffReport { writeln!( out, "{}", - c.red(&format!(" - {:<35} {}", pkg.name, format_size(pkg.size))) + c.red(&format!( + " - {:<35} {}", + pkg.name, + format_size(pkg.total_size_bytes) + )) ) .unwrap(); } @@ -745,7 +749,11 @@ impl DiffReport { writeln!( out, "{}", - c.green(&format!(" + {:<35} {}", pkg.name, format_size(pkg.size))) + c.green(&format!( + " + {:<35} {}", + pkg.name, + format_size(pkg.total_size_bytes) + )) ) .unwrap(); } @@ -767,7 +775,11 @@ impl DiffReport { writeln!( out, "{}", - c.red(&format!(" - {:<35} {}", pkg.name, format_size(pkg.size))) + c.red(&format!( + " - {:<35} {}", + pkg.name, + format_size(pkg.total_size_bytes) + )) ) .unwrap(); } @@ -788,7 +800,11 @@ impl DiffReport { writeln!( out, "{}", - c.green(&format!(" + {:<35} {}", pkg.name, format_size(pkg.size))) + c.green(&format!( + " + {:<35} {}", + pkg.name, + format_size(pkg.total_size_bytes) + )) ) .unwrap(); } @@ -1021,6 +1037,33 @@ mod tests { assert!(json.get("limit").is_none()); } + #[test] + fn diff_report_json_package_fields() { + let report = DiffReport { + entry_a: "a.ts".into(), + entry_b: "b.ts".into(), + weight_a: 1000, + weight_b: 800, + weight_delta: -200, + dynamic_weight_a: 0, + dynamic_weight_b: 0, + dynamic_weight_delta: 0, + shared_count: 0, + only_in_a: vec![DiffPackageEntry { + name: "zod".into(), + total_size_bytes: 500, + }], + only_in_b: vec![], + dynamic_only_in_a: vec![], + dynamic_only_in_b: vec![], + limit: 10, + }; + let json: serde_json::Value = serde_json::from_str(&report.to_json()).unwrap(); + assert_eq!(json["only_in_a"][0]["name"], "zod"); + assert_eq!(json["only_in_a"][0]["total_size_bytes"], 500); + assert!(json["only_in_a"][0].get("size").is_none()); + } + #[test] fn packages_report_json_fields() { let report = PackagesReport {