Skip to content

fix(plugins): add/rc audit P2 batch — honest hints, local-dir add, rc guards - #240

Merged
caomengxuan666 merged 1 commit into
masterfrom
fix/audit-p2-176
Oct 10, 2026
Merged

caomengxuan666 merged 1 commit into
masterfrom
fix/audit-p2-176

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Closes #176. 逐项处置(wt82-L08 P2 审计集合):

Fixed(本次修复,各配回归测试)

  1. add -h 报错形态错 → niu plugin add -h/--help 现在是 usage 请求,新增 verb 级 print_plugin_add_usage(含选项与后续步骤),不再报 "unknown plugin source option '-h'"。测试:plugin_add_h_is_a_usage_request。
  2. already-declared 提示对残条失效 → 残条(已声明未安装)场景改指 niu plugin sync --prune(wt83 [P1] 失败的 plugin add 留下无法移除的 spec 残条:每次启动永远打印 deferred 行,唯一出路是手编文件 #174 的既有出路);已安装场景保留 niu plugin source remove 提示。实现:sync::declared_entry_state(复用 record_for_entry 判安装态)。测试:already_declared_hint_matches_the_state。备注:残条本身(回滚/可清除)已由 wt83 [P1] 失败的 plugin add 留下无法移除的 spec 残条:每次启动永远打印 deferred 行,唯一出路是手编文件 #174([P2] add/rc 审计 P2 集合:错误信息误导、本地目录劫持、CRLF 全文件改写、插件动词不备份 rc、块内用户行静默丢弃 #176 的 P1 单)修复,本条修的是提示文案。
  3. 本地目录叫 oh-my-bash 被劫持到 GitHub origin → add 路径先做本地路径稳定化,已存在的本地路径不再走 catalog 解析;整个 add 离线成功本身即劫持已除的反证。测试:local_dir_named_like_a_catalog_id_is_not_hijacked。
  4. cwd 相对路径原样存进 spec → 本地路径 target 统一存词法规范化绝对路径(正斜杠,避免 Windows canonicalize 的 \\?\ 前缀),换目录后 sync 仍解析同一棵树。测试:relative_path_targets_are_stored_absolute。
  5. usage 漏 --url → niu plugin --help 与 add usage 均补 --url <git-url>。测试:plugin_usage_mentions_url_option。
  6. 托管块内用户行被静默丢弃 → 每次块重写时,块内不属于受管语法(theme/受管数组/loader 片段/DirectFiles 守卫行)且不在新 canonical 块中的行,迁移到块正下方(带迁移注释头)并 stderr 告警;受管行仍随 spec 增删。测试:user_lines_inside_a_managed_block_migrate_out(并验证 spec 删除的受管行不外迁、迁移后字节稳定)。禁用(remove)路径同样迁移用户行。
  7. CRLF 用户 rc 被整文件改写为 LF → 写入前检测整文件行尾,重写保持原行尾(CRLF stays CRLF),字节等价重写不再产生任何 diff。测试:crlf_rc_keeps_its_line_endings_through_block_writes。
  8. 标记近似行产生第二个无管理同 id 块 → 近似标记(缺尖括号等手改痕迹)识别为 span:重写时直接修复为精确受管块(告警),不再并排追加第二块;近似 begin 无 end 与精确 begin 无 end 同策略报错。测试:near_marker_block_is_repaired_not_duplicated。备注:缩进形态本就被 trim 匹配覆盖(现状核对:无问题)。
  9. 插件动词写 rc 从不备份、备份永不清理 → 所有插件动词经 write_managed_block/remove_managed_block 写 rc 前一律备份到 ~/.niubash/backups/.niubashrc.<stamp>.bak(与向导同目录同命名),写后裁剪保留最近 10 份(向导的旧备份同样被治理)。测试:plugin_verbs_backup_the_rc_and_prune_old_backups。

Already-fixed / 现状核对结论

测试

  • cargo test -p niubash-runtime --lib plugins::assets(16 通过,含 4 个新单测)
  • cargo test --test issue176_rc_audit(5 通过,新集成套件)
  • plugin_spec_sync / plugin_assets / plugin_sources / defaults_floor / theme_preview_channel 全绿。
  • plugins::distros 3 个 "offline" 用例与 smoke_1_3_0 d2_wizard 在干净 master 上同样失败(网络 reset / 交互 PTY 超时),与本 PR 无关。

cargo fmt 已过。未合并,等待 review。

… guards (closes #176)

Per-item disposition of the P2 audit set:

- add -h/--help is a usage request with its own verb usage (was
  'unknown plugin source option'); usage texts now document --url.
- A cwd directory named like a catalog id (oh-my-bash/) is adopted as a
  local tree: the add path no longer re-resolves an existing local path
  through the catalog to the official GitHub origin.
- Local path targets are stored cwd-independent in the spec (lexically
  normalized absolute, forward slashes) instead of the raw relative
  spelling that strands after a directory change.
- The already-declared refusal names a removal path that works for the
  state it names: a stranded declaration (declared, never installed)
  points at 'niu plugin sync --prune'; an installed source keeps the
  'niu plugin source remove' hint (declared_entry_state in sync).
- User lines hand-written inside a managed rc block are migrated out
  (below the block, under a marker comment) with a stderr warning on
  every rewrite; managed theme/array/loader lines are classified and
  dropped with the spec as before.
- A CRLF rc keeps CRLF through block rewrites (whole-file EOL
  detection; byte-identical rewrites no longer churn the file).
- Hand-edited near-marker blocks (missing bracket) are repaired into the
  exact managed form instead of gaining a second unmanaged same-id
  block; a near begin with no end is an error, like the exact case.
- Every plugin verb that rewrites the rc backs it up to
  ~/.niubash/backups first, and the backup set is pruned to the newest
  10 (the wizard era never cleaned up).

Tests: assets.rs unit tests (CRLF, migration, near-marker, backup
retention), tests/issue176_rc_audit.rs (add -h usage, --url doc, no
hijack, absolute targets, state-matched duplicate hints).
@caomengxuan666
caomengxuan666 merged commit 71141ea into master Oct 10, 2026
3 of 9 checks passed
@caomengxuan666
caomengxuan666 deleted the fix/audit-p2-176 branch October 10, 2026 03:21
caomengxuan666 added a commit that referenced this pull request Oct 10, 2026
…notes draft (#254)

- Version 1.3.4 -> 1.4.0 (workspace root + crates/niubash-runtime;
  Cargo.lock synced; internal niubash-runtime dep requirement aligned
  1.2.5 -> 1.4.0). The rubash engine requirement stays 1.3.4: it is
  semver-open (^1.3.4 admits the engine's 1.4.0), and the committed
  [patch] resolves it to the local ../rubash worktree, whose Cargo.toml
  still says 1.3.4 until the engine cuts its own release.
- CHANGELOG: the Unreleased section becomes [1.4.0] - 2026-10-10. Also
  repairs the committed merge damage from #243 (stray conflict marker
  and the #241 doctor-advice entry glued onto the carapace entry) and
  folds in the merged cycle: #235 #239 #246 #247 #250 #251 #252 #253
  plus a compact rubash 1.4.0 engine summary. #240's P2-batch content
  stays under [1.3.4] where the file already records it (no dup).
- docs/release-notes-1.4.0-draft.md: zh+en draft release notes
  (Added / Fixed / Performance), winuxcmd #1151/#1154-#1157 marked as
  in-flight for the coordinator, plus the local verification log:
  release build PASS (niu.exe 10.6 MB), MSIX packed unsigned with a
  placeholder identity (5.1 MB), wpm-source main carries all four
  preinstall packages, and cargo publish --dry-run chain findings
  (rubash -> niubash-runtime -> niubash, blocked on the engine's
  crates.io release).

No tag, no release workflow trigger, no in-flight PRs merged.
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.

[P2] add/rc 审计 P2 集合:错误信息误导、本地目录劫持、CRLF 全文件改写、插件动词不备份 rc、块内用户行静默丢弃

1 participant