Repository navigation
fix(#1732): resolve dsh binary beyond bare PATH name; decode GBK subprocess output - #1734
Conversation
…rocess output A dsh profile bundle's bili proxy runs inside the dsh desktop app's process tree, whose PATH does not carry the npm/pnpm global bin dirs — bare 'dsh' failed with the cmd.exe 'not recognized' error every check cycle, freezing the profile copy (violates the #1196 live-update-path contract). - resolveDshBinary: BILI_DSH_BIN override -> PATH (win32 honors PATHEXT) -> known install locations a GUI host omits (node dir, %APPDATA%\npm, %LOCALAPPDATA%\pnpm, ~/.local/bin, /usr/local/bin, homebrew) -> bare 'dsh' fallback. Same pattern as launcher.resolveNodeRuntime (#1429). - decodeChildOutput: strict UTF-8 -> GBK -> lossy UTF-8, so Chinese-Windows cmd.exe stderr no longer lands in the log as mojibake; runners capture raw buffers. - refreshDshProfileBundles failure warn now carries the manual-fix command; ENOENT message mentions the probed locations.
📦 Built Package ArtifactBranch: Option A — Install this exact build (recommended)npm install -g billion-context@0.0.1753-pr.1734.8aeab23This exact version is immutable and reproducible. The rolling Option B — Download artifact
tar xzf billion-context-pr1734.tgz
npm install -g packageInstall instructions are refreshed on each push. |
placeholder |
更正:我几分钟前误发到本线程的 “placeholder” 评论是空草稿发错了地方(当时正在审 #1735 发布 PR),不含任何内容,请忽略。正式 review 已发到 #1735。 |
[bot] 🏷 Review complete — one test bug found & fixed directly on the PR branch ( ① Original issue (#1732) — direction verified. Root-cause analysis holds: ② Regression audit — existing behaviors inventoried:
③ Code review. Resolver logic sound: empty ④ Tests. The 9 new tests have teeth (resolver matrix, real-file wiring, GBK hex vector, degrade-without-throw). Minor non-blocking gap: the raw-Buffer→decode wiring inside ⑤ CI failure — root-caused, fixed on-branch. Both Windows runners failed exactly one test (3342 total, 1 fail each): the new spawn-wiring test asserted Ship order reminder (§5): this touches auto-update machinery — merge no-op v0.1.175 (PR #1735) first, observe a real 修复了 Windows GUI 宿主下 dsh profile 副本因裸 |
- defaultAsyncRun: execFile's default utf8 mode lossily stringified GBK bytes BEFORE decodeChildOutput ever saw them — and the async lane is exactly the auto-update refresh path, #1732's main victim. Capture raw buffers with encoding:"buffer" instead. - formatDshError: the Buffer branch used toString("utf8"), bypassing the decoder; raw stderr buffers (reachable now that the async runner throws with Buffer stderr) must go through decodeChildOutput. - decodeChildOutput: strict UTF-8 alone cannot distinguish GBK runs whose lead/trail bytes are also valid UTF-8 (GBK 系统 = cfb5cdb3 decodes as Greek "ϵς" with no U+FFFD in sight). Content heuristic: consecutive Greek/Coptic/Cyrillic plus a GBK re-read that yields CJK means the bytes were GBK all along. Verified on a zh-CN Windows VM against a stripped PATH: cmd.exe's 系统找不到指定的路径。 and dsh-forwarded "'pnpm' 不是内部或外部命令" now render readably in refresh failures (previously mojibake); resolveDshBinary probing was re-confirmed in the same runs.
Closes #1732
Problem
A dsh profile bundle's bili proxy (installed at
$DSH_HOME/profiles/<name>/node_modules/billion-context) runs inside the dsh desktop app's process tree. That process's PATH does not carry the npm/pnpm global bin dirs, so the periodic self-update's owner-channel refresh (dsh plugin --profile <name> add billion-context@<latest>) spawned a baredshthroughcmd.exe /d /s /cand failed every check cycle with'dsh' 不是内部或外部命令…— leaving the profile copy permanently frozen. That violates the #1196 Install-Lane & Update-Ownership Contract rule 2 ("every copy must have a LIVE update path … Permanent divergence is a bug"). Secondary symptom: the GBK error bytes landed mojibaked in the UTF-8 log file.Changes (
src/dsh-channel.ts+ tests only)resolveDshBinary(env, platform, existsImpl, execPath)(exported for tests) replaces the privatedshCommand. Resolution order:BILI_DSH_BINoverride — unchanged, used as-is;PATHEXTordering (default.COM;.EXE;.BAT;.CMD); returns the full path;launcher.resolveNodeRuntime([Bug] Electron 宿主(DSH 桌面版)下 resolveNodeRuntime 找不到 node:代理起不来、5 个工具全丢、会话被撑爆到模型拒答 #1429): the running node's own dir (npm's default global prefix),%APPDATA%\npm,%LOCALAPPDATA%\pnpm; on posix/usr/local/bin,/opt/homebrew/bin,/opt/local/bin,~/.local/bin;dshfallback when nothing is found — today's error path preserved.No
isDshProfileCopygate: probes only accept files that exist and PATH always wins, so this is strictly broader with no behavior risk for shell-launched setups.decodeChildOutput(buf)(exported for tests) — strict UTF-8 → GBK → lossy UTF-8. Both default runners now capture raw buffers instead ofencoding: "utf8", so Chinese-Windows cmd.exe/pnpm stderr decodes correctly into the log instead of mojibake. Pure ASCII and valid UTF-8 output decodes byte-identically to before.Actionable failure guidance: the per-profile refresh-failure warn now ends with the exact manual command (
dsh plugin --profile <name> add billion-context@<v>from a shell wheredshresolves, or pointBILI_DSH_BINat the executable); the ENOENT message mentions the probed locations.Behavior changes (old → new)
dsh(unlessBILI_DSH_BIN)existsSyncprobes perdsh plugininvocationencoding: "utf8")…failed: <detail>…failed: <detail> — manual fix: run … (or point BILI_DSH_BIN …)No config surface changes:
BILI_DSH_BINpre-existed and is untouched; no new env vars, fields, or CLI flags.Shipping note (§5 — load-bearing updater machinery)
This touches the auto-update's dsh channel (
src/dsh-channel.ts, imported bysrc/update.ts). Per AGENTS.md §5 it must ship after a no-op release validates the current upgrade path end-to-end — see the accompanying no-op release PR (v0.1.175, branch2026-09-30_release-v0.1.175). Ship order: merge the no-op release first, confirm a realauto-updated 0.1.174 → 0.1.175observation, then merge this PR and release it as v0.1.176.Pre-flight (local, branch head)
npm run typecheck— cleannpm test— 3342 tests, 0 fail (17 skipped by design), incl. 10 new: resolver matrix (override / PATHEXT ordering / GUI-minimal-PATH→%APPDATA%\npm / node-dir / %LOCALAPPDATA%\pnpm / posix fallbacks / bare-fallback), wiring test (resolved binary actually reaches the runner), GBK + UTF-8 decode vectorsnpm run build— success, dist-import-annotations OK