Skip to content

fix: 终端工具扫描只认可执行条目 —— 手册页/文档/同名目录不再冒充命令(issue #31) - #32

Open
youyv wants to merge 1 commit into
KannaKuron:mainfrom
youyv:fix/31-scancommands-executable-extensions
Open

youyv wants to merge 1 commit into
KannaKuron:mainfrom
youyv:fix/31-scancommands-executable-extensions

Conversation

@youyv

@youyv youyv commented Oct 16, 2026

Copy link
Copy Markdown

按 #31 的评审口径实现,只做扩展名白名单这一步。

改动

  • src/toolchain.js:新增 EXEC_EXTS = {.exe,.cmd,.bat,.com},扩展名不在白名单的条目直接跳过;无扩展名照旧命中(/usr/bin/make、fzf 这类)。纯函数改动、零 io 变更 —— 没有给 io.readdir 加 stat/Dirent,无扩展名目录的区分按你的意见留作后续。
  • tests/smoke.mjs:新增「only executable extensions resolve」一例,锁三层(手册页/文档/目录不命中;无扩展名真可执行仍命中;just.1 排在 just.exe 前时首个可执行命中者路径正确,另覆盖 .EXE 大小写)+ 判定层联动断言(扫不到 ⇒ missing ⇒ isActionable 为真)。
  • CHANGELOG.md:新增 ## v0.40.2 — 2026-10-16 条目(fix)。

验证

  • npm test(Windows 10.0.26200 / Node 24.19.0):237 pass / 0 fail(基线 236 + 本用例 1)。
  • 新用例在未修复的源码上确实失败:actual: 'C:/pkg\just.1'、expected: 'C:/pkg\just.exe' —— 正是 issue 里手册页抢先命中的症状;修复后通过。这条用例不是「恒真」的。
  • 真机读数:Casey.Just 便携包目录里 just.1 与 just.exe 并存,字典序 .1 < .e(修复前已实测复现)。

两点说明

  1. 版本号:CHANGELOG 按下一个补丁版写成 v0.40.2,但没有动 package.json / dsh.plugin.json 的 version —— 发版节奏归你们;若打算并进 0.41.0,改个标题即可。
  2. 顺带发现(与本 PR 无关,未改):仓库 package-lock.json 里 5 个依赖的 resolved 指向 registry.npmmirror.com。npm 12 把这类 URL 规格视为 remote 并默认拒绝(EALLOWREMOTE,allow-remote = "none"),所以在这种 npm 上 npm ci 会直接失败。我本地只是把这 5 条临时改回 registry.npmjs.org(integrity 不变)才跑起套件,改动没有进提交(git status 只含上列三个文件)。CI 目前无恙(Node 22/24 自带的 npm 没有这道闸),但值得知道。

目录区分那一步(无扩展名目录 vs 无扩展名可执行文件)等你们定了 io 的形状,我可以接着做。

…on#31)

scanCommands stripped ANY extension, so an entry that merely shared a tool's
stem resolved as that tool. MEASURED: readdir sorts `just.1` (the man page)
before `just.exe` in winget's portable package directory, and the first hit
wins — the card's path column pointed at the man page.

The decision layer followed: classifyToolState() falls back to `hasCommand`
when winget does not own the package, so a machine that genuinely lacks the
command but happens to carry a same-named doc/man page/directory is reported
as `external` and never gets its install entry.

Gate the scan on an executable-extension whitelist (.exe/.cmd/.bat/.com) while
keeping extension-less entries resolving: Git for Windows ships its own
executables that way (/usr/bin/make, fzf).

Directory discrimination is deliberately left for a follow-up — it needs a
stat/Dirent capability on io.readdir and would touch callers, so this stays a
pure-function change with zero io contract drift.

npm test: 237 pass / 0 fail (Windows 10.0.26200, Node 24.19.0). The new smoke
case fails on the unfixed source (actual 'C:/pkg\\just.1', expected
'C:/pkg\\just.exe').
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