Skip to content

Refs #2738 / Refs #2846: selective special-compspec query + drive-letter completion carve-out - #3145

Merged
caomengxuan666 merged 6 commits into
masterfrom
fix/C3-wave1
Nov 10, 2026
Merged

caomengxuan666 merged 6 commits into
masterfrom
fix/C3-wave1

Conversation

@caomengxuan666

@caomengxuan666 caomengxuan666 commented Nov 8, 2026 •

Copy link
Copy Markdown
Member

180 单令第一波 · 组 C3(两单同 PR,逐单钉分开提交)。UNVERIFIED-BY-CAPTAIN —— 队长复核未做;车道验证数字见 REPORT(随交付信回)。

Refs 行

Refs #2738
Refs #2846

CI 说明(先说清一红)

现头 CI 9 pass + 1 skipping,唯一红 = niubash builds against this tree:该 job 第一步 cmp rubash/docs/api-ledger.md niubash/docs/api-ledger.md 因本 PR 的账本新增行与 niubash 仓镜像副本未同步而 differ(byte 98300, line 1261——正是下方 §2.3 新行)。两副本在基底逐字节一致;把本 PR 的同一账本 diff 应用到 niubash 仓 docs/api-ledger.md 即恢复一致(账本镜像同步的既定跟进项,归队长排期)。其余全绿含 API ledger tripwire(286 符号齐全)、Rust tests(lib)、goldens、跨目标检查。

#2738 — 选择性特殊 compspec 查询(API 缺口)

根因:公开契约缺失。引擎内部 -D/-E/-I 三槽分开存储与解析(resolve_compspec;GNU pcomplete.c 的 DEFAULTCMD / EMPTYCMD / INITIALWORD 本就是三个独立槽),但 Session 面只有 has_compspec(command)——把命令自身注册与三槽 OR 在一起——宿主门无法只为某一类打开;且 -E 空行与 -I 首词正是没有命令名可问的两个位置。位置门 has_compspec_at 已由 #2856 落地,本单补选择性注册查询:

  • Session::has_special_compspec(kind) + 公开枚举 SpecialCompspecKind { Default, Empty, Initial }(src/api/capabilities.rs,经 rubash::api 导出),Executor 同名方法落 public_accessors.rs;纯注册查询,语义与 name 形式对齐,位置治理仍归 has_compspec_at。
  • 账本入账 +5 符号(item + 3 variant + method)+ §2.3 行(staged 计数 0,宿主接线在 niubash 侧 B5-11 后续)+ §4 行补记;scripts/check-api-ledger.py 全 286 符号通过。
  • 钉 tests/issue2738_special_compspec_query.rs(6 格:无注册全假、三类各只答本类、named 注册不漏入特殊类、多类独立)。

#2846 — Windows 盘符词被 COMP_WORDBREAKS 切断(引擎 carve-out)

根因:complete_line_candidates_with_dynamic_detailed 走 split_for_completion → tokenize_completion_region 按 COMP_WORDBREAKS 切词,默认集含 :(bashline.c:313),C:/... 在冒号处断开、只补冒号后片段、盘符前缀被丢(niubash #918 探针:宿主 token 视图不切、切分在引擎)。

修法:tokenize_completion_region 单点 carve-out——当前 token 恰为一个 ASCII 字母时,紧随的 : 归入词内。GNU 无盘符概念,此面无 GNU oracle,是引擎平台语义面(单内定性):只在词首两字节触发;多字母头之后、盘符冒号之后的冒号照旧断开。不改签名、不改 COMP_WORDBREAKS 绑定、不动宿主。

  • 钉 tests/issue2846_drive_letter_completion.rs(5 格:-F hook 视角的 $2/COMP_CWORD/COMP_WORDS 整词、-W 词表候选保盘符、文件名补全端到端保盘符、多字母头冒号仍断开的守卫格、命令位置 -I hook 整词)。

本 PR 删除了什么

无删除。净增:#2738 为纯新增公开面(2 方法 + 1 枚举 + 账本记录),既有 has_compspec 行为不变;#2846 为 tokenizer 内一处条件新增,无既有路径被移除或改道。合计 8 文件(src 5 + ledger 1 + tests 2)。

tokenize_completion_region split the completion word at every
COMP_WORDBREAKS character, so C:/... was cut at the colon and only
the post-colon fragment completed; the drive prefix was discarded
(niubash#918 probe). A colon that follows a single ASCII letter at
the start of a word now belongs to the word. GNU has no drive
letters (bashline.c:313 keeps ':' in the default break set), so
this is an engine platform-semantics carve-out: it fires only at a
word's first two bytes, and a colon anywhere else breaks as before.
…#2738)

Executor::has_compspec ORs the command's own registration and all
three special slots (-D/-E/-I) together, so a host gate cannot open
for exactly the class that governs a position - and the -E empty
line and -I initial word are the positions with no command name to
ask about. Session::has_special_compspec(kind) + SpecialCompspecKind
answer for one slot; GNU keeps the three in separate slots
(pcomplete.c DEFAULTCMD / EMPTYCMD / INITIALWORD). The position
gate stays has_compspec_at (rubash#2856). Ledger: +5 symbols
(item + 3 variants + method), staged count 0 ahead of the host
adoption.
…cwd (Refs #2846)

path_completion_candidates listed the word's directory part against
the process cwd: shell_directory_entries maps the shell path and
reads the directory, but a relative directory part (a plain sub/dir,
a bare word's '.', or a drive-shaped first component like C:) is
resolved by GNU's generator against the shell's one cwd
(lib/readline/complete.c:2587, opendir in
rl_filename_completion_function), and the session cwd is a state
field, not the process cwd. After a session cd the listing missed
and drive-relative words completed to []. Anchor the mapped
directory at the session cwd with the existing G-02 discipline
(anchor_at_session_cwd, already followed by the lookup and glob
walks); absolute directory parts pass through unchanged. No drive
special-casing: C: is an ordinary relative component on this
platform (complete.c:2523-2531 gates the drive reading to
MS-DOS/Win32).
@caomengxuan666
caomengxuan666 marked this pull request as ready for review November 10, 2026 05:09
@caomengxuan666
caomengxuan666 merged commit e1afd25 into master Nov 10, 2026
11 checks passed
caomengxuan666 added a commit that referenced this pull request Nov 10, 2026
Fixes #2794

## What

`RunClassification` grows an `expansion_error_discard` face: whether the run's terminal unit ended in an expansion-error DISCARD — a FATAL-class word-expansion error the executor adjudicated an interactive DISCARD at its raise point instead of a fatal FORCE_EOF jump. Until now that fate (status 1, `Flow::Completed`, no unwind, every classification flag false) was indistinguishable from an ordinary status-1 completion to a host reading only the classification.

## Mechanism

- GNU basis: the FATAL class takes `interactive_shell ? &expand_wdesc_error : &expand_wdesc_fatal` — `${var:?}` (subst.c:10416-10418), nounset unbound (subst.c:11032-11034), bad @-transform (subst.c:8949), arithmetic nounset (expr.c:1208-1216). The error branch is a DISCARD: the unit is dropped with status 1 and the reader lives (eval.c:111-128).
- The executor notes the verdict at the adjudication points themselves — every FATAL-class arm where `expansion_error_is_interactive_discard()` selects the DISCARD (15 arms across the simple-command pre-scan, heredoc finish, `raise_word_expansion_error`, the arithmetic-nounset gates, the bare-arithmetic fast entry, the assignment-only arithmetic consumer, pipeline element gates, and the `[[ ]]` operand gates plus its arithmetic-comparison nounset trap) — into a per-unit record that mirrors Q6 arm B's `unit_signal_discard`. No session-layer re-derivation. The arm census was completed at captain review by full enumeration of the predicate's call sites plus producer/consumer tracing of the `arithmetic_nounset_error` and `conditional_expansion_fatal` latches: three ruling paths the first pass missed (the bare-`(( ))` fast entry ruling on its own arm, the assignment-only command consuming the latch itself, and the `[[ ]]` arith-compare trap ruling at the trap rather than at its downstream conversion) now note at their own arms too.
- The grouped driver carries the record per group beside `terminal_discard` (same most-recent-group semantics, same skipped-group reset) into `GroupedRunClassification`; `Session::run`'s grouped route, `outcome_after_driver`, and `Session::take_classification` report it on `RunClassification`. The startup-file literals report `false` (a non-reader route, like their `signal_discard`).
- The fact can stand alongside `errexit_break`: the discard dropped the line; the verdict on its status ended the session.
- Boundary: the lesser expansion classes (bad substitution and kin) carry no interactive/fatal branch in GNU and never set the face — locked by a consumer boundary cell.

## Tests

- The fate matrix stays locked by `tests/issue2794_expansion_error_discard_classification.rs` (7 cells, unchanged): base and head both 7 passed / 0 failed.
- New consumer assertions in `src/api/consumer_tests.rs` ride the field the pin could not reference before it existed: grouped + line routes with survival and per-run clearing, the `-e` coexistence cell, the non-interactive fatal counter-cell, a nounset member cell, the plain-failure / lesser-class boundary cells, and the three census-completion cells — bare-`(( ))` arithmetic nounset (both routes), assignment-only arithmetic nounset, and `[[ ]]` arithmetic-comparison nounset.
- Lib bilateral failure name sets base vs head: equal (see verification notes in the lane report).

## Ledger

`docs/api-ledger.md`: a dated header addendum records the field, a follow-up addendum records the census completion of the noting-arm set, and the §2.3 `Session::take_classification` row's value list gains the expansion-error discard. `RunClassification` rides inside `RunOutcome`'s recorded entry and stays unlisted as its own §6 symbol, so no §6 entry is added and no census count moves; the new executor note/take pair is driver-internal plumbing of the same unrecorded kind as the `unit_signal_discard` pair.

**Merge gate:** the niubash copy of `docs/api-ledger.md` must be synced in the same batch before this merges (the #3145 / niubash#976 pattern), so the two copies stay byte-identical.

## 本 PR 删除了什么

无删除路径。纯新增:一个分类字段、一条 executor 单元记录及其注记/读取对、15 处裁定点注记、driver 与 session 的同位携带、consumer 断言与账本记录。唯一的删除计数是账本 §2.3 一行括注的原地扩写(+21/−1 中的 −1)。
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