← Back to Pull requests

du: expand suffix-only block size regression coverage #15008

Open
mattsu2020 opened this pull request with 137 lines diff across 1 files
View on GitHub
mattsu2020 mattsu2020 commented on Oct 01, 2026 12:26 UTC
Author

The suffix-only block-size display is already fixed on main. Add regression coverage for unit spelling, rounding, environment variables, and option overrides.

Refs #7738.

Diff: 137 lines (+113 / -24) across 1 files Reviewer: sylvestre Review duration: 92136m
All Vouch review confidence checks passed
Residual risk 0.04 = Change Risk (0.39) × (1 − Review Confidence (0.89)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.39 · 137 lines diff across 1 files
0.39
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.89 · 5 substantive comment(s)
0.89
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 50%
88%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size diff_size
0.295
Real PR Conversation Timeline
17 items
codspeed[bot] codspeed[bot] commented on Oct 01, 2026 13:55 UTC
Bot

<!-- __CODSPEED_PERFORMANCE_REPORT_COMMENT__ -->

Merging this PR will not alter performance

✅ 8 untouched benchmarks
⏩ 444 skipped benchmarks[^skipped]

---

<sub>Comparing <code>mattsu2020:codex/du-block-size-units</code> (15121bc) with <code>main</code> (e88a115)[^unexpected-base]</sub>

<a href="https://app.codspeed.io/uutils/coreutils/branches/mattsu2020%3Acodex%2Fdu-block-size-units?utm_source=github&utm_medium=comment-v2&utm_content=button">
<picture>
<source media="(prefers-color-scheme: dark)" srcset="https://codspeed.io/pr-report/open-in-codspeed-dark.svg">
<source media="(prefers-color-scheme: light)" srcset="https://codspeed.io/pr-report/open-in-codspeed-light.svg">
<img alt="Open in CodSpeed" src="https://codspeed.io/pr-report/open-in-codspeed-light.svg" width="169" height="32">
</picture>
</a>

[^skipped]: 444 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.
[^unexpected-base]: No successful run was found on <code>main</code> (9edd4e3) during the generation of this report, so e88a115 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

github-actions[bot] github-actions[bot] commented on Oct 01, 2026 14:34 UTC
Bot

<!-- gnu-comment-bot -->
GNU testsuite comparison:

Skip an intermittent issue tests/misc/usage_vs_getopt (fails in this run but passes in the 'main' branch)
Congrats! The gnu test tests/pr/options is no longer failing!

xtqqczze xtqqczze commented on Oct 05, 2026 11:40 UTC
Contributor

@mattsu2020 please drop merge commit and then rebase

sylvestre sylvestre commented on code on Dec 01, 2026 07:16 UTC
Code Review
tests/by-util/test_du.rs:1
@@ -298,6 +298,96 @@ fn test_du_env_block_size_hierarchy() {
     assert_eq!(expected, result2);
 }
 
+#[test]
+fn test_du_block_size_unit_display() {

four nested loops and ~130 du runs, this is hard to read
could you please make it a flat table like test_du_suffix_only_block_size? or just extend that one

sylvestre sylvestre commented on code on Dec 01, 2026 07:16 UTC
Code Review
tests/by-util/test_du.rs:1
@@ -298,6 +298,96 @@ fn test_du_env_block_size_hierarchy() {
     assert_eq!(expected, result2);
 }
 
+#[test]
+fn test_du_block_size_unit_display() {
+    use std::fmt::Write;
+
+    let ts = TestScenario::new(util_name!());
+    // Sparse files exercise rounding without depending on filesystem allocation.
+    let files = ["empty", "below", "exact", "above", "large"];
+    for (unit, bytes, suffix) in [
+        ("K", 1024_u64, "K"),
+        ("k", 1024, "K"),
+        ("KiB", 1024, "KiB"),
+        ("kiB", 1024, "KiB"),
+        ("M", 1_048_576, "M"),
+        ("m", 1_048_576, "M"),
+        ("MiB", 1_048_576, "MiB"),
+        ("miB", 1_048_576, "MiB"),
+        ("kB", 1000, "kB"),
+        ("KB", 1000, "kB"),
+        ("MB", 1_000_000, "MB"),
+        ("mB", 1_000_000, "MB"),
+        ("kD", 1000, "K"),
+    ] {
+        let large_blocks = if bytes <= 1024 { 12_345 } else { 12 };
+        let lengths = [0, bytes - 1, bytes, bytes + 1, bytes * large_blocks + 17];
+        for (file, len) in files.iter().zip(lengths) {
+            std::fs::File::create(ts.fixtures.plus(file))
+                .unwrap()
+                .set_len(len)
+                .unwrap();
+        }
+        for prefix in ["", "1"] {
+            let value = format!("{prefix}{unit}");
+            let display_suffix = if prefix.is_empty() { suffix } else { "" };
+            let mut expected = String::new();
+            for (file, count) in files.iter().zip([0, 1, 1, 2, large_blocks + 1]) {
+                writeln!(expected, "{count}{display_suffix}\t{file}").unwrap();
+            }
+            for source in [

do we need every unit through all 5 sources? the source precedence is already covered by test_du_env_block_size_hierarchy

sylvestre sylvestre commented on code on Dec 01, 2026 07:16 UTC
Code Review
tests/by-util/test_du.rs:1
@@ -298,6 +298,96 @@ fn test_du_env_block_size_hierarchy() {
     assert_eq!(expected, result2);
 }
 
+#[test]
+fn test_du_block_size_unit_display() {
+    use std::fmt::Write;
+
+    let ts = TestScenario::new(util_name!());
+    // Sparse files exercise rounding without depending on filesystem allocation.
+    let files = ["empty", "below", "exact", "above", "large"];
+    for (unit, bytes, suffix) in [
+        ("K", 1024_u64, "K"),
+        ("k", 1024, "K"),
+        ("KiB", 1024, "KiB"),
+        ("kiB", 1024, "KiB"),
+        ("M", 1_048_576, "M"),
+        ("m", 1_048_576, "M"),
+        ("MiB", 1_048_576, "MiB"),
+        ("miB", 1_048_576, "MiB"),
+        ("kB", 1000, "kB"),
+        ("KB", 1000, "kB"),
+        ("MB", 1_000_000, "MB"),
+        ("mB", 1_000_000, "MB"),
+        ("kD", 1000, "K"),

please add a short comment on why kD shows K and not kB

mattsu2020 mattsu2020 commented on code on Dec 01, 2026 09:31 UTC
Code Review
tests/by-util/test_du.rs:1
@@ -298,6 +298,96 @@ fn test_du_env_block_size_hierarchy() {
     assert_eq!(expected, result2);
 }
 
+#[test]
+fn test_du_block_size_unit_display() {

fixed it

mattsu2020 mattsu2020 commented on code on Dec 01, 2026 09:31 UTC
Code Review
tests/by-util/test_du.rs:1
@@ -298,6 +298,96 @@ fn test_du_env_block_size_hierarchy() {
     assert_eq!(expected, result2);
 }
 
+#[test]
+fn test_du_block_size_unit_display() {
+    use std::fmt::Write;
+
+    let ts = TestScenario::new(util_name!());
+    // Sparse files exercise rounding without depending on filesystem allocation.
+    let files = ["empty", "below", "exact", "above", "large"];
+    for (unit, bytes, suffix) in [
+        ("K", 1024_u64, "K"),
+        ("k", 1024, "K"),
+        ("KiB", 1024, "KiB"),
+        ("kiB", 1024, "KiB"),
+        ("M", 1_048_576, "M"),
+        ("m", 1_048_576, "M"),
+        ("MiB", 1_048_576, "MiB"),
+        ("miB", 1_048_576, "MiB"),
+        ("kB", 1000, "kB"),
+        ("KB", 1000, "kB"),
+        ("MB", 1_000_000, "MB"),
+        ("mB", 1_000_000, "MB"),
+        ("kD", 1000, "K"),
+    ] {
+        let large_blocks = if bytes <= 1024 { 12_345 } else { 12 };
+        let lengths = [0, bytes - 1, bytes, bytes + 1, bytes * large_blocks + 17];
+        for (file, len) in files.iter().zip(lengths) {
+            std::fs::File::create(ts.fixtures.plus(file))
+                .unwrap()
+                .set_len(len)
+                .unwrap();
+        }
+        for prefix in ["", "1"] {
+            let value = format!("{prefix}{unit}");
+            let display_suffix = if prefix.is_empty() { suffix } else { "" };
+            let mut expected = String::new();
+            for (file, count) in files.iter().zip([0, 1, 1, 2, large_blocks + 1]) {
+                writeln!(expected, "{count}{display_suffix}\t{file}").unwrap();
+            }
+            for source in [

fixed it

mattsu2020 mattsu2020 commented on code on Dec 01, 2026 09:31 UTC
Code Review
tests/by-util/test_du.rs:1
@@ -298,6 +298,96 @@ fn test_du_env_block_size_hierarchy() {
     assert_eq!(expected, result2);
 }
 
+#[test]
+fn test_du_block_size_unit_display() {
+    use std::fmt::Write;
+
+    let ts = TestScenario::new(util_name!());
+    // Sparse files exercise rounding without depending on filesystem allocation.
+    let files = ["empty", "below", "exact", "above", "large"];
+    for (unit, bytes, suffix) in [
+        ("K", 1024_u64, "K"),
+        ("k", 1024, "K"),
+        ("KiB", 1024, "KiB"),
+        ("kiB", 1024, "KiB"),
+        ("M", 1_048_576, "M"),
+        ("m", 1_048_576, "M"),
+        ("MiB", 1_048_576, "MiB"),
+        ("miB", 1_048_576, "MiB"),
+        ("kB", 1000, "kB"),
+        ("KB", 1000, "kB"),
+        ("MB", 1_000_000, "MB"),
+        ("mB", 1_000_000, "MB"),
+        ("kD", 1000, "K"),

add comment

xtqqczze xtqqczze commented on code on Dec 02, 2026 02:40 UTC
Code Review
tests/by-util/test_du.rs:1
@@ -298,23 +298,73 @@ fn test_du_env_block_size_hierarchy() {
     assert_eq!(expected, result2);
 }
 
+#[test]
+fn test_du_block_size_display_overrides() {
+    let ts = TestScenario::new(util_name!());
+    std::fs::File::create(ts.fixtures.plus("data"))
+        .unwrap()
+        .set_len(4097)
+        .unwrap();
+    for (args, expected) in [

consider using rstest cases

xtqqczze xtqqczze commented on code on Dec 02, 2026 02:41 UTC
Code Review
tests/by-util/test_du.rs:1
@@ -298,23 +298,73 @@ fn test_du_env_block_size_hierarchy() {
     assert_eq!(expected, result2);
 }
 
+#[test]
+fn test_du_block_size_display_overrides() {
+    let ts = TestScenario::new(util_name!());
+    std::fs::File::create(ts.fixtures.plus("data"))
+        .unwrap()
+        .set_len(4097)
+        .unwrap();
+    for (args, expected) in [
+        (vec!["-k"], "5\tdata\n"),
+        (vec!["-m"], "1\tdata\n"),
+        (vec!["-b"], "4097\tdata\n"),
+        (vec!["-h"], "4.1K\tdata\n"),
+        (vec!["--block-size=1KiB"], "5\tdata\n"),
+        (vec!["--block-size=2KiB"], "3\tdata\n"),
+        (vec!["-BKiB", "-k"], "5\tdata\n"),
+        (vec!["-k", "-BKiB"], "5KiB\tdata\n"),
+        (vec!["-c", "-BKiB"], "5KiB\tdata\n5KiB\ttotal\n"),
+    ] {
+        ts.ucmd()
+            .env("DU_BLOCK_SIZE", "KiB")
+            .args(&["-A", "data"])
+            .args(&args)
+            .succeeds()
+            .stdout_only(expected);
+    }
+    ts.ucmd()
+        .env("DU_BLOCK_SIZE", "invalid")
+        .env("BLOCK_SIZE", "KiB")
+        .args(&["-A", "data"])
+        .succeeds()
+        .stdout_only("5\tdata\n");
+}
+
 #[test]
 fn test_du_suffix_only_block_size() {
     let ts = TestScenario::new(util_name!());
     let file = "file";
     ts.fixtures.write(file, "x");
 
     for (arg, env, expected) in [

consider using rstest cases

xtqqczze xtqqczze commented on code on Dec 02, 2026 02:41 UTC
Code Review
tests/by-util/test_du.rs:1
@@ -330,6 +380,37 @@ fn test_du_suffix_only_block_size() {
     }
 }
 
+#[test]
+fn test_du_suffix_only_block_size_rounding() {
+    let ts = TestScenario::new(util_name!());
+    let file = "data";
+    let fpath = ts.fixtures.plus(file);
+
+    for (len, arg, expected) in [

consider using rstest cases

mattsu2020 mattsu2020 commented on code on Dec 02, 2026 08:32 UTC
Code Review
tests/by-util/test_du.rs:1
@@ -330,6 +380,37 @@ fn test_du_suffix_only_block_size() {
     }
 }
 
+#[test]
+fn test_du_suffix_only_block_size_rounding() {
+    let ts = TestScenario::new(util_name!());
+    let file = "data";
+    let fpath = ts.fixtures.plus(file);
+
+    for (len, arg, expected) in [

fixed it

mattsu2020 mattsu2020 commented on code on Dec 02, 2026 08:33 UTC
Code Review
tests/by-util/test_du.rs:1
@@ -298,23 +298,73 @@ fn test_du_env_block_size_hierarchy() {
     assert_eq!(expected, result2);
 }
 
+#[test]
+fn test_du_block_size_display_overrides() {
+    let ts = TestScenario::new(util_name!());
+    std::fs::File::create(ts.fixtures.plus("data"))
+        .unwrap()
+        .set_len(4097)
+        .unwrap();
+    for (args, expected) in [
+        (vec!["-k"], "5\tdata\n"),
+        (vec!["-m"], "1\tdata\n"),
+        (vec!["-b"], "4097\tdata\n"),
+        (vec!["-h"], "4.1K\tdata\n"),
+        (vec!["--block-size=1KiB"], "5\tdata\n"),
+        (vec!["--block-size=2KiB"], "3\tdata\n"),
+        (vec!["-BKiB", "-k"], "5\tdata\n"),
+        (vec!["-k", "-BKiB"], "5KiB\tdata\n"),
+        (vec!["-c", "-BKiB"], "5KiB\tdata\n5KiB\ttotal\n"),
+    ] {
+        ts.ucmd()
+            .env("DU_BLOCK_SIZE", "KiB")
+            .args(&["-A", "data"])
+            .args(&args)
+            .succeeds()
+            .stdout_only(expected);
+    }
+    ts.ucmd()
+        .env("DU_BLOCK_SIZE", "invalid")
+        .env("BLOCK_SIZE", "KiB")
+        .args(&["-A", "data"])
+        .succeeds()
+        .stdout_only("5\tdata\n");
+}
+
 #[test]
 fn test_du_suffix_only_block_size() {
     let ts = TestScenario::new(util_name!());
     let file = "file";
     ts.fixtures.write(file, "x");
 
     for (arg, env, expected) in [

fixed it

mattsu2020 mattsu2020 commented on code on Dec 02, 2026 08:33 UTC
Code Review
tests/by-util/test_du.rs:1
@@ -298,23 +298,73 @@ fn test_du_env_block_size_hierarchy() {
     assert_eq!(expected, result2);
 }
 
+#[test]
+fn test_du_block_size_display_overrides() {
+    let ts = TestScenario::new(util_name!());
+    std::fs::File::create(ts.fixtures.plus("data"))
+        .unwrap()
+        .set_len(4097)
+        .unwrap();
+    for (args, expected) in [

fixed it

Reviewers
Assignees
mattsu2020 mattsu2020
Labels
risk: low confidence: 88.8% reviewed
Vouch Risk Breakdown
AI-powered review risk analysis
Change Risk
Change Risk · Model 1 (XGBoost)
Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
Score: 39.5% (MEDIUM) · Higher = larger blast radius
39.5%
Review Confidence
Review Confidence · Models 2 & 3
Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
Score: 88.8% · Lower = rushed or shallow review
88.8%
Residual Risk
Residual Risk · Core Equation
Residual = Change × (1 − Confidence)
Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
Score: 4.4% · Safe to merge
4.4%