Skip to content

fix(df): align --output columns to GNU widths; never pad the last column (Refs #1657) - #1666

Closed
caomengxuan666 wants to merge 2 commits into
mainfrom
fix/1657-df-output-colwidth
Closed

caomengxuan666 wants to merge 2 commits into
mainfrom
fix/1657-df-output-colwidth

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

fix(df): align --output columns to GNU widths; never pad the last column (Refs #1657)

修了什么

df --output 的定制表现在按 GNU df.c print_table 的规则渲染:

  • 每字段最小列宽(coreutils 9.4 df.c field_data):source 14、fstype 4、
    size/used/avail/itotal/iused/iavail 5、pcent/ipcent 4、target/file 0;
    列宽 = max(最小宽度,表头宽,最宽 cell),按显示列数计量。
  • 末列不再右填充:左对齐末列裸打、右对齐末列保留左填充
    (MBA_NO_RIGHT_PAD 只禁右填充);--total 行走同一 printer。
  • 只改 src/commands/df.cpp 的 print_custom_output_table + 新增
    output_field_min_width;默认模式渲染器已正确,不动。

GNU 语义

  • df.c field_data(:177-210):各字段最小宽度与对齐方向。
  • df.c print_table(:377-408):单空格分隔、末列 MBA_NO_RIGHT_PAD。
  • df.c:642/:1256:列宽只向上长,含表头。
  • df.c:488:--output 下 avail 表头为 "Avail"(WinuxCmd 现状一致,不改)。

验证(Linux,GNU coreutils 9.4 oracle;Windows 腿待复核轮)

  • 两枚新钉(tests/unit/df/df_unit_test.cpp):
    df_output_no_trailing_blanks_and_header_uses_min_width、
    df_output_last_column_header_not_padded。
  • 独立算法 harness(工作区 probes/table_logic_check.cpp):新算法在
    6 个 GNU 探针形上与 oracle 输出逐字节一致(含 12 列全表与 --total
    行);旧算法复现 issue 所报形态。7/7 PASS。
  • fail-first:本地无 MSVC 构建,钉的 fail-first 由旧算法复现 + issue
    实测输出锁定,须由 CI / X299 腿在复核轮实测确认。
  • 未改用户可见文本(只改空白填充),无 I18N 同步。

删了什么

  • 未删产品代码路径。本 PR 只改 --output 表的空白填充规则:替换的是
    末列"静默右填充"与"表头按字节宽"的旧行为(与 GNU 有差,见上);
    其它输出形态逐点核对不变。无文档/账本改动。

Refs #1657

@caomengxuan666

Copy link
Copy Markdown
Member Author

Review verdict: FAIL (F1 — blocking)

PR #1666 (head 035ae2b3, base 8be156e3) cannot merge on this head: its two new pins do not compile on MSVC.

F1 — new test pins use assertion spellings that don't exist in the test framework

CI run 43577541076 (CMake Windows Multi-Arch CI), exactly one failing job — build-windows (x64, x64, x64, default), job 132394976462 — the only CI job that builds the winuxcmd-tests binary (ENABLE_TESTS=ON only for x64 + default). Its failed log shows 6 hard errors, all in the new test file, exit code 2; the product df.cpp object compiled clean:

  • tests/unit/df/df_unit_test.cpp(591): error C2143/C2059 — EXPECT_TRUE(...) << "trailing blank in: [...]" streams into a do {…} while (0) macro (tests/framework/wctest.h:208-214); no other test file streams after EXPECT_TRUE.
  • (600): error C3861: 'ASSERT_GT': identifier not found — ASSERT_GT is defined nowhere in wctest.h (only ASSERT_TRUE/FALSE, ASSERT_EQ/NE, ASSERT_LE/GE, ASSERT_CONTAINS) and appears nowhere else in tests/ except these two lines.
  • Same pair again at (648)/(651). No other errors in the log.

I pulled the failed log myself and confirmed all six errors verbatim; this is not a flake or an environment red.

Rework prescription

  • Replace both ASSERT_GT(a, b) with ASSERT_TRUE(a > b).
  • Delete both << "trailing blank in: [...]" streams (or move the line into a TEST_LOG).
  • Do not add an ASSERT_GT macro to the framework for two call sites.

After rework, the focused re-review must re-run CI to green and run the X299 legs (2 cells green on head, red on base, df ctest suite). Fail-first is deferred — the pins don't compile, so no green/red exists to measure yet.

What verified green (product fix itself is mechanism-correct)

  • Mechanism: output_field_min_width() reproduces GNU df.c:177-210 exactly (source 14, fstype 4, size/used/avail/itotal/iused/iavail 5, pcent/ipcent 4, target/file 0); width = max(min, header, widest cell) per df.c:642/:1256; last-column MBA_NO_RIGHT_PAD (df.c:397-400); --total row participates in width computation; all 12 enum values covered; no underflow/OOB.
  • GNU oracle: the reviewer ran local GNU df 9.4 — header, right-aligned last col, 12-col table all match the pin expectations.
  • Harness: the lane's table_logic_check.cpp re-compiled and re-run by the reviewer — 7/7 PASS, byte-identical.
  • CI, other run: 43577541067 (GNU master differential) = SUCCESS — the product binary passes the GNU differential; the failure is confined to the test file.
  • Hygiene: git diff --check clean; PR body has the deletion section, Refs [df] --output 末列尾随空格、表头未按列宽对齐 #1657 only; no user-visible text changed (i18n-drift success). Intersection merge-base..live-tip = empty (merge-base 8be156e3 = tip at review time) — no update-branch needed when it re-merges.

Nits / notes (non-blocking)

  • N1: PR body overclaims the default-mode renderer is correct — default-mode fs_w starts at header width 10, not GNU's 14 minimum. Same mechanism family, different face; the merge body must not repeat it; follow-up candidate.
  • N2 (disclosed limitation): width counts UTF-8 code points, not GNU mbswidth; shared with the pre-existing default renderer, out of scope.
  • rust2 note: rust2/crates/winux-cmds/src/df.rs carries the same two residuals — recorded for the rust2-df author, no issue filed (unshipped code).

Merge notes

Do not merge on this head. Refs #1657 stays OPEN after any future merge; the captain closes it by hand after the X299 leg.

@caomengxuan666

Copy link
Copy Markdown
Member Author

队长复核:FAIL(钉文件编不过)

build-windows x64 default 红,原因是钉文件本身编译失败(队长读过失败日志原文):

tests/unit/df/df_unit_test.cpp(591): error C2143: syntax error: missing ';' before '<<'
tests/unit/df/df_unit_test.cpp(591): error C2059: syntax error: '<<'
tests/unit/df/df_unit_test.cpp(600): error C3861: 'ASSERT_GT': identifier not found
tests/unit/df/df_unit_test.cpp(648): error C2143: syntax error: missing ';' before '<<'
tests/unit/df/df_unit_test.cpp(648): error C2059: syntax error: '<<'
tests/unit/df/df_unit_test.cpp(651): error C3861: 'ASSERT_GT': identifier not found

本仓是自定义 harness、非 gtest:EXPECT_TRUE 是语句宏,不支持 << 串流;ASSERT_GT/ASSERT_LT 不存在(EXPECT_GT 有)。产品改动本身是对的(GNU df.c field_data 已逐字对上);只须机械修钉:ASSERT_GT(a,b) → ASSERT_TRUE((a)>(b)) 或 EXPECT_GT,删 EXPECT_TRUE(...) << "..." 的 << 部分。

@caomengxuan666

Copy link
Copy Markdown
Member Author

Superseded: #1657 fix merged via #1695.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant