Skip to content

fix(script_driver): query the unix winsize for process_console_size (Refs #3330) - #3919

Merged
caomengxuan666 merged 3 commits into
masterfrom
fix/3330-process-console-size-unix
Nov 19, 2026
Merged

caomengxuan666 merged 3 commits into
masterfrom
fix/3330-process-console-size-unix

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

根因

unix 的 process_console_size() / stdin_console_size() 是既有桩恒返 None,于是 COLUMNS 未设时 help 宽度、select 菜单宽度与交互式 LINES/COLUMNS 绑定一路回退到 80,即使终端是 120/100 列。

GNU 锚点:general.c:1461-1479 default_columns(COLUMNS 非正数时 check_window_size → get_new_window_size(0, NULL, &c));lib/sh/winsize.c(input_tty() = shell_tty 或 stderr 的 fd,ioctl TIOCGWINSZ,仅 ws_row > 0 && ws_col > 0 时采用);lib/readline/terminal.c:293-374 _rl_get_screen_size(对 rl_instream 的同一 ioctl)。

改动

仅 src/script_driver.rs(+67/−1):新增 unix_console_size_of_fd(fd)(libc::ioctl TIOCGWINSZ,采用门与 winsize.c 一致);process_console_size 先开 /dev/tty(失败则按 GNU 的 input_tty 回退序试 stderr → stdin → stdout);stdin_console_size 对 STDIN_FILENO 做同一 ioctl。libc 0.2 已是依赖。

新钉 tests/issue3330_help_width_winsize.rs(pty 120/100 两档,COLUMNS/LINES 均 unset,裸 help 版式格逐行 pin,另断言两档均不等于 80 格)+ pty 驱动 tests/interactive/support/pty_help_width_probe.py。

验证(UNVERIFIED-BY-CAPTAIN;队长复核待 CI 裁定)

  • 基底腿(新服务器):钉 fail-first 成立(120/100 两档皆红,实测 80 格);基底全量 lib 1280/0(TMPDIR 绕过服务器 /tmp 权限问题)。
  • 修后腿(同机):120 列档绿;100 列档初跑差一行,诊断为钉驱动的 locale 边界问题,已以提交 42d7e9b(驱动 pin LC_ALL=C)修正——该修正后修后腿未重跑。
  • 服务器链路今晚 23:1x 起自 VM 侧不可达(出口代理 banner 超时),修后腿日志队长暂时读不到;本 PR 的钉以头 census 为裁定依据(census 跑全茎)。
  • 附带发现:issue3185_help_listing_column_major 在现尖 census 恒红(pwd 表项 [-LPW] 扩展后期望格未重生成),已另立 残差:issue3185 茎恒红——pwd 表项 [-LPW] 扩展后期望格未重生成 #3918,不在本 PR 动。

Refs #3330。

本 PR 删除了什么:

  • src/script_driver.rs 内 unix 的 process_console_size / stdin_console_size 两个恒返 None 的桩实现被真实 winsize 查询替换;未删除任何文件、测试或公开面。

…Refs #3330)

GNU general.c:1461 default_columns takes COLUMNS when it parses
positive, else the window size from get_new_window_size
(lib/sh/winsize.c: tcgetwinsize on input_tty(), the controlling
terminal else stderr), else 80. The unix process_console_size was a
stub returning None, so every COLUMNS-unset consumer (bare `help`
listing, `select` menus, the interactive LINES/COLUMNS bind) fell
back to 80 at any window width; stdin_console_size was stubbed the
same way, so the readline screen-size bind never saw a stdin
terminal either. Implement both on TIOCGWINSZ: /dev/tty first (GNU's
shell_tty, so the query works with stdio redirected), then stderr /
stdin / stdout; stdin_console_size ioctls fd 0 (terminal.c
_rl_get_screen_size on rl_instream). Degenerate (zero) dimensions
stay None, matching winsize.c's ws_row > 0 && ws_col > 0 gate.

Nails: tests/issue3330_help_width_winsize.rs (pty widths 120/100,
COLUMNS unset; grids rendered from rubash's 78-entry table and
validated byte-for-byte against the GNU 5.3.20 oracle at COLUMNS=100
and the oracle-validated #3185 grids at 80/120) +
tests/interactive/support/pty_help_width_probe.py.
The 100-column nail failed on the fixed leg with a single differing
row (the `select` row lost its trailing `>`): the leg runs under an
en_US.UTF-8 locale, so the shell selects the wdispcolumn renderer,
while the nail's grids are the single-byte dispcolumn (LC_ALL=C)
render. GNU shows the same split (help.def wdispcolumn vs
dispcolumn; oracle verified at COLUMNS=100 under C and C.UTF-8).
Pin LC_ALL=C in the driver env so the grids apply on any leg locale.

Also fix the driver's os.waitpid unpack (2-tuple, not 3) and apply
the rustfmt diffs the fixed leg reported (script_driver.rs,
issue3330_help_width_winsize.rs).
@caomengxuan666
caomengxuan666 marked this pull request as ready for review November 19, 2026 00:45
@caomengxuan666
caomengxuan666 merged commit 622ee66 into master Nov 19, 2026
10 of 12 checks passed
caomengxuan666 added a commit that referenced this pull request Nov 19, 2026
## 根因

`issue3185_help_listing_column_major` 在现尖恒红(队长 census:0 PASS / 1 FAIL),红在四张期望格的 `pwd` 行(第 12 行)。`HELP_ENTRIES` 里的表项现在是 `pwd [-LPW]`(src/builtins/help.rs:608),而四张期望格生成于表项还是 `[-LP]` 之时,未随 `-W` 落地而重生成。非 #3185 本身复发。

## 抉择:保留 `[-LPW]`(#3918 方案 2)

- `-W` 是真实功能:`src/builtins/pwd.rs` Mode::Win32(#3716,niubash#993 §6 的 MSYS conv-to-win32 显示形),有专属茎 tests/niubash993_pwd_w.rs。
- 表项之外,`help pwd` 短档(src/builtins/help_texts.rs:1332)、usage 行(src/builtins/pwd.rs:123)与 issue2753/2791 钉早已是 `[-LPW]`;把表项改回 `[-LP]` 会让裸 `help` 与 `help pwd`、`pwd -x` 三处互不一致。
- #3716 提交正文已明言:usage/help 渲染 `pwd [-LPW]` 是有意偏离 GNU goldens 的 MSYS persona 取舍。

## GNU 锚点

- GNU 5.3.20 的 $SHORT_DOC 是 `pwd [-LP]`(builtins/cd.def:436、builtins/builtins.c:68)。
- oracle 实测(~/workspace/rubash-audit/build-gnu/bash-5.3/bash,5.3.20):`LC_ALL=C COLUMNS=80/120 help` 的 pwd 行均为 `pwd [-LP]`;`help pwd` 首行 `pwd: pwd [-LP]`。
- 故 `[-LPW]` 是有意的 rubash 扩展,与本文件头注已载明的 `env` 额外条目同类。

## 改动

仅 tests/issue3185_help_listing_column_major.rs(+9/−4):四张期望格的 pwd 行 `[-LP]` → `[-LPW]`,另加 5 行头注说明取舍与生成器出处。未碰 #3919(#3330)的文件表(src/script_driver.rs、pty 宽度探针、issue3330 测试)。

## 生成与验证

- 生成器 ~/workspace/fix-3918/gen_expected_3918.py(由 #3330 的 gen_expected.py 改编,REPO 指向本车道树):渲染器先对 GNU 5.3.20 oracle 自身的 77 条输出(rubash 表去 `env`、pwd 回 `[-LP]`)在 COLUMNS=80 与 120 下逐字节校验通过;再对落盘四格校验——除 pwd 行外零差异;重生成后四格与现表逐行一致(UTF8_80 第 21 行为 wdispcolumn 边界行,按原样保留)。
- fail-first(渲染器层):修前渲染器输出与落盘四格恰差 pwd 行一处;修后零差。另有队长 census 的茎现红佐证。

## 验证状态:UNVERIFIED-BY-CAPTAIN

**本车道未跑任何二进制腿**:新服务器 SSH 三次均 banner 超时(经 egress 代理 198.19.0.1:3128,23:5x 三次);X299 反向隧道断;Simular box 钱包为空;本 VM 本地构建禁。base/fix 两份 tarball 已备在 ~/workspace/fix-3918/(rubash-3918-base.tgz / rubash-3918-fixed.tgz),待队长在恢复的路线上补跑:基底茎 fail-first + 修后茎 6/6 + lib 对齐。

## 本 PR 删除了什么

无。仅重生成四张期望格的 pwd 行与 5 行头注;无产品代码改动,无文件删除。

## 队长复核(头 bb3e080)

- 服务器腿(队长跑):fixed 树自带钉 **6/6 PASS**,base(47a24b28)同钉 **0/6 FAIL**——fail-first 成立(基线期望网格缺 W)。
- 头 CI census 72:自带钉 6/6 绿,相对尖集新增仅 issue1902 抖动格;goldens 仅基线二名;CLI/Rust/cross/Windows/shell/ledger/niu 全绿;macOS 腿为 cancelled 且 steps 为空(未运行,非产品红,日志 blob 已过期、由 jobs API 核实)。
- 纯测试对齐(四格 pwd 期望 [-LP]→[-LPW],与 niu #993 §6 的既定扩展一致);与现尖零交集已核(merge-base 以来无人动 issue3185 钉文件),免 update-branch。Refs-only,合后手关 #3918;#3924(pwd 用法行钉间矛盾)随之解闸。
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