Skip to content

fix(repl): terminate the gather on a stray close inside an open group - #484

Merged
caomengxuan666 merged 2 commits into
masterfrom
fix/482
Oct 21, 2026
Merged

caomengxuan666 merged 2 commits into
masterfrom
fix/482

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Summary

Fixes #482. A stray ) inside an OPEN multi-line grouped command made the input gather unbounded: is_repl_input_complete kept waiting for the unclosed { so the REPL (reedline, --noediting, piped -i, stdin gather) sat in PS2 forever with no diagnostic. GNU abandons the group at the token: syntax error near unexpected token ')', rc 2, back to PS1. The #431 stray-close guard only audits COMPLETE groups — this input never became one.

Host half:

  • scan_repl_input emits ;;/;&/;;;& as single operators.
  • is_repl_input_complete tracks an open case by phase (operand → in → pattern → body): ) and ;;-family that can close nothing are judged complete so the armed engine parse prints GNU's diagnostic rather than PS2-wedging; a)/(a|b)/;; inside case remain legal so real multi-line cases gather.
  • Foreign keyword closers (fi/done/esac/}) mismatched under a keyword opener end the gather the same way; under (/case frames they stay legal words (arithmetic text, patterns).

Engine half: unixwin/rubash#955 (lands first — the group gather stops at the stray token and unclosed {/( EOF paths report the mismatched closer at its line). Local Cargo.toml patch pointed at the fixed checkout for verification; lockfile refreshed.

Refs #431, #368, #367.

Test plan

  • tests/issue482_stray_close_gather.rs: 8 cases — ticket repro via stdin/-s/-i/-c (GNU-verbatim line 2: syntax error near unexpected token ')' + echo, rc 2), interactive PS1 recovery (rc=2-recovered runs), mid-command and case-body strays, 10-form normal-group battery — all green
  • cargo test --test issue431_stray_close_paren 8/8, cargo test -p niubash-runtime --lib repl:: 68/68
  • GNU 5.2.37 (Git Bash) script-file probes byte-match niu output for -i, stdin, -s, -c (WSL forbidden by task discipline)
  • cargo fmt --check clean; no full suite run (task scope: targeted only)

Dependency note

Merge order: unixwin/rubash#955 first; this PR's Cargo.lock then pins the merged rubash commit. Left open for human review per task discipline.

… (niubash#482)

`{ echo c` opens a brace group; the next line `)` closes nothing — GNU
reports `syntax error near unexpected token `)'' at that line, abandons
the whole group, rc 2, and the session returns to PS1. Niubash's input
completeness scanner had no such terminal condition: the open `{` kept
the buffer "incomplete" forever, so the REPL (reedline, --noediting and
piped `-i` alike) wedged in PS2 with no diagnostic. The niubash#431
stray-close guard only audits COMPLETE groups, which this input never
became.

- scan_repl_input now emits `;;`/`;&`/`;;;&` as single operators (they
  are case-clause terminators, not two `;`).
- is_repl_input_complete tracks an open `case` by phase (operand / in /
  pattern / body): `)` and `;;`-family that cannot close anything are
  judged complete so the armed engine parse reports GNU's diagnostic
  instead of gathering forever; `a)`/`(a|b)`/`;;` inside case stay
  legal so real multi-line cases still gather.
- Foreign keyword closers (`fi`/`done`/`esac`/`}`) mismatched under a
  keyword opener end the gather the same way — GNU's read-time verdict;
  under `(`/case frames they remain legal words (arithmetic, patterns).
- Engine side (unixwin/rubash#955): the group gather stops at the stray
  token and the unclosed-`{`/`(` EOF paths report the mismatched closer
  at its line instead of `unexpected end of file`.

GNU 5.2.37 script-file probes (WSL forbidden by task): `niu -i`, stdin,
`-s` and `-c` transcripts all byte-match GNU for the ticket family.

Tests: tests/issue482_stray_close_gather.rs — 8 cases covering the
ticket repro, PS1 recovery + rc=2, mid-command/case-body strays and a
normal-group battery; `cargo test -p niubash-runtime --lib repl::` 68/68.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@caomengxuan666

Copy link
Copy Markdown
Member Author

Review verdict: hold — CI red on a one-line lockfile defect; semantics verified green locally (read-only review, left for author re-push)

The blocker is mechanical and precisely root-caused. All 8 failed jobs die at cargo build --locked with cannot update the lock file ... because --locked was passed — reproduced deterministically on this machine with the PR tree against a current-rubash sibling. The PR's Cargo.lock drops the single "sha2", line from the rubash package's dependency list. Cause: the lockfile was refreshed against the rubash fix/482 checkout, which branched at a83a09d3 — before rubash#939 (3cd3cfa7) added sha2 to rubash's Cargo.toml. niubash CI clones rubash master as the [patch] sibling, and master's manifest declares sha2, so --locked refuses. Verified locally: re-adding that one line makes cargo metadata --locked pass; nothing else in the lockfile drifts. Fix: re-add "sha2", to the rubash entry in Cargo.lock (or refresh the lockfile against current rubash master) and re-push — no code change needed.

Everything else was verified green locally (PR tree + rubash@95700a5b, the now-merged engine half, as the [patch] sibling):

  • issue482_stray_close_gather 8/8, issue431_stray_close_paren 8/8, niubash-runtime --lib repl:: 68/68, repl_command 7/7, issue365_alias_suppression_multiline 11/11, cargo fmt --check clean.
  • Combined -i probe prints exactly one niu: line 2: syntax error near unexpected token ')' then recovers to PS1 (rc=2-recovered runs) — matches GNU (Git Bash 5.2.37) piped--i byte-shape; no double diagnostic, no double termination with the engine half.
  • Normal-group battery (10 forms incl. if true; then/fi, case (a|b), a=(1 2\n), $(), for ((;;))) green; empty case x in esac matches GNU on both faces.
  • Red baseline on niubash master: 6/8 issue482 tests fail (diagnostic + wedge asserts), confirming discriminative power; with the merged engine the failure set shrinks to exactly the 2 host-only faces (mid_command, case_body) — the halves are complementary, this PR is the required half for exactly those.

Merge order note: engine half landed first as unixwin/rubash#955 (95700a5b), as planned in the PR description. Once the lockfile line is fixed and CI goes green, this is ready to merge on sight.

Same one-line fix as 9f4621a on master: rubash master gained a sha2
dependency (#939 provenance work); this branch's lock was refreshed
against a pre-sha2 checkout. Unblocks the 8 --locked CI jobs.
@caomengxuan666
caomengxuan666 merged commit 8dd8407 into master Oct 21, 2026
8 of 9 checks passed
caomengxuan666 added a commit that referenced this pull request Oct 21, 2026
… parallel batch) (#485)

## 终审:通过,合并

Cargo.lock hunk 去除后的返工验收四项全过(head `273841c7`):

1. **diff 只剩 logo.rs** — `master...head` 仅 `crates/niubash-runtime/src/logo.rs`(6 处 `chunks_exact(N)` → `as_chunks::<N>().0.iter()`,机械改写、余量丢弃语义与 `chunks_exact` 一致);返工 commit 本身单文件。`Cargo.lock` 与 master(`8dd8407`)`cmp` 逐字节一致。
2. **chunks_exact_to_as_chunks = 0** — `cargo clippy -p niubash-runtime --all-targets`,rustc/clippy 1.99.0(与口径一致):该 lint 0 报。
3. **其余类别零变化** — 与 master 同命令全类别 tally 逐行 diff,唯一差异即 `chunks_exact_to_as_chunks` 1→0;`needless_borrow`(exact)0、`cloned_ref_to_slice_refs` 0 保持。
4. **runtime 测试绿** — `cargo test -p niubash-runtime --lib --locked`:567 passed / 0 failed。

CI:`build-and-test` 红点为 `console_window_gate` 已知 flake(`detached_builtin_only_session_allocates_zero_conhosts`,tests/console_window_gate.rs:382),其余单测面在该 job 内全 ok;cross-check ×2、cross-target ×4、smoke 全 pass —— 按容忍口径放行。另注:base 落后 master(#484 已并),但本 PR diff 与之零交集,MERGEABLE。
@caomengxuan666
caomengxuan666 deleted the fix/482 branch October 21, 2026 08:16
caomengxuan666 added a commit that referenced this pull request Oct 22, 2026
* docs(skill): refresh agent skill bundle for the 1.4.3 surface

The corpus transcript predated the GNU invocation face and the verbatim
handoff, and the prose still described the retired oh-my-niu stack
(niubash#145) and the managed-block rc era (niubash#359).

- corpus: recapture `niu --help` (GNU long/short option face, verbatim
  handoff spellings --encoded-command/-EncodedCommand/--ec + v1:,
  --cwd-state, --install-wt-shortcuts, plugin migrate-rc, skill
  install|status, portal lines, primary-only rc wording)
- SKILL.md: 83/83 suite ledger (2026-10-12 re-run), argv[0] hardlink
  faces, generated-loader startup (before rc, NIU_PLUGIN_LOADER=off,
  migrate-rc), NIU_SHELL+SHELL exports, behavior notes for the gather
  wedge / bare-drive / negative-cache / unset-inherited / marker-zone /
  dolbrace / ordered-fd / CJK-readline fixes, verbatim handoff for hosts
  that cannot quote
- references: prompt-plugins.md rewritten for the spec+lockfile+loader
  model; paths.md gains bare drive designators; wpm.md notes same-session
  visibility of fresh installs; quickref.md gains the host-level verbs
- generate-skill.py: capability snapshot names `config`, the verbatim
  handoff, and `migrate-rc`
- check-rename-clean.baseline regenerated: drops the retired winuxshrc-
  migration help line, absorbs docs/src residue already on master, and
  records the intentional WINUXSH_SHELL mention in SKILL.md

Refs niubash#474 #477 #481 #482 #483 #484 #490 #943 #948 #952 niubash#359
Refs rubash#940 #947 #951 #952 #953 #955 #957 #976 #977 #979

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* docs(skill): correct SHELL export claim — filled only when unset

NIU_SHELL is exported unconditionally, but SHELL is backfilled with the
niu.exe path only when the host left it unset (shell.rs shell_was_missing
gate); a parent-supplied SHELL passes through. Aligns the NIU_SHELL
paragraph with the actual behavior per review on #498.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>

---------

Co-authored-by: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
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.

[P1][reader] stray ")" inside an open multi-line group wedges the interactive REPL in PS2 with no diagnostic (GNU 5.3 recovers)

1 participant