Skip to content

fix(wpm): interaction audit fixes - outdated receipt anchoring, install --json, help force semantics (#1156) - #1158

Merged
caomengxuan666 merged 2 commits into
mainfrom
ux/wpm-audit
Oct 10, 2026
Merged

caomengxuan666 merged 2 commits into
mainfrom
ux/wpm-audit

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Closes #1156

实测驱动的逐项处置表

# 疑点 实测结论 处置
1 uninstall 的 y/N 确认不读管道 stdin 证伪(本分支已修复)。工作树构建实测:echo y | wpm uninstall jq 正确确认并卸载;n/EOF 中止且不删文件。0095bab(已在 origin/main)改为 std::getline(std::cin, ...)。#1154 事故中的旧发布版二进制早于该提交 already-fixed + 回归测试钉死行为(管道 y / 管道 n / EOF 三例)
2a install --force 未在 help 的 install 说明中出现 属实。--help 的 install 行仅写 "install one or more packages",Options 段的 -f, --force 未说明可重装 fixed:help install 行补 "use --force to reinstall or overwrite" + 测试断言
2b 重装时被锁文件静默跳过仍报成功 证伪(现状已正确)。实测锁住 usr/bin/jq.exe(无 FILE_SHARE_DELETE 打开)后:install --force → exit 1 + wpm: failed to install ... being used by another process;uninstall -y → exit 1 + failed to remove,removed=0 failed=1。#1154 实测的"报成功但文件未变"根因是下载缓存键不含版本(疑点 3),非锁文件跳过 already-correct(补锁文件回归测试,install/uninstall 各一,断言非零退出)
3 缓存键不含版本 本 PR 不处置(修复进行中,关联 #1154 的 PR 负责),见 issue 备注 defer(归属 #1154)
4 outdated / index update / install 索引副本不一致窗口期 属实且比"窗口期"更严重。outdated 用本地索引版本 vs 远程索引版本:一旦 wpm index update,本地==远程,此后永久报 "all installed packages are up to date",即使磁盘上仍是旧版(receipt 里记录的实装版本为 1.0.0、远程 2.0.0 时仍报无更新,已实测复现) fixed:outdated 改以 install receipts(.wpm/installed/*.json,且校验 destinations 仍在磁盘)为已装版本来源,无 receipt 的旧式安装回退到本地索引;outdated 从此不依赖本地索引副本。+回归测试
5 automation 友好性:-y 覆盖、--json 缺失 -y:已生效——唯一交互提示是 uninstall 确认,-y/--yes 任意位置解析均跳过(实测 wpm -y uninstall jq 与 wpm uninstall jq -y 等价);GNU/apt 惯例上 -y 不应隐含 --force 重装,维持现状。--json:install 缺失(实测输出人读文本)、list 已有 fixed(分层交付第一批):install --json 输出单一 JSON payload(schema 1、results[]、failed,状态机 installed/already_installed/would_install/not_found/not_installable/preflight_failed/download_failed/error,errors[] 内联),全部人读进度走 stderr,下载进度条在 --json 下禁用;already_installed 按 apt 惯例 exit 0。附带 index update --json 输出 payload(且命令内自动刷新不再向调用方 stdout 泄漏第二个 JSON 文档)。+回归测试(含 stdout 纯净性断言)

实现说明

  • outdated:receipts 优先(receipt_install_records),本地索引回退仅覆盖无 receipt 的历史安装;比较基准从"本地索引副本"改为"磁盘实装版本",疑点 4 的不一致窗口整体消除。
  • install --json:install_package 增加 json_result 出参,全部退出路径经 finish() 记录结果;preflight_install_destinations 增加 messages 出参供 payload 的 errors[] 使用;download_artifact/extract_archive/copy_artifact_files/create_package_shims/create_package_aliases/cleanup_legacy_flat_artifacts/refresh_index_once/update_index 增加 json 路由参数。
  • wpm restore / install --from 走同一 install_packages 通道,自动获得 --json 支持。

测试

  • tests/winuxcmd-tests.exe --gtest_filter=wpm.*:50/50 通过(41 存量 + 9 新增,覆盖管道 y/n/EOF、-y 跳过提示、help force 文案、锁文件 install/uninstall 非零退出、outdated 在 index update 后的 receipt 锚定、install --json 精确 payload 与 stdout 纯净性、index update --json payload)。
  • --gtest_filter=winuxcmd.*:28/28 通过。
  • 端到端手工探针(file:// 索引夹具、锁句柄、管道):全部符合预期,过程见 PR 描述(构建于 VS18 + Ninja,-DBUILD_FFI=OFF,pcre2 复用主仓缓存)。

后续(不在本 PR)

Measured-driven audit of the five reported friction points, each reproduced
or refuted against a worktree build before fixing:

- outdated vs index update (fixed): installed versions now anchor on install
  receipts (.wpm/installed/*.json, destinations verified) instead of the
  local index copy. Comparing the local index against the freshly fetched
  remote index made 'wpm outdated' permanently claim 'all installed packages
  are up to date' after any 'wpm index update', even while old files were
  still on disk. Pre-receipt installs keep the index-version fallback.
- install --json (fixed): 'wpm install' now supports --json with one
  machine-readable payload on stdout (schema 1, results[] with statuses
  installed/already_installed/would_install/not_found/not_installable/
  preflight_failed/download_failed/error + errors[]), matching uninstall.
  All human progress (downloading, extracting, installing files, alias/shim
  notes, auto index refresh) routes to stderr in --json mode; the download
  progress bar is suppressed so WT_SESSION cannot pollute the stream.
  already_installed exits 0 per apt convention; failures exit non-zero.
- index update --json (fixed): emits {schema,status,source} on stdout, human
  line to stderr. Auto-refreshes inside other commands never leak a payload
  into the caller's stdout (update_index grows a json_payload flag).
- help: 'install' now documents its --force reinstall/overwrite semantics
  (the Options entry alone did not say reinstalling is possible).
- uninstall piped stdin / -y (already fixed on this branch, verified):
  0095bab's confirmation reads std::cin, so 'echo y | wpm uninstall x'
  confirms, 'n'/EOF abort without removal, and -y works in any position.
- locked destination files (already correct, verified): install --force and
  uninstall fail loudly with exit 1 and a 'failed to install/remove'
  message; nothing is silently skipped.

Regression tests: 9 new cases in tests/unit/wpm (piped y/n/EOF confirmation,
-y skip, help force wording, locked-file install/uninstall exit codes,
outdated-after-index-update receipt anchoring, install --json exact payload
purity, index update --json payload). wpm group: 50/50 pass.

Note: per AGENTS.md the new/changed i18n keys (command.wpm.custom_help
fallback text, command.wpm.error.download_failed_generic/copy_failed/
shim_failed/alias_failed) need a follow-up catalog sync in
unixwin/winuxcmd-i18n; English fallbacks land here first.

Closes #1156
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.

[ux] WPM 交互行为审计:反直觉点排查与修复(实测驱动)

1 participant