Skip to content

test(builtins): align pwd usage pins to [-LPW] (Refs #3924) - #3935

Merged
caomengxuan666 merged 1 commit into
masterfrom
fix/3924-pwd-usage-pin-align
Nov 19, 2026
Merged

caomengxuan666 merged 1 commit into
masterfrom
fix/3924-pwd-usage-pin-align

Conversation

@caomengxuan666

@caomengxuan666 caomengxuan666 commented Nov 19, 2026 •

Copy link
Copy Markdown
Member

概要

统一仓内对 pwd usage 行的互斥断言。产品侧的 usage/short-doc 早已是 pwd [-LPW](-W 为 niu #993 §6 的既定扩展,见 src/builtins/pwd.rs:123、src/builtins/help_texts.rs:1332、src/builtins/help.rs:608),且 PR #3922 已把 issue3185 期望网格对齐到 [-LPW];但 issue705 与 issue3348 的四处钉仍断言 GNU 形状 pwd [-LP],与产品现状及其余钉(issue2753 / issue2791 / niubash993 / part_021 / issue3185 / issue3330)互斥。本 PR 把这四处断言 rubash 自身输出的钉对齐到 [-LPW]。

Refs #3924

改动(逐钉)

文件:行 原断言 处置
tests/issue705_error_branding.rs:395 pwd: usage: pwd [-LP](rubash -c "pwd -Q" 的 stderr 全文断言) 改 [-LPW]
tests/issue3348_comsub_forged_pwd_logical_regressions.rs:255 stderr.contains("pwd: usage: pwd [-LP]") 改 [-LPW]
tests/issue3348_comsub_forged_pwd_logical_regressions.rs:269 同上 改 [-LPW]
tests/issue3348_comsub_forged_pwd_logical_regressions.rs:298 stdout.starts_with("pwd: pwd [-LP]\n")(pwd --help 首行) 改 [-LPW]

四处均经上下文核读,断言对象均为 rubash 自身输出,无一为 GNU 对照期望。

本 PR 删除了什么

无删除。纯测试断言对齐:2 文件、4 行字符串内容变更;src/ 一行未动;tests/gnu-compat/upstream-rights/builtins.right:358,452 的 GNU oracle golden(pwd [-LP],GNU 本尊输出)原样保留。

验证

服务器腿在工作区 REPORT 中记录(base fail-first + 对齐后逐 stem 跑绿 + issue3185 对照)。

UNVERIFIED-BY-CAPTAIN

队长复核(头 f66fd22)

更正(队长,合入后):上文「腿结果节为空」一句不确——车道服务器腿实际已跑完并记入 REPORT(队长读 REPORT 时点早于其落盘):issue3348 base 15 过 3 红(红格恰为本单三格)→ fixed 18/0;issue3185 对照 6/0;issue705 茎在服务器直跑下 9 格因 argv0 品牌前缀集体红(base/fixed 名单逐名相同,CI census 内为 0),属既存环境伪影、与本 PR 无关。复核证据链完整。

issue705 and issue3348 still asserted the GNU usage line 'pwd [-LP]'
while the product's pwd usage/short-doc has carried the deliberate
[-LPW] extension since niu #993 s6 (src/builtins/pwd.rs:123,
help_texts.rs:1332, help.rs:608). Align the four rubash-output
assertions to the product shape; the GNU oracle golden in
tests/gnu-compat/upstream-rights/builtins.right keeps [-LP].
@caomengxuan666
caomengxuan666 marked this pull request as ready for review November 19, 2026 01:52
@caomengxuan666
caomengxuan666 merged commit 4b58266 into master Nov 19, 2026
9 of 12 checks passed
caomengxuan666 pushed a commit that referenced this pull request Nov 19, 2026
…le (Fixes #3321)

Fixes #3321

## What was fixed

`controlling_terminal_available()` only asked whether stderr is a tty (or `/dev/tty` opens) and never attempted the foreground acquisition, so an interactive shell started in a background process group ran straight through with job control on (`$-` = `himBHc`) where GNU stops on SIGTTIN until foregrounded or, with SIGTTIN blocked, bails after 18 attempts with `initialize_job_control: no job control in background` and drops `m` (`jobs.c:4731-4869`).

The fix makes `controlling_terminal_available()` return a `TerminalAvailability` enum (Available / Unavailable / BackgroundBail) running GNU's loop: `shell_tty` is dup(stderr) or open(`/dev/tty`) when forced-interactive and stderr is not a tty (`jobs.c:4749-4766`); while `tcgetpgrp` says background, restore SIGTTIN to DFL and stop, bailing after the 18th kill (`tty_sigs++ > 16`, `jobs.c:4798`) with only the first diagnostic (`goto just_bail` skips the second line, `jobs.c:4797`). `establish_interactive_job_control` dispatches on the enum; the Unavailable arm keeps the two existing diagnostics untouched.

The stop is delivered with `pthread_kill` to the looping thread, not `kill(0, SIGTTIN)`: rubash's main logic runs on a spawned worker thread (`main.rs`, 512MiB stack) while the OS thread parks in join, so a group-directed kill lands on an arbitrary thread and the group stop reaches the looping thread only asynchronously — supervisor verification measured `kill(0, ...)` returning in 2-3us while the loop spun up to all 18 iterations before any stop took effect, making the pin flaky (2/4, 3/4). A thread-directed `pthread_kill` stops the looping thread synchronously inside the call (270-680us round-trip through fg+CONT in a C model, one iteration, deterministic over 10 runs); the stop still arrests the whole process group, so the session leader's waitpid sees it exactly as with GNU's kill.

## What was deleted

Nothing. No files, features, or tests were removed.

## A correction to the issue text (please do not quote it verbatim)

The issue says the shape "would be misjudged as no ctty", but the measured direction is the opposite: unpatched rubash misjudges UNAVAILABLE job control as available (never stops, never errors, `$-` stays `himBHc`). The fix adds the foreground-acquire attempt the issue asks for.

## Verification (all run, per-item counts)

- Regression pin `tests/issue3321_background_pgrp_job_control.rs`: **4/4 pass** (new pty harness `tests/interactive/support/pty_background_pgrp_probe.py`, built per the issue's gate note: one fresh pty session per leg, session leader holds the ctty, shell forked into a new background group). Legs: `bg-stop-then-fg` (must SIGTTIN-stop, then `himBHc` after fg, no diagnostics), `bg-sigttin-blocked` (no stop, only the background diagnostic, no second diagnostic, `hiBHc`), `bg-stderr-pipe` (same stop-then-fg with piped stderr), `fg-control` (direct `himBHc`, no stop). Fail-first on the unpatched tree (supervisor re-ran with the patch method): **1 passed / 3 failed** — green was exactly the `fg-control`. Supervisor re-ran the pin **10 times, 4/4 every time** (the `kill(0, ...)` form was flaky at 2/4 and 3/4, which is how the thread-delivery race was found).
- GNU 5.3.20 oracle: **4/4** on the same harness (5/5 on the `bg-stop-then-fg` leg alone); blocked-face stderr byte-identical except the program-name prefix (`bash:` vs `target/debug/rubash:`, expected).
- Adjacent: `issue2948_monitor_flag_regressions` 6/6, `issue2731_interactive_monitor_default` 6/6, `issue2774_interactive_no_tty_job_control` 4/4, `issue2487_suspend_job_control_gate` 11/11.
- `cargo build -j 2` clean, `cargo fmt --check` clean. `src/lexer/continuation.rs` untouched.

## Owed

1. **Behaviour change for the captain to know about**: an interactive rubash started in a background process group now stops like GNU until foregrounded — this is GNU behaviour itself (`bash -i &` does this), but rubash previously ran straight through; a `run_interactive_stdin` library host driving it from a background group stops the same way (GNU stops at the same place).
2. The non-interactive `-m` arm (`main.rs`) still only looks at whether stderr is a tty — that is GNU's force path, a different face, and #2948 already pins its current behaviour. Out of scope here.
3. `running_in_background` (`jobs.c:4865`) has no rubash counterpart and no consumer; not introduced here.
4. The pin needs python3 + the pty module (same pattern as `pty_read_probe.py`); without that environment the test skips cleanly.


## 队长复核(新头 a5012fd,第 11 轮)

- 旧头(973ae7a3,2026-11-12 代)三红已点名并在新代全部消失:`issue2859_jobs_face_stopped_job_counts`(Rust tests/macOS 转绿)、`issue2875_input_procsub_child_runs_as_rubash_shell`(goldens 回到基线二名)——均为旧基底伪影,与 foreground-acquire 改动无涉。
- 新头 CI:自带钉 issue3321 **4/4 全绿**(census 内);census 72,新增仅 issue2883 read-prompt 抖动格;CLI 唯一红 = 已裁定 coproc flake;其余腿全绿。
- 本 PR 删除了什么:script_driver.rs 内旧的 `controlling_terminal_available()` 实现体(stderr-is-terminal + /dev/tty 开探版,约 40 行)由 foreground-acquire 尝试版整体替换;无其他删除。
- 与现尖(4b582664,#3935 的两个测试文件)零交集,免再 update-branch。合后 #3321 由 Fixes 自动关;A29 与 #3320 的 script_driver 面随之解闸(#3320 仍待 #3538/#3930)。
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